[LinuxBIOS] r2505 - trunk/LinuxBIOSv2/util/flashrom

svn at openbios.org svn at openbios.org
Wed Nov 22 01:29:53 CET 2006


Author: stepan
Date: 2006-11-22 01:29:51 +0100 (Wed, 22 Nov 2006)
New Revision: 2505

Modified:
   trunk/LinuxBIOSv2/util/flashrom/Makefile
   trunk/LinuxBIOSv2/util/flashrom/jedec.c
Log:
apply patch from Giampiero Giancipoli <gianci at email.it>:

Fixed write_page_write_jedec() in jedec.c. Added a check-reprogram loop
in the same function, to come around the high page write failure rate on
some boards.

This patch includes the changes suggested by Ron to simplify the control
flow.

It also includes trivial changes by me to make flashrom build on newer 
systems (libpci needs libz now). I also made a small type case compile fix
and proper return code handling in one or two places.

Signed-off-by: Giampiero Giancipoli <gianci at email.it>
Signed-off-by: Ronald G Minnich <rminnich at gmail.com>
Signed-off-by: Stefan Reinauer <stepan at coresystems.de>
Acked-by: Stefan Reinauer <stepan at coresystems.de>



Modified: trunk/LinuxBIOSv2/util/flashrom/Makefile
===================================================================
--- trunk/LinuxBIOSv2/util/flashrom/Makefile	2006-11-21 23:51:08 UTC (rev 2504)
+++ trunk/LinuxBIOSv2/util/flashrom/Makefile	2006-11-22 00:29:51 UTC (rev 2505)
@@ -10,7 +10,7 @@
 STRIP	= strip
 #CFLAGS  = -O2 -g -Wall -Werror
 CFLAGS  = -Os -Wall -Werror -DDISABLE_DOC # -DTS5300
-LDFLAGS = -lpci -static
+LDFLAGS = -lpci -lz -static 
 
 
 OBJS  = flash_enable.o udelay.o jedec.o sst28sf040.o am29f040b.o mx29f002.o  \

Modified: trunk/LinuxBIOSv2/util/flashrom/jedec.c
===================================================================
--- trunk/LinuxBIOSv2/util/flashrom/jedec.c	2006-11-21 23:51:08 UTC (rev 2504)
+++ trunk/LinuxBIOSv2/util/flashrom/jedec.c	2006-11-22 00:29:51 UTC (rev 2505)
@@ -3,6 +3,8 @@
  *
  *
  * Copyright 2000 Silicon Integrated System Corporation
+ * Copyright 2006 Giampiero Giancipoli <gianci at email.it>
+ * Copyright 2006 coresystems GmbH <info at coresystems.de>
  *
  *	This program is free software; you can redistribute it and/or modify
  *	it under the terms of the GNU General Public License as published by
@@ -29,6 +31,8 @@
 #include "jedec.h"
 #include "debug.h"
 
+#define MAX_REFLASH_TRIES 0x10
+
 int probe_jedec(struct flashchip *flash)
 {
 	volatile uint8_t *bios = flash->virt_addr;
@@ -134,34 +138,58 @@
 int write_page_write_jedec(volatile uint8_t *bios, uint8_t *src,
 			   volatile uint8_t *dst, int page_size)
 {
-	int i;
+	int i, tried = 0, start_index = 0, ok;
+	volatile uint8_t *d = dst;
+	uint8_t *s = src;
 
+retry:
 	/* Issue JEDEC Data Unprotect comand */
 	*(volatile uint8_t *) (bios + 0x5555) = 0xAA;
 	*(volatile uint8_t *) (bios + 0x2AAA) = 0x55;
 	*(volatile uint8_t *) (bios + 0x5555) = 0xA0;
 
 	/* transfer data from source to destination */
-	for (i = 0; i < page_size; i++) {
+	for (i = start_index; i < page_size; i++) {
 		/* If the data is 0xFF, don't program it */
-		if (*src == 0xFF)
-			continue;
-		*dst++ = *src++;
+		if (*src != 0xFF ) 
+			*dst = *src;
+		dst++;
+		src++;
 	}
 
 	toggle_ready_jedec(dst - 1);
 
-	return 0;
+	dst = d;
+	src = s;
+	ok = 1;
+	for (i = 0; i < page_size; i++) {
+		if ( *dst != *src ) 
+		{
+			ok = 0;
+			break;
+		}
+		dst++;
+		src++;
+	}
+		
+	if (!ok && tried++ < MAX_REFLASH_TRIES) {
+		start_index = i;
+ 		goto retry;
+ 	}
+	if (!ok) {
+		fprintf( stderr, " page %d failed!\n", (unsigned int)(d-bios)/page_size );
+	}
+	return (!ok);
 }
 
 int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
 			     volatile uint8_t *dst)
 {
-	int tried = 0;
+	int tried = 0, ok = 1;
 
 	/* If the data is 0xFF, don't program it */
 	if (*src == 0xFF) {
-		return 0;
+		return -1;
 	}
 
 retry:
@@ -174,11 +202,14 @@
 	*dst = *src;
 	toggle_ready_jedec(bios);
 
-	if (*dst != *src && tried++ < 0x10) {
+	if (*dst != *src && tried++ < MAX_REFLASH_TRIES) {
  		goto retry;
  	}
 
-	return 0;
+	if (tried >= MAX_REFLASH_TRIES)
+		ok=0;
+
+	return (!ok);
 }
 
 int write_sector_jedec(volatile uint8_t *bios, uint8_t *src,
@@ -202,10 +233,14 @@
 	volatile uint8_t *bios = flash->virt_addr;
 
 	erase_chip_jedec(flash);
-	if (*bios != (uint8_t) 0xff) {
-		printf("ERASE FAILED\n");
-		return -1;
-	}
+        // dumb check if erase was successful.
+        for (i=0; i < total_size; i++) {
+                if (bios[i] != (uint8_t)0xff) {
+                        printf("ERASE FAILED\n");
+                        return -1;
+                }
+        }
+
 	printf("Programming Page: ");
 	for (i = 0; i < total_size / page_size; i++) {
 		printf("%04d at address: 0x%08x", i, i * page_size);





More information about the coreboot mailing list