Files
picomap/lib/picotool/picotool.go

33 lines
667 B
Go
Raw Normal View History

2026-04-03 13:25:31 +09:00
package picotool
import (
"fmt"
"os/exec"
"time"
2026-04-03 13:25:31 +09:00
)
func Load(uf2Path string, serial string, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
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
}
if time.Now().After(deadline) {
return fmt.Errorf("picotool load: %w\n%s", err, out)
}
2026-04-03 13:25:31 +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
}