Replace calls to chip_readb in a loop with chip_readn in jedec.c.

Signed-off-by: Urja Rannikko <[email protected]>

---

patch inlined too:
Index: jedec.c
===================================================================
--- jedec.c     (revision 580)
+++ jedec.c     (working copy)
@@ -21,6 +21,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */

+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include "flash.h"

 #define MAX_REFLASH_TRIES 0x10
@@ -251,6 +254,7 @@
        int i, tried = 0, start_index = 0, ok;
        chipaddr d = dst;
        uint8_t *s = src;
+       uint8_t *tmpbuf = NULL;

 retry:
        /* Issue JEDEC Data Unprotect comand */
@@ -272,14 +276,14 @@
        dst = d;
        src = s;
        ok = 1;
-       for (i = 0; i < page_size; i++) {
-               if (chip_readb(dst) != *src) {
-                       ok = 0;
-                       break;
+       tmpbuf = malloc(page_size);
+       if (!tmpbuf) {
+               fprintf(stderr,"Error: cannot allocate memory\n");
+               exit(1);
                }
-               dst++;
-               src++;
-       }
+       chip_readn(tmpbuf,dst,page_size);
+       if (memcmp(tmpbuf,src,page_size) != 0) ok = 0;
+       free(tmpbuf);

        if (!ok && tried++ < MAX_REFLASH_TRIES) {
                start_index = i;
@@ -341,15 +345,29 @@
        int total_size = flash->total_size * 1024;
        int page_size = flash->page_size;
        chipaddr bios = flash->virtual_memory;
+       uint8_t *tmpbuf;

        erase_chip_jedec(flash);
        // dumb check if erase was successful.
-       for (i = 0; i < total_size; i++) {
-               if (chip_readb(bios + i) != 0xff) {
-                       printf("ERASE FAILED @%d, val %02x!\n", i, 
chip_readb(bios + i));
-                       return -1;
+       // We'll do that in page_size chunks to detect failure earlier on slow 
links
+
+       tmpbuf = malloc(page_size);
+       if (!tmpbuf) {
+               fprintf(stderr,"Error: cannot allocate memory\n");
+               exit(1);
                }
+       for (i = 0; i < total_size; i+=page_size) {
+               int n;
+               chip_readn(tmpbuf,bios+i,page_size);
+               for(n=0;n<page_size;n++) {
+                       if (tmpbuf[n] != 0xff) {
+                               printf("ERASE FAILED @%d, val %02x!\n", i+n, 
tmpbuf[n]);
+                               free(tmpbuf);
+                               return -1;
+                       }
+               }
        }
+       free(tmpbuf);

        printf("Programming page: ");
        for (i = 0; i < total_size / page_size; i++) {

-- 
urjaman

Attachment: jedec_readb_to_readn.patch
Description: Binary data

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

Reply via email to