dummyflasher.c: Move 'flashchip_contents' into emu_data

Move 'flashchip_contents' out of global scope and
into the emu_data reentrent struct.

Change-Id: I11dfe713dd2fecfd3981ab50e31c9215d00bc787
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/54722
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71358
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/dummyflasher.c b/dummyflasher.c
index 395186f..add7579 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -36,7 +36,6 @@
 #endif
 
 #if EMULATE_CHIP
-static uint8_t *flashchip_contents = NULL;
 enum emu_chip {
 	EMULATE_NONE,
 	EMULATE_ST_M25P10_RES,
@@ -63,6 +62,8 @@
 	unsigned char spi_ignorelist[256];
 	unsigned int spi_blacklist_size;
 	unsigned int spi_ignorelist_size;
+
+	uint8_t *flashchip_contents;
 };
 
 #if EMULATE_SPI_CHIP
@@ -140,13 +141,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);
@@ -365,8 +366,8 @@
 		return 1;
 	}
 	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;
 	}
@@ -389,7 +390,7 @@
 #endif
 
 	msg_pdbg("Filling fake flash chip with 0xff, size %i\n", data->emu_chip_size);
-	memset(flashchip_contents, 0xff, data->emu_chip_size);
+	memset(data->flashchip_contents, 0xff, data->emu_chip_size);
 
 	/* Will be freed by shutdown function if necessary. */
 	data->emu_persistent_image = extract_programmer_param("image");
@@ -405,10 +406,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 {
@@ -419,7 +420,7 @@
 
 dummy_init_out:
 	if (register_shutdown(dummy_shutdown, data)) {
-		free(flashchip_contents);
+		free(data->flashchip_contents);
 		free(data);
 		return 1;
 	}
@@ -653,7 +654,7 @@
 		/* 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];
@@ -667,7 +668,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_AAI_WORD_PROGRAM:
@@ -689,7 +690,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) {
@@ -702,7 +703,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;
@@ -726,7 +727,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:
@@ -744,7 +745,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:
@@ -762,7 +763,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:
@@ -778,7 +779,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:
@@ -794,7 +795,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: