[coreboot] [flashrom] [patch] Replace chip_readb in a loop with chip_readn in jedec.c

Urja Rannikko urjaman at gmail.com
Sat Jun 6 23:57:20 CEST 2009


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

Signed-off-by: Urja Rannikko <urjaman at gmail.com>

---

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jedec_readb_to_readn.patch
Type: application/octet-stream
Size: 1950 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20090607/a5134cd2/attachment.obj>


More information about the coreboot mailing list