Switch commands to slog, disable net_poll pending fix
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -15,19 +16,19 @@ import (
|
||||
func main() {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
slog.Error("fatal", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
buildDir := filepath.Join(wd, "firmware", "build")
|
||||
|
||||
if err := run(buildDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
slog.Error("fatal", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func build(buildDir string) error {
|
||||
fmt.Println("Configuring...")
|
||||
slog.Info("configuring")
|
||||
cmake := exec.Command("cmake", "-S", filepath.Join(filepath.Dir(buildDir)), "-B", buildDir)
|
||||
cmake.Stdout = os.Stdout
|
||||
cmake.Stderr = os.Stderr
|
||||
@@ -35,7 +36,7 @@ func build(buildDir string) error {
|
||||
return fmt.Errorf("cmake failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Building...")
|
||||
slog.Info("building")
|
||||
cmd := exec.Command("make", "-C", buildDir)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@@ -65,10 +66,13 @@ func run(buildDir string) error {
|
||||
|
||||
serials := make([]string, 2)
|
||||
errs := make([]error, 2)
|
||||
uf2Names := []string{"picomap", "picomap_test"}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := range 2 {
|
||||
log := slog.With("dev", devs[i])
|
||||
wg.Go(func() {
|
||||
log.Info("connecting for info")
|
||||
c, err := client.NewSerial(devs[i], 2*time.Second)
|
||||
if err != nil {
|
||||
errs[i] = err
|
||||
@@ -81,18 +85,20 @@ func run(buildDir string) error {
|
||||
return
|
||||
}
|
||||
serials[i] = boardSerial(info.BoardID)
|
||||
log.Info("got info", "serial", serials[i], "firmware", info.FirmwareName)
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
for i, err := range errs {
|
||||
if err != nil {
|
||||
return fmt.Errorf("info %s: %w", devs[i], err)
|
||||
return fmt.Errorf("[%s] info: %w", devs[i], err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Sending PICOBOOT requests...")
|
||||
for i := range 2 {
|
||||
log := slog.With("serial", serials[i])
|
||||
wg.Go(func() {
|
||||
log.Info("sending PICOBOOT")
|
||||
c, err := client.NewSerial(devs[i], 2*time.Second)
|
||||
if err != nil {
|
||||
errs[i] = err
|
||||
@@ -101,8 +107,10 @@ func run(buildDir string) error {
|
||||
err = c.PICOBOOT()
|
||||
c.Close()
|
||||
if err != nil {
|
||||
errs[i] = fmt.Errorf("PICOBOOT %s: %w", devs[i], err)
|
||||
errs[i] = fmt.Errorf("PICOBOOT %s: %w", serials[i], err)
|
||||
return
|
||||
}
|
||||
log.Info("PICOBOOT sent")
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
@@ -117,19 +125,23 @@ func run(buildDir string) error {
|
||||
filepath.Join(buildDir, "picomap_test.uf2"),
|
||||
}
|
||||
|
||||
fmt.Println("Loading firmware...")
|
||||
for i := range 2 {
|
||||
log := slog.With("serial", serials[i])
|
||||
wg.Go(func() {
|
||||
log.Info("loading", "uf2", uf2Names[i])
|
||||
errs[i] = picotool.Load(uf2s[i], serials[i], 10*time.Second)
|
||||
if errs[i] == nil {
|
||||
log.Info("loaded", "uf2", uf2Names[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
for i, err := range errs {
|
||||
if err != nil {
|
||||
return fmt.Errorf("load %s: %w", serials[i], err)
|
||||
return fmt.Errorf("[%s] load: %w", serials[i], err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Done.")
|
||||
slog.Info("done")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user