Add dispatch loop, copy_to_ram, retry picotool load without sleep
This commit is contained in:
@@ -6,25 +6,20 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func WaitForBootsel(serial string, timeout time.Duration) error {
|
||||
func Load(uf2Path string, serial string, timeout time.Duration) error {
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
cmd := exec.Command("picotool", "info", "--ser", serial)
|
||||
if err := cmd.Run(); err == nil {
|
||||
var out []byte
|
||||
var err error
|
||||
for {
|
||||
cmd := exec.Command("picotool", "load", uf2Path, "-x", "--ser", serial)
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if time.Now().After(deadline) {
|
||||
return fmt.Errorf("picotool load: %w\n%s", err, out)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("device %s not found in BOOTSEL after %v", serial, timeout)
|
||||
}
|
||||
|
||||
func Load(uf2Path string, serial string) error {
|
||||
cmd := exec.Command("picotool", "load", uf2Path, "-x", "--ser", serial)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("picotool load: %w\n%s", err, out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Reboot(serial string) error {
|
||||
|
||||
Reference in New Issue
Block a user