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
10 changes: 10 additions & 0 deletions pkg/espflasher/flasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ func (f *Flasher) ChipName() string {
return "Unknown"
}

// BootloaderFlashOffset returns the flash offset where the bootloader image
// lives for the connected chip. Returns (0, false) if the chip has not been
// detected yet (e.g. connect() has not completed).
func (f *Flasher) BootloaderFlashOffset() (uint32, bool) {
if f.chip == nil {
return 0, false
}
return f.chip.BootloaderFlashOffset, true
}

// connect performs the bootloader connection sequence:
// reset → sync → detect chip.
func (f *Flasher) connect() error {
Expand Down
23 changes: 23 additions & 0 deletions pkg/espflasher/flasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ func TestFlasherChipName(t *testing.T) {
}
}

func TestFlasherBootloaderFlashOffset(t *testing.T) {
// ESP32: 0x1000
f := &Flasher{chip: defESP32, opts: DefaultOptions()}
off, ok := f.BootloaderFlashOffset()
if !ok || off != 0x1000 {
t.Errorf("ESP32 BootloaderFlashOffset() = (0x%X, %v), want (0x1000, true)", off, ok)
}

// ESP32-S3: 0x0
f2 := &Flasher{chip: defESP32S3, opts: DefaultOptions()}
off, ok = f2.BootloaderFlashOffset()
if !ok || off != 0x0 {
t.Errorf("ESP32-S3 BootloaderFlashOffset() = (0x%X, %v), want (0x0, true)", off, ok)
}

// Chip not detected yet: returns (0, false)
f3 := &Flasher{opts: DefaultOptions()}
off, ok = f3.BootloaderFlashOffset()
if ok || off != 0 {
t.Errorf("undetected BootloaderFlashOffset() = (0x%X, %v), want (0x0, false)", off, ok)
}
}

func TestFlashImagePatchesHeader(t *testing.T) {
// Verify that FlashImage calls patchImageHeader by checking that an
// invalid flash mode causes an error.
Expand Down
Loading