From 1bba5f5d7bcb8bcb587b2c612d1f89b56f7f8ebd Mon Sep 17 00:00:00 2001 From: Kenneth Bell Date: Fri, 14 Apr 2023 21:36:29 +0100 Subject: [PATCH] targets: make msd-volume-name an array --- compileopts/target.go | 2 +- main.go | 91 +++++++++++++++------------- targets/circuitplay-bluefruit.json | 2 +- targets/circuitplay-express.json | 2 +- targets/clue-alpha.json | 2 +- targets/feather-m0-express.json | 2 +- targets/feather-m0.json | 2 +- targets/feather-m4-can.json | 2 +- targets/feather-m4.json | 2 +- targets/feather-nrf52840-sense.json | 2 +- targets/feather-nrf52840.json | 2 +- targets/grandcentral-m4.json | 2 +- targets/hifive1b.json | 2 +- targets/itsybitsy-m0.json | 2 +- targets/itsybitsy-m4.json | 2 +- targets/itsybitsy-nrf52840.json | 2 +- targets/matrixportal-m4.json | 2 +- targets/mdbt50qrx-uf2.json | 2 +- targets/metro-m4-airlift.json | 2 +- targets/microbit-v2.json | 2 +- targets/microbit.json | 2 +- targets/nano-33-ble-s140v6-uf2.json | 2 +- targets/nano-33-ble-s140v7-uf2.json | 2 +- targets/nicenano.json | 2 +- targets/nrf52840-mdk-usb-dongle.json | 2 +- targets/pca10056.json | 2 +- targets/pybadge.json | 2 +- targets/pygamer.json | 2 +- targets/pyportal.json | 2 +- targets/qtpy.json | 2 +- targets/reelboard.json | 2 +- targets/rp2040.json | 2 +- targets/trinket-m0.json | 2 +- targets/wioterminal.json | 2 +- targets/xiao-ble.json | 2 +- targets/xiao.json | 2 +- 36 files changed, 85 insertions(+), 76 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go index 30573a86..40a1d445 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -50,7 +50,7 @@ type TargetSpec struct { PortReset string `json:"flash-1200-bps-reset"` SerialPort []string `json:"serial-port"` // serial port IDs in the form "vid:pid" FlashMethod string `json:"flash-method"` - FlashVolume string `json:"msd-volume-name"` + FlashVolume []string `json:"msd-volume-name"` FlashFilename string `json:"msd-firmware-name"` UF2FamilyID string `json:"uf2-family-id"` BinaryFormat string `json:"binary-format"` diff --git a/main.go b/main.go index 7a474f16..3b3b1a30 100644 --- a/main.go +++ b/main.go @@ -945,28 +945,29 @@ func touchSerialPortAt1200bps(port string) (err error) { return fmt.Errorf("opening port: %s", err) } -func flashUF2UsingMSD(volume, tmppath string, options *compileopts.Options) error { +func flashUF2UsingMSD(volumes []string, tmppath string, options *compileopts.Options) error { // find standard UF2 info path - var infoPath string - switch runtime.GOOS { - case "linux", "freebsd": - fi, err := os.Stat("/run/media") - if err != nil || !fi.IsDir() { - infoPath = "/media/*/" + volume + "/INFO_UF2.TXT" - } else { - infoPath = "/run/media/*/" + volume + "/INFO_UF2.TXT" - } - case "darwin": - infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT" - case "windows": - path, err := windowsFindUSBDrive(volume, options) - if err != nil { - return err + infoPaths := make([]string, 0, len(volumes)) + for _, volume := range volumes { + switch runtime.GOOS { + case "linux", "freebsd": + fi, err := os.Stat("/run/media") + if err != nil || !fi.IsDir() { + infoPaths = append(infoPaths, "/media/*/"+volume+"/INFO_UF2.TXT") + } else { + infoPaths = append(infoPaths, "/run/media/*/"+volume+"/INFO_UF2.TXT") + } + case "darwin": + infoPaths = append(infoPaths, "/Volumes/"+volume+"/INFO_UF2.TXT") + case "windows": + path, err := windowsFindUSBDrive(volume, options) + if err == nil { + infoPaths = append(infoPaths, path+"/INFO_UF2.TXT") + } } - infoPath = path + "/INFO_UF2.TXT" } - d, err := locateDevice(volume, infoPath, options.Timeout) + d, err := locateDevice(volumes, infoPaths, options.Timeout) if err != nil { return err } @@ -974,28 +975,29 @@ func flashUF2UsingMSD(volume, tmppath string, options *compileopts.Options) erro return moveFile(tmppath, filepath.Dir(d)+"/flash.uf2") } -func flashHexUsingMSD(volume, tmppath string, options *compileopts.Options) error { +func flashHexUsingMSD(volumes []string, tmppath string, options *compileopts.Options) error { // find expected volume path - var destPath string - switch runtime.GOOS { - case "linux", "freebsd": - fi, err := os.Stat("/run/media") - if err != nil || !fi.IsDir() { - destPath = "/media/*/" + volume - } else { - destPath = "/run/media/*/" + volume - } - case "darwin": - destPath = "/Volumes/" + volume - case "windows": - path, err := windowsFindUSBDrive(volume, options) - if err != nil { - return err + destPaths := make([]string, 0, len(volumes)) + for _, volume := range volumes { + switch runtime.GOOS { + case "linux", "freebsd": + fi, err := os.Stat("/run/media") + if err != nil || !fi.IsDir() { + destPaths = append(destPaths, "/media/*/"+volume) + } else { + destPaths = append(destPaths, "/run/media/*/"+volume) + } + case "darwin": + destPaths = append(destPaths, "/Volumes/"+volume) + case "windows": + path, err := windowsFindUSBDrive(volume, options) + if err == nil { + destPaths = append(destPaths, path+"/") + } } - destPath = path + "/" } - d, err := locateDevice(volume, destPath, options.Timeout) + d, err := locateDevice(volumes, destPaths, options.Timeout) if err != nil { return err } @@ -1003,21 +1005,28 @@ func flashHexUsingMSD(volume, tmppath string, options *compileopts.Options) erro return moveFile(tmppath, d+"/flash.hex") } -func locateDevice(volume, path string, timeout time.Duration) (string, error) { +func locateDevice(volumes, paths []string, timeout time.Duration) (string, error) { var d []string var err error for start := time.Now(); time.Since(start) < timeout; { - d, err = filepath.Glob(path) - if err != nil { - return "", err + for _, path := range paths { + d, err = filepath.Glob(path) + if err != nil { + return "", err + } + if d != nil { + break + } } + if d != nil { break } + time.Sleep(500 * time.Millisecond) } if d == nil { - return "", errors.New("unable to locate device: " + volume) + return "", errors.New("unable to locate any volume: [" + strings.Join(volumes, ",") + "]") } return d[0], nil } diff --git a/targets/circuitplay-bluefruit.json b/targets/circuitplay-bluefruit.json index 1f37955a..16d3013b 100644 --- a/targets/circuitplay-bluefruit.json +++ b/targets/circuitplay-bluefruit.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["circuitplay_bluefruit"], "serial-port": ["239a:8045"], - "msd-volume-name": "CPLAYBTBOOT" + "msd-volume-name": ["CPLAYBTBOOT"] } diff --git a/targets/circuitplay-express.json b/targets/circuitplay-express.json index e503151b..7355eb58 100644 --- a/targets/circuitplay-express.json +++ b/targets/circuitplay-express.json @@ -4,6 +4,6 @@ "flash-1200-bps-reset": "true", "flash-method": "msd", "serial-port": ["239a:8018"], - "msd-volume-name": "CPLAYBOOT", + "msd-volume-name": ["CPLAYBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/clue-alpha.json b/targets/clue-alpha.json index 66fe7455..3a559219 100644 --- a/targets/clue-alpha.json +++ b/targets/clue-alpha.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["clue_alpha"], "serial-port": ["239a:8072", "239a:8071"], - "msd-volume-name": "CLUEBOOT" + "msd-volume-name": ["CLUEBOOT"] } diff --git a/targets/feather-m0-express.json b/targets/feather-m0-express.json index edfd9792..5f5214e1 100644 --- a/targets/feather-m0-express.json +++ b/targets/feather-m0-express.json @@ -5,6 +5,6 @@ "serial-port": ["239a:801b"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "FEATHERBOOT", + "msd-volume-name": ["FEATHERBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/feather-m0.json b/targets/feather-m0.json index 2d50c5bd..fa965db6 100644 --- a/targets/feather-m0.json +++ b/targets/feather-m0.json @@ -5,6 +5,6 @@ "serial-port": ["239a:801b", "239a:800b"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "FEATHERBOOT", + "msd-volume-name": ["FEATHERBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/feather-m4-can.json b/targets/feather-m4-can.json index 7eac4d8e..91ede189 100644 --- a/targets/feather-m4-can.json +++ b/targets/feather-m4-can.json @@ -5,6 +5,6 @@ "serial-port": ["239a:80cd"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "FTHRCANBOOT", + "msd-volume-name": ["FTHRCANBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/feather-m4.json b/targets/feather-m4.json index faffd0de..66eac03d 100644 --- a/targets/feather-m4.json +++ b/targets/feather-m4.json @@ -5,6 +5,6 @@ "serial-port": ["239a:8022"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "FEATHERBOOT", + "msd-volume-name": ["FEATHERBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/feather-nrf52840-sense.json b/targets/feather-nrf52840-sense.json index 1d182c54..8a4e862a 100644 --- a/targets/feather-nrf52840-sense.json +++ b/targets/feather-nrf52840-sense.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["feather_nrf52840_sense"], "serial-port": ["239a:8087", "239a:8088"], - "msd-volume-name": "FTHRSNSBOOT" + "msd-volume-name": ["FTHRSNSBOOT"] } diff --git a/targets/feather-nrf52840.json b/targets/feather-nrf52840.json index ce932513..bd4c488d 100644 --- a/targets/feather-nrf52840.json +++ b/targets/feather-nrf52840.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["feather_nrf52840"], "serial-port": ["239a:8029", "239a:802a"], - "msd-volume-name": "FTHR840BOOT" + "msd-volume-name": ["FTHR840BOOT"] } diff --git a/targets/grandcentral-m4.json b/targets/grandcentral-m4.json index 243ff0a9..c1413515 100644 --- a/targets/grandcentral-m4.json +++ b/targets/grandcentral-m4.json @@ -5,7 +5,7 @@ "serial-port": ["239a:8031"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "GCM4BOOT", + "msd-volume-name": ["GCM4BOOT"], "msd-firmware-name": "firmware.uf2", "openocd-interface": "jlink" } diff --git a/targets/hifive1b.json b/targets/hifive1b.json index 1084531b..6f0ec6c2 100644 --- a/targets/hifive1b.json +++ b/targets/hifive1b.json @@ -4,7 +4,7 @@ "serial": "uart", "linkerscript": "targets/hifive1b.ld", "flash-method": "msd", - "msd-volume-name": "HiFive", + "msd-volume-name": ["HiFive"], "msd-firmware-name": "firmware.hex", "jlink-device": "fe310" } diff --git a/targets/itsybitsy-m0.json b/targets/itsybitsy-m0.json index 59de6651..d8b4d5d4 100644 --- a/targets/itsybitsy-m0.json +++ b/targets/itsybitsy-m0.json @@ -5,6 +5,6 @@ "serial-port": ["239a:800f", "239a:8012"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "ITSYBOOT", + "msd-volume-name": ["ITSYBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/itsybitsy-m4.json b/targets/itsybitsy-m4.json index 527d3fd7..0134e2f3 100644 --- a/targets/itsybitsy-m4.json +++ b/targets/itsybitsy-m4.json @@ -5,6 +5,6 @@ "flash-1200-bps-reset": "true", "flash-method": "msd", "serial-port": ["239a:802b"], - "msd-volume-name": "ITSYM4BOOT", + "msd-volume-name": ["ITSYM4BOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/itsybitsy-nrf52840.json b/targets/itsybitsy-nrf52840.json index a38d9b83..d294ae5b 100644 --- a/targets/itsybitsy-nrf52840.json +++ b/targets/itsybitsy-nrf52840.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["itsybitsy_nrf52840"], "serial-port": ["239A:8052", "239A:8051"], - "msd-volume-name": "ITSY840BOOT" + "msd-volume-name": ["ITSY840BOOT"] } diff --git a/targets/matrixportal-m4.json b/targets/matrixportal-m4.json index 9d38d602..7a7156f0 100644 --- a/targets/matrixportal-m4.json +++ b/targets/matrixportal-m4.json @@ -5,7 +5,7 @@ "serial-port": ["239a:80c9", "239a:80ca"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "MATRIXBOOT", + "msd-volume-name": ["MATRIXBOOT"], "msd-firmware-name": "firmware.uf2", "openocd-transport": "swd", "openocd-interface": "jlink", diff --git a/targets/mdbt50qrx-uf2.json b/targets/mdbt50qrx-uf2.json index 7e28df54..17a29b33 100644 --- a/targets/mdbt50qrx-uf2.json +++ b/targets/mdbt50qrx-uf2.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["mdbt50qrx"], "serial-port": ["239a:810b", "239a:810c"], - "msd-volume-name": "MDBT50QBOOT" + "msd-volume-name": ["MDBT50QBOOT"] } diff --git a/targets/metro-m4-airlift.json b/targets/metro-m4-airlift.json index 644a4642..4bc29f9d 100644 --- a/targets/metro-m4-airlift.json +++ b/targets/metro-m4-airlift.json @@ -5,6 +5,6 @@ "serial-port": ["239A:8037"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "METROM4BOOT", + "msd-volume-name": ["METROM4BOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/microbit-v2.json b/targets/microbit-v2.json index c8c7461c..6cb78b90 100644 --- a/targets/microbit-v2.json +++ b/targets/microbit-v2.json @@ -4,6 +4,6 @@ "serial": "uart", "flash-method": "msd", "openocd-interface": "cmsis-dap", - "msd-volume-name": "MICROBIT", + "msd-volume-name": ["MICROBIT"], "msd-firmware-name": "firmware.hex" } diff --git a/targets/microbit.json b/targets/microbit.json index a890100d..2478cf5c 100644 --- a/targets/microbit.json +++ b/targets/microbit.json @@ -4,6 +4,6 @@ "serial": "uart", "flash-method": "msd", "openocd-interface": "cmsis-dap", - "msd-volume-name": "MICROBIT", + "msd-volume-name": ["MICROBIT"], "msd-firmware-name": "firmware.hex" } diff --git a/targets/nano-33-ble-s140v6-uf2.json b/targets/nano-33-ble-s140v6-uf2.json index 218a5cd9..9dfc9b80 100644 --- a/targets/nano-33-ble-s140v6-uf2.json +++ b/targets/nano-33-ble-s140v6-uf2.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["nano_33_ble"], "serial-port": ["239a:8063", "239a:0063"], - "msd-volume-name": "NANO33BOOT" + "msd-volume-name": ["NANO33BOOT"] } diff --git a/targets/nano-33-ble-s140v7-uf2.json b/targets/nano-33-ble-s140v7-uf2.json index 7095a876..4c95c330 100644 --- a/targets/nano-33-ble-s140v7-uf2.json +++ b/targets/nano-33-ble-s140v7-uf2.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v7-uf2"], "build-tags": ["nano_33_ble"], "serial-port": ["239a:8063", "239a:0063"], - "msd-volume-name": "NANO33BOOT" + "msd-volume-name": ["NANO33BOOT"] } diff --git a/targets/nicenano.json b/targets/nicenano.json index 210bfae7..f775ab6d 100644 --- a/targets/nicenano.json +++ b/targets/nicenano.json @@ -1,5 +1,5 @@ { "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["nicenano"], - "msd-volume-name": "NICENANO" + "msd-volume-name": ["NICENANO"] } diff --git a/targets/nrf52840-mdk-usb-dongle.json b/targets/nrf52840-mdk-usb-dongle.json index 6d84c56f..5f34a243 100644 --- a/targets/nrf52840-mdk-usb-dongle.json +++ b/targets/nrf52840-mdk-usb-dongle.json @@ -1,5 +1,5 @@ { "inherits": ["nrf52840", "nrf52840-s140v6-uf2"], "build-tags": ["nrf52840_mdk_usb_dongle"], - "msd-volume-name": "MDK-DONGLE" + "msd-volume-name": ["MDK-DONGLE"] } diff --git a/targets/pca10056.json b/targets/pca10056.json index b604624c..de660b44 100644 --- a/targets/pca10056.json +++ b/targets/pca10056.json @@ -4,7 +4,7 @@ "serial": "uart", "flash-method": "command", "flash-command": "nrfjprog -f nrf52 --sectorerase --program {hex} --reset", - "msd-volume-name": "JLINK", + "msd-volume-name": ["JLINK"], "msd-firmware-name": "firmware.hex", "openocd-interface": "jlink", "openocd-transport": "swd" diff --git a/targets/pybadge.json b/targets/pybadge.json index c80b3e3a..232a1bab 100644 --- a/targets/pybadge.json +++ b/targets/pybadge.json @@ -5,6 +5,6 @@ "flash-1200-bps-reset": "true", "flash-method": "msd", "serial-port": ["239a:8033"], - "msd-volume-name": "PYBADGEBOOT", + "msd-volume-name": ["PYBADGEBOOT"], "msd-firmware-name": "arcade.uf2" } diff --git a/targets/pygamer.json b/targets/pygamer.json index d6ccfc2a..cbd1abf9 100644 --- a/targets/pygamer.json +++ b/targets/pygamer.json @@ -5,6 +5,6 @@ "serial-port": ["239a:803d", "239a:803e"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "PYGAMERBOOT", + "msd-volume-name": ["PYGAMERBOOT"], "msd-firmware-name": "arcade.uf2" } diff --git a/targets/pyportal.json b/targets/pyportal.json index 37313fb3..bc503926 100644 --- a/targets/pyportal.json +++ b/targets/pyportal.json @@ -5,6 +5,6 @@ "flash-1200-bps-reset": "true", "flash-method": "msd", "serial-port": ["239a:8035", "239a:8036"], - "msd-volume-name": "PORTALBOOT", + "msd-volume-name": ["PORTALBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/qtpy.json b/targets/qtpy.json index 0ff27083..49a67901 100644 --- a/targets/qtpy.json +++ b/targets/qtpy.json @@ -5,6 +5,6 @@ "serial-port": ["239a:80cb"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "QTPY_BOOT", + "msd-volume-name": ["QTPY_BOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/reelboard.json b/targets/reelboard.json index b6da0a44..240eb371 100644 --- a/targets/reelboard.json +++ b/targets/reelboard.json @@ -3,7 +3,7 @@ "build-tags": ["reelboard"], "serial": "uart", "flash-method": "msd", - "msd-volume-name": "reel-board", + "msd-volume-name": ["reel-board"], "msd-firmware-name": "firmware.hex", "openocd-interface": "cmsis-dap" } diff --git a/targets/rp2040.json b/targets/rp2040.json index 99a568a7..34241036 100644 --- a/targets/rp2040.json +++ b/targets/rp2040.json @@ -4,7 +4,7 @@ "flash-1200-bps-reset": "true", "flash-method": "msd", "serial": "usb", - "msd-volume-name": "RPI-RP2", + "msd-volume-name": ["RPI-RP2"], "msd-firmware-name": "firmware.uf2", "binary-format": "uf2", "uf2-family-id": "0xe48bff56", diff --git a/targets/trinket-m0.json b/targets/trinket-m0.json index f43ecfe1..91dd48b9 100644 --- a/targets/trinket-m0.json +++ b/targets/trinket-m0.json @@ -5,6 +5,6 @@ "serial-port": ["239a:801e"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "TRINKETBOOT", + "msd-volume-name": ["TRINKETBOOT"], "msd-firmware-name": "firmware.uf2" } diff --git a/targets/wioterminal.json b/targets/wioterminal.json index 17e7c3fd..64b505de 100644 --- a/targets/wioterminal.json +++ b/targets/wioterminal.json @@ -5,7 +5,7 @@ "serial-port": ["2886:802d"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "Arduino", + "msd-volume-name": ["Arduino"], "msd-firmware-name": "firmware.uf2", "openocd-verify": true } diff --git a/targets/xiao-ble.json b/targets/xiao-ble.json index 242accab..a9359cd4 100644 --- a/targets/xiao-ble.json +++ b/targets/xiao-ble.json @@ -2,5 +2,5 @@ "inherits": ["nrf52840", "nrf52840-s140v7-uf2"], "build-tags": ["xiao_ble"], "serial-port": ["2886:8045"], - "msd-volume-name": "XIAO-SENSE" + "msd-volume-name": ["XIAO-SENSE"] } diff --git a/targets/xiao.json b/targets/xiao.json index 9f16d60c..f5878743 100644 --- a/targets/xiao.json +++ b/targets/xiao.json @@ -5,6 +5,6 @@ "serial-port": ["2886:802f"], "flash-1200-bps-reset": "true", "flash-method": "msd", - "msd-volume-name": "Arduino", + "msd-volume-name": ["Arduino","Seeed XIAO"], "msd-firmware-name": "firmware.uf2" }