package picotool import ( "fmt" "os/exec" "time" ) func WaitForBootsel(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 { return nil } time.Sleep(100 * time.Millisecond) } 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 { cmd := exec.Command("picotool", "reboot", "--ser", serial) out, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("picotool reboot: %w\n%s", err, out) } return nil }