Author: stuge
Date: 2008-12-05 03:22:30 +0100 (Fri, 05 Dec 2008)
New Revision: 3797

Modified:
   trunk/util/flashrom/flashrom.c
Log:
flashrom: Check if erase succeeds and exit with error on failure.

flashrom used to exit 0 even if erase failed. Not anymore.

Signed-off-by: Peter Stuge <[EMAIL PROTECTED]>
Acked-by: Stefan Reinauer <[EMAIL PROTECTED]>


Modified: trunk/util/flashrom/flashrom.c
===================================================================
--- trunk/util/flashrom/flashrom.c      2008-12-04 23:42:36 UTC (rev 3796)
+++ trunk/util/flashrom/flashrom.c      2008-12-05 02:22:30 UTC (rev 3797)
@@ -250,6 +250,7 @@
 {
        uint8_t *buf;
        unsigned long size;
+       size_t erasedbytes;
        FILE *image;
        /* Probe for up to three flash chips. */
        struct flashchip *flash, *flashes[3];
@@ -533,13 +534,25 @@
 
        if (erase_it) {
                printf("Erasing flash chip... ");
-               if (!flash->erase) {
-                       fprintf(stderr, "Error: flashrom has no erase function 
for this flash chip.\n");
+               if (NULL == flash->erase) {
+                       printf("FAILED!\n");
+                       fprintf(stderr, "ERROR: flashrom has no erase function 
for this flash chip.\n");
                        return 1;
                }
                flash->erase(flash);
-               printf("done.\n");
-               exit(0);
+               if (NULL == flash->read)
+                       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) {
                if ((image = fopen(filename, "w")) == NULL) {
                        perror(filename);


--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to