mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-29 07:53:44 +02:00
Check if erase succeeds and exit with error on failure
Flashrom used to exit 0 even if erase failed. Not anymore. Corresponding to flashrom svn r359 and coreboot v2 svn r3797. Signed-off-by: Peter Stuge <peter@stuge.se> Acked-by: Stefan Reinauer <stepan@coresystems.de>
This commit is contained in:
parent
052cdc337e
commit
f0c811dd15
21
flashrom.c
21
flashrom.c
@ -250,6 +250,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
size_t erasedbytes;
|
||||||
FILE *image;
|
FILE *image;
|
||||||
/* Probe for up to three flash chips. */
|
/* Probe for up to three flash chips. */
|
||||||
struct flashchip *flash, *flashes[3];
|
struct flashchip *flash, *flashes[3];
|
||||||
@ -533,13 +534,25 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (erase_it) {
|
if (erase_it) {
|
||||||
printf("Erasing flash chip... ");
|
printf("Erasing flash chip... ");
|
||||||
if (!flash->erase) {
|
if (NULL == flash->erase) {
|
||||||
fprintf(stderr, "Error: flashrom has no erase function for this flash chip.\n");
|
printf("FAILED!\n");
|
||||||
|
fprintf(stderr, "ERROR: flashrom has no erase function for this flash chip.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
flash->erase(flash);
|
flash->erase(flash);
|
||||||
printf("done.\n");
|
if (NULL == flash->read)
|
||||||
exit(0);
|
memcpy(buf, (const char *)flash->virtual_memory, size);
|
||||||
|
else
|
||||||
|
flash->read(flash, buf);
|
||||||
|
for (erasedbytes = 0; erasedbytes <= size; erasedbytes++)
|
||||||
|
if (0xff != buf[erasedbytes]) {
|
||||||
|
printf("FAILED!\n");
|
||||||
|
fprintf(stderr, "ERROR at 0x%08x: Expected=0xff, Read=0x%02x\n",
|
||||||
|
erasedbytes, buf[erasedbytes]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("SUCCESS.\n");
|
||||||
|
return 0;
|
||||||
} else if (read_it) {
|
} else if (read_it) {
|
||||||
if ((image = fopen(filename, "w")) == NULL) {
|
if ((image = fopen(filename, "w")) == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user