As long as a programmer's check_trans code does not rely on the previous invocation of its init function one can trivially set that programmer's check_trans function instead of the dummy's default one. This allows for even better testing of the SPI infrastructure code under near realworld conditions.
FIXME: add other programmers FIXME: add manpage doc
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- dummyflasher.c | 15 ++++++++++++++- programmer.h | 2 ++ wbsio_spi.c | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/dummyflasher.c b/dummyflasher.c index 4e08386..1d63b7a 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -119,7 +119,7 @@ static uint32_t dummy_chip_readl(const struct flashctx *flash, static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
-static const struct spi_programmer spi_programmer_dummyflasher = { +static struct spi_programmer spi_programmer_dummyflasher = { .type = SPI_CONTROLLER_DUMMY, .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_UNSPECIFIED, @@ -373,6 +373,19 @@ int dummy_init(void) msg_pdbg("Initial status register is set to 0x%02x.\n", emu_status); } + tmp = extract_programmer_param("spi_prog"); + if (tmp) { + if (!strcmp(tmp, "wbsio")) { + spi_programmer_dummyflasher.check_trans = wbsio_spi_check_trans; + msg_pdbg("Using SPI payload limitations of the %s programmer.\n", tmp); + } else { + msg_perr("Error: emulation of a programmer requested, " + "but the programmer could not be parsed "%s".\n", tmp); + free(tmp); + return 1; + } + } + free(tmp); #endif
msg_pdbg("Filling fake flash chip with 0xff, size %i\n", emu_chip_size); diff --git a/programmer.h b/programmer.h index bcd9547..c2373e6 100644 --- a/programmer.h +++ b/programmer.h @@ -585,6 +585,8 @@ int mcp6x_spi_init(int want_spi); int sb600_probe_spi(struct pci_dev *dev);
/* wbsio_spi.c */ +int wbsio_spi_check_trans(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, + const unsigned char *writearr); int wbsio_check_for_spi(void); #endif
diff --git a/wbsio_spi.c b/wbsio_spi.c index ec14c28..6164ae7 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -108,7 +108,7 @@ static uint8_t determine_mode(struct flashctx *flash, unsigned int writecnt, uns return 0; }
-static int wbsio_spi_check_trans(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, +int wbsio_spi_check_trans(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr) { if (determine_mode(flash, writecnt, readcnt, writearr) == 0)