main: update espflasher and auto-use best available flashing options on esp32

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2026-04-07 20:19:35 +02:00
committed by Ron Evans
parent d274545e63
commit f4a6e0373b
3 changed files with 24 additions and 13 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ require (
golang.org/x/sys v0.30.0
golang.org/x/tools v0.30.0
gopkg.in/yaml.v2 v2.4.0
tinygo.org/x/espflasher v0.4.0
tinygo.org/x/espflasher v0.5.0
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74
)
+2 -2
View File
@@ -58,7 +58,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tinygo.org/x/espflasher v0.4.0 h1:0N+Ei+0qT/wGkGIoMaY2g+oI519VA5G4kUVUYHedTv8=
tinygo.org/x/espflasher v0.4.0/go.mod h1:a3hRV9EETPUkfPE6P14p4A6jKKth+oD5gtQz3nmij+8=
tinygo.org/x/espflasher v0.5.0 h1:aLYv6ldFw/Bxj36e4DaEqjGMUwx+LvI7xdapqz49LQ8=
tinygo.org/x/espflasher v0.5.0/go.mod h1:a3hRV9EETPUkfPE6P14p4A6jKKth+oD5gtQz3nmij+8=
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74 h1:ovavgTdIBWCH8YWlcfq9gkpoyT1+IxMKSn+Df27QwE8=
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
+21 -10
View File
@@ -1094,10 +1094,15 @@ const (
)
func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Options) error {
var opts *espflasher.FlasherOptions
opts := espflasher.DefaultOptions()
opts.Compress = true
opts.Logger = &espflasher.StdoutLogger{W: os.Stdout}
if options.BaudRate != 0 {
opts.FlashBaudRate = options.BaudRate
}
// On Windows, we have to explicitly specify the reset mode to use USB JTAG.
if runtime.GOOS == "windows" && resetMode == jtagReset {
opts = espflasher.DefaultOptions()
opts.ResetMode = espflasher.ResetUSBJTAG
}
@@ -1108,8 +1113,6 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
defer flasher.Close()
chipName := flasher.ChipName()
fmt.Printf("Connected to %s\n", chipName)
offset := uint32(0x0)
if chipName == "ESP32" {
offset = 0x1000
@@ -1121,18 +1124,26 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
return err
}
if err := flasher.EraseFlash(); err != nil {
return fmt.Errorf("erase failed: %v", err)
}
progress := func(current, total int) {
pct := float64(current) / float64(total) * 100
bar := int(pct / 2)
fmt.Printf("\r[%-50s] %6.1f%%", strings.Repeat("#", bar)+strings.Repeat(".", 50-bar), pct)
if current >= total {
fmt.Println()
}
}
// Flash with progress reporting
err = flasher.FlashImage(data, offset, func(current, total int) {
fmt.Printf("\rFlashing: %d/%d bytes (%.0f%%)", current, total,
float64(current)/float64(total)*100)
})
err = flasher.FlashImage(data, offset, progress)
if err != nil {
return err
}
fmt.Println()
time.Sleep(time.Second)
// Reset the device to run the new firmware
flasher.Reset()