From 154794ac5162dfaa22b9e4d6712c9b612156883d Mon Sep 17 00:00:00 2001 From: Ralph Metzler Date: Wed, 8 Jun 2016 12:11:08 +0200 Subject: [PATCH] add support to read unique ids --- apps/octonet/ddtest.c | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/apps/octonet/ddtest.c b/apps/octonet/ddtest.c index a53a923..3941029 100644 --- a/apps/octonet/ddtest.c +++ b/apps/octonet/ddtest.c @@ -145,7 +145,6 @@ int ReadFlash(int ddb, int argc, char *argv[], uint32_t Flags) } - int FlashDetect(int dev) { uint8_t Cmd = 0x9F; @@ -765,7 +764,6 @@ uint32_t GetFPGA_ID(uint8_t * Buffer) } - int FlashProg(int dev,int argc, char* argv[],uint32_t Flags) { uint8_t * Buffer = NULL; @@ -1652,6 +1650,60 @@ int lic_erase(int dev, int argc, char* argv[], uint32_t Flags) return err; } +static int read_sfpd(int dev, uint8_t adr, uint8_t *val) +{ + uint8_t cmd[5] = { 0x5a, 0, 0, adr, 00 }; + int r; + + r = FlashIO(dev, cmd, 5, val, 1); + if (r < 0) + return r; + return 0; +} + +static int read_sst_id(int dev, uint8_t *id) +{ + uint8_t cmd[2] = { 0x88, 0 }; + uint8_t buf[9]; + int r; + + r = FlashIO(dev, cmd, 2, buf, 9); + if (r < 0) + return r; + memcpy(id, buf + 1, 8); + return 0; +} + +int read_id(int dev, int argc, char* argv[], uint32_t Flags) +{ + int Flash = FlashDetect(dev); + uint8_t Cmd;; + uint8_t Id[8]; + uint32_t len, i, adr; + + + switch(Flash) { + case SPANSION_S25FL116K: + case SPANSION_S25FL132K: + case SPANSION_S25FL164K: + for (i = 0; i < 8; i++) + read_sfpd(dev, 0xf8 + i, &Id[i]); + len = 8; + break; + case SSTI_SST25VF064C: + read_sst_id(dev, Id); + len = 8; + break; + default: + printf("Unsupported Flash\n"); + break; + } + printf("ID: "); + for (i = 0; i < 8; i++) + printf("%02x ", Id[i]); + printf("\n"); + +} struct SCommand CommandTable[] = { @@ -1661,7 +1713,7 @@ struct SCommand CommandTable[] = { "register", GetSetRegister, 1, "Get/Set Register : reg |<[0x]regnum> [[0x]value(32)]" }, { "flashread", ReadFlash, 1, "Read Flash : flashread " }, - { "flashio", FlashIO, 1, "Flash IO : flashio .. " }, + { "flashio", FlashIOC, 1, "Flash IO : flashio .. " }, { "flashprog", FlashProg, 1, "Flash Programming : flashprog [
]" }, { "flashprog", FlashProg, 1, "Flash Programming : flashprog -SubVendorID " }, { "flashprog", FlashProg, 1, "Flash Programming : flashprog -Jump
" }, @@ -1676,6 +1728,7 @@ struct SCommand CommandTable[] = { "licimport", lic_import, 1, "License Import : licimport" }, { "licexport", lic_export, 1, "License Export : licexport" }, { "licerase", lic_erase, 1, "License Erase : licerase" }, + { "read_id", read_id, 1, "Read Unique ID : read_id" }, { NULL,NULL,0 } };