Switch all flash chips to partial write. The inner write functions which handle partial write are renamed to the original name of their wrappers. The write wrappers are removed.
This patch depends on Re: [flashrom] [PATCH] Refactor remaining write wrappers Tests are appreciated.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
--- flashrom-partial_write_inner_function_cleanup_annotate/82802ab.c 2010-10-10 22:33:45.000000000 +0200 +++ flashrom-partial_write_switchover/82802ab.c 2010-10-11 14:16:48.000000000 +0200 @@ -144,7 +144,8 @@ return 0; }
-int write_page_82802ab(struct flashchip *flash, uint8_t *src, int start, int len) +/* chunksize is 1 */ +int write_82802ab(struct flashchip *flash, uint8_t *src, int start, int len) { int i; chipaddr dst = flash->virtual_memory + start; @@ -160,12 +161,6 @@ return 0; }
-/* chunksize is 1 */ -int write_82802ab(struct flashchip *flash, uint8_t *buf) -{ - return write_page_82802ab(flash, buf, 0, flash->total_size * 1024); -} - int unlock_28f004s5(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; --- flashrom-partial_write_inner_function_cleanup_annotate/chipdrivers.h 2010-10-10 22:25:29.000000000 +0200 +++ flashrom-partial_write_switchover/chipdrivers.h 2010-10-11 14:19:04.000000000 +0200 @@ -39,10 +39,8 @@ int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen); int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen); int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen); -int spi_chip_write_1(struct flashchip *flash, uint8_t *buf); -int spi_chip_write_256(struct flashchip *flash, uint8_t *buf); -int spi_chip_write_1_new(struct flashchip *flash, uint8_t *buf, int start, int len); -int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len); +int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, int start, int len); +int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len); uint8_t spi_read_status_register(void); int spi_prettyprint_status_register_at25df(struct flashchip *flash); @@ -61,16 +59,14 @@ int spi_nbyte_read(int addr, uint8_t *bytes, int len); int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize); int spi_write_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize); -int spi_aai_write_new(struct flashchip *flash, uint8_t *buf, int start, int len); -int spi_aai_write(struct flashchip *flash, uint8_t *buf); +int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len);
/* 82802ab.c */ uint8_t wait_82802ab(struct flashchip *flash); int probe_82802ab(struct flashchip *flash); int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize); -int write_82802ab(struct flashchip *flash, uint8_t *buf); +int write_82802ab(struct flashchip *flash, uint8_t *buf, int start, int len); void print_status_82802ab(uint8_t status); -int write_page_82802ab(struct flashchip *flash, uint8_t *src, int start, int len); int unlock_82802ab(struct flashchip *flash); int unlock_28f004s5(struct flashchip *flash);
@@ -81,21 +77,18 @@ int write_byte_program_jedec(chipaddr bios, uint8_t *src, chipaddr dst); int probe_jedec(struct flashchip *flash); -int write_jedec(struct flashchip *flash, uint8_t *buf); -int write_jedec_1(struct flashchip *flash, uint8_t *buf); +int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len); +int write_jedec_1(struct flashchip *flash, uint8_t *buf, int start, int len); int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int pagesize); int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize); int erase_chip_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize); -int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, int start, int len); -int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size);
/* m29f400bt.c */ int probe_m29f400bt(struct flashchip *flash); int block_erase_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len); int block_erase_chip_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len); -int write_m29f400bt(struct flashchip *flash, uint8_t *buf); +int write_m29f400bt(struct flashchip *flash, uint8_t *buf, int start, int len); void protect_m29f400bt(chipaddr bios); -int write_page_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len);
/* pm49fl00x.c */ int unlock_49fl00x(struct flashchip *flash); @@ -104,8 +97,7 @@ /* sst28sf040.c */ int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen); int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size); -int write_28sf040(struct flashchip *flash, uint8_t *buf); -int write_sector_28sf040(struct flashchip *flash, uint8_t *src, int start, int len); +int write_28sf040(struct flashchip *flash, uint8_t *buf, int start, int len); int unprotect_28sf040(struct flashchip *flash); int protect_28sf040(struct flashchip *flash);
--- flashrom-partial_write_inner_function_cleanup_annotate/flash.h 2010-10-10 18:30:10.000000000 +0200 +++ flashrom-partial_write_switchover/flash.h 2010-10-11 14:15:07.000000000 +0200 @@ -135,7 +135,7 @@
int (*printlock) (struct flashchip *flash); int (*unlock) (struct flashchip *flash); - int (*write) (struct flashchip *flash, uint8_t *buf); + int (*write) (struct flashchip *flash, uint8_t *buf, int start, int len); int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
/* Some flash devices have an additional register space. */ --- flashrom-partial_write_inner_function_cleanup_annotate/flashrom.c 2010-10-08 23:34:41.000000000 +0200 +++ flashrom-partial_write_switchover/flashrom.c 2010-10-11 14:24:06.000000000 +0200 @@ -1639,7 +1639,7 @@ return 1; } msg_cinfo("Writing flash chip... "); - ret = flash->write(flash, buf); + ret = flash->write(flash, buf, 0, flash->total_size * 1024); if (ret) { msg_cerr("FAILED!\n"); emergency_help_message(); --- flashrom-partial_write_inner_function_cleanup_annotate/jedec.c 2010-10-11 14:13:31.000000000 +0200 +++ flashrom-partial_write_switchover/jedec.c 2010-10-11 14:16:16.000000000 +0200 @@ -336,7 +336,8 @@ return failed; }
-int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, int start, int len) +/* chunksize is 1 */ +int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len) { int i, failed = 0; chipaddr dst = flash->virtual_memory + start; @@ -398,13 +399,14 @@ return failed; }
+/* chunksize is page_size */ /* * Write a part of the flash chip. * FIXME: Use the chunk code from Michael Karcher instead. * This function is a slightly modified copy of spi_write_chunked. * Each page is written separately in chunks with a maximum size of chunksize. */ -int write_jedec_pages(struct flashchip *flash, uint8_t *buf, int start, int len) +int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len) { int i, starthere, lenhere; /* FIXME: page_size is the wrong variable. We need max_writechunk_size @@ -437,18 +439,6 @@ return 0; }
-/* chunksize is page_size */ -int write_jedec(struct flashchip *flash, uint8_t *buf) -{ - return write_jedec_pages(flash, buf, 0, flash->total_size * 1024); -} - -/* chunksize is 1 */ -int write_jedec_1(struct flashchip *flash, uint8_t * buf) -{ - return write_sector_jedec_common(flash, buf, 0, flash->total_size * 1024); -} - /* erase chip with block_erase() prototype */ int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr, unsigned int blocksize) --- flashrom-partial_write_inner_function_cleanup_annotate/m29f400bt.c 2010-10-10 22:33:58.000000000 +0200 +++ flashrom-partial_write_switchover/m29f400bt.c 2010-10-11 14:19:52.000000000 +0200 @@ -27,7 +27,8 @@ 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC functions. */
-int write_page_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len) +/* chunksize is 1 */ +int write_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len) { int i; chipaddr bios = flash->virtual_memory; @@ -139,9 +140,3 @@ } return erase_m29f400bt(flash); } - -/* chunksize is 1 */ -int write_m29f400bt(struct flashchip *flash, uint8_t *buf) -{ - return write_page_m29f400bt(flash, buf, 0, flash->total_size * 1024); -} --- flashrom-partial_write_inner_function_cleanup_annotate/spi25.c 2010-10-08 23:34:42.000000000 +0200 +++ flashrom-partial_write_switchover/spi25.c 2010-10-11 14:22:43.000000000 +0200 @@ -1304,7 +1304,7 @@ * (e.g. due to size constraints in IT87* for over 512 kB) */ /* real chunksize is 1, logical chunksize is 1 */ -int spi_chip_write_1_new(struct flashchip *flash, uint8_t *buf, int start, int len) +int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, int start, int len) { int i, result = 0;
@@ -1319,12 +1319,7 @@ return 0; }
-int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) -{ - return spi_chip_write_1_new(flash, buf, 0, flash->total_size * 1024); -} - -int spi_aai_write_new(struct flashchip *flash, uint8_t *buf, int start, int len) +int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len) { uint32_t pos = start; int result; @@ -1363,7 +1358,7 @@ case SPI_CONTROLLER_WBSIO: msg_perr("%s: impossible with this SPI controller," " degrading to byte program\n", __func__); - return spi_chip_write_1_new(flash, buf, start, len); + return spi_chip_write_1(flash, buf, start, len); #endif #endif default: @@ -1415,9 +1410,3 @@ spi_write_disable(); return 0; } - -int spi_aai_write(struct flashchip *flash, uint8_t *buf) -{ - return spi_aai_write_new(flash, buf, 0, flash->total_size * 1024); -} - --- flashrom-partial_write_inner_function_cleanup_annotate/spi.c 2010-10-08 23:34:42.000000000 +0200 +++ flashrom-partial_write_switchover/spi.c 2010-10-11 14:21:30.000000000 +0200 @@ -245,7 +245,7 @@ * .write_256 = spi_chip_write_1 */ /* real chunksize is up to 256, logical chunksize is 256 */ -int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len) +int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { if (!spi_programmer[spi_controller].write_256) { msg_perr("%s called, but SPI page write is unsupported on this " @@ -257,20 +257,6 @@ return spi_programmer[spi_controller].write_256(flash, buf, start, len); }
-/* Wrapper function until the generic code is converted to partial writes. */ -int spi_chip_write_256(struct flashchip *flash, uint8_t *buf) -{ - int ret; - - msg_pinfo("Programming flash... "); - ret = spi_chip_write_256_new(flash, buf, 0, flash->total_size * 1024); - if (!ret) - msg_pinfo("done.\n"); - else - msg_pinfo("\n"); - return ret; -} - /* * Get the lowest allowed address for read accesses. This often happens to * be the lowest allowed address for all commands which take an address. --- flashrom-partial_write_inner_function_cleanup_annotate/sst28sf040.c 2010-10-10 22:40:48.000000000 +0200 +++ flashrom-partial_write_switchover/sst28sf040.c 2010-10-11 14:20:24.000000000 +0200 @@ -78,7 +78,8 @@ return 0; }
-int write_sector_28sf040(struct flashchip *flash, uint8_t *src, int start, int len) +/* chunksize is 1 */ +int write_28sf040(struct flashchip *flash, uint8_t *src, int start, int len) { int i; chipaddr bios = flash->virtual_memory; @@ -119,12 +120,6 @@ return 0; }
-/* chunksize is 1 */ -int write_28sf040(struct flashchip *flash, uint8_t *buf) -{ - return write_sector_28sf040(flash, buf, 0, flash->total_size * 1024); -} - int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) {