fix(flasher): pass detected flash size to SPI_SET_PARAMS (#41)#42
Open
dsbaars wants to merge 1 commit intotinygo-org:mainfrom
Open
fix(flasher): pass detected flash size to SPI_SET_PARAMS (#41)#42dsbaars wants to merge 1 commit intotinygo-org:mainfrom
dsbaars wants to merge 1 commit intotinygo-org:mainfrom
Conversation
…ucceed
attachFlash hardcoded 4 MB in spiSetParams regardless of FlashSize / detected
chip size. The stub uses this value as a write bound, so any write past 4 MB
on a larger chip is rejected with RESPONSE_FAILED_SPI_OP (status 0xC4),
even though detectFlashSize correctly identifies the chip as 8 MB / 16 MB.
Reproducible on ESP32-S3 with an 8 MB flash by writing at offset 0x6F0000:
the first compressed block fails with `command 0x11 failed: status=0xC4`.
esptool and esptool-js both pass the actual size to SPI_SET_PARAMS for this
exact reason ("the flash chip should be configured with the real size").
This change:
- adds flashSizeStringToBytes helper for the existing 1MB..128MB names
- splits attachFlash so the size step is a reusable configureSPIForSize
- re-runs configureSPIForSize after detectFlashSize in FlashImages so the
stub gets the real chip size before the first write
Falls back to 4 MB when FlashSize is empty / "keep" / unrecognised, matching
the previous behaviour for the unconfigured case.
Fixes tinygo-org#41
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.
Fixes #41.
What's wrong
attachFlashhardcodes4*1024*1024inspiSetParamsregardless ofFlasherOptions.FlashSizeor whatdetectFlashSize()finds on the chip. The stub uses this value as a write bound — any write past 4 MB is rejected withRESPONSE_FAILED_SPI_OP(status0xC4).Reproducible on ESP32-S3 with 8 MB flash by writing a partition at
0x6F0000: the first compressed block fails withcommand 0x11 failed: status=0xC4 error=0x00.esptool.pyandesptool-jsboth pass the real size toSPI_SET_PARAMSfor this exact reason (esptool/cmds.py:1852 — "the flash chip should be configured with the real size").What this PR does
flashSizeStringToBytesfor the existing1MB..128MBsize names.attachFlashso the size step becomes a reusableconfigureSPIForSize.configureSPIForSizeafterdetectFlashSizeinFlashImagesso the stub gets the real chip size before the first write.FlashSizeis empty /keep/ unrecognised — preserves prior behaviour for the unconfigured case.Test plan
go test ./pkg/espflasher/— all existing tests still pass.0x6F0000withstatus=0xC4. With this patch the storage partition flashes through to MD5 verify.ChipType != ChipESP8266, matching the ESP8266 short-circuit at the top ofattachFlash).