@@ -356,9 +356,62 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
356356 return fmt .Errorf (tr ("loading boards: %s" ), err )
357357 }
358358
359+ if ! platform .PluggableDiscoveryAware {
360+ convertLegacyPlatformToPluggableDiscovery (platform )
361+ }
359362 return nil
360363}
361364
365+ func convertLegacyPlatformToPluggableDiscovery (platform * cores.PlatformRelease ) {
366+ toolsProps := platform .Properties .SubTree ("tools" ).FirstLevelOf ()
367+ for toolName , toolProps := range toolsProps {
368+ if ! toolProps .ContainsKey ("upload.network_pattern" ) {
369+ continue
370+ }
371+
372+ // Convert network_pattern configuration to pluggable discovery
373+ convertedToolName := toolName + "__pluggable_network"
374+ convertedProps := convertLegacyNetworkPatternToPluggableDiscovery (toolProps , convertedToolName )
375+
376+ // Merge the converted properties in the root configuration
377+ platform .Properties .Merge (convertedProps )
378+
379+ // Add the network upload to the boards using the old method
380+ for _ , board := range platform .Boards {
381+ oldUploadTool := board .Properties .Get ("upload.tool" )
382+ if oldUploadTool == toolName && ! board .Properties .ContainsKey ("upload.tool.network" ) {
383+ board .Properties .Set ("upload.tool.network" , convertedToolName )
384+ // fmt.Printf("ADDED: %s.upload.tool.network=%s\n", board, convertedToolName)
385+ }
386+ }
387+ }
388+ }
389+
390+ func convertLegacyNetworkPatternToPluggableDiscovery (props * properties.Map , newToolName string ) * properties.Map {
391+ pattern , ok := props .GetOk ("upload.network_pattern" )
392+ if ! ok {
393+ return nil
394+ }
395+ props .Remove ("upload.network_pattern" )
396+ pattern = strings .ReplaceAll (pattern , "{serial.port}" , "{upload.port.address}" )
397+ pattern = strings .ReplaceAll (pattern , "{network.port}" , "{upload.port.properties.port}" )
398+ if strings .Contains (pattern , "{network.password}" ) {
399+ props .Set ("upload.field.password" , "Password" )
400+ props .Set ("upload.field.password.secret" , "true" )
401+ pattern = strings .ReplaceAll (pattern , "{network.password}" , "{upload.field.password}" )
402+ }
403+ props .Set ("upload.pattern" , pattern )
404+
405+ prefix := "tools." + newToolName + "."
406+ res := properties .NewMap ()
407+ for _ , k := range props .Keys () {
408+ v := props .Get (k )
409+ res .Set (prefix + k , v )
410+ // fmt.Println("ADDED:", prefix+k+"="+v)
411+ }
412+ return res
413+ }
414+
362415func (pm * PackageManager ) loadProgrammer (programmerProperties * properties.Map ) * cores.Programmer {
363416 return & cores.Programmer {
364417 Name : programmerProperties .Get ("name" ),
0 commit comments