|
@ -945,28 +945,29 @@ func touchSerialPortAt1200bps(port string) (err error) { |
|
|
return fmt.Errorf("opening port: %s", err) |
|
|
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
|
|
|
// find standard UF2 info path
|
|
|
var infoPath string |
|
|
infoPaths := make([]string, 0, len(volumes)) |
|
|
|
|
|
for _, volume := range volumes { |
|
|
switch runtime.GOOS { |
|
|
switch runtime.GOOS { |
|
|
case "linux", "freebsd": |
|
|
case "linux", "freebsd": |
|
|
fi, err := os.Stat("/run/media") |
|
|
fi, err := os.Stat("/run/media") |
|
|
if err != nil || !fi.IsDir() { |
|
|
if err != nil || !fi.IsDir() { |
|
|
infoPath = "/media/*/" + volume + "/INFO_UF2.TXT" |
|
|
infoPaths = append(infoPaths, "/media/*/"+volume+"/INFO_UF2.TXT") |
|
|
} else { |
|
|
} else { |
|
|
infoPath = "/run/media/*/" + volume + "/INFO_UF2.TXT" |
|
|
infoPaths = append(infoPaths, "/run/media/*/"+volume+"/INFO_UF2.TXT") |
|
|
} |
|
|
} |
|
|
case "darwin": |
|
|
case "darwin": |
|
|
infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT" |
|
|
infoPaths = append(infoPaths, "/Volumes/"+volume+"/INFO_UF2.TXT") |
|
|
case "windows": |
|
|
case "windows": |
|
|
path, err := windowsFindUSBDrive(volume, options) |
|
|
path, err := windowsFindUSBDrive(volume, options) |
|
|
if err != nil { |
|
|
if err == nil { |
|
|
return err |
|
|
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 { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@ -974,28 +975,29 @@ func flashUF2UsingMSD(volume, tmppath string, options *compileopts.Options) erro |
|
|
return moveFile(tmppath, filepath.Dir(d)+"/flash.uf2") |
|
|
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
|
|
|
// find expected volume path
|
|
|
var destPath string |
|
|
destPaths := make([]string, 0, len(volumes)) |
|
|
|
|
|
for _, volume := range volumes { |
|
|
switch runtime.GOOS { |
|
|
switch runtime.GOOS { |
|
|
case "linux", "freebsd": |
|
|
case "linux", "freebsd": |
|
|
fi, err := os.Stat("/run/media") |
|
|
fi, err := os.Stat("/run/media") |
|
|
if err != nil || !fi.IsDir() { |
|
|
if err != nil || !fi.IsDir() { |
|
|
destPath = "/media/*/" + volume |
|
|
destPaths = append(destPaths, "/media/*/"+volume) |
|
|
} else { |
|
|
} else { |
|
|
destPath = "/run/media/*/" + volume |
|
|
destPaths = append(destPaths, "/run/media/*/"+volume) |
|
|
} |
|
|
} |
|
|
case "darwin": |
|
|
case "darwin": |
|
|
destPath = "/Volumes/" + volume |
|
|
destPaths = append(destPaths, "/Volumes/"+volume) |
|
|
case "windows": |
|
|
case "windows": |
|
|
path, err := windowsFindUSBDrive(volume, options) |
|
|
path, err := windowsFindUSBDrive(volume, options) |
|
|
if err != nil { |
|
|
if err == nil { |
|
|
return err |
|
|
destPaths = append(destPaths, path+"/") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
destPath = path + "/" |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
d, err := locateDevice(volume, destPath, options.Timeout) |
|
|
d, err := locateDevice(volumes, destPaths, options.Timeout) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@ -1003,10 +1005,11 @@ func flashHexUsingMSD(volume, tmppath string, options *compileopts.Options) erro |
|
|
return moveFile(tmppath, d+"/flash.hex") |
|
|
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 d []string |
|
|
var err error |
|
|
var err error |
|
|
for start := time.Now(); time.Since(start) < timeout; { |
|
|
for start := time.Now(); time.Since(start) < timeout; { |
|
|
|
|
|
for _, path := range paths { |
|
|
d, err = filepath.Glob(path) |
|
|
d, err = filepath.Glob(path) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return "", err |
|
|
return "", err |
|
@ -1014,10 +1017,16 @@ func locateDevice(volume, path string, timeout time.Duration) (string, error) { |
|
|
if d != nil { |
|
|
if d != nil { |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if d != nil { |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
time.Sleep(500 * time.Millisecond) |
|
|
} |
|
|
} |
|
|
if d == nil { |
|
|
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 |
|
|
return d[0], nil |
|
|
} |
|
|
} |
|
|