Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Unified Diff: dummyflasher.c

Issue 6791015: Support variable-size SPI chip for dummy programmer. (Closed) Base URL: ssh://gitrw.chromium.org:9222/flashrom.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dummyflasher.c
diff --git a/dummyflasher.c b/dummyflasher.c
index 473e45e9c3193915206e445147daed0f142117d4..7cdbcdc8a3d7003855d844c62159a93080203402 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -22,6 +22,7 @@
#include "flash.h"
#include "chipdrivers.h"
#include "programmer.h"
+#include "flashchips.h"
/* Remove the #define below if you don't want SPI flash chip emulation. */
#define EMULATE_SPI_CHIP 1
@@ -37,12 +38,20 @@
#endif
#if EMULATE_CHIP
+/* The name of variable-size virtual chip. A 4MB flash example:
+ * flashrom -p dummy:emulate=VIRTUAL-4194304
+ */
+#define VIRTUAL_CHIP_NAME "VIRTUAL"
+#endif
+
+#if EMULATE_CHIP
static uint8_t *flashchip_contents = NULL;
enum emu_chip {
EMULATE_NONE,
EMULATE_ST_M25P10_RES,
EMULATE_SST_SST25VF040_REMS,
EMULATE_SST_SST25VF032B,
+ EMULATE_VIRTUAL,
Stefan Reinauer 2011/04/01 17:47:06 Since this emulates a Winbond, should it be called
Louis 2011/04/02 01:48:52 My initial attempt is to emulate any size of flash
dhendrix 2011/04/02 23:43:32 SGTM.
Louis 2011/04/07 02:28:14 Done.
};
static enum emu_chip emu_chip = EMULATE_NONE;
static char *emu_persistent_image = NULL;
@@ -156,6 +165,32 @@ int dummy_init(void)
msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
"write)\n");
}
+ if (!strncmp(tmp, VIRTUAL_CHIP_NAME, strlen(VIRTUAL_CHIP_NAME))) {
+ char *size_str;
+ emu_chip = EMULATE_VIRTUAL;
+ strtok(tmp, "-"); // prefix is discarded.
+ if (NULL == (size_str = strtok(NULL, "-")) || !*size_str) {
+ msg_perr("Please specify flash size, "
+ "example: %s-65536\n", VIRTUAL_CHIP_NAME);
Stefan Reinauer 2011/04/01 17:47:06 Can we use KB instead of bytes here? 64, 128, 256,
Louis 2011/04/02 01:48:52 This is intentional for -p dummy:VIRTUAL-`stat
dhendrix 2011/04/02 23:43:32 Good point... if desired, maybe we can add somethi
dhendrix 2011/04/02 23:43:32 I think it would be better to treat size (and pote
Louis 2011/04/07 02:28:14 Done.
Louis 2011/04/07 02:28:14 Done.
+ free(tmp);
+ return 1;
+ }
+ emu_chip_size = atoi(size_str);
+ if (emu_chip_size & (emu_chip_size - 1)) {
+ msg_perr("Specified flash size is not power of 2.\n");
+ free(tmp);
+ return 1;
+ }
+ emu_max_byteprogram_size = 256;
+ emu_max_aai_size = 0;
+ emu_jedec_se_size = 4 * 1024;
+ emu_jedec_be_52_size = 32 * 1024;
+ emu_jedec_be_d8_size = 64 * 1024;
+ emu_jedec_ce_60_size = emu_chip_size;
+ emu_jedec_ce_c7_size = emu_chip_size;
+ msg_pdbg("Emulating virtual SPI flash chip (size=%d bytes)\n",
+ emu_chip_size);
+ }
#endif
if (emu_chip == EMULATE_NONE) {
msg_perr("Invalid chip specified for emulation: %s\n", tmp);
@@ -305,15 +340,29 @@ static int emulate_spi_chip_response(unsigned int writecnt, unsigned int readcnt
readarr[1] = 0x44;
break;
case JEDEC_RDID:
- if (emu_chip != EMULATE_SST_SST25VF032B)
- break;
- /* Respond with SST_SST25VF032B. */
- if (readcnt > 0)
- readarr[0] = 0xbf;
- if (readcnt > 1)
- readarr[1] = 0x25;
- if (readcnt > 2)
- readarr[2] = 0x4a;
+ if (emu_chip == EMULATE_SST_SST25VF032B) {
+ /* Respond with SST_SST25VF032B. */
+ if (readcnt > 0)
+ readarr[0] = 0xbf;
+ if (readcnt > 1)
+ readarr[1] = 0x25;
+ if (readcnt > 2)
+ readarr[2] = 0x4a;
+ } else if (emu_chip == EMULATE_VIRTUAL) {
+ /* Winbond W25X series flashes are easy to map.
+ * 128KB -- ID: 0x3011
+ * 256KB -- ID: 0x3012
+ * : :
+ * 8192KB -- ID: 0x3017
+ * TODO: map more chips in future for other sizes.
Stefan Reinauer 2011/04/01 17:47:06 Should we make sure we only pass sizes supported b
Louis 2011/04/02 01:48:52 Will refine this to support any size. On 2011/04/
+ */
+ uint16_t dev_id = WINBOND_NEX_W25X10;
+ int size = emu_chip_size >> 17;
+ for (; size >>= 1; dev_id++);
+ if (readcnt > 0) readarr[0] = WINBOND_NEX_ID;
+ if (readcnt > 1) readarr[1] = dev_id >> 8;
+ if (readcnt > 2) readarr[2] = dev_id & 0xff;
+ }
break;
case JEDEC_RDSR:
memset(readarr, 0, readcnt);
@@ -495,6 +544,7 @@ int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
case EMULATE_ST_M25P10_RES:
case EMULATE_SST_SST25VF040_REMS:
case EMULATE_SST_SST25VF032B:
+ case EMULATE_VIRTUAL:
if (emulate_spi_chip_response(writecnt, readcnt, writearr,
readarr)) {
msg_perr("Invalid command sent to flash chip!\n");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698