aboutsummaryrefslogtreecommitdiffstats
path: root/iceprog
diff options
context:
space:
mode:
authorPiotr Esden-Tempski <piotr@esden.net>2018-08-18 15:26:37 -0700
committerPiotr Esden-Tempski <piotr@esden.net>2018-08-18 15:26:37 -0700
commitf4ff8f76309d82773881a24cad9d13116ce36025 (patch)
tree11a2a239f373e20b8c24fe0319a63d9d4b2ffe5c /iceprog
parent3ba1acf31bc0ee83d8b545af03e144cb942d1f88 (diff)
downloadicestorm-f4ff8f76309d82773881a24cad9d13116ce36025.tar.gz
icestorm-f4ff8f76309d82773881a24cad9d13116ce36025.tar.bz2
icestorm-f4ff8f76309d82773881a24cad9d13116ce36025.zip
Improved JEDEC ID read function.
The function now checks how long the extended JEDEC ID field is for the particular FLASH chip and only reads the amount provided by the chip.
Diffstat (limited to 'iceprog')
-rw-r--r--iceprog/iceprog.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index ca3ce48..42abd86 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -322,16 +322,42 @@ static void sram_chip_select(bool assert)
static void flash_read_id()
{
- // fprintf(stderr, "read flash ID..\n");
+ /* JEDEC ID structure:
+ * Byte No. | Data Type
+ * ---------+----------
+ * 0 | FC_JEDECID Request Command
+ * 1 | MFG ID
+ * 2 | Dev ID 1
+ * 3 | Dev ID 2
+ * 4 | Ext Dev Str Len
+ */
- uint8_t data[21] = { FC_JEDECID };
+ uint8_t data[260] = { FC_JEDECID };
+ int len = 5; // command + 4 response bytes
+
+ if (verbose) fprintf(stderr, "read flash ID..\n");
flash_chip_select(true);
- xfer_spi(data, 21);
+
+ // Write command and read first 4 bytes
+ xfer_spi(data, len);
+
+ if(data[4] == 0xFF)
+ fprintf(stderr, "Extended Device String Length is 0xFF, "
+ "this is likely a read error. Ignorig...\n");
+ else {
+ // Read extended JEDEC ID bytes
+ if(data[4] != 0) {
+ len += data[4];
+ xfer_spi(data + 5, len - 5);
+ }
+ }
+
flash_chip_select(false);
+ // TODO: Add full decode of the JEDEC ID.
fprintf(stderr, "flash ID:");
- for (int i = 1; i < 21; i++)
+ for (int i = 1; i < len; i++)
fprintf(stderr, " 0x%02X", data[i]);
fprintf(stderr, "\n");
}