Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ The library is organized in layers:

The flasher includes pre-compiled bootloader stubs from [esp-flasher-stub](https://github.com/espressif/esp-flasher-stub) releases. To update stubs:

1. Edit `STUB_VERSION` in `tools/update-stubs.sh` to the desired release version
1. Edit `stubVersion` in `tools/update-stubs.go` to the desired release version
2. Run `go generate ./pkg/espflasher/...` to download and embed the latest stubs
3. The `go:generate` directive in `pkg/espflasher/stub.go` will invoke `tools/update-stubs.sh`
3. The `go:generate` directive in `pkg/espflasher/stub.go` will invoke `tools/update-stubs.go`

## Protocol Reference

Expand Down
2 changes: 1 addition & 1 deletion pkg/espflasher/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
)

//go:generate bash ../../tools/update-stubs.sh
//go:generate go run ../../tools/update-stubs.go
//go:embed stubs
var stubFS embed.FS

Expand Down
71 changes: 71 additions & 0 deletions tools/update-stubs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Command update-stubs downloads pre-compiled bootloader stubs from the
// esp-flasher-stub GitHub releases and writes them to pkg/espflasher/stubs/.
package main

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
)

const (
stubVersion = "v0.5.1"
baseURL = "https://github.com/espressif/esp-flasher-stub/releases/download/" + stubVersion
)

var chips = []string{
"esp8266",
"esp32",
"esp32s2",
"esp32s3",
"esp32c2",
"esp32c3",
"esp32c5",
"esp32c6",
"esp32h2",
}

func main() {
// Resolve the stubs directory relative to this tool's source file.
stubDir := filepath.Join("..", "pkg", "espflasher", "stubs")
if dir := os.Getenv("STUB_DIR"); dir != "" {
stubDir = dir
}

fmt.Printf("Downloading stubs from %s to %s\n", baseURL, stubDir)

for _, chip := range chips {
url := baseURL + "/" + chip + ".json"
dest := filepath.Join(stubDir, chip+".json")

if err := download(url, dest); err != nil {
fmt.Fprintf(os.Stderr, "error downloading %s: %v\n", chip, err)
os.Exit(1)
}
}

fmt.Printf("Successfully updated all %d stubs to %s\n", len(chips), stubVersion)
}

func download(url, dest string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("HTTP %s for %s", resp.Status, url)
}

f, err := os.Create(dest)
if err != nil {
return err
}
defer f.Close()

_, err = io.Copy(f, resp.Body)
return err
}
15 changes: 0 additions & 15 deletions tools/update-stubs.sh

This file was deleted.

Loading