change chip specific functions towards functions found in 82820ab.c change unprotect_28sf040(chipaddr bios) to unlock_28sf040(struct flashchip *flash) add unlock_stm50flw0x0x Signed-off-by: Sean Nelson --- chipdrivers.h | 2 + flashchips.c | 105 +++++++++++++++++++++++++++++++------------------------- sst28sf040.c | 20 +++++++--- stm50flw0x0x.c | 16 ++++++++ 4 files changed, 90 insertions(+), 53 deletions(-) diff --git a/chipdrivers.h b/chipdrivers.h index ca82c2d..6c63831 100644 --- a/chipdrivers.h +++ b/chipdrivers.h @@ -90,26 +90,27 @@ void write_page_m29f400bt(chipaddr bios, uint8_t *src, /* pm49fl00x.c */ int unlock_49fl00x(struct flashchip *flash); int lock_49fl00x(struct flashchip *flash); /* sharplhf00l04.c */ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen); int write_lhf00l04(struct flashchip *flash, uint8_t *buf); /* sst28sf040.c */ int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen); int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size); int write_28sf040(struct flashchip *flash, uint8_t *buf); +int unlock_28sf040(struct flashchip *flash); /* sst49lfxxxc.c */ int probe_49lfxxxc(struct flashchip *flash); int erase_49lfxxxc(struct flashchip *flash); int erase_sector_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size); int erase_block_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size); int erase_chip_49lfxxxc(struct flashchip *flash, unsigned int addr, unsigned int blocksize); int write_49lfxxxc(struct flashchip *flash, uint8_t *buf); int unlock_49lfxxxc(struct flashchip *flash); /* sst_fwhub.c */ int printlock_sst_fwhub(struct flashchip *flash); int unlock_sst_fwhub(struct flashchip *flash); @@ -120,15 +121,16 @@ int printlock_w39v040c(struct flashchip *flash); /* w39V080fa.c */ int unlock_winbond_fwhub(struct flashchip *flash); /* w29ee011.c */ int probe_w29ee011(struct flashchip *flash); /* stm50flw0x0x.c */ int probe_stm50flw0x0x(struct flashchip *flash); int erase_stm50flw0x0x(struct flashchip *flash); int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize); int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize); int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen); int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf); +int unlock_stm50flw0x0x(struct flashchip *flash); #endif /* !__CHIPDRIVERS_H__ */ diff --git a/flashchips.c b/flashchips.c index 3670731..52c6fc6 100644 --- a/flashchips.c +++ b/flashchips.c @@ -3443,35 +3443,33 @@ struct flashchip flashchips[] = { .total_size = 1024, .page_size = 64 * 1024, .feature_bits = FEATURE_EITHER_RESET | FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_ZERO, .block_erasers = { { .eraseblocks = { {64 * 1024, 15}, {8 * 1024, 8} }, - .block_erase = erase_lhf00l04_block, + .block_erase = erase_82802ab_block, }, { - .eraseblocks = { - {1024 * 1024, 1} - }, + .eraseblocks = { {1024 * 1024, 1} }, .block_erase = NULL, /* 30 D0, only in A/A mux mode */ }, }, - .write = write_lhf00l04, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "Spansion", .name = "S25FL008A", .bustype = CHIP_BUSTYPE_SPI, .manufacture_id = SPANSION_ID, .model_id = SPANSION_S25FL008A, .total_size = 1024, .page_size = 256, .tested = TEST_OK_PREW, .probe = probe_spi_rdid, @@ -3725,26 +3723,27 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (sst28sf040.c) */ .block_erasers = { { .eraseblocks = { {128, 4096} }, .block_erase = erase_sector_28sf040, }, { .eraseblocks = { {512 * 1024, 1} }, .block_erase = erase_chip_28sf040, } }, + .unlock = unlock_28sf040, .write = write_28sf040, .read = read_memmapped, }, { .vendor = "SST", .name = "SST29EE010", .bustype = CHIP_BUSTYPE_PARALLEL, .manufacture_id = SST_ID, .model_id = SST_29EE010, .total_size = 128, .page_size = 128, .feature_bits = FEATURE_LONG_RESET, @@ -4184,26 +4183,27 @@ struct flashchip flashchips[] = { { .eraseblocks = { {4 * 1024, 128} }, .block_erase = erase_sector_49lfxxxc, }, { .eraseblocks = { {64 * 1024, 7}, {32 * 1024, 1}, {8 * 1024, 2}, {16 * 1024, 1}, }, .block_erase = erase_block_49lfxxxc, } }, + .unlock = unlock_49lfxxxc, .write = write_49lfxxxc, .read = read_memmapped, }, { .vendor = "SST", .name = "SST49LF008A", .bustype = CHIP_BUSTYPE_FWH, /* A/A Mux */ .manufacture_id = SST_ID, .model_id = SST_49LF008A, .total_size = 1024, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP | FEATURE_EITHER_RESET, @@ -4247,26 +4247,27 @@ struct flashchip flashchips[] = { { .eraseblocks = { {4 * 1024, 256} }, .block_erase = erase_sector_49lfxxxc, }, { .eraseblocks = { {64 * 1024, 15}, {32 * 1024, 1}, {8 * 1024, 2}, {16 * 1024, 1}, }, .block_erase = erase_block_49lfxxxc, } }, + .unlock = unlock_49lfxxxc, .write = write_49lfxxxc, .read = read_memmapped, }, { .vendor = "SST", .name = "SST49LF016C", .bustype = CHIP_BUSTYPE_FWH, .manufacture_id = SST_ID, .model_id = SST_49LF016C, .total_size = 2048, .page_size = 4 * 1024, .feature_bits = FEATURE_REGISTERMAP, @@ -4278,26 +4279,27 @@ struct flashchip flashchips[] = { { .eraseblocks = { {4 * 1024, 512} }, .block_erase = erase_sector_49lfxxxc, }, { .eraseblocks = { {64 * 1024, 31}, {32 * 1024, 1}, {8 * 1024, 2}, {16 * 1024, 1}, }, .block_erase = erase_block_49lfxxxc, } }, + .unlock = unlock_49lfxxxc, .write = write_49lfxxxc, .read = read_memmapped, }, { .vendor = "SST", .name = "SST49LF020", .bustype = CHIP_BUSTYPE_LPC, .manufacture_id = SST_ID, .model_id = SST_49LF020, .total_size = 256, .page_size = 16 * 1024, .feature_bits = FEATURE_EITHER_RESET, @@ -4937,80 +4939,81 @@ struct flashchip flashchips[] = { { { .eraseblocks = { {64 * 1024, 8}, }, .block_erase = erase_sector_jedec, }, { .eraseblocks = { {512 * 1024, 1} }, .block_erase = erase_chip_block_jedec, } }, .write = write_jedec_1, .read = read_memmapped, }, - { - .vendor = "ST", - .name = "M29W512B", - .bustype = CHIP_BUSTYPE_PARALLEL, - .manufacture_id = ST_ID, - .model_id = ST_M29W512B, - .total_size = 64, - .page_size = 64 * 1024, - .feature_bits = FEATURE_ADDR_2AA | FEATURE_EITHER_RESET, - .tested = TEST_OK_PREW, - .probe = probe_jedec, - .probe_timing = TIMING_ZERO, - .block_erasers = - { - { - .eraseblocks = { {64 * 1024, 1} }, - .block_erase = erase_chip_block_jedec, - } - }, - .write = write_jedec_1, - .read = read_memmapped, - }, + { + .vendor = "ST", + .name = "M29W512B", + .bustype = CHIP_BUSTYPE_PARALLEL, + .manufacture_id = ST_ID, + .model_id = ST_M29W512B, + .total_size = 64, + .page_size = 64 * 1024, + .feature_bits = FEATURE_ADDR_2AA | FEATURE_EITHER_RESET, + .tested = TEST_OK_PREW, + .probe = probe_jedec, + .probe_timing = TIMING_ZERO, + .block_erasers = + { + { + .eraseblocks = { {64 * 1024, 1} }, + .block_erase = erase_chip_block_jedec, + } + }, + .write = write_jedec_1, + .read = read_memmapped, + }, { .vendor = "ST", .name = "M50FLW040A", .bustype = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FLW040A, .total_size = 512, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_FIXME, .block_erasers = { { .eraseblocks = { {4 * 1024, 16}, /* sector */ {64 * 1024, 5}, /* block */ {4 * 1024, 16}, /* sector */ {4 * 1024, 16}, /* sector */ }, .block_erase = NULL, }, { .eraseblocks = { {64 * 1024, 8}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {512 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FLW040B", .bustype = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FLW040B, .total_size = 512, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, @@ -5018,33 +5021,34 @@ struct flashchip flashchips[] = { .probe_timing = TIMING_FIXME, .block_erasers = { { .eraseblocks = { {4 * 1024, 16}, /* sector */ {4 * 1024, 16}, /* sector */ {64 * 1024, 5}, /* block */ {4 * 1024, 16}, /* sector */ }, .block_erase = NULL, }, { .eraseblocks = { {64 * 1024, 8}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {512 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FLW080A", .bustype = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FLW080A, .total_size = 1024, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, @@ -5052,33 +5056,34 @@ struct flashchip flashchips[] = { .probe_timing = TIMING_FIXME, .block_erasers = { { .eraseblocks = { {4 * 1024, 16}, /* sector */ {64 * 1024, 13}, /* block */ {4 * 1024, 16}, /* sector */ {4 * 1024, 16}, /* sector */ }, .block_erase = NULL, }, { .eraseblocks = { {64 * 1024, 16}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {1024 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FLW080B", .bustype = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FLW080B, .total_size = 1024, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, @@ -5086,174 +5091,180 @@ struct flashchip flashchips[] = { .probe_timing = TIMING_FIXME, .block_erasers = { { .eraseblocks = { {4 * 1024, 16}, /* sector */ {4 * 1024, 16}, /* sector */ {64 * 1024, 13}, /* block */ {4 * 1024, 16}, /* sector */ }, .block_erase = NULL, }, { .eraseblocks = { {64 * 1024, 16}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {1024 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FW002", .bustype = CHIP_BUSTYPE_FWH, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FW002, .total_size = 256, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (sst49lfxxxc.c) */ .block_erasers = { { .eraseblocks = { {64 * 1024, 3}, {32 * 1024, 1}, {8 * 1024, 2}, {16 * 1024, 1}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {256 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FW016", .bustype = CHIP_BUSTYPE_FWH, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FW016, .total_size = 2048, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ .block_erasers = { { .eraseblocks = { {64 * 1024, 32}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {2 * 1024 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FW040", .bustype = CHIP_BUSTYPE_FWH, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FW040, .total_size = 512, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, - .tested = TEST_OK_PRW, + .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ .block_erasers = { { .eraseblocks = { {64 * 1024, 8}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {512 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50FW080", .bustype = CHIP_BUSTYPE_FWH, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50FW080, .total_size = 1024, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, - .tested = TEST_OK_PRW, + .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ .block_erasers = { { .eraseblocks = { {64 * 1024, 16}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {1024 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "ST", .name = "M50LPW116", .bustype = CHIP_BUSTYPE_LPC, /* A/A Mux */ .manufacture_id = ST_ID, .model_id = ST_M50LPW116, .total_size = 2048, .page_size = 64 * 1024, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_ZERO, /* Datasheet has no timing info specified */ .block_erasers = { { .eraseblocks = { {4 * 1024, 16}, {64 * 1024, 30}, {32 * 1024, 1}, {8 * 1024, 2}, {16 * 1024, 1}, }, - .block_erase = erase_block_stm50flw0x0x, + .block_erase = erase_82802ab_block, }, { .eraseblocks = { {2 * 1024 * 1024, 1} }, .block_erase = erase_chip_stm50flw0x0x, } }, - .write = write_stm50flw0x0x, + .unlock = unlock_stm50flw0x0x, + .write = write_82802ab, .read = read_memmapped, }, { .vendor = "SyncMOS", .name = "S29C31004T", .bustype = CHIP_BUSTYPE_PARALLEL, .manufacture_id = SYNCMOS_ID, .model_id = S29C31004T, .total_size = 512, .page_size = 128, .feature_bits = FEATURE_EITHER_RESET, .tested = TEST_UNTESTED, diff --git a/sst28sf040.c b/sst28sf040.c index 0c90526..3b82109 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -20,46 +20,54 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "flash.h" #include "chipdrivers.h" #define AUTO_PG_ERASE1 0x20 #define AUTO_PG_ERASE2 0xD0 #define AUTO_PGRM 0x10 #define CHIP_ERASE 0x30 #define RESET 0xFF #define READ_ID 0x90 -static void protect_28sf040(chipaddr bios) +int lock_28sf040(struct flashchip *flash) { + chipaddr bios = flash->virtual_memory; + chip_readb(bios + 0x1823); chip_readb(bios + 0x1820); chip_readb(bios + 0x1822); chip_readb(bios + 0x0418); chip_readb(bios + 0x041B); chip_readb(bios + 0x0419); chip_readb(bios + 0x040A); + + return 0; } -static void unprotect_28sf040(chipaddr bios) +int unlock_28sf040(struct flashchip *flash) { + chipaddr bios = flash->virtual_memory; + chip_readb(bios + 0x1823); chip_readb(bios + 0x1820); chip_readb(bios + 0x1822); chip_readb(bios + 0x0418); chip_readb(bios + 0x041B); chip_readb(bios + 0x0419); chip_readb(bios + 0x041A); + + return 0; } 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)) { @@ -86,67 +94,67 @@ int write_sector_28sf040(chipaddr bios, uint8_t *src, chipaddr dst, chip_writeb(*src++, dst++); /* wait for Toggle bit ready */ toggle_ready_jedec(bios); } return 0; } int erase_28sf040(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; - unprotect_28sf040(bios); + unlock_28sf040(flash); chip_writeb(CHIP_ERASE, bios); chip_writeb(CHIP_ERASE, bios); - protect_28sf040(bios); + lock_28sf040(flash); programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { fprintf(stderr, "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); + unlock_28sf040(flash); printf("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"); return -1; } /* write to the sector */ printf("%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"); } printf("\n"); - protect_28sf040(bios); + lock_28sf040(flash); 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", __func__); return -1; } return erase_28sf040(flash); } diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c index 7095aec..982147d 100644 --- a/stm50flw0x0x.c +++ b/stm50flw0x0x.c @@ -91,26 +91,42 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset) } } else { printf_debug("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); return -1; } } return 0; } +int unlock_stm50flw0x0x(struct flashchip *flash) +{ + int i; + int total_size = flash->total_size * 1024; + int page_size = flash->page_size; + + for (i = 0; i < total_size / page_size; i++) { + if (unlock_block_stm50flw0x0x(flash, i * page_size)) { + fprintf(stderr, "UNLOCK FAILED!\n"); + return -1; + } + } + + return 0; +} + int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize) { chipaddr bios = flash->virtual_memory + block; // clear status register chip_writeb(0x50, bios); printf_debug("Erase at 0x%lx\n", bios); // now start it chip_writeb(0x20, bios); chip_writeb(0xd0, bios); programmer_delay(10); wait_stm50flw0x0x(flash->virtual_memory); -- 1.6.6