Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/54722 )
Change subject: dummyflasher.c: Move 'flashchip_contents' into emu_data ......................................................................
dummyflasher.c: Move 'flashchip_contents' into emu_data
Move 'flashchip_contents' out of global scope and into the emu_data reentrent struct.
BUG=none BRANCH=none TEST=builds
Change-Id: I11dfe713dd2fecfd3981ab50e31c9215d00bc787 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M dummyflasher.c 1 file changed, 20 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/22/54722/1
diff --git a/dummyflasher.c b/dummyflasher.c index 5581d0b..ce8300f 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -37,7 +37,6 @@ #endif
#if EMULATE_CHIP -static uint8_t *flashchip_contents = NULL; enum emu_chip { EMULATE_NONE, EMULATE_ST_M25P10_RES, @@ -71,6 +70,7 @@ unsigned int spi_ignorelist_size;
unsigned int spi_write_256_chunksize; + uint8_t *flashchip_contents; };
#if EMULATE_SPI_CHIP @@ -353,14 +353,14 @@ /* Truncate to emu_chip_size. */ offs %= data->emu_chip_size; if (readcnt > 0) - memcpy(readarr, flashchip_contents + offs, readcnt); + memcpy(readarr, data->flashchip_contents + offs, readcnt); break; case JEDEC_READ_4BA: offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4]; /* Truncate to emu_chip_size. */ offs %= data->emu_chip_size; if (readcnt > 0) - memcpy(readarr, flashchip_contents + offs, readcnt); + memcpy(readarr, data->flashchip_contents + offs, readcnt); break; case JEDEC_BYTE_PROGRAM: offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; @@ -374,7 +374,7 @@ msg_perr("Max BYTE PROGRAM size exceeded!\n"); return 1; } - memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4); + memcpy(data->flashchip_contents + offs, writearr + 4, writecnt - 4); data->emu_modified = 1; break; case JEDEC_BYTE_PROGRAM_4BA: @@ -389,7 +389,7 @@ msg_perr("Max BYTE PROGRAM size exceeded!\n"); return 1; } - memcpy(flashchip_contents + offs, writearr + 5, writecnt - 5); + memcpy(data->flashchip_contents + offs, writearr + 5, writecnt - 5); data->emu_modified = 1; break; case JEDEC_AAI_WORD_PROGRAM: @@ -411,7 +411,7 @@ writearr[3]; /* Truncate to emu_chip_size. */ aai_offs %= data->emu_chip_size; - memcpy(flashchip_contents + aai_offs, writearr + 4, 2); + memcpy(data->flashchip_contents + aai_offs, writearr + 4, 2); aai_offs += 2; } else { if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) { @@ -424,7 +424,7 @@ "too long!\n"); return 1; } - memcpy(flashchip_contents + aai_offs, writearr + 1, 2); + memcpy(data->flashchip_contents + aai_offs, writearr + 1, 2); aai_offs += 2; } data->emu_modified = 1; @@ -448,7 +448,7 @@ if (offs & (data->emu_jedec_se_size - 1)) msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs); offs &= ~(data->emu_jedec_se_size - 1); - memset(flashchip_contents + offs, 0xff, data->emu_jedec_se_size); + memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_se_size); data->emu_modified = 1; break; case JEDEC_BE_52: @@ -466,7 +466,7 @@ if (offs & (data->emu_jedec_be_52_size - 1)) msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs); offs &= ~(data->emu_jedec_be_52_size - 1); - memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size); + memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size); data->emu_modified = 1; break; case JEDEC_BE_D8: @@ -484,7 +484,7 @@ if (offs & (data->emu_jedec_be_d8_size - 1)) msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs); offs &= ~(data->emu_jedec_be_d8_size - 1); - memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size); + memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size); data->emu_modified = 1; break; case JEDEC_CE_60: @@ -500,7 +500,7 @@ } /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */ /* emu_jedec_ce_60_size is emu_chip_size. */ - memset(flashchip_contents, 0xff, data->emu_jedec_ce_60_size); + memset(data->flashchip_contents, 0xff, data->emu_jedec_ce_60_size); data->emu_modified = 1; break; case JEDEC_CE_C7: @@ -516,7 +516,7 @@ } /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */ /* emu_jedec_ce_c7_size is emu_chip_size. */ - memset(flashchip_contents, 0xff, data->emu_jedec_ce_c7_size); + memset(data->flashchip_contents, 0xff, data->emu_jedec_ce_c7_size); data->emu_modified = 1; break; case JEDEC_SFDP: @@ -643,13 +643,13 @@ if (emu_data->emu_chip != EMULATE_NONE) { if (emu_data->emu_persistent_image && emu_data->emu_modified) { msg_pdbg("Writing %s\n", emu_data->emu_persistent_image); - write_buf_to_file(flashchip_contents, + write_buf_to_file(emu_data->flashchip_contents, emu_data->emu_chip_size, emu_data->emu_persistent_image); free(emu_data->emu_persistent_image); emu_data->emu_persistent_image = NULL; } - free(flashchip_contents); + free(emu_data->flashchip_contents); } #endif free(data); @@ -970,8 +970,8 @@ } free(tmp);
- flashchip_contents = malloc(data->emu_chip_size); - if (!flashchip_contents) { + data->flashchip_contents = malloc(data->emu_chip_size); + if (!data->flashchip_contents) { msg_perr("Out of memory!\n"); return 1; } @@ -995,7 +995,7 @@
msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n", data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size); - memset(flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size); + memset(data->flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
/* Will be freed by shutdown function if necessary. */ data->emu_persistent_image = extract_programmer_param("image"); @@ -1011,10 +1011,10 @@ if ((uintmax_t)image_stat.st_size == data->emu_chip_size) { msg_pdbg("matches.\n"); msg_pdbg("Reading %s\n", data->emu_persistent_image); - if (read_buf_from_file(flashchip_contents, data->emu_chip_size, + if (read_buf_from_file(data->flashchip_contents, data->emu_chip_size, data->emu_persistent_image)) { msg_perr("Unable to read %s\n", data->emu_persistent_image); - free(flashchip_contents); + free(data->flashchip_contents); return 1; } } else { @@ -1025,7 +1025,7 @@
dummy_init_out: if (register_shutdown(dummy_shutdown, data)) { - free(flashchip_contents); + free(data->flashchip_contents); free(data); return 1; }