1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

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>
This commit is contained in:
Carl-Daniel Hailfinger 2012-08-30 21:41:00 +00:00
parent 250c321a9d
commit af2cac0e13

View File

@ -493,6 +493,9 @@ static int emulate_spi_chip_response(unsigned int writecnt,
{ {
unsigned int offs, i, toread; unsigned int offs, i, toread;
static int unsigned aai_offs; 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) { if (writecnt == 0) {
msg_perr("No command sent to the chip!\n"); 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]) { switch (writearr[0]) {
case JEDEC_RES: case JEDEC_RES:
if (emu_chip != EMULATE_ST_M25P10_RES) if (writecnt < JEDEC_RES_OUTSIZE)
break; break;
/* Respond with ST_M25P10_RES. */ /* offs calculation is only needed for SST chips which treat RES like REMS. */
if (readcnt > 0) offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
readarr[0] = 0x10; 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; break;
case JEDEC_REMS: 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; break;
/* Respond with SST_SST25VF040_REMS. */ offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
if (readcnt > 0) offs += writecnt - JEDEC_REMS_OUTSIZE;
readarr[0] = 0xbf; switch (emu_chip) {
if (readcnt > 1) case EMULATE_SST_SST25VF040_REMS:
readarr[1] = 0x44; 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; break;
case JEDEC_RDID: case JEDEC_RDID:
switch (emu_chip) { switch (emu_chip) {