>From 678648fc20347b89803abf1f787f9607a8718806 Mon Sep 17 00:00:00 2001 From: Sean Nelson Date: Wed, 24 Mar 2010 13:31:37 -0700 Subject: [PATCH 1/3] convert chips' message printing to msg_c* Signed-off-by: Sean Nelson --- 82802ab.c | 59 ++++++++++++++------------- jedec.c | 54 +++++++++++++------------- m29f400bt.c | 59 +++++++++++++-------------- sharplhf00l04.c | 22 +++++----- spi25.c | 118 +++++++++++++++++++++++++++--------------------------- sst28sf040.c | 16 ++++---- sst49lfxxxc.c | 26 ++++++------ sst_fwhub.c | 14 +++--- stm50flw0x0x.c | 29 +++++++------- w29ee011.c | 4 +- w39v040c.c | 2 +- w39v080fa.c | 28 +++++++------- 12 files changed, 215 insertions(+), 216 deletions(-) diff --git a/82802ab.c b/82802ab.c index b6bd689..99f64fe 100644 --- a/82802ab.c +++ b/82802ab.c @@ -24,72 +24,72 @@ * - URL: http://www.intel.com/design/chipsets/datashts/290658.htm * - PDF: http://download.intel.com/design/chipsets/datashts/29065804.pdf * - Order number: 290658-004 */ #include #include #include "flash.h" #include "chipdrivers.h" // I need that Berkeley bit-map printer void print_status_82802ab(uint8_t status) { - printf_debug("%s", status & 0x80 ? "Ready:" : "Busy:"); - printf_debug("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); - printf_debug("%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); - printf_debug("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); - printf_debug("%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); - printf_debug("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); - printf_debug("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); + msg_cspew("%s", status & 0x80 ? "Ready:" : "Busy:"); + msg_cspew("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); + msg_cspew("%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); + msg_cspew("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); + msg_cspew("%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); + msg_cspew("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); + msg_cspew("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); } int probe_82802ab(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; uint8_t flashcontent1, flashcontent2; /* Reset to get a clean state */ chip_writeb(0xFF, bios); programmer_delay(10); /* Enter ID mode */ chip_writeb(0x90, bios); programmer_delay(10); id1 = chip_readb(bios); id2 = chip_readb(bios + 0x01); /* Leave ID mode */ chip_writeb(0xFF, bios); programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2); + msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2); if (!oddparity(id1)) - printf_debug(", id1 parity violation"); + msg_cspew(", id1 parity violation"); /* Read the product ID location again. We should now see normal flash contents. */ flashcontent1 = chip_readb(bios); flashcontent2 = chip_readb(bios + 0x01); if (id1 == flashcontent1) - printf_debug(", id1 is normal flash content"); + msg_cspew(", id1 is normal flash content"); if (id2 == flashcontent2) - printf_debug(", id2 is normal flash content"); + msg_cspew(", id2 is normal flash content"); - printf_debug("\n"); + msg_cdbg("\n"); if (id1 != flash->manufacture_id || id2 != flash->model_id) return 0; if (flash->feature_bits & FEATURE_REGISTERMAP) map_flash_registers(flash); return 1; } uint8_t wait_82802ab(chipaddr bios) { uint8_t status; @@ -127,145 +127,146 @@ int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int // clear status register chip_writeb(0x50, bios + page); // now start it chip_writeb(0x20, bios + page); chip_writeb(0xd0, bios + page); programmer_delay(10); // now let's see what the register is status = wait_82802ab(bios); print_status_82802ab(status); if (check_erased_range(flash, page, pagesize)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("DONE BLOCK 0x%x\n", page); + msg_cinfo("DONE BLOCK 0x%x\n", page); return 0; } int erase_82802ab(struct flashchip *flash) { int i; unsigned int total_size = flash->total_size * 1024; - printf("total_size is %d; flash->page_size is %d\n", + msg_cspew("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) if (erase_block_82802ab(flash, i, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("DONE ERASE\n"); + msg_cinfo("DONE ERASE\n"); return 0; } void write_page_82802ab(chipaddr bios, uint8_t *src, chipaddr dst, int page_size) { int i; for (i = 0; i < page_size; i++) { /* transfer data from source to destination */ chip_writeb(0x40, dst); chip_writeb(*src++, dst++); wait_82802ab(bios); } } int write_82802ab(struct flashchip *flash, uint8_t *buf) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; uint8_t *tmpbuf = malloc(page_size); if (!tmpbuf) { - printf("Could not allocate memory!\n"); + msg_cerr("Could not allocate memory!\n"); exit(1); } - printf("Programming page: \n"); + msg_cinfo("Programming page: \n"); for (i = 0; i < total_size / page_size; i++) { - 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("%04d at address: 0x%08x", i, i * page_size); + msg_cdbg("\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"); + msg_cdbg("%04d at address: 0x%08x", i, i * page_size); /* Auto Skip Blocks, which already contain the desired data * Faster, because we only write, what has changed * More secure, because blocks, which are excluded * (with the exclude or layout feature) * or not erased and rewritten; their data is retained also in * sudden power off situations */ chip_readn(tmpbuf, bios + i * page_size, page_size); if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) { - printf("SKIPPED\n"); + msg_cspew("SKIPPED\n"); continue; } /* erase block by block and write block by block; this is the most secure way */ if (erase_block_82802ab(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_82802ab(bios, buf + i * page_size, bios + i * page_size, page_size); } - printf("\n"); + msg_cinfo("DONE!\n"); free(tmpbuf); return 0; } int unlock_28f004s5(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0; int i; /* Clear status register */ chip_writeb(0x50, bios); /* Read identifier codes */ chip_writeb(0x90, bios); /* Read master lock-bit */ mcfg = chip_readb(bios + 0x3); - msg_cinfo("master lock is "); + msg_cspew("master lock is "); if (mcfg) { - msg_cdbg("locked!\n"); + msg_cspew("locked!\n"); } else { - msg_cdbg("unlocked!\n"); + msg_cspew("unlocked!\n"); can_unlock = 1; } /* Read block lock-bits */ for (i = 0; i < flash->total_size * 1024; i+= (64 * 1024)) { bcfg = chip_readb(bios + i + 2); // read block lock config - msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un"); + msg_cspew("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un"); if (bcfg) { need_unlock = 1; } } /* Reset chip */ chip_writeb(0xFF, bios); /* Unlock: clear block lock-bits, if needed */ if (can_unlock && need_unlock) { + msg_cinfo("Unlock: "); chip_writeb(0x60, bios); chip_writeb(0xD0, bios); chip_writeb(0xFF, bios); + msg_cinfo("Done!\n"); } /* Error: master locked or a block is locked */ if (!can_unlock && need_unlock) { msg_cerr("At least one block is locked and lockdown is active!\n"); return -1; } return 0; } diff --git a/jedec.c b/jedec.c index fee7302..fbea35f 100644 --- a/jedec.c +++ b/jedec.c @@ -45,27 +45,27 @@ void toggle_ready_jedec_common(chipaddr dst, int delay) tmp1 = chip_readb(dst) & 0x40; while (i++ < 0xFFFFFFF) { if (delay) programmer_delay(delay); tmp2 = chip_readb(dst) & 0x40; if (tmp1 == tmp2) { break; } tmp1 = tmp2; } if (i > 0x100000) - printf_debug("%s: excessive loops, i=0x%x\n", __func__, i); + msg_cdbg("%s: excessive loops, i=0x%x\n", __func__, i); } void toggle_ready_jedec(chipaddr dst) { toggle_ready_jedec_common(dst, 0); } /* Some chips require a minimum delay between toggle bit reads. * The Winbond W39V040C wants 50 ms between reads on sector erase toggle, * but experiments show that 2 ms are already enough. Pick a safety factor * of 4 and use an 8 ms delay. * Given that erase is slow on all chips, it is recommended to use * toggle_ready_jedec_slow in erase functions. @@ -79,56 +79,56 @@ void data_polling_jedec(chipaddr dst, uint8_t data) { unsigned int i = 0; uint8_t tmp; data &= 0x80; while (i++ < 0xFFFFFFF) { tmp = chip_readb(dst) & 0x80; if (tmp == data) { break; } } if (i > 0x100000) - printf_debug("%s: excessive loops, i=0x%x\n", __func__, i); + msg_cdbg("%s: excessive loops, i=0x%x\n", __func__, i); } void start_program_jedec_common(struct flashchip *flash, unsigned int mask) { chipaddr bios = flash->virtual_memory; chip_writeb(0xAA, bios + (0x5555 & mask)); chip_writeb(0x55, bios + (0x2AAA & mask)); chip_writeb(0xA0, bios + (0x5555 & mask)); } int probe_jedec_common(struct flashchip *flash, unsigned int mask) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; uint32_t largeid1, largeid2; uint32_t flashcontent1, flashcontent2; int probe_timing_enter, probe_timing_exit; if (flash->probe_timing > 0) probe_timing_enter = probe_timing_exit = flash->probe_timing; else if (flash->probe_timing == TIMING_ZERO) { /* No delay. */ probe_timing_enter = probe_timing_exit = 0; } else if (flash->probe_timing == TIMING_FIXME) { /* == _IGNORED */ - printf_debug("Chip lacks correct probe timing information, " + msg_cdbg("Chip lacks correct probe timing information, " "using default 10mS/40uS. "); probe_timing_enter = 10000; probe_timing_exit = 40; } else { - printf("Chip has negative value in probe_timing, failing " + msg_cdbg("Chip has negative value in probe_timing, failing " "without chip access\n"); return 0; } /* Issue JEDEC Product ID Entry command */ chip_writeb(0xAA, bios + (0x5555 & mask)); if (probe_timing_enter) programmer_delay(10); chip_writeb(0x55, bios + (0x2AAA & mask)); if (probe_timing_enter) programmer_delay(10); chip_writeb(0x90, bios + (0x5555 & mask)); if (probe_timing_enter) @@ -156,50 +156,50 @@ int probe_jedec_common(struct flashchip *flash, unsigned int mask) if ((flash->feature_bits & FEATURE_SHORT_RESET) == FEATURE_LONG_RESET) { chip_writeb(0xAA, bios + (0x5555 & mask)); if (probe_timing_exit) programmer_delay(10); chip_writeb(0x55, bios + (0x2AAA & mask)); if (probe_timing_exit) programmer_delay(10); } chip_writeb(0xF0, bios + (0x5555 & mask)); if (probe_timing_exit) programmer_delay(probe_timing_exit); - printf_debug("%s: id1 0x%02x, id2 0x%02x", __func__, largeid1, largeid2); + msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, largeid1, largeid2); if (!oddparity(id1)) - printf_debug(", id1 parity violation"); + msg_cdbg(", id1 parity violation"); /* Read the product ID location again. We should now see normal flash contents. */ flashcontent1 = chip_readb(bios); flashcontent2 = chip_readb(bios + 0x01); /* Check if it is a continuation ID, this should be a while loop. */ if (flashcontent1 == 0x7F) { flashcontent1 <<= 8; flashcontent1 |= chip_readb(bios + 0x100); } if (flashcontent2 == 0x7F) { flashcontent2 <<= 8; flashcontent2 |= chip_readb(bios + 0x101); } if (largeid1 == flashcontent1) - printf_debug(", id1 is normal flash content"); + msg_cdbg(", id1 is normal flash content"); if (largeid2 == flashcontent2) - printf_debug(", id2 is normal flash content"); + msg_cdbg(", id2 is normal flash content"); - printf_debug("\n"); + msg_cdbg("\n"); if (largeid1 != flash->manufacture_id || largeid2 != flash->model_id) return 0; if (flash->feature_bits & FEATURE_REGISTERMAP) map_flash_registers(flash); return 1; } int erase_sector_jedec_common(struct flashchip *flash, unsigned int page, unsigned int pagesize, unsigned int mask) { chipaddr bios = flash->virtual_memory; @@ -213,27 +213,27 @@ int erase_sector_jedec_common(struct flashchip *flash, unsigned int page, programmer_delay(10); chip_writeb(0xAA, bios + (0x5555 & mask)); programmer_delay(10); chip_writeb(0x55, bios + (0x2AAA & mask)); programmer_delay(10); chip_writeb(0x30, bios + page); programmer_delay(10); /* wait for Toggle bit ready */ toggle_ready_jedec_slow(bios); if (check_erased_range(flash, page, pagesize)) { - fprintf(stderr,"ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int erase_block_jedec_common(struct flashchip *flash, unsigned int block, unsigned int blocksize, unsigned int mask) { chipaddr bios = flash->virtual_memory; /* Issue the Sector Erase command */ chip_writeb(0xAA, bios + (0x5555 & mask)); programmer_delay(10); @@ -243,27 +243,27 @@ int erase_block_jedec_common(struct flashchip *flash, unsigned int block, programmer_delay(10); chip_writeb(0xAA, bios + (0x5555 & mask)); programmer_delay(10); chip_writeb(0x55, bios + (0x2AAA & mask)); programmer_delay(10); chip_writeb(0x50, bios + block); programmer_delay(10); /* wait for Toggle bit ready */ toggle_ready_jedec_slow(bios); if (check_erased_range(flash, block, blocksize)) { - fprintf(stderr,"ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int erase_chip_jedec_common(struct flashchip *flash, unsigned int mask) { int total_size = flash->total_size * 1024; chipaddr bios = flash->virtual_memory; /* Issue the JEDEC Chip Erase command */ chip_writeb(0xAA, bios + (0x5555 & mask)); programmer_delay(10); @@ -272,27 +272,27 @@ int erase_chip_jedec_common(struct flashchip *flash, unsigned int mask) chip_writeb(0x80, bios + (0x5555 & mask)); programmer_delay(10); chip_writeb(0xAA, bios + (0x5555 & mask)); programmer_delay(10); chip_writeb(0x55, bios + (0x2AAA & mask)); programmer_delay(10); chip_writeb(0x10, bios + (0x5555 & mask)); programmer_delay(10); toggle_ready_jedec_slow(bios); if (check_erased_range(flash, 0, total_size)) { - fprintf(stderr,"ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int write_byte_program_jedec_common(struct flashchip *flash, uint8_t *src, chipaddr dst, unsigned int mask) { int tried = 0, failed = 0; chipaddr bios = flash->virtual_memory; /* If the data is 0xFF, don't program it and don't complain. */ if (*src == 0xFF) { @@ -320,27 +320,27 @@ retry: int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, chipaddr dst, unsigned int page_size, unsigned int mask) { int i, failed = 0; chipaddr olddst; olddst = dst; for (i = 0; i < page_size; i++) { if (write_byte_program_jedec_common(flash, src, dst, mask)) failed = 1; dst++, src++; } if (failed) - fprintf(stderr, " writing sector at 0x%lx failed!\n", olddst); + msg_cdbg(" writing sector at 0x%lx failed!\n", olddst); return failed; } int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size, unsigned int mask) { int i, tried = 0, failed; uint8_t *s = src; chipaddr bios = flash->virtual_memory; chipaddr dst = bios + start; chipaddr d = dst; @@ -354,121 +354,121 @@ retry: if (*src != 0xFF) chip_writeb(*src, dst); dst++; src++; } toggle_ready_jedec(dst - 1); dst = d; src = s; failed = verify_range(flash, src, start, page_size, NULL); if (failed && tried++ < MAX_REFLASH_TRIES) { - fprintf(stderr, "retrying.\n"); + msg_cdbg("retrying.\n"); goto retry; } if (failed) { - fprintf(stderr, " page 0x%lx failed!\n", + msg_cdbg(" page 0x%lx failed!\n", (d - bios) / page_size); } return failed; } int getaddrmask(struct flashchip *flash) { switch (flash->feature_bits & FEATURE_ADDR_MASK) { case FEATURE_ADDR_FULL: return MASK_FULL; break; case FEATURE_ADDR_2AA: return MASK_2AA; break; case FEATURE_ADDR_AAA: return MASK_AAA; break; default: - fprintf(stderr, "%s called with unknown mask\n", __func__); + msg_cerr("%s called with unknown mask\n", __func__); return 0; break; } } int write_jedec(struct flashchip *flash, uint8_t *buf) { int mask; int i, failed = 0; int total_size = flash->total_size * 1024; int page_size = flash->page_size; mask = getaddrmask(flash); if (erase_chip_jedec(flash)) { - fprintf(stderr,"ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + msg_cinfo("Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + msg_cdbg("%04d at address: 0x%08x", i, i * page_size); if (write_page_write_jedec_common(flash, buf + i * page_size, i * page_size, page_size, mask)) failed = 1; - 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"); + msg_cdbg("\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"); + msg_cinfo("DONE!\n"); return failed; } int write_jedec_1(struct flashchip *flash, uint8_t * buf) { int i; chipaddr bios = flash->virtual_memory; chipaddr dst = bios; int mask; mask = getaddrmask(flash); programmer_delay(10); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + msg_cinfo("Programming page: "); for (i = 0; i < flash->total_size; i++) { if ((i & 0x3) == 0) - printf("address: 0x%08lx", (unsigned long)i * 1024); + msg_cdbg("address: 0x%08lx", (unsigned long)i * 1024); write_sector_jedec_common(flash, buf + i * 1024, dst + i * 1024, 1024, mask); if ((i & 0x3) == 0) - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + msg_cdbg("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + msg_cinfo("DONE!\n"); return 0; } /* erase chip with block_erase() prototype */ int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr, unsigned int blocksize) { int mask; mask = getaddrmask(flash); if ((addr != 0) || (blocksize != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } return erase_chip_jedec_common(flash, mask); } int probe_jedec(struct flashchip *flash) { int mask; mask = getaddrmask(flash); return probe_jedec_common(flash, mask); } diff --git a/m29f400bt.c b/m29f400bt.c index c394074..ec97386 100644 --- a/m29f400bt.c +++ b/m29f400bt.c @@ -32,28 +32,27 @@ void write_page_m29f400bt(chipaddr bios, uint8_t *src, { int i; for (i = 0; i < page_size; i++) { chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); chip_writeb(0xA0, bios + 0xAAA); /* transfer data from source to destination */ chip_writeb(*src, dst); //chip_writeb(0xF0, bios); //programmer_delay(5); toggle_ready_jedec(dst); - printf - ("Value in the flash at address 0x%lx = %#x, want %#x\n", + msg_cinfo("Value in the flash at address 0x%lx = %#x, want %#x\n", (dst - bios), chip_readb(dst), *src); dst++; src++; } } int probe_m29f400bt(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); @@ -63,198 +62,198 @@ int probe_m29f400bt(struct flashchip *flash) id1 = chip_readb(bios); /* The data sheet says id2 is at (bios + 0x01) and id2 listed in * flash.h does not match. It should be possible to use JEDEC probe. */ id2 = chip_readb(bios + 0x02); chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); chip_writeb(0xF0, bios + 0xAAA); programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; return 0; } int erase_m29f400bt(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); chip_writeb(0x80, bios + 0xAAA); chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); chip_writeb(0x10, bios + 0xAAA); programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int block_erase_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len) { chipaddr bios = flash->virtual_memory; chipaddr dst = bios + start; chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); chip_writeb(0x80, bios + 0xAAA); chip_writeb(0xAA, bios + 0xAAA); chip_writeb(0x55, bios + 0x555); //chip_writeb(0x10, bios + 0xAAA); chip_writeb(0x30, dst); programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, start, len)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int block_erase_chip_m29f400bt(struct flashchip *flash, unsigned int address, unsigned int blocklen) { if ((address != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } return erase_m29f400bt(flash); } int write_m29f400bt(struct flashchip *flash, uint8_t *buf) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; //erase_m29f400bt (flash); - printf("Programming page:\n "); + msg_cinfo("Programming page:\n "); /********************************* *Pages for M29F400BT: * 16 0x7c000 0x7ffff TOP * 8 0x7a000 0x7bfff * 8 0x78000 0x79fff * 32 0x70000 0x77fff * 64 0x60000 0x6ffff * 64 0x50000 0x5ffff * 64 0x40000 0x4ffff *--------------------------------- * 64 0x30000 0x3ffff * 64 0x20000 0x2ffff * 64 0x10000 0x1ffff * 64 0x00000 0x0ffff BOTTOM *********************************/ - printf("total_size/page_size = %d\n", total_size / page_size); + msg_cinfo("total_size/page_size = %d\n", total_size / page_size); for (i = 0; i < (total_size / page_size) - 1; i++) { - printf("%04d at address: 0x%08x\n", i, i * page_size); + msg_cinfo("%04d at address: 0x%08x\n", i, i * page_size); if (block_erase_m29f400bt(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(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"); + msg_cinfo("\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("%04d at address: 0x%08x\n", 7, 0x70000); + msg_cinfo("%04d at address: 0x%08x\n", 7, 0x70000); if (block_erase_m29f400bt(flash, 0x70000, 32 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024); - printf("%04d at address: 0x%08x\n", 8, 0x78000); + msg_cinfo("%04d at address: 0x%08x\n", 8, 0x78000); if (block_erase_m29f400bt(flash, 0x78000, 8 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024); - printf("%04d at address: 0x%08x\n", 9, 0x7a000); + msg_cinfo("%04d at address: 0x%08x\n", 9, 0x7a000); if (block_erase_m29f400bt(flash, 0x7a000, 8 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024); - printf("%04d at address: 0x%08x\n", 10, 0x7c000); + msg_cinfo("%04d at address: 0x%08x\n", 10, 0x7c000); if (block_erase_m29f400bt(flash, 0x7c000, 16 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024); - printf("\n"); + msg_cinfo("\n"); return 0; } int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf) { chipaddr bios = flash->virtual_memory; - printf("Programming page:\n "); + msg_cinfo("Programming page:\n "); /********************************* *Pages for M29F400BT: * 16 0x7c000 0x7ffff TOP * 8 0x7a000 0x7bfff * 8 0x78000 0x79fff * 32 0x70000 0x77fff * 64 0x60000 0x6ffff * 64 0x50000 0x5ffff * 64 0x40000 0x4ffff *--------------------------------- * 64 0x30000 0x3ffff * 64 0x20000 0x2ffff * 64 0x10000 0x1ffff * 64 0x00000 0x0ffff BOTTOM *********************************/ - printf("%04d at address: 0x%08x\n", 7, 0x00000); + msg_cinfo("%04d at address: 0x%08x\n", 7, 0x00000); if (block_erase_m29f400bt(flash, 0x00000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x10000); + msg_cinfo("%04d at address: 0x%08x\n", 7, 0x10000); if (block_erase_m29f400bt(flash, 0x10000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x20000); + msg_cinfo("%04d at address: 0x%08x\n", 7, 0x20000); if (block_erase_m29f400bt(flash, 0x20000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x30000); + msg_cinfo("%04d at address: 0x%08x\n", 7, 0x30000); if (block_erase_m29f400bt(flash, 0x30000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024); - printf("\n"); + msg_cinfo("\n"); return 0; } diff --git a/sharplhf00l04.c b/sharplhf00l04.c index 3f5cf3d..e8a9cdf 100644 --- a/sharplhf00l04.c +++ b/sharplhf00l04.c @@ -24,60 +24,60 @@ /* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec * or wait_82802ab. */ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen) { chipaddr bios = flash->virtual_memory + blockaddr; chipaddr wrprotect = flash->virtual_registers + blockaddr + 2; uint8_t status; // clear status register chip_writeb(0x50, bios); - printf("Erase at 0x%lx\n", bios); + msg_cinfo("Erase at 0x%lx\n", bios); status = wait_82802ab(flash->virtual_memory); print_status_82802ab(status); // clear write protect - printf("write protect is at 0x%lx\n", (wrprotect)); - printf("write protect is 0x%x\n", chip_readb(wrprotect)); + msg_cinfo("write protect is at 0x%lx\n", (wrprotect)); + msg_cinfo("write protect is 0x%x\n", chip_readb(wrprotect)); chip_writeb(0, wrprotect); - printf("write protect is 0x%x\n", chip_readb(wrprotect)); + msg_cinfo("write protect is 0x%x\n", chip_readb(wrprotect)); // now start it chip_writeb(0x20, bios); chip_writeb(0xd0, bios); programmer_delay(10); // now let's see what the register is status = wait_82802ab(flash->virtual_memory); print_status_82802ab(status); - printf("DONE BLOCK 0x%x\n", blockaddr); + msg_cinfo("DONE BLOCK 0x%x\n", blockaddr); if (check_erased_range(flash, blockaddr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int write_lhf00l04(struct flashchip *flash, uint8_t *buf) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + msg_cinfo("Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + msg_cinfo("%04d at address: 0x%08x", i, i * page_size); write_page_82802ab(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"); + msg_cinfo("\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"); + msg_cinfo("\n"); return 0; } diff --git a/spi25.c b/spi25.c index 54121b0..7253c53 100644 --- a/spi25.c +++ b/spi25.c @@ -29,125 +29,125 @@ #include "spi.h" void spi_prettyprint_status_register(struct flashchip *flash); static int spi_rdid(unsigned char *readarr, int bytes) { const unsigned char cmd[JEDEC_RDID_OUTSIZE] = { JEDEC_RDID }; int ret; int i; ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr); if (ret) return ret; - printf_debug("RDID returned"); + msg_cdbg("RDID returned"); for (i = 0; i < bytes; i++) - printf_debug(" 0x%02x", readarr[i]); - printf_debug(". "); + msg_cdbg(" 0x%02x", readarr[i]); + msg_cdbg(". "); return 0; } static int spi_rems(unsigned char *readarr) { unsigned char cmd[JEDEC_REMS_OUTSIZE] = { JEDEC_REMS, 0, 0, 0 }; uint32_t readaddr; int ret; ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr); if (ret == SPI_INVALID_ADDRESS) { /* Find the lowest even address allowed for reads. */ readaddr = (spi_get_valid_read_addr() + 1) & ~1; cmd[1] = (readaddr >> 16) & 0xff, cmd[2] = (readaddr >> 8) & 0xff, cmd[3] = (readaddr >> 0) & 0xff, ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr); } if (ret) return ret; - printf_debug("REMS returned %02x %02x. ", readarr[0], readarr[1]); + msg_cdbg("REMS returned %02x %02x. ", readarr[0], readarr[1]); return 0; } static int spi_res(unsigned char *readarr) { unsigned char cmd[JEDEC_RES_OUTSIZE] = { JEDEC_RES, 0, 0, 0 }; uint32_t readaddr; int ret; ret = spi_send_command(sizeof(cmd), JEDEC_RES_INSIZE, cmd, readarr); if (ret == SPI_INVALID_ADDRESS) { /* Find the lowest even address allowed for reads. */ readaddr = (spi_get_valid_read_addr() + 1) & ~1; cmd[1] = (readaddr >> 16) & 0xff, cmd[2] = (readaddr >> 8) & 0xff, cmd[3] = (readaddr >> 0) & 0xff, ret = spi_send_command(sizeof(cmd), JEDEC_RES_INSIZE, cmd, readarr); } if (ret) return ret; - printf_debug("RES returned %02x. ", readarr[0]); + msg_cdbg("RES returned %02x. ", readarr[0]); return 0; } int spi_write_enable(void) { const unsigned char cmd[JEDEC_WREN_OUTSIZE] = { JEDEC_WREN }; int result; /* Send WREN (Write Enable) */ result = spi_send_command(sizeof(cmd), 0, cmd, NULL); if (result) - fprintf(stderr, "%s failed\n", __func__); + msg_cerr("%s failed\n", __func__); return result; } int spi_write_disable(void) { const unsigned char cmd[JEDEC_WRDI_OUTSIZE] = { JEDEC_WRDI }; /* Send WRDI (Write Disable) */ return spi_send_command(sizeof(cmd), 0, cmd, NULL); } static int probe_spi_rdid_generic(struct flashchip *flash, int bytes) { unsigned char readarr[4]; uint32_t id1; uint32_t id2; if (spi_rdid(readarr, bytes)) return 0; if (!oddparity(readarr[0])) - printf_debug("RDID byte 0 parity violation. "); + msg_cdbg("RDID byte 0 parity violation. "); /* Check if this is a continuation vendor ID */ if (readarr[0] == 0x7f) { if (!oddparity(readarr[1])) - printf_debug("RDID byte 1 parity violation. "); + msg_cdbg("RDID byte 1 parity violation. "); id1 = (readarr[0] << 8) | readarr[1]; id2 = readarr[2]; if (bytes > 3) { id2 <<= 8; id2 |= readarr[3]; } } else { id1 = readarr[0]; id2 = (readarr[1] << 8) | readarr[2]; } - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) { /* Print the status register to tell the * user about possible write protection. */ spi_prettyprint_status_register(flash); return 1; } /* Test if this is a pure vendor match. */ if (id1 == flash->manufacture_id && GENERIC_DEVICE_ID == flash->model_id) @@ -182,44 +182,44 @@ int probe_spi_rdid4(struct flashchip *flash) case SPI_CONTROLLER_FT2232: #endif #if DUMMY_SUPPORT == 1 case SPI_CONTROLLER_DUMMY: #endif #if BUSPIRATE_SPI_SUPPORT == 1 case SPI_CONTROLLER_BUSPIRATE: #endif #if DEDIPROG_SUPPORT == 1 case SPI_CONTROLLER_DEDIPROG: #endif return probe_spi_rdid_generic(flash, 4); default: - printf_debug("4b ID not supported on this SPI controller\n"); + msg_cdbg("4b ID not supported on this SPI controller\n"); } return 0; } int probe_spi_rems(struct flashchip *flash) { unsigned char readarr[JEDEC_REMS_INSIZE]; uint32_t id1, id2; if (spi_rems(readarr)) return 0; id1 = readarr[0]; id2 = readarr[1]; - printf_debug("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); + msg_cdbg("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) { /* Print the status register to tell the * user about possible write protection. */ spi_prettyprint_status_register(flash); return 1; } /* Test if this is a pure vendor match. */ if (id1 == flash->manufacture_id && GENERIC_DEVICE_ID == flash->model_id) @@ -252,130 +252,130 @@ int probe_spi_res(struct flashchip *flash) * 0x00 0x00. In that case, RES is pointless. */ if (!spi_rems(readarr) && memcmp(readarr, allff, JEDEC_REMS_INSIZE) && memcmp(readarr, all00, JEDEC_REMS_INSIZE)) { msg_cdbg("Ignoring RES in favour of REMS.\n"); return 0; } if (spi_res(readarr)) return 0; /* FIXME: Handle the case where RES gives a 2-byte response. */ id2 = readarr[0]; - printf_debug("%s: id 0x%x\n", __func__, id2); + msg_cdbg("%s: id 0x%x\n", __func__, id2); if (id2 != flash->model_id) return 0; /* Print the status register to tell the * user about possible write protection. */ spi_prettyprint_status_register(flash); return 1; } uint8_t spi_read_status_register(void) { const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR }; /* FIXME: No workarounds for driver/hardware bugs in generic code. */ unsigned char readarr[2]; /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */ int ret; /* Read Status Register */ ret = spi_send_command(sizeof(cmd), sizeof(readarr), cmd, readarr); if (ret) - fprintf(stderr, "RDSR failed!\n"); + msg_cerr("RDSR failed!\n"); return readarr[0]; } /* Prettyprint the status register. Common definitions. */ void spi_prettyprint_status_register_common(uint8_t status) { - printf_debug("Chip status register: Bit 5 / Block Protect 3 (BP3) is " + msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is " "%sset\n", (status & (1 << 5)) ? "" : "not "); - printf_debug("Chip status register: Bit 4 / Block Protect 2 (BP2) is " + msg_cdbg("Chip status register: Bit 4 / Block Protect 2 (BP2) is " "%sset\n", (status & (1 << 4)) ? "" : "not "); - printf_debug("Chip status register: Bit 3 / Block Protect 1 (BP1) is " + msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is " "%sset\n", (status & (1 << 3)) ? "" : "not "); - printf_debug("Chip status register: Bit 2 / Block Protect 0 (BP0) is " + msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is " "%sset\n", (status & (1 << 2)) ? "" : "not "); - printf_debug("Chip status register: Write Enable Latch (WEL) is " + msg_cdbg("Chip status register: Write Enable Latch (WEL) is " "%sset\n", (status & (1 << 1)) ? "" : "not "); - printf_debug("Chip status register: Write In Progress (WIP/BUSY) is " + msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is " "%sset\n", (status & (1 << 0)) ? "" : "not "); } /* Prettyprint the status register. Works for * ST M25P series * MX MX25L series */ void spi_prettyprint_status_register_st_m25p(uint8_t status) { - printf_debug("Chip status register: Status Register Write Disable " + msg_cdbg("Chip status register: Status Register Write Disable " "(SRWD) is %sset\n", (status & (1 << 7)) ? "" : "not "); - printf_debug("Chip status register: Bit 6 is " + msg_cdbg("Chip status register: Bit 6 is " "%sset\n", (status & (1 << 6)) ? "" : "not "); spi_prettyprint_status_register_common(status); } void spi_prettyprint_status_register_sst25(uint8_t status) { - printf_debug("Chip status register: Block Protect Write Disable " + msg_cdbg("Chip status register: Block Protect Write Disable " "(BPL) is %sset\n", (status & (1 << 7)) ? "" : "not "); - printf_debug("Chip status register: Auto Address Increment Programming " + msg_cdbg("Chip status register: Auto Address Increment Programming " "(AAI) is %sset\n", (status & (1 << 6)) ? "" : "not "); spi_prettyprint_status_register_common(status); } /* Prettyprint the status register. Works for * SST 25VF016 */ void spi_prettyprint_status_register_sst25vf016(uint8_t status) { const char *bpt[] = { "none", "1F0000H-1FFFFFH", "1E0000H-1FFFFFH", "1C0000H-1FFFFFH", "180000H-1FFFFFH", "100000H-1FFFFFH", "all", "all" }; spi_prettyprint_status_register_sst25(status); - printf_debug("Resulting block protection : %s\n", + msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); } void spi_prettyprint_status_register_sst25vf040b(uint8_t status) { const char *bpt[] = { "none", "0x70000-0x7ffff", "0x60000-0x7ffff", "0x40000-0x7ffff", "all blocks", "all blocks", "all blocks", "all blocks" }; spi_prettyprint_status_register_sst25(status); - printf_debug("Resulting block protection : %s\n", + msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); } void spi_prettyprint_status_register(struct flashchip *flash) { uint8_t status; status = spi_read_status_register(); - printf_debug("Chip status register is %02x\n", status); + msg_cdbg("Chip status register is %02x\n", status); switch (flash->manufacture_id) { case ST_ID: if (((flash->model_id & 0xff00) == 0x2000) || ((flash->model_id & 0xff00) == 0x2500)) spi_prettyprint_status_register_st_m25p(status); break; case MX_ID: if ((flash->model_id & 0xff00) == 0x2000) spi_prettyprint_status_register_st_m25p(status); break; case SST_ID: switch (flash->model_id) { case 0x2541: @@ -406,44 +406,44 @@ int spi_chip_erase_60(struct flashchip *flash) .writecnt = JEDEC_CE_60_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_CE_60 }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_disable_blockprotect(); if (result) { - fprintf(stderr, "spi_disable_blockprotect failed\n"); + msg_cerr("spi_disable_blockprotect failed\n"); return result; } result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", + msg_cerr("%s failed during command execution\n", __func__); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 1-85 s, so wait in 1 s steps. */ /* FIXME: We assume spi_read_status_register will never fail. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int spi_chip_erase_c7(struct flashchip *flash) { int result; struct spi_command cmds[] = { { .writecnt = JEDEC_WREN_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_WREN }, .readcnt = 0, @@ -452,54 +452,54 @@ int spi_chip_erase_c7(struct flashchip *flash) .writecnt = JEDEC_CE_C7_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_CE_C7 }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_disable_blockprotect(); if (result) { - fprintf(stderr, "spi_disable_blockprotect failed\n"); + msg_cerr("spi_disable_blockprotect failed\n"); return result; } result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", __func__); + msg_cerr("%s failed during command execution\n", __func__); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 1-85 s, so wait in 1 s steps. */ /* FIXME: We assume spi_read_status_register will never fail. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int spi_chip_erase_60_c7(struct flashchip *flash) { int result; result = spi_chip_erase_60(flash); if (result) { - printf_debug("spi_chip_erase_60 failed, trying c7\n"); + msg_cdbg("spi_chip_erase_60 failed, trying c7\n"); result = spi_chip_erase_c7(flash); } return result; } int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { int result; struct spi_command cmds[] = { { .writecnt = JEDEC_WREN_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_WREN }, .readcnt = 0, @@ -513,37 +513,37 @@ int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int (addr & 0xff) }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 100-4000 ms, so wait in 100 ms steps. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(100 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } /* Block size is usually * 64k for Macronix * 32k for SST * 4-32k non-uniform for EON */ int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { int result; @@ -562,37 +562,37 @@ int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int (addr & 0xff) }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 100-4000 ms, so wait in 100 ms steps. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(100 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } /* Block size is usually * 4k for PMC */ int spi_block_erase_d7(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { int result; struct spi_command cmds[] = { { @@ -609,61 +609,61 @@ int spi_block_erase_d7(struct flashchip *flash, unsigned int addr, unsigned int (addr & 0xff) }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 100-4000 ms, so wait in 100 ms steps. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(100 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int spi_chip_erase_d8(struct flashchip *flash) { int i, rc = 0; int total_size = flash->total_size * 1024; int erase_size = 64 * 1024; spi_disable_blockprotect(); - printf("Erasing chip: \n"); + msg_cinfo("Erasing chip: \n"); for (i = 0; i < total_size / erase_size; i++) { rc = spi_block_erase_d8(flash, i * erase_size, erase_size); if (rc) { - fprintf(stderr, "Error erasing block at 0x%x\n", i); + msg_cerr("Error erasing block at 0x%x\n", i); break; } } - printf("\n"); + msg_cinfo("\n"); return rc; } /* Sector size is usually 4k, though Macronix eliteflash has 64k */ int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { int result; struct spi_command cmds[] = { { .writecnt = JEDEC_WREN_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_WREN }, .readcnt = 0, @@ -677,72 +677,72 @@ int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int (addr & 0xff) }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); return result; } /* Wait until the Write-In-Progress bit is cleared. * This usually takes 15-800 ms, so wait in 10 ms steps. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(10 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } return spi_chip_erase_60(flash); } int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } return spi_chip_erase_c7(flash); } int spi_write_status_enable(void) { const unsigned char cmd[JEDEC_EWSR_OUTSIZE] = { JEDEC_EWSR }; int result; /* Send EWSR (Enable Write Status Register). */ result = spi_send_command(sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL); if (result) - fprintf(stderr, "%s failed\n", __func__); + msg_cerr("%s failed\n", __func__); return result; } /* * This is according the SST25VF016 datasheet, who knows it is more * generic that this... */ int spi_write_status_register(int status) { int result; struct spi_command cmds[] = { { @@ -755,27 +755,27 @@ int spi_write_status_register(int status) .writecnt = JEDEC_WRSR_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", + msg_cerr("%s failed during command execution\n", __func__); } return result; } int spi_byte_program(int addr, uint8_t databyte) { int result; struct spi_command cmds[] = { { .writecnt = JEDEC_WREN_OUTSIZE, .writearr = (const unsigned char[]){ JEDEC_WREN }, .readcnt = 0, @@ -790,27 +790,27 @@ int spi_byte_program(int addr, uint8_t databyte) databyte }, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); } return result; } int spi_nbyte_program(int addr, uint8_t *bytes, int len) { int result; /* FIXME: Switch to malloc based on len unless that kills speed. */ unsigned char cmd[JEDEC_BYTE_PROGRAM_OUTSIZE - 1 + 256] = { JEDEC_BYTE_PROGRAM, (addr >> 16) & 0xff, (addr >> 8) & 0xff, @@ -825,56 +825,56 @@ int spi_nbyte_program(int addr, uint8_t *bytes, int len) }, { .writecnt = JEDEC_BYTE_PROGRAM_OUTSIZE - 1 + len, .writearr = cmd, .readcnt = 0, .readarr = NULL, }, { .writecnt = 0, .writearr = NULL, .readcnt = 0, .readarr = NULL, }}; if (!len) { - fprintf(stderr, "%s called for zero-length write\n", __func__); + msg_cerr("%s called for zero-length write\n", __func__); return 1; } if (len > 256) { - fprintf(stderr, "%s called for too long a write\n", __func__); + msg_cerr("%s called for too long a write\n", __func__); return 1; } memcpy(&cmd[4], bytes, len); result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + msg_cerr("%s failed during command execution at address 0x%x\n", __func__, addr); } return result; } int spi_disable_blockprotect(void) { uint8_t status; int result; status = spi_read_status_register(); /* If there is block protection in effect, unprotect it first. */ if ((status & 0x3c) != 0) { - printf_debug("Some block protection in effect, disabling\n"); + msg_cdbg("Some block protection in effect, disabling\n"); result = spi_write_status_register(status & ~0x3c); if (result) { - fprintf(stderr, "spi_write_status_register failed\n"); + msg_cerr("spi_write_status_register failed\n"); return result; } } return 0; } int spi_nbyte_read(int address, uint8_t *bytes, int len) { const unsigned char cmd[JEDEC_READ_OUTSIZE] = { JEDEC_READ, (address >> 16) & 0xff, (address >> 8) & 0xff, (address >> 0) & 0xff, @@ -926,61 +926,61 @@ int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, /* * Program chip using byte programming. (SLOW!) * This is for chips which can only handle one byte writes * and for chips where memory mapped programming is impossible * (e.g. due to size constraints in IT87* for over 512 kB) */ int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) { int total_size = 1024 * flash->total_size; int i, result = 0; spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + msg_cinfo("Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("done.\n"); + msg_cinfo("done.\n"); for (i = 0; i < total_size; i++) { result = spi_byte_program(i, buf[i]); if (result) return 1; while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(10); } return 0; } int spi_aai_write(struct flashchip *flash, uint8_t *buf) { uint32_t pos = 2, size = flash->total_size * 1024; unsigned char w[6] = {0xad, 0, 0, 0, buf[0], buf[1]}; int result; switch (spi_controller) { #if INTERNAL_SUPPORT == 1 case SPI_CONTROLLER_WBSIO: - fprintf(stderr, "%s: impossible with Winbond SPI masters," + msg_cerr("%s: impossible with Winbond SPI masters," " degrading to byte program\n", __func__); return spi_chip_write_1(flash, buf); #endif default: break; } if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } /* FIXME: This will fail on ICH/VIA SPI. */ result = spi_write_enable(); if (result) return result; spi_send_command(6, 0, w, NULL); while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(5); /* SST25VF040B Tbp is max 10us */ while (pos < size) { w[1] = buf[pos++]; w[2] = buf[pos++]; spi_send_command(3, 0, w, NULL); diff --git a/sst28sf040.c b/sst28sf040.c index 0c90526..b9e33ab 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -53,27 +53,27 @@ static void unprotect_28sf040(chipaddr bios) } int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size) { chipaddr bios = flash->virtual_memory; chip_writeb(AUTO_PG_ERASE1, bios); chip_writeb(AUTO_PG_ERASE2, bios + address); /* wait for Toggle bit ready */ toggle_ready_jedec(bios); if (check_erased_range(flash, address, sector_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int write_sector_28sf040(chipaddr bios, uint8_t *src, chipaddr dst, unsigned int page_size) { int i; for (i = 0; i < page_size; i++) { /* transfer data from source to destination */ if (*src == 0xFF) { @@ -95,58 +95,58 @@ int write_sector_28sf040(chipaddr bios, uint8_t *src, chipaddr dst, int erase_28sf040(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; unprotect_28sf040(bios); chip_writeb(CHIP_ERASE, bios); chip_writeb(CHIP_ERASE, bios); protect_28sf040(bios); programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int write_28sf040(struct flashchip *flash, uint8_t *buf) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; unprotect_28sf040(bios); - printf("Programming page: "); + msg_cinfo("Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_sector_28sf040(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: 0x%08x", i, i * page_size); + msg_cinfo("%04d at address: 0x%08x", i, i * page_size); write_sector_28sf040(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"); + msg_cinfo("\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"); + msg_cinfo("\n"); protect_28sf040(bios); return 0; } int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } return erase_28sf040(flash); } diff --git a/sst49lfxxxc.c b/sst49lfxxxc.c index e7e5b61..1331cda 100644 --- a/sst49lfxxxc.c +++ b/sst49lfxxxc.c @@ -17,106 +17,106 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "flash.h" #include "chipdrivers.h" int unlock_block_49lfxxxc(struct flashchip *flash, unsigned long address, unsigned char bits) { unsigned long lock = flash->virtual_registers + address + 2; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", lock, chip_readb(lock)); + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock, chip_readb(lock)); chip_writeb(bits, lock); return 0; } static int write_lockbits_49lfxxxc(struct flashchip *flash, unsigned char bits) { chipaddr registers = flash->virtual_registers; int i, left = flash->total_size * 1024; unsigned long address; - printf_debug("\nbios=0x%08lx\n", registers); + msg_cdbg("\nbios=0x%08lx\n", registers); for (i = 0; left > 65536; i++, left -= 65536) { - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", registers + (i * 65536) + 2, chip_readb(registers + (i * 65536) + 2)); chip_writeb(bits, registers + (i * 65536) + 2); } address = i * 65536; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 32768; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 8192; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 8192; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); return 0; } int unlock_49lfxxxc(struct flashchip *flash) { return write_lockbits_49lfxxxc(flash, 0); } int erase_sector_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size) { uint8_t status; chipaddr bios = flash->virtual_memory; chip_writeb(0x30, bios); chip_writeb(0xD0, bios + address); status = wait_82802ab(bios); if (check_erased_range(flash, address, sector_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } return 0; } int write_49lfxxxc(struct flashchip *flash, uint8_t *buf) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; write_lockbits_49lfxxxc(flash, 0); - printf("Programming page: "); + msg_cinfo("Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_sector_49lfxxxc(flash, i * page_size, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: 0x%08x", i, i * page_size); + msg_cinfo("%04d at address: 0x%08x", i, i * page_size); write_page_82802ab(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"); + msg_cinfo("\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"); + msg_cinfo("\n"); chip_writeb(0xFF, bios); return 0; } diff --git a/sst_fwhub.c b/sst_fwhub.c index 328d39a..2b867c8 100644 --- a/sst_fwhub.c +++ b/sst_fwhub.c @@ -23,59 +23,59 @@ /* Adapted from the Intel FW hub stuff for 82802ax parts. */ #include #include #include "flash.h" #include "chipdrivers.h" int check_sst_fwhub_block_lock(struct flashchip *flash, int offset) { chipaddr registers = flash->virtual_registers; uint8_t blockstatus; blockstatus = chip_readb(registers + offset + 2); - printf_debug("Lock status for 0x%06x (size 0x%06x) is %02x, ", + msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ", offset, flash->page_size, blockstatus); switch (blockstatus & 0x3) { case 0x0: - printf_debug("full access\n"); + msg_cdbg("full access\n"); break; case 0x1: - printf_debug("write locked\n"); + msg_cdbg("write locked\n"); break; case 0x2: - printf_debug("locked open\n"); + msg_cdbg("locked open\n"); break; case 0x3: - printf_debug("write locked down\n"); + msg_cdbg("write locked down\n"); break; } /* Return content of the write_locked bit */ return blockstatus & 0x1; } int clear_sst_fwhub_block_lock(struct flashchip *flash, int offset) { chipaddr registers = flash->virtual_registers; uint8_t blockstatus; blockstatus = check_sst_fwhub_block_lock(flash, offset); if (blockstatus) { - printf_debug("Trying to clear lock for 0x%06x... ", offset) + msg_cdbg("Trying to clear lock for 0x%06x... ", offset); chip_writeb(0, registers + offset + 2); blockstatus = check_sst_fwhub_block_lock(flash, offset); - printf_debug("%s\n", (blockstatus) ? "failed" : "OK"); + msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK"); } return blockstatus; } int printlock_sst_fwhub(struct flashchip *flash) { int i; for (i = 0; i < flash->total_size * 1024; i += flash->page_size) check_sst_fwhub_block_lock(flash, i); return 0; diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c index 3300969..cb17690 100644 --- a/stm50flw0x0x.c +++ b/stm50flw0x0x.c @@ -51,100 +51,99 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset) * * Sometimes, the BIOS does this for you; so you propably * don't need to worry about that. */ /* Check, if it's is a top/bottom-block with 4k-sectors. */ /* TODO: What about the other types? */ if ((offset == 0) || (offset == (flash->model_id == ST_M50FLW080A ? 0xE0000 : 0x10000)) || (offset == 0xF0000)) { // unlock each 4k-sector for (j = 0; j < 0x10000; j += 0x1000) { - printf_debug("unlocking at 0x%x\n", offset + j); + msg_cdbg("unlocking at 0x%x\n", offset + j); chip_writeb(unlock_sector, wrprotect + offset + j); if (chip_readb(wrprotect + offset + j) != unlock_sector) { - printf("Cannot unlock sector @ 0x%x\n", + msg_cinfo("Cannot unlock sector @ 0x%x\n", offset + j); return -1; } } } else { - printf_debug("unlocking at 0x%x\n", offset); + msg_cdbg("unlocking at 0x%x\n", offset); chip_writeb(unlock_sector, wrprotect + offset); if (chip_readb(wrprotect + offset) != unlock_sector) { - printf("Cannot unlock sector @ 0x%x\n", offset); + msg_cinfo("Cannot unlock sector @ 0x%x\n", offset); return -1; } } return 0; } int unlock_stm50flw0x0x(struct flashchip *flash) { int i; for (i = 0; i < flash->total_size * 1024; i+= flash->page_size) { if(unlock_block_stm50flw0x0x(flash, i)) { - fprintf(stderr, "UNLOCK FAILED!\n"); + msg_cerr("UNLOCK FAILED!\n"); return -1; } } return 0; } int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsigned int sectorsize) { chipaddr bios = flash->virtual_memory + sector; // clear status register chip_writeb(0x50, bios); - printf_debug("Erase at 0x%lx\n", bios); + msg_cdbg("Erase at 0x%lx\n", bios); // now start it chip_writeb(0x32, bios); chip_writeb(0xd0, bios); programmer_delay(10); wait_82802ab(flash->virtual_memory); if (check_erased_range(flash, sector, sectorsize)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } - printf("DONE BLOCK 0x%x\n", sector); + msg_cinfo("DONE BLOCK 0x%x\n", sector); return 0; } int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { int i; int total_size = flash->total_size * 1024; int page_size = flash->page_size; if ((addr != 0) || (blocklen != flash->total_size * 1024)) { msg_cerr("%s called with incorrect arguments\n", __func__); return -1; } - printf("Erasing page:\n"); + msg_cinfo("Erasing page:\n"); for (i = 0; i < total_size / page_size; i++) { - 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("%04d at address: 0x%08x ", i, i * page_size); + msg_cinfo("\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"); + msg_cinfo("%04d at address: 0x%08x ", i, i * page_size); //if (unlock_block_stm50flw0x0x(flash, i * page_size)) { - // fprintf(stderr, "UNLOCK FAILED!\n"); + // msg_cerr("UNLOCK FAILED!\n"); // return -1; //} if (erase_block_82802ab(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_cerr("ERASE FAILED!\n"); return -1; } } - printf("\n"); + msg_cinfo("\n"); return 0; } diff --git a/w29ee011.c b/w29ee011.c index 63cf4fc..6b88a1c 100644 --- a/w29ee011.c +++ b/w29ee011.c @@ -19,27 +19,27 @@ */ #include #include "flash.h" #include "chipdrivers.h" int probe_w29ee011(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; extern char *chip_to_probe; if (!chip_to_probe || strcmp(chip_to_probe, "W29EE011")) { - printf_debug("Probing disabled for Winbond W29EE011 because " + msg_cdbg("Probing disabled for Winbond W29EE011 because " "the probing sequence puts the AMIC A49LF040A in " "a funky state. Use 'flashrom -c W29EE011' if you " "have a board with this chip.\n"); return 0; } /* Issue JEDEC Product ID Entry command */ chip_writeb(0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(0x80, bios + 0x5555); programmer_delay(10); @@ -52,20 +52,20 @@ int probe_w29ee011(struct flashchip *flash) /* Read product ID */ id1 = chip_readb(bios); id2 = chip_readb(bios + 0x01); /* Issue JEDEC Product ID Exit command */ chip_writeb(0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(0xF0, bios + 0x5555); programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; return 0; } diff --git a/w39v040c.c b/w39v040c.c index 74cd1e2..2a8bd7b 100644 --- a/w39v040c.c +++ b/w39v040c.c @@ -32,17 +32,17 @@ int printlock_w39v040c(struct flashchip *flash) programmer_delay(10); chip_writeb(0x90, bios + 0x5555); programmer_delay(10); lock = chip_readb(bios + 0xfff2); chip_writeb(0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(0xF0, bios + 0x5555); programmer_delay(40); - printf("%s: Boot block #TBL is %slocked, rest of chip #WP is %slocked.\n", + msg_cinfo("%s: Boot block #TBL is %slocked, rest of chip #WP is %slocked.\n", __func__, lock & 0x4 ? "" : "un", lock & 0x8 ? "" : "un"); return 0; } diff --git a/w39v080fa.c b/w39v080fa.c index 047f86b..62c55f4 100644 --- a/w39v080fa.c +++ b/w39v080fa.c @@ -16,57 +16,57 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "flash.h" #include "chipdrivers.h" static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset) { chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; - printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset, + msg_cdbg("Trying to unlock block @0x%08x = 0x%02x\n", offset, chip_readb(wrprotect)); locking = chip_readb(wrprotect); switch (locking & 0x7) { case 0: - printf_debug("Full Access.\n"); + msg_cdbg("Full Access.\n"); return 0; case 1: - printf_debug("Write Lock (Default State).\n"); + msg_cdbg("Write Lock (Default State).\n"); chip_writeb(0, wrprotect); return 0; case 2: - printf_debug("Locked Open (Full Access, Lock Down).\n"); + msg_cdbg("Locked Open (Full Access, Lock Down).\n"); return 0; case 3: - fprintf(stderr, "Error: Write Lock, Locked Down.\n"); + msg_cerr("Error: Write Lock, Locked Down.\n"); return -1; case 4: - printf_debug("Read Lock.\n"); + msg_cdbg("Read Lock.\n"); chip_writeb(0, wrprotect); return 0; case 5: - printf_debug("Read/Write Lock.\n"); + msg_cdbg("Read/Write Lock.\n"); chip_writeb(0, wrprotect); return 0; case 6: - fprintf(stderr, "Error: Read Lock, Locked Down.\n"); + msg_cerr("Error: Read Lock, Locked Down.\n"); return -1; case 7: - fprintf(stderr, "Error: Read/Write Lock, Locked Down.\n"); + msg_cerr("Error: Read/Write Lock, Locked Down.\n"); return -1; } /* We will never reach this point, but GCC doesn't know */ return -1; } int unlock_winbond_fwhub(struct flashchip *flash) { int i, total_size = flash->total_size * 1024; chipaddr bios = flash->virtual_memory; uint8_t locking; @@ -79,35 +79,35 @@ int unlock_winbond_fwhub(struct flashchip *flash) chip_writeb(0x55, bios + 0x2AAA); chip_writeb(0x90, bios + 0x5555); programmer_delay(10); /* Read Hardware Lock Bits */ locking = chip_readb(bios + 0xffff2); /* Product Identification Exit */ chip_writeb(0xAA, bios + 0x5555); chip_writeb(0x55, bios + 0x2AAA); chip_writeb(0xF0, bios + 0x5555); programmer_delay(10); - printf_debug("Lockout bits:\n"); + msg_cdbg("Lockout bits:\n"); if (locking & (1 << 2)) - fprintf(stderr, "Error: hardware bootblock locking (#TBL).\n"); + msg_cerr("Error: hardware bootblock locking (#TBL).\n"); else - printf_debug("No hardware bootblock locking (good!)\n"); + msg_cdbg("No hardware bootblock locking (good!)\n"); if (locking & (1 << 3)) - fprintf(stderr, "Error: hardware block locking (#WP).\n"); + msg_cerr("Error: hardware block locking (#WP).\n"); else - printf_debug("No hardware block locking (good!)\n"); + msg_cdbg("No hardware block locking (good!)\n"); if (locking & ((1 << 2) | (1 << 3))) return -1; /* Unlock the complete chip */ for (i = 0; i < total_size; i += flash->page_size) if (unlock_block_winbond_fwhub(flash, i)) return -1; return 0; } -- 1.6.6