mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-29 16:03:47 +02:00
Fix eraseblock walking and add a few more checks to make sure such bugs get caught in the future
I found this bug during a code review. A consistency check for eraseblock definitions has been merged as well. Corresponding to flashrom svn r800. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com>
This commit is contained in:
parent
5d5c072422
commit
9d48916de6
27
flashrom.c
27
flashrom.c
@ -806,10 +806,11 @@ int read_flash(struct flashchip *flash, char *filename)
|
|||||||
int erase_flash(struct flashchip *flash)
|
int erase_flash(struct flashchip *flash)
|
||||||
{
|
{
|
||||||
int i, j, k, ret = 0, found = 0;
|
int i, j, k, ret = 0, found = 0;
|
||||||
|
unsigned int start, len;
|
||||||
|
|
||||||
printf("Erasing flash chip... ");
|
printf("Erasing flash chip... ");
|
||||||
for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
|
for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
|
||||||
unsigned long done = 0;
|
unsigned int done = 0;
|
||||||
struct block_eraser eraser = flash->block_erasers[k];
|
struct block_eraser eraser = flash->block_erasers[k];
|
||||||
|
|
||||||
printf_debug("Looking at blockwise erase function %i... ", k);
|
printf_debug("Looking at blockwise erase function %i... ", k);
|
||||||
@ -833,17 +834,39 @@ int erase_flash(struct flashchip *flash)
|
|||||||
found = 1;
|
found = 1;
|
||||||
printf_debug("trying... ");
|
printf_debug("trying... ");
|
||||||
for (i = 0; i < NUM_ERASEREGIONS; i++) {
|
for (i = 0; i < NUM_ERASEREGIONS; i++) {
|
||||||
|
/* Blocks with zero size are bugs in flashchips.c.
|
||||||
|
* FIXME: This check should be performed on startup.
|
||||||
|
*/
|
||||||
|
if (eraser.eraseblocks[i].count &&
|
||||||
|
!eraser.eraseblocks[i].size) {
|
||||||
|
fprintf(stderr, "ERROR: Erase region with size "
|
||||||
|
"0 for this chip. Please report a bug "
|
||||||
|
"at flashrom@flashrom.org\n");
|
||||||
|
ret = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* count==0 for all automatically initialized array
|
/* count==0 for all automatically initialized array
|
||||||
* members so the loop below won't be executed for them.
|
* members so the loop below won't be executed for them.
|
||||||
*/
|
*/
|
||||||
for (j = 0; j < eraser.eraseblocks[i].count; j++) {
|
for (j = 0; j < eraser.eraseblocks[i].count; j++) {
|
||||||
ret = eraser.block_erase(flash, done + eraser.eraseblocks[i].size * j, eraser.eraseblocks[i].size);
|
start = done + eraser.eraseblocks[i].size * j;
|
||||||
|
len = eraser.eraseblocks[i].size;
|
||||||
|
printf_debug("0x%06x-0x%06x, ", start,
|
||||||
|
start + len - 1);
|
||||||
|
ret = eraser.block_erase(flash, start, len);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
|
done += eraser.eraseblocks[i].count *
|
||||||
|
eraser.eraseblocks[i].size;
|
||||||
}
|
}
|
||||||
|
printf_debug("\n");
|
||||||
|
if (done != flash->total_size * 1024)
|
||||||
|
fprintf(stderr, "ERROR: Erase region walking erased "
|
||||||
|
"0x%06x bytes total, expected 0x%06x bytes.",
|
||||||
|
done, flash->total_size * 1024);
|
||||||
/* If everything is OK, don't try another erase function. */
|
/* If everything is OK, don't try another erase function. */
|
||||||
if (!ret)
|
if (!ret)
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user