Might help - this is how the native code does it. --- jedec.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/jedec.c b/jedec.c index 30c343f..aa32714 100644 --- a/jedec.c +++ b/jedec.c @@ -50,7 +50,14 @@ void toggle_ready_jedec_common(chipaddr dst, int delay) programmer_delay(delay); tmp2 = chip_readb(dst) & 0x40; if (tmp1 == tmp2) { - break; + /* Recheck to avoid spurious results. */ + programmer_delay(delay); + tmp1 = chip_readb(dst) & 0x40; + if (tmp1 == tmp2) + break; + msg_cdbg("Spurious toggle ready!\n"); + /* Avoid a false positive during next loop. */ + tmp2 = tmp1; } tmp1 = tmp2; } @@ -300,14 +307,16 @@ int write_byte_program_jedec_common(struct flashchip *flash, uint8_t *src, }
retry: + chip_readb(bios); /* Issue JEDEC Byte Program command */ start_program_jedec_common(flash, mask);
/* transfer data from source to destination */ chip_writeb(*src, dst); - toggle_ready_jedec(bios); + toggle_ready_jedec(dst);
if (chip_readb(dst) != *src && tried++ < MAX_REFLASH_TRIES) { + msg_cerr("Retrying the write at 0x%lx\n", dst); goto retry; }
@@ -364,7 +373,7 @@ retry: failed = verify_range(flash, src, start, page_size, NULL);
if (failed && tried++ < MAX_REFLASH_TRIES) { - msg_cerr("retrying.\n"); + msg_cerr("Retrying the write at 0x%lx\n", dst); goto retry; } if (failed) { @@ -430,20 +439,31 @@ int write_jedec_1(struct flashchip *flash, uint8_t * buf) mask = getaddrmask(flash);
programmer_delay(10); +#if 0 if (erase_flash(flash)) { msg_cerr("ERASE FAILED!\n"); return -1; } +#else + msg_cinfo("Not erasing!\n"); +#endif + msg_cinfo("Checking if the to-be-written range is already erased\n"); + if (check_erased_range(flash, 128 * 1024, 320 * 1024)) { + msg_cerr("Range 0x20000-0x6ffff is not in erased state!\n"); + return -1; + }
- msg_cinfo("Programming page: "); - for (i = 0; i < flash->total_size; i++) { + msg_cinfo("Programming 1k sized pages, starting at 128k, ending at 448k: "); + for (i = 128; i < flash->total_size - 64; i++) { if ((i & 0x3) == 0) - msg_cinfo("address: 0x%08lx", (unsigned long)i * 1024); + msg_cinfo("address: 0x%08lx,", (unsigned long)i * 1024);
write_sector_jedec_common(flash, buf + i * 1024, dst + i * 1024, 1024, mask);
+#if 0 if ((i & 0x3) == 0) msg_cinfo("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); +#endif }
msg_cinfo("DONE!\n");