Flash erase + write: complete SPI flash driver#19
Open
Conversation
CMD_ERASE handler with progress reporting per sector. CMD_WRITE routes flash addresses to flash write handler (receive to RAM staging, verify CRC, program page-by-page, verify readback). flash_unlock() clears BP bits in SPI status register. fmc_enter_normal/fmc_enter_boot helpers for mode switching. Known issues (needs hardware debugging): - fmc_enter_boot doesn't reliably switch back to boot mode - Flash BP bits not clearing (status register write may need different approach) - After failed erase, FMC stuck in normal mode (reads return I/O buffer) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The FMC_STATUS register (0xAC) returns stale values — WREN command appeared to fail (WEL never set) because we read status from there. Reading via FMC_OP_READ_DATA into the I/O buffer gives the real flash status register. Also: fmc_enter_normal configures SPI pads and clears WP in GLOBAL_CFG. fmc_enter_boot uses CRG soft reset (FMC_CFG bit 0 can't be cleared by writing once in normal mode). Erase verified on real hi3516ev300: sector 0xF0000 erased to all 0xFF, CRC32 matches expected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixed spi_wait_wip to use DATA path for status reads (matching the flash_read_status fix). Client write_flash splits into WRITE_MAX_TRANSFER blocks to avoid FIFO overflow, same as write_memory. Tested on hi3516ev300: erase sector 0xF0000, write 64KB of bootrom data in 4x16KB blocks, read back byte-for-byte verified, cleaned up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Summary
Complete flash erase and write support for the bare-metal agent. The SPI flash driver now supports read, erase, and write — the full flash recovery capability.
Key Fixes
FMC_OP_READ_DATAinto the I/O buffer gives the real flash status. This was why WREN never appeared to set the WEL bit.Protocol
CMD_ERASE(0x04): erase sectors with per-sector progress reportingCMD_WRITEto flash addresses: receive data to RAM staging, verify CRC, program page-by-page, verify readbackflash_unlock(): clear block protection bits (BP0-BP4) via SPI status register writeTest Results (real hi3516ev300, W25Q128 16MB)
Test plan
🤖 Generated with Claude Code