From c64f1970d60a25deda4ec7444f8e91dab5508b95 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Thu, 2 Jun 2022 08:52:56 +0200 Subject: [PATCH] spiFlash: stop if jedec_id == 0xffffff --- src/spiFlash.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/spiFlash.cpp b/src/spiFlash.cpp index 44c3f9a..ed5832b 100644 --- a/src/spiFlash.cpp +++ b/src/spiFlash.cpp @@ -272,8 +272,15 @@ bool SPIFlash::dump(const std::string &filename, const int &base_addr, int SPIFlash::erase_and_prog(int base_addr, uint8_t *data, int len) { - if (_jedec_id == 0) - read_id(); + if (_jedec_id == 0) { + try { + read_id(); + } catch(std::exception &e) { + printError(e.what()); + return -1; + } + } + bool must_relock = false; // used to relock after write; /* microchip SST26VF032B have global lock set @@ -432,6 +439,10 @@ void SPIFlash::read_id() printf("%x ", rx[i]); } + /* something wrong with read */ + if ((_jedec_id >> 8) == 0xffff) + throw std::runtime_error("Read ID failed"); + if (_verbose > 0) printf("read %x\n", _jedec_id); auto t = flash_list.find(_jedec_id >> 8);