From f44641e91e11dbabb7e9a8e87dc3d4e47dd9311a Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sat, 16 Apr 2022 15:23:17 -0700 Subject: [PATCH] utils: Add sanity check when reading SPI flash ID Signed-off-by: Alex Forencich --- utils/flash_spi.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/flash_spi.c b/utils/flash_spi.c index 43b4b4f4a..30d2061bf 100644 --- a/utils/flash_spi.c +++ b/utils/flash_spi.c @@ -344,6 +344,13 @@ int spi_flash_init(struct flash_device *fdev) printf("Memory type: 0x%02x\n", mem_type); printf("Memory capacity: 0x%02x\n", mem_capacity); + if (mfr_id == 0 || mfr_id == 0xff) + { + fprintf(stderr, "Failed to read flash ID\n"); + spi_flash_deselect(fdev); + return -1; + } + // convert from BCD mem_capacity = (mem_capacity & 0xf) + (((mem_capacity >> 4) & 0xf) * 10);