cmd: Ensure sf operates on spi flash
PATCH 1/1 cmd: Ensure sf operates on spi flash
Currently, the sf command will probe anything attached to an spi bus, regardless of whether it is UCLASS_SPI_FLASH. This came up when testing the mmc_spi driver, which is accessed via spi but is UCLASS_MMC. If the uclass is not what sf expects, then the "flash" variable will not actually have type spi_nor. This patch adds a check so we don't clobber any data if the user requests us to probe a device which is not an spi flash.
Signed-off-by Sean Anderson <[email protected]>
--- cmd/sf.c | 4 ++++ 1 file changed, 4 insertions(+)
cmd/sf.c +4 -0
@@ -132,6 +132,10 @@ static int do_spi_flash_probe(int argc, char * const argv[])printf ("Failed to initialize SPI flash at %u:%u (error %d)\n" , bus, cs, ret);return 1 ; + }else if (new->driver->id !=UCLASS_SPI_FLASH ) { +printf ("SPI device is not SPI flash: uclass is %d, expected %d\n" , + new->driver->id,UCLASS_SPU_FLASH ); +return 1 ; } flash =dev_get_uclass_priv (new);
Signature · 1 line
2.25.0
PATCH v2 1/1 cmd: Ensure sf operates on spi flash
Currently, the sf command will probe anything attached to an spi bus, regardless of whether it is UCLASS_SPI_FLASH. This came up when testing the mmc_spi driver, which is accessed via spi but is UCLASS_MMC. If the uclass is not what sf expects, then the "flash" variable will not actually have type spi_nor. This patch adds a check so we don't clobber any data if the user requests us to probe a device which is not an spi flash.
---
Changes for v2:
Fixed Signed-off-by line
Fix typo (SPU_FLASH -> SPI_FLASH)
cmd/sf.c | 4 ++++ 1 file changed, 4 insertions(+)
cmd/sf.c +4 -0
@@ -132,6 +132,10 @@ static int do_spi_flash_probe(int argc, char * const argv[])printf ("Failed to initialize SPI flash at %u:%u (error %d)\n" , bus, cs, ret);return 1 ; + }else if (new->driver->id !=UCLASS_SPI_FLASH ) { +printf ("SPI device is not SPI flash: uclass is %d, expected %d\n" , + new->driver->id,UCLASS_SPI_FLASH ); +return 1 ; } flash =dev_get_uclass_priv (new);
Signature · 1 line
2.25.0
PATCH v2 1/1 cmd: Ensure sf operates on spi flash
Hi Sean,
Quoted 3 lines · Sean Anderson
Currently, the sf command will probe anything attached to an spi bus, regardless of whether it is
UCLASS_SPI_FLASH. This came up when testing themmc_spidriver,
Did you do something like:
=> sf probe 1 0
?
Quoted 5 lines
which is accessed via spi but is
UCLASS_MMC. If the uclass is not what sf expects, then the "flash" variable will not actually have typespi_nor. This patch adds a check so we don't clobber any data if the user requests us to probe a device which is not an spi flash.
Quoted 9 lines
Signed-off-by Sean Anderson <[email protected]>---
Changes for v2:
Fixed Signed-off-by line
Fix typo (SPU_FLASH->SPI_FLASH)cmd/sf.c | 4 ++++ 1 file changed, 4 insertions(+)
Regards,
Bin
PATCH v2 1/1 cmd: Ensure sf operates on spi flash
Quoted 10 lines · Bin Meng
Hi Sean,
Quoted 3 lines · Sean Anderson
Currently, the sf command will probe anything attached to an spi bus, regardless of whether it is
UCLASS_SPI_FLASH. This came up when testing themmc_spidriver,Did you do something like:
=> sf probe 1 0
sf probe 0, but yes. I forgot that my spi bus 0 had the SD card on it not the spi flash. I feel like this sort of thing should be caught by u-boot to prevent the user from almost certainly causing a segfault.
--Sean