fix: correctly write image header for flash#1
Merged
deadprogram merged 1 commit intomainfrom Feb 27, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.