diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2012-08-30 21:41:00 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2012-08-30 21:41:00 +0000 |
commit | af2cac0e13dafbf9e26328a85e9e423f2ca5ccfa (patch) | |
tree | 9e350ad5215d0cd91fa77818834b2e7557305748 | |
parent | 250c321a9d10d05959ff002be7e5f178b8c9637e (diff) | |
download | flashrom-af2cac0e13dafbf9e26328a85e9e423f2ca5ccfa.tar.gz flashrom-af2cac0e13dafbf9e26328a85e9e423f2ca5ccfa.tar.bz2 flashrom-af2cac0e13dafbf9e26328a85e9e423f2ca5ccfa.zip |
Add RES/REMS support to all dummyflasher emulated chips as a test case
Fix a few odd corner cases in RES/REMS support in dummyflasher
emulation which became noticeable once RES/REMS was used heavily.
Corresponding to flashrom svn r1589.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
-rw-r--r-- | dummyflasher.c | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/dummyflasher.c b/dummyflasher.c index 66d0df03..2803f76f 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -493,6 +493,9 @@ static int emulate_spi_chip_response(unsigned int writecnt, { unsigned int offs, i, toread; static int unsigned aai_offs; + const unsigned char sst25vf040_rems_response[2] = {0xbf, 0x44}; + const unsigned char sst25vf032b_rems_response[2] = {0xbf, 0x4a}; + const unsigned char mx25l6436_rems_response[2] = {0xc2, 0x16}; if (writecnt == 0) { msg_perr("No command sent to the chip!\n"); @@ -529,20 +532,54 @@ static int emulate_spi_chip_response(unsigned int writecnt, switch (writearr[0]) { case JEDEC_RES: - if (emu_chip != EMULATE_ST_M25P10_RES) + if (writecnt < JEDEC_RES_OUTSIZE) break; - /* Respond with ST_M25P10_RES. */ - if (readcnt > 0) - readarr[0] = 0x10; + /* offs calculation is only needed for SST chips which treat RES like REMS. */ + offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; + offs += writecnt - JEDEC_REMS_OUTSIZE; + switch (emu_chip) { + case EMULATE_ST_M25P10_RES: + if (readcnt > 0) + memset(readarr, 0x10, readcnt); + break; + case EMULATE_SST_SST25VF040_REMS: + for (i = 0; i < readcnt; i++) + readarr[i] = sst25vf040_rems_response[(offs + i) % 2]; + break; + case EMULATE_SST_SST25VF032B: + for (i = 0; i < readcnt; i++) + readarr[i] = sst25vf032b_rems_response[(offs + i) % 2]; + break; + case EMULATE_MACRONIX_MX25L6436: + if (readcnt > 0) + memset(readarr, 0x16, readcnt); + break; + default: /* ignore */ + break; + } break; case JEDEC_REMS: - if (emu_chip != EMULATE_SST_SST25VF040_REMS) + /* REMS response has wraparound and uses an address parameter. */ + if (writecnt < JEDEC_REMS_OUTSIZE) break; - /* Respond with SST_SST25VF040_REMS. */ - if (readcnt > 0) - readarr[0] = 0xbf; - if (readcnt > 1) - readarr[1] = 0x44; + offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; + offs += writecnt - JEDEC_REMS_OUTSIZE; + switch (emu_chip) { + case EMULATE_SST_SST25VF040_REMS: + for (i = 0; i < readcnt; i++) + readarr[i] = sst25vf040_rems_response[(offs + i) % 2]; + break; + case EMULATE_SST_SST25VF032B: + for (i = 0; i < readcnt; i++) + readarr[i] = sst25vf032b_rems_response[(offs + i) % 2]; + break; + case EMULATE_MACRONIX_MX25L6436: + for (i = 0; i < readcnt; i++) + readarr[i] = mx25l6436_rems_response[(offs + i) % 2]; + break; + default: /* ignore */ + break; + } break; case JEDEC_RDID: switch (emu_chip) { |