Skip to content

feat: optionally reset ext flash before use - #967

Open
vhdirk wants to merge 1 commit into
wolfSSL:masterfrom
vhdirk:reset-ext-flash-before-use
Open

vhdirk wants to merge 1 commit into
wolfSSL:masterfrom
vhdirk:reset-ext-flash-before-use

Conversation

@vhdirk

@vhdirk vhdirk commented Nov 2, 2026 •

Copy link
Copy Markdown

Our ext flash has a rather peculiar 'feature' in that we sometimes get an invalid response when first accessing the ext flash. Resetting the flash chip prior alleviates this problem.

This is highly specific and I don't expect this to make it into wolfboot as is, but I'm hopeful we can come to some sort of solution where we don't need to patch every new wolfboot version.

I'm also curious what function this particular line has: 3444c47#diff-315ae084c53140288a75552950c9b0dab78db6e39b69173980741b4687a7633bL181

To be honest, we don't actually know the whole reason for this bit any more. The original author is no longer working with us.

Our ext flash has a rather peculiar 'feature' in that SPI sometimes
locks up when first accessing the ext flash. Resetting the flash chip
prior alleviates this problem.

This is highly specific and I don't expect this to make it into wolfboot
as is, but I'm hopeful we can come to some sort of solution where we
don't need to patch every new wolfboot version.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved SPI flash transaction and reset-sequencing defects can hang boot, prevent reset recovery, and produce incorrect JEDEC IDs.

4 open issues
What changed in this PR

This PR adds an optional software reset during external SPI flash probing to address reported first-access lockups without requiring downstream patches.

Changes:

  • Defines reset-enable (0x66) and reset (0x99) commands.
  • Adds a RESET_EXT_FLASH-guarded reset sequence and delay loops.
  • Changes the device-identification transaction around the reset option.
File Description
src/​spi_flash.c Adds optional flash reset handling and modifies probe sequencing.

Review effort: Balanced

Comment thread src/spi_flash.c
@@ -186,9 +188,28 @@ uint16_t spi_flash_probe(void)
int i;
spi_init(0,0);
wait_busy();
Comment thread src/spi_flash.c
spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH);
spi_write(MDID);
notused = spi_read();
write_address(0);
Comment thread src/spi_flash.c
notused = spi_read();
write_address(0);
#else
notused = spi_read();
Comment thread src/spi_flash.c
spi_write(RST);
notused = spi_read();
spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH);
for (i = 0; i < 18000; i++);
@dgarske

dgarske commented Nov 2, 2026

Copy link
Copy Markdown
Member

Okay to test. Company contributor agreement on file.

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.

3 participants