[flashrom] [PATCH] dummyflasher: Add a status register to SPI chips.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Tue Jan 31 06:51:00 CET 2012


This is just a quick hack, that could be expanded. What do you think?

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

diff --git a/dummyflasher.c b/dummyflasher.c
index 99f81f5..4ccfd9c 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -55,6 +55,7 @@ static unsigned int emu_jedec_be_52_size = 0;
 static unsigned int emu_jedec_be_d8_size = 0;
 static unsigned int emu_jedec_ce_60_size = 0;
 static unsigned int emu_jedec_ce_c7_size = 0;
+static uint8_t emu_status = 0;
 #endif
 #endif
 
@@ -126,6 +127,9 @@ int dummy_init(void)
 {
 	char *bustext = NULL;
 	char *tmp = NULL;
+#if EMULATE_SPI_CHIP
+	char *status = NULL;
+#endif
 #if EMULATE_CHIP
 	struct stat image_stat;
 #endif
@@ -178,6 +182,14 @@ int dummy_init(void)
 		goto dummy_init_out;
 	}
 #if EMULATE_SPI_CHIP
+	status = extract_programmer_param("status");
+	if (status) {
+		emu_status = atoi(status);
+		msg_pdbg("Initial status register is set to 0x%02x.\n",
+			 emu_status);
+		free(status);
+	}
+
 	if (!strcmp(tmp, "M25P10.RES")) {
 		emu_chip = EMULATE_ST_M25P10_RES;
 		emu_chip_size = 128 * 1024;
@@ -385,10 +397,26 @@ static int emulate_spi_chip_response(unsigned int writecnt,
 		if (readcnt > 2)
 			readarr[2] = 0x4a;
 		break;
-	case JEDEC_RDSR:
-		memset(readarr, 0, readcnt);
+	case JEDEC_RDSR: {
+		uint8_t tmp_status = emu_status;
 		if (aai_active)
-			memset(readarr, 1 << 6, readcnt);
+			tmp_status |= 1 << 6;
+		memset(readarr, tmp_status, readcnt);
+		break;
+	}
+	case JEDEC_WREN:
+		emu_status |= (1 << 1);
+		break;
+	case JEDEC_WRSR:
+		if (!(emu_status & (1 << 1))) {
+			msg_perr("WRSR attempted, but WEL is 0!\n");
+			return 1;
+		}
+		if (aai_active) {
+			msg_perr("WRSR attempted during AAI sequence!\n");
+			return 1;
+		}
+		emu_status = writearr[1] & 0xFC; /* resets WEL and WIP */
 		break;
 	case JEDEC_READ:
 		offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
-- 
1.7.1





More information about the flashrom mailing list