2026-04-03 13:25:31 +09:00
|
|
|
package picotool
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os/exec"
|
2026-04-06 09:19:26 +09:00
|
|
|
"time"
|
2026-04-03 13:25:31 +09:00
|
|
|
)
|
|
|
|
|
|
2026-04-06 17:36:41 +09:00
|
|
|
func Load(uf2Path string, serial string, timeout time.Duration) error {
|
2026-04-06 09:19:26 +09:00
|
|
|
deadline := time.Now().Add(timeout)
|
2026-04-06 17:36:41 +09:00
|
|
|
var out []byte
|
|
|
|
|
var err error
|
|
|
|
|
for {
|
|
|
|
|
cmd := exec.Command("picotool", "load", uf2Path, "-x", "--ser", serial)
|
|
|
|
|
out, err = cmd.CombinedOutput()
|
|
|
|
|
if err == nil {
|
2026-04-06 09:19:26 +09:00
|
|
|
return nil
|
|
|
|
|
}
|
2026-04-06 17:36:41 +09:00
|
|
|
if time.Now().After(deadline) {
|
|
|
|
|
return fmt.Errorf("picotool load: %w\n%s", err, out)
|
|
|
|
|
}
|
2026-04-03 13:25:31 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 21:48:47 +09:00
|
|
|
func Reboot(serial string) error {
|
|
|
|
|
cmd := exec.Command("picotool", "reboot", "--ser", serial)
|
2026-04-03 13:25:31 +09:00
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("picotool reboot: %w\n%s", err, out)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|