Seeing RES, most chips output model_id repeatedly, but some early chip(s? sst25lf0x0a) output manuf_id and model_id alternatively. Add support for it.
There are other problems to solve until ich7 spi chips could be better supported. 1. Some boards have opmenu locked down. For those boards, we had better build an opcode table according to the current opmenu, instead of writing one into it. 2. ich7(or the compatible spi chips it controls) does address translation. We need to recalculate and rewrite the command address before we let it go.
Signed-off-by: FENG yu ning fengyuning1984@gmail.com
Index: flashrom/spi.c =================================================================== --- flashrom/spi.c (revision 3775) +++ flashrom/spi.c (working copy) @@ -77,7 +77,7 @@
if (spi_command(sizeof(cmd), JEDEC_RES_INSIZE, cmd, readarr)) return 1; - printf_debug("RES returned %02x.\n", readarr[0]); + printf_debug("RES returned %02x %02x.\n", readarr[0], readarr[1]); return 0; }
@@ -198,7 +198,9 @@
int probe_spi_res(struct flashchip *flash) { + /* asserts 3 >= MAX(JEDEC_RDID_INSIZE, JEDEC_RES_INSIZE) */ unsigned char readarr[3]; + uint32_t manuf_id; uint32_t model_id;
/* Check if RDID was successful and did not return 0xff 0xff 0xff. @@ -211,11 +213,25 @@ if (spi_res(readarr)) return 0;
- model_id = readarr[0]; - printf_debug("%s: id 0x%x\n", __FUNCTION__, model_id); - if (model_id != flash->model_id) - return 0; + /* spi_res reads in 2 bytes. Seeing RES(0xab), most chips output + * model_id repeatedly, some(like sst25lf0x0a) output manuf_id and + * model_id alternatively. + */ + if (readarr[0] == readarr[1]) { + model_id = readarr[0]; + printf_debug("%s: id 0x%x\n", __FUNCTION__, model_id); + if (model_id != flash->model_id) + return 0; + } else { + manuf_id = readarr[0]; + model_id = readarr[1]; + printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, manuf_id, + model_id); + if (manuf_id != flash->manufacture_id || model_id != flash->model_id) + return 0; + }
+ /* Print the status register to tell the * user about possible write protection. */ Index: flashrom/spi.h =================================================================== --- flashrom/spi.h (revision 3775) +++ flashrom/spi.h (working copy) @@ -37,7 +37,7 @@ /* Read Electronic Signature */ #define JEDEC_RES 0xab #define JEDEC_RES_OUTSIZE 0x04 -#define JEDEC_RES_INSIZE 0x01 +#define JEDEC_RES_INSIZE 0x02
/* Write Enable */ #define JEDEC_WREN 0x06