Use improved abstraction for verify_range(). The new abstraction can handle out-of-band chip communication protocols as well. Check SPI chip erase results with check_erased_range().
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-check_erased_range_use_flash_read/spi.c =================================================================== --- flashrom-check_erased_range_use_flash_read/spi.c (Revision 602) +++ flashrom-check_erased_range_use_flash_read/spi.c (Arbeitskopie) @@ -430,6 +430,10 @@ /* FIXME: We assume spi_read_status_register will never fail. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); + if (check_erased_range(flash, 0, flash->total_size * 1024)) { + fprintf(stderr, "ERASE FAILED!\n"); + return -1; + } return 0; }
@@ -458,6 +462,10 @@ /* FIXME: We assume spi_read_status_register will never fail. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); + if (check_erased_range(flash, 0, flash->total_size * 1024)) { + fprintf(stderr, "ERASE FAILED!\n"); + return -1; + } return 0; }
Index: flashrom-check_erased_range_use_flash_read/flashrom.c =================================================================== --- flashrom-check_erased_range_use_flash_read/flashrom.c (Revision 602) +++ flashrom-check_erased_range_use_flash_read/flashrom.c (Arbeitskopie) @@ -262,7 +262,6 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message) { int i, j, starthere, lenhere, ret = 0; - chipaddr bios = flash->virtual_memory; int page_size = flash->page_size; uint8_t *readbuf = malloc(page_size);
@@ -298,7 +297,7 @@ starthere = max(start, i * page_size); /* Length of bytes in the range in this page. */ lenhere = min(start + len, (i + 1) * page_size) - starthere; - chip_readn(readbuf, bios + starthere, lenhere); + flash->read(flash, readbuf, starthere, lenhere); for (j = 0; j < lenhere; j++) { if (cmpbuf[starthere - start + j] != readbuf[j]) { fprintf(stderr, "%s FAILED at 0x%08x! "
Updated patch.
Use correct abstraction for verify_range(). The new abstraction can handle out-of-band chip communication protocols as well. The old abstraction caused spurious false positives for erase on SPI and spurious false negatives for verify on SPI.
Make verify_flash() use verify_range().
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-check_erased_range_use_flash_read/flashrom.c =================================================================== --- flashrom-check_erased_range_use_flash_read/flashrom.c (Revision 618) +++ flashrom-check_erased_range_use_flash_read/flashrom.c (Arbeitskopie) @@ -261,13 +261,16 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message) { int i, j, starthere, lenhere, ret = 0; - chipaddr bios = flash->virtual_memory; int page_size = flash->page_size; uint8_t *readbuf = malloc(page_size);
if (!len) goto out_free;
+ if (!flash->read) { + fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n"); + return 1; + } if (!readbuf) { fprintf(stderr, "Could not allocate memory!\n"); exit(1); @@ -297,7 +300,7 @@ starthere = max(start, i * page_size); /* Length of bytes in the range in this page. */ lenhere = min(start + len, (i + 1) * page_size) - starthere; - chip_readn(readbuf, bios + starthere, lenhere); + flash->read(flash, readbuf, starthere, lenhere); for (j = 0; j < lenhere; j++) { if (cmpbuf[starthere - start + j] != readbuf[j]) { fprintf(stderr, "%s FAILED at 0x%08x! " @@ -369,44 +372,17 @@
int verify_flash(struct flashchip *flash, uint8_t *buf) { - int idx; + int ret; int total_size = flash->total_size * 1024; - uint8_t *buf2 = (uint8_t *) calloc(total_size, sizeof(char)); - if (!flash->read) { - printf("FAILED!\n"); - fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n"); - return 1; - } else - flash->read(flash, buf2, 0, total_size);
printf("Verifying flash... ");
- if (verbose) - printf("address: 0x00000000\b\b\b\b\b\b\b\b\b\b"); + ret = verify_range(flash, buf, 0, total_size, NULL);
- for (idx = 0; idx < total_size; idx++) { - if (verbose && ((idx & 0xfff) == 0xfff)) - printf("0x%08x", idx); + if (!ret) + printf("VERIFIED. \n");
- if (*(buf2 + idx) != *(buf + idx)) { - if (verbose) - printf("0x%08x FAILED!", idx); - else - printf("FAILED at 0x%08x!", idx); - printf(" Expected=0x%02x, Read=0x%02x\n", - *(buf + idx), *(buf2 + idx)); - return 1; - } - - if (verbose && ((idx & 0xfff) == 0xfff)) - printf("\b\b\b\b\b\b\b\b\b\b"); - } - if (verbose) - printf("\b\b\b\b\b\b\b\b\b\b "); - - printf("VERIFIED. \n"); - - return 0; + return ret; }
int read_flash(struct flashchip *flash, char *filename)
On Mon, Jun 22, 2009 at 11:26:54AM +0200, Carl-Daniel Hailfinger wrote:
Updated patch.
Use correct abstraction for verify_range(). The new abstraction can handle out-of-band chip communication protocols as well. The old abstraction caused spurious false positives for erase on SPI and spurious false negatives for verify on SPI.
Make verify_flash() use verify_range().
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Looks good, tested on sb600.
Uwe.
On 24.06.2009 00:17, Uwe Hermann wrote:
On Mon, Jun 22, 2009 at 11:26:54AM +0200, Carl-Daniel Hailfinger wrote:
Use correct abstraction for verify_range(). The new abstraction can handle out-of-band chip communication protocols as well. The old abstraction caused spurious false positives for erase on SPI and spurious false negatives for verify on SPI.
Make verify_flash() use verify_range().
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Looks good, tested on sb600.
Thanks, committed in r629.
Regards, Carl-Daniel