[flashrom] [PATCH] dummyflasher.c: add an "empty" parameter and initialize with random bytes by default

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Thu Jul 21 17:54:46 CEST 2011


previously the dummies were initialized to be empty (all ones), which makes writes skip
erasing altogether. with this patch the default is to fill it with random bytes instead and the
old behavior can be enforced with stating "empty=yes" on the command line.

Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 dummyflasher.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/dummyflasher.c b/dummyflasher.c
index fca228c..b463ea4 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -94,6 +94,8 @@ int dummy_init(void)
 {
 	char *bustext = NULL;
 	char *tmp = NULL;
+	char *empty;
+	int e = 0;
 #if EMULATE_CHIP
 	struct stat image_stat;
 #endif
@@ -128,6 +130,13 @@ int dummy_init(void)
 		msg_pdbg("Support for all flash bus types disabled.\n");
 	free(bustext);
 
+	empty = extract_programmer_param("empty");
+	if (empty != NULL) {
+		if (strstr(empty, "yes"))
+			e = 1;
+		free(empty);
+	}
+
 	tmp = extract_programmer_param("spi_write_256_chunksize");
 	if (tmp) {
 		spi_write_256_chunksize = atoi(tmp);
@@ -198,8 +207,17 @@ int dummy_init(void)
 		return 1;
 	}
 
-	msg_pdbg("Filling fake flash chip with 0xff, size %i\n", emu_chip_size);
-	memset(flashchip_contents, 0xff, emu_chip_size);
+	msg_pdbg("Filling fake flash chip containing %i bytes with ",
+		 emu_chip_size);
+	if (e) {
+		msg_pdbg("0xff.\n");
+		memset(flashchip_contents, 0xff, emu_chip_size);
+	} else {
+		msg_pdbg("random data.\n");
+		unsigned int i;
+		for (i = 0; i < emu_chip_size; i++)
+			flashchip_contents[i] = rand();
+	}
 
 	emu_persistent_image = extract_programmer_param("image");
 	if (!emu_persistent_image) {
-- 
1.7.1





More information about the flashrom mailing list