diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-03-22 03:30:58 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-03-22 03:30:58 +0000 |
commit | 408e47af32b06613576bff74c0f455fc00220d58 (patch) | |
tree | df195f58fca631cc9e175305a8167b7249937f57 | |
parent | 50415d2e48a510e8799217805a6bd12e49606272 (diff) | |
download | flashrom-408e47af32b06613576bff74c0f455fc00220d58.tar.gz flashrom-408e47af32b06613576bff74c0f455fc00220d58.tar.bz2 flashrom-408e47af32b06613576bff74c0f455fc00220d58.zip |
Multibyte SPI write for the Bus Pirate
Corresponding to flashrom svn r964.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Sean Nelson <audiohacked@gmail.com>
-rw-r--r-- | buspirate_spi.c | 37 | ||||
-rw-r--r-- | flash.h | 1 | ||||
-rw-r--r-- | spi.c | 2 |
3 files changed, 38 insertions, 2 deletions
diff --git a/buspirate_spi.c b/buspirate_spi.c index f1a0be1d..dc491e20 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -316,4 +316,39 @@ int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len return spi_read_chunked(flash, buf, start, len, 12); } -/* We could do 12-byte writes, but for now we use the generic 1-byte code. */ +int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf) +{ + int total_size = 1024 * flash->total_size; + int i; + + spi_disable_blockprotect(); + /* Erase first. */ + msg_pinfo("Erasing flash before programming... "); + if (erase_flash(flash)) { + msg_perr("ERASE FAILED!\n"); + return -1; + } + msg_pinfo("done.\n"); + + /* FIXME: We could do 12 byte writes, but then we'd have to make sure + * not to cross a 256 byte page boundary. This problem only applies to + * writes, reads can cross page boundaries just fine. + */ + for (i = 0; i < total_size; i += 8) { + int l, r; + if (i + 8 <= total_size) + l = 8; + else + l = total_size - i; + + if ((r = spi_nbyte_program(i, &buf[i], l))) { + msg_perr("%s: write fail %d\n", __func__, r); + return 1; + } + + while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) + /* loop */; + } + + return 0; +} @@ -504,6 +504,7 @@ int buspirate_spi_init(void); int buspirate_spi_shutdown(void); int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); +int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf); /* dediprog.c */ int dediprog_init(void); @@ -108,7 +108,7 @@ const struct spi_programmer spi_programmer[] = { .command = buspirate_spi_send_command, .multicommand = default_spi_send_multicommand, .read = buspirate_spi_read, - .write_256 = spi_chip_write_1, + .write_256 = buspirate_spi_write_256, }, #endif |