From 19b6945a40d17703124db0a5f3259bb8e7d6dff7 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Wed, 8 Dec 2004 02:10:33 +0000 Subject: [PATCH] add retry to write_byte_program_jedec(), 99% success rate git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1814 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/flash_and_burn/flash_rom.c | 13 ----------- util/flash_and_burn/jedec.c | 8 ++++++- util/flash_and_burn/sst_fwhub.c | 25 +++++---------------- util/flash_and_burn/sst_fwhub.h | 40 --------------------------------- 4 files changed, 12 insertions(+), 74 deletions(-) diff --git a/util/flash_and_burn/flash_rom.c b/util/flash_and_burn/flash_rom.c index c01f5314b7..bf338ccb3c 100644 --- a/util/flash_and_burn/flash_rom.c +++ b/util/flash_and_burn/flash_rom.c @@ -200,19 +200,6 @@ int main(int argc, char *argv[]) unsigned int exclude_start_position=0, exclude_end_position=0; // [x,y) char *tempstr=NULL; -#if 0 - -#if 1 - /* Keep fallback image */ - exclude_start_position = 0x60000; - exclude_end_position = 0x80000; -#else - /* Keep DMI etc. */ - exclude_start_position = 0x60000; - exclude_end_position = 0x70000; -#endif - -#endif if (argc > 1) { /* Yes, print them. */ diff --git a/util/flash_and_burn/jedec.c b/util/flash_and_burn/jedec.c index 0344b6985c..8cab944943 100644 --- a/util/flash_and_burn/jedec.c +++ b/util/flash_and_burn/jedec.c @@ -176,11 +176,14 @@ int write_page_write_jedec(volatile unsigned char *bios, unsigned char *src, int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src, volatile unsigned char *dst) { + int tried = 0; + /* If the data is 0xFF, don't program it */ if (*src == 0xFF) { return 0; } +retry: /* Issue JEDEC Byte Program command */ *(volatile unsigned char *) (bios + 0x5555) = 0xAA; *(volatile unsigned char *) (bios + 0x2AAA) = 0x55; @@ -188,9 +191,12 @@ int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src, /* transfer data from source to destination */ *dst = *src; - toggle_ready_jedec(bios); + if (*dst != *src && tried++ < 0x10) { + goto retry; + } + return 0; } diff --git a/util/flash_and_burn/sst_fwhub.c b/util/flash_and_burn/sst_fwhub.c index 71f5d33823..d9dd467095 100644 --- a/util/flash_and_burn/sst_fwhub.c +++ b/util/flash_and_burn/sst_fwhub.c @@ -79,10 +79,8 @@ int probe_sst_fwhub(struct flashchip *flash) myusec_delay(10); - // we need to mmap the write-protect space. - printf("mapping control register at %x\n", 0 - 0x400000 -size); bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - flash->fd_mem, (off_t) (0 - 0x400000 - size)); + flash->fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1)); if (bios == MAP_FAILED) { // it's this part but we can't map it ... perror("Error MMAP /dev/mem"); @@ -101,23 +99,16 @@ unsigned char wait_sst_fwhub(volatile unsigned char *bios) int erase_sst_fwhub_block(struct flashchip *flash, int offset) { - volatile unsigned char *bios = flash->virt_addr + offset; - volatile unsigned char *wrprotect = - flash->virt_addr_2 + offset + 2; + volatile unsigned char *wrprotect = flash->virt_addr_2 + offset + 2; unsigned char status; - // clear status register - printf("Erase at %p\n", bios); + //printf("Erase at %p\n", bios); // clear write protect - printf("write protect is at %p\n", (wrprotect)); - printf("write protect is 0x%x\n", *(wrprotect)); *(wrprotect) = 0; - printf("write protect is 0x%x\n", *(wrprotect)); erase_block_jedec(flash->virt_addr, offset); status = wait_sst_fwhub(flash->virt_addr); - //print_sst_fwhub_status(status); - printf("DONE BLOCK 0x%x\n", offset); + return (0); } @@ -126,11 +117,8 @@ int erase_sst_fwhub(struct flashchip *flash) int i; unsigned int total_size = flash->total_size * 1024; - printf("total_size is %d; flash->page_size is %d\n", - total_size, flash->page_size); for (i = 0; i < total_size; i += flash->page_size) erase_sst_fwhub_block(flash, i); - printf("DONE ERASE\n"); return (0); } @@ -145,7 +133,6 @@ void write_page_sst_fwhub(volatile char *bios, char *src, src++; dst++; } - } int write_sst_fwhub(struct flashchip *flash, unsigned char *buf) @@ -165,10 +152,8 @@ int write_sst_fwhub(struct flashchip *flash, unsigned char *buf) printf("%04d at address: 0x%08x", i, i * page_size); write_page_sst_fwhub(bios, buf + i * page_size, bios + i * page_size, page_size); - printf - ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } printf("\n"); - protect_sst_fwhub(bios); return (0); } diff --git a/util/flash_and_burn/sst_fwhub.h b/util/flash_and_burn/sst_fwhub.h index 3569130508..eb2b364e62 100644 --- a/util/flash_and_burn/sst_fwhub.h +++ b/util/flash_and_burn/sst_fwhub.h @@ -5,44 +5,4 @@ extern int probe_sst_fwhub(struct flashchip *flash); extern int erase_sst_fwhub(struct flashchip *flash); extern int write_sst_fwhub(struct flashchip *flash, unsigned char *buf); -extern __inline__ void toggle_ready_sst_fwhub(volatile char *dst) -{ - unsigned int i = 0; - char tmp1, tmp2; - - tmp1 = *dst & 0x40; - - while (i++ < 0xFFFFFF) { - tmp2 = *dst & 0x40; - if (tmp1 == tmp2) { - break; - } - tmp1 = tmp2; - } -} - -extern __inline__ void data_polling_sst_fwhub(volatile char *dst, char data) -{ - unsigned int i = 0; - char tmp; - - data &= 0x80; - - while (i++ < 0xFFFFFF) { - tmp = *dst & 0x80; - if (tmp == data) { - break; - } - } -} - -extern __inline__ void protect_sst_fwhub(volatile char *bios) -{ - *(volatile char *) (bios + 0x5555) = 0xAA; - *(volatile char *) (bios + 0x2AAA) = 0x55; - *(volatile char *) (bios + 0x5555) = 0xA0; - - usleep(200); -} - #endif /* !__SST_FWHUB_H__ */