mirror of https://github.com/wolfSSL/wolfBoot.git
F-7983: propagate OctoSPI status-read failures in octospi_wait_ready()
octospi_wait_ready() pre-zeros sr and ignored the return value of octospi_cmd(). A failed status-register transfer therefore left sr == 0 and the do/while loop exited as if the flash were no longer BUSY, so a page program or sector erase that could not be confirmed completed was reported as successful by nor_flash_write()/nor_flash_erase() and, with it, by hal_flash_write/erase and ext_flash_write/erase. Make octospi_wait_ready() return -1 when the status read transfer fails, and abort both NOR mutation loops with -1 in that case, matching the existing error handling for the program/erase command transfers themselves. Note: the wait loop remains unbounded if the flash genuinely stays BUSY (stuck operation) — a separate concern from the false-success path fixed here; a bounded timeout would need a timing reference this HAL does not have and no sibling HAL currently uses one. Verified: make TARGET=stm32n6 (full build, wolfboot.bin + signed test-app image), tools/unit-tests suite green. Hardware fault injection required to reproduce, so no host unit test.pull/859/head
parent
4fb9e81b44
commit
014046689f
|
|
@ -144,14 +144,18 @@ static void RAMFUNCTION octospi_write_enable(void)
|
|||
NULL, 0, SPI_MODE_NONE, 0);
|
||||
}
|
||||
|
||||
static void RAMFUNCTION octospi_wait_ready(void)
|
||||
static int RAMFUNCTION octospi_wait_ready(void)
|
||||
{
|
||||
uint8_t sr;
|
||||
do {
|
||||
sr = 0;
|
||||
octospi_cmd(1, READ_SR_CMD, 0, SPI_MODE_NONE,
|
||||
&sr, 1, SPI_MODE_SINGLE, 0);
|
||||
/* A failed status-register transfer must not read as "ready":
|
||||
* sr stays zero and the loop would exit as if the flash were idle. */
|
||||
if (octospi_cmd(1, READ_SR_CMD, 0, SPI_MODE_NONE,
|
||||
&sr, 1, SPI_MODE_SINGLE, 0) < 0)
|
||||
return -1;
|
||||
} while (sr & FLASH_SR_BUSY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void RAMFUNCTION octospi_enable_mmap(void)
|
||||
|
|
@ -737,7 +741,10 @@ static int RAMFUNCTION nor_flash_write(uint32_t offset, const uint8_t *data,
|
|||
if (ret < 0)
|
||||
break;
|
||||
|
||||
octospi_wait_ready();
|
||||
if (octospi_wait_ready() < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
offset += write_sz;
|
||||
data += write_sz;
|
||||
|
|
@ -766,7 +773,10 @@ static int RAMFUNCTION nor_flash_erase(uint32_t offset, int len)
|
|||
if (ret < 0)
|
||||
break;
|
||||
|
||||
octospi_wait_ready();
|
||||
if (octospi_wait_ready() < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
offset += FLASH_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue