Skip to contentSkip to conversation

spl: spi: fix loss of spl_load() error on soft reset

PATCH In review Dimitrios Siganos 2 participants 2 messages Feb 17 – Mar 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: spi: fix loss of spl_load() error on soft reset

When CONFIG_SPI_FLASH_SOFT_RESET is enabled, spi_nor_remove() is called after spl_load() to switch the flash back to legacy SPI mode. However, the return value of spi_nor_remove() unconditionally overwrites the return value of spl_load(), discarding any load error.

Fix this by preserving the spl_load() error and only propagating the spi_nor_remove() error as a fallback. Also log a message when spi_nor_remove() fails, since in the case where spl_load() already failed its error would otherwise be silently discarded.

---
 common/spl/spl_spi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
common/spl/spl_spi.c +10 -2
index e8e62d5f9fb..3d4b70f7c33 100644
@@ -124,8 +124,16 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 	}
 
 	err = spl_load(spl_image, bootdev, &load, 0, payload_offs);
-	if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET))
-		err = spi_nor_remove(flash);
+	if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
+		int ret = spi_nor_remove(flash);
+
+		if (ret) {
+			printf("%s: Failed to remove SPI NOR flash: %d\n",
+			       __func__, ret);
+			if (!err)
+				err = ret;
+		}
+	}
 	return err;
 }
 /* Use priorty 1 so that boards can override this */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Dimitrios Siganos

When CONFIG_SPI_FLASH_SOFT_RESET is enabled, spi_nor_remove() is called after spl_load() to switch the flash back to legacy SPI mode. However, the return value of spi_nor_remove() unconditionally overwrites the return value of spl_load(), discarding any load error.

Fix this by preserving the spl_load() error and only propagating the spi_nor_remove() error as a fallback. Also log a message when spi_nor_remove() fails, since in the case where spl_load() already failed its error would otherwise be silently discarded.

[...]

Applied to u-boot/next, thanks!

[1/1] spl: spi: fix loss of spl_load() error on soft reset

      commit: e7ad95aa3f1180823e07dd30c8c24494a07ca814
Signature · 1 line
Tom