Replace calls to chip_readb in a loop with chip_readn in jedec.c.
Signed-off-by: Urja Rannikko urjaman@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++) {
On Sun, Jun 7, 2009 at 00:57, Urja Rannikkourjaman@gmail.com wrote:
Replace calls to chip_readb in a loop with chip_readn in jedec.c.
Signed-off-by: Urja Rannikko urjaman@gmail.com
ping?
Carl-Daniel, you said you have improved upon this, care to send that patch if so?
-- urjaman
On 06.06.2009 23:57, Urja Rannikko wrote:
Replace calls to chip_readb in a loop with chip_readn in jedec.c.
Signed-off-by: Urja Rannikko urjaman@gmail.com
I tried to create generic erase checking instead.
The subject of my mail was: [coreboot] [PATCH] flashrom: Check if erase worked, check return codes
Regards, Carl-Daniel