1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-30 16:33:41 +02:00

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().

Tested by Uwe on SB600.

Corresponding to flashrom svn r629.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
This commit is contained in:
Carl-Daniel Hailfinger 2009-06-24 08:20:45 +00:00
parent 5d1f41857b
commit 23290664ed

View File

@ -276,13 +276,16 @@ int check_erased_range(struct flashchip *flash, int start, int len)
int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message) int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message)
{ {
int i, j, starthere, lenhere, ret = 0; int i, j, starthere, lenhere, ret = 0;
chipaddr bios = flash->virtual_memory;
int page_size = flash->page_size; int page_size = flash->page_size;
uint8_t *readbuf = malloc(page_size); uint8_t *readbuf = malloc(page_size);
if (!len) if (!len)
goto out_free; goto out_free;
if (!flash->read) {
fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
return 1;
}
if (!readbuf) { if (!readbuf) {
fprintf(stderr, "Could not allocate memory!\n"); fprintf(stderr, "Could not allocate memory!\n");
exit(1); exit(1);
@ -312,7 +315,7 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c
starthere = max(start, i * page_size); starthere = max(start, i * page_size);
/* Length of bytes in the range in this page. */ /* Length of bytes in the range in this page. */
lenhere = min(start + len, (i + 1) * page_size) - starthere; 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++) { for (j = 0; j < lenhere; j++) {
if (cmpbuf[starthere - start + j] != readbuf[j]) { if (cmpbuf[starthere - start + j] != readbuf[j]) {
fprintf(stderr, "%s FAILED at 0x%08x! " fprintf(stderr, "%s FAILED at 0x%08x! "
@ -384,44 +387,17 @@ notfound:
int verify_flash(struct flashchip *flash, uint8_t *buf) int verify_flash(struct flashchip *flash, uint8_t *buf)
{ {
int idx; int ret;
int total_size = flash->total_size * 1024; 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... "); printf("Verifying flash... ");
if (verbose) ret = verify_range(flash, buf, 0, total_size, NULL);
printf("address: 0x00000000\b\b\b\b\b\b\b\b\b\b");
for (idx = 0; idx < total_size; idx++) { if (!ret)
if (verbose && ((idx & 0xfff) == 0xfff)) printf("VERIFIED. \n");
printf("0x%08x", idx);
if (*(buf2 + idx) != *(buf + idx)) { return ret;
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;
} }
int read_flash(struct flashchip *flash, char *filename) int read_flash(struct flashchip *flash, char *filename)