Skip to content

fix: correctly write image header for flash#1

Merged
deadprogram merged 1 commit intomainfrom
flash-esp32-improved
Feb 27, 2026
Merged

fix: correctly write image header for flash#1
deadprogram merged 1 commit intomainfrom
flash-esp32-improved

Conversation

@deadprogram
Copy link
Member

espflash wrote the binary to flash without patching the image header. The ESP32 ROM bootloader reads flash configuration (SPI mode, clock frequency, flash size) from bytes 2-3 of the image at 0x1000. If those values don't match the hardware, the ROM can't communicate with the flash chip.

Changes:

New file image.go - patchImageHeader() patches bytes 2-3 of ESP images (flash mode, frequency, size) and recomputes the appended SHA256 hash if present.

New options in FlasherOptions: FlashMode (qio/qout/dio/dout), FlashFreq (80m/40m/etc.), FlashSize (1MB/2MB/4MB/etc.). Default is "keep" (don't modify the binary), matching esptool.py behavior.

Header patching integrated into FlashImage and FlashImages - runs before padding and compression.

Fixed FlashSizes encoding - the maps had incorrect values (JEDEC IDs instead of image header encoding). Fixed to use the correct upper-nibble values (e.g., 2MB=0x10, 4MB=0x20) matching esptool.py.

CLI flags -fm, -ff, -fs added to the command tool.

espflash wrote the binary to flash without patching the image header.
The ESP32 ROM bootloader reads flash configuration (SPI mode, clock frequency,
flash size) from bytes 2-3 of the image at 0x1000. If those values don't match
the hardware, the ROM can't communicate with the flash chip.

Changes:

New file image.go - patchImageHeader() patches bytes 2-3 of ESP images
(flash mode, frequency, size) and recomputes the appended SHA256 hash if present.

New options in FlasherOptions: FlashMode (qio/qout/dio/dout),
FlashFreq (80m/40m/etc.), FlashSize (1MB/2MB/4MB/etc.).
Default is "keep" (don't modify the binary), matching esptool.py behavior.

Header patching integrated into FlashImage and FlashImages - runs before
padding and compression.

Fixed FlashSizes encoding - the maps had incorrect values (JEDEC IDs instead
of image header encoding). Fixed to use the correct upper-nibble values
(e.g., 2MB=0x10, 4MB=0x20) matching esptool.py.

CLI flags -fm, -ff, -fs added to the command tool.

Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram deadprogram merged commit 54d773b into main Feb 27, 2026
@deadprogram deadprogram deleted the flash-esp32-improved branch February 27, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant