diff options
author | Kenneth Bell <[email protected]> | 2023-04-14 21:36:29 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-04-17 18:56:32 +0200 |
commit | 1bba5f5d7bcb8bcb587b2c612d1f89b56f7f8ebd (patch) | |
tree | a5f0b985d50fb88a7782caee05dd6fae416276e1 | |
parent | 48ef68dd866b9f9d5b18ae5e9b6772cbcc6441b3 (diff) | |
download | tinygo-1bba5f5d7bcb8bcb587b2c612d1f89b56f7f8ebd.tar.gz tinygo-1bba5f5d7bcb8bcb587b2c612d1f89b56f7f8ebd.zip |
targets: make msd-volume-name an array
36 files changed, 85 insertions, 76 deletions
diff --git a/compileopts/target.go b/compileopts/target.go index 30573a863..40a1d445c 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"` @@ -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 1f37955a2..16d3013b5 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 e503151b9..7355eb583 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 66fe7455a..3a5592196 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 edfd97925..5f5214e12 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 2d50c5bdb..fa965db63 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 7eac4d8e3..91ede1898 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 faffd0de7..66eac03d2 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 1d182c542..8a4e862ac 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 ce932513f..bd4c488d7 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 243ff0a93..c14135153 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 1084531b3..6f0ec6c20 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 59de6651f..d8b4d5d4a 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 527d3fd77..0134e2f33 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 a38d9b83c..d294ae5be 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 9d38d6027..7a7156f0d 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 7e28df540..17a29b337 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 644a4642a..4bc29f9d3 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 c8c7461c3..6cb78b902 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 a890100da..2478cf5c1 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 218a5cd97..9dfc9b802 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 7095a8768..4c95c3300 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 210bfae7f..f775ab6d9 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 6d84c56fd..5f34a2436 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 b604624cf..de660b448 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 c80b3e3a2..232a1bab2 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 d6ccfc2aa..cbd1abf9f 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 37313fb39..bc503926e 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 0ff27083c..49a67901b 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 b6da0a449..240eb371c 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 99a568a79..342410368 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 f43ecfe16..91dd48b95 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 17e7c3fd7..64b505de5 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 242accab7..a9359cd4b 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 9f16d60ce..f5878743e 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" } |