From 6b399c3bfe92c3c054464cc3399ce81e09c96f4f Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Mon, 2 Nov 2026 16:26:04 +0100 Subject: [PATCH 1/2] feat: optionally reset ext flash before use 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. --- src/spi_flash.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/spi_flash.c b/src/spi_flash.c index 4a33b364ea..9fd32c447e 100644 --- a/src/spi_flash.c +++ b/src/spi_flash.c @@ -49,8 +49,10 @@ #define BYTE_WRITE 0x02 #define AUTOINC 0xAD #define EWSR 0x50 +#define RSTEN 0x66 #define EBSY 0x70 #define DBSY 0x80 +#define RST 0x99 #ifdef TEST_EXT_FLASH static int test_ext_flash(void); @@ -186,9 +188,28 @@ uint16_t spi_flash_probe(void) int i; spi_init(0,0); wait_busy(); + +#ifdef RESET_EXT_FLASH + /* Reset Flash chip as it doesn't always respond properly to first request */ + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); + spi_write(RSTEN); + notused = spi_read(); + spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); + for (i = 0; i < 10; i++); + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); + spi_write(RST); + notused = spi_read(); + spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); + for (i = 0; i < 18000; i++); + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); spi_write(MDID); notused = spi_read(); + write_address(0); +#else + notused = spi_read(); +#endif + spi_write(0xFF); manuf = spi_read(); spi_write(0xFF); From 84590d9a0169d8abd1ecf1e07fc1c18d1985a640 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Thu, 5 Nov 2026 11:31:18 +0100 Subject: [PATCH 2/2] restructure, remove empty loops --- src/spi_flash.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/spi_flash.c b/src/spi_flash.c index 9fd32c447e..0e33c19c36 100644 --- a/src/spi_flash.c +++ b/src/spi_flash.c @@ -185,9 +185,7 @@ uint16_t spi_flash_probe(void) { uint8_t manuf, product, notused; uint16_t manuf_prod; - int i; spi_init(0,0); - wait_busy(); #ifdef RESET_EXT_FLASH /* Reset Flash chip as it doesn't always respond properly to first request */ @@ -195,20 +193,17 @@ uint16_t spi_flash_probe(void) spi_write(RSTEN); notused = spi_read(); spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); - for (i = 0; i < 10; i++); + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); spi_write(RST); notused = spi_read(); spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); - for (i = 0; i < 18000; i++); +#endif + wait_busy(); spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); spi_write(MDID); notused = spi_read(); - write_address(0); -#else - notused = spi_read(); -#endif spi_write(0xFF); manuf = spi_read();