I found this in the Bus Pirate forum, apparently written by Patrick Georgi. Patrick, do you want to add a signoff?
Index: flash.h =================================================================== --- flash.h (Revision 916) +++ flash.h (Arbeitskopie) @@ -502,6 +502,7 @@ 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); Index: buspirate_spi.c =================================================================== --- buspirate_spi.c (Revision 916) +++ buspirate_spi.c (Arbeitskopie) @@ -316,4 +316,27 @@ 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; + + msg_pdbg("total_size is %d\n", total_size); + for (i = 0; i < total_size; i += 12) { + int l, r; + if (i + 12 <= total_size) + l = 12; + 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; +} Index: spi.c =================================================================== --- spi.c (Revision 916) +++ spi.c (Arbeitskopie) @@ -108,7 +108,7 @@ .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
On 10.03.2010 01:44, Carl-Daniel Hailfinger wrote:
I found this in the Bus Pirate forum, apparently written by Patrick Georgi.
There was one bug: Writes are not allowed to cross a page boundary. Given that we want to finish the generic chunked write sometime soon, the patch below (which I shamelessly copied from ft2232spi.c) reduces write size to 8 and should work for all currently supported SPI chips.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-buspirate_write_256/flash.h =================================================================== --- flashrom-buspirate_write_256/flash.h (Revision 929) +++ flashrom-buspirate_write_256/flash.h (Arbeitskopie) @@ -504,6 +504,7 @@ 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); Index: flashrom-buspirate_write_256/buspirate_spi.c =================================================================== --- flashrom-buspirate_write_256/buspirate_spi.c (Revision 929) +++ flashrom-buspirate_write_256/buspirate_spi.c (Arbeitskopie) @@ -316,4 +316,39 @@ 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; +} Index: flashrom-buspirate_write_256/spi.c =================================================================== --- flashrom-buspirate_write_256/spi.c (Revision 929) +++ flashrom-buspirate_write_256/spi.c (Arbeitskopie) @@ -108,7 +108,7 @@ .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
On 3/9/10 4:55 PM, Carl-Daniel Hailfinger wrote:
On 10.03.2010 01:44, Carl-Daniel Hailfinger wrote:
I found this in the Bus Pirate forum, apparently written by Patrick Georgi.
There was one bug: Writes are not allowed to cross a page boundary. Given that we want to finish the generic chunked write sometime soon, the patch below (which I shamelessly copied from ft2232spi.c) reduces write size to 8 and should work for all currently supported SPI chips.
Signed-off-by: Carl-Daniel Hailfingerc-d.hailfinger.devel.2006@gmx.net
Acked-by: Sean Nelson audiohacked@gmail.com
On 21.03.2010 03:40, Sean Nelson wrote:
On 3/9/10 4:55 PM, Carl-Daniel Hailfinger wrote:
Writes are not allowed to cross a page boundary. Given that we want to finish the generic chunked write sometime soon, the patch below (which I shamelessly copied from ft2232spi.c) reduces write size to 8 and should work for all currently supported SPI chips.
Signed-off-by: Carl-Daniel Hailfingerc-d.hailfinger.devel.2006@gmx.net
Acked-by: Sean Nelson audiohacked@gmail.com
Thanks, r964.
Regards, Carl-Daniel