Commit 28accc27 authored by Sean Nelson's avatar Sean Nelson
Browse files

Various JEDEC refactorings touching 82802ab.c, sharplhf00l04.c and stm50flw0x0x.c


Rename print_82802ab_status to print_status_82802ab add unlock_82802ab strip unlock code from erase_block_82802ab rename erase_82802ab_block  to erase_block_80280ab delete sharplhf00l04.o from Makefile delete *_lhf00l04* from chipdrivers.h.

add unlock_stm50flw0x0x
delete wait_stm50flw0x0x
delete write_page_stm50flw0x0x
convert erase_stm50flw0x0x to erase_chip_stm50flw0x0x
delete write_stm50flw0x0x
add unlock_82802ab to two Intel chips with TEST_BAD_WRITE
change the status of 82802AB, 82802AC, M50FW040, M50FW080 to TEST_OK_PR

Corresponding to flashrom svn r948.
Signed-off-by: default avatarSean Nelson <audiohacked@gmail.com>
Acked-by: default avatarCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
parent 6499d5a6
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "chipdrivers.h" #include "chipdrivers.h"
// I need that Berkeley bit-map printer // I need that Berkeley bit-map printer
void print_82802ab_status(uint8_t status) void print_status_82802ab(uint8_t status)
{ {
printf_debug("%s", status & 0x80 ? "Ready:" : "Busy:"); printf_debug("%s", status & 0x80 ? "Ready:" : "Busy:");
printf_debug("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); printf_debug("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
...@@ -92,18 +92,27 @@ uint8_t wait_82802ab(chipaddr bios) ...@@ -92,18 +92,27 @@ uint8_t wait_82802ab(chipaddr bios)
return status; return status;
} }
int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int pagesize) int unlock_82802ab(struct flashchip *flash)
{
int i;
//chipaddr wrprotect = flash->virtual_registers + page + 2;
for (i = 0; i < flash->total_size; i+= flash->page_size)
{
chip_writeb(0, flash->virtual_registers + i + 2);
}
return 0;
}
int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chipaddr wrprotect = flash->virtual_registers + page + 2;
uint8_t status; uint8_t status;
// clear status register // clear status register
chip_writeb(0x50, bios + page); chip_writeb(0x50, bios + page);
// clear write protect
chip_writeb(0, wrprotect);
// now start it // now start it
chip_writeb(0x20, bios + page); chip_writeb(0x20, bios + page);
chip_writeb(0xd0, bios + page); chip_writeb(0xd0, bios + page);
...@@ -111,7 +120,7 @@ int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int ...@@ -111,7 +120,7 @@ int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int
// now let's see what the register is // now let's see what the register is
status = wait_82802ab(bios); status = wait_82802ab(bios);
print_82802ab_status(status); print_status_82802ab(status);
if (check_erased_range(flash, page, pagesize)) { if (check_erased_range(flash, page, pagesize)) {
fprintf(stderr, "ERASE FAILED!\n"); fprintf(stderr, "ERASE FAILED!\n");
...@@ -130,7 +139,7 @@ int erase_82802ab(struct flashchip *flash) ...@@ -130,7 +139,7 @@ int erase_82802ab(struct flashchip *flash)
printf("total_size is %d; flash->page_size is %d\n", printf("total_size is %d; flash->page_size is %d\n",
total_size, flash->page_size); total_size, flash->page_size);
for (i = 0; i < total_size; i += flash->page_size) for (i = 0; i < total_size; i += flash->page_size)
if (erase_82802ab_block(flash, i, flash->page_size)) { if (erase_block_82802ab(flash, i, flash->page_size)) {
fprintf(stderr, "ERASE FAILED!\n"); fprintf(stderr, "ERASE FAILED!\n");
return -1; return -1;
} }
...@@ -184,7 +193,7 @@ int write_82802ab(struct flashchip *flash, uint8_t *buf) ...@@ -184,7 +193,7 @@ int write_82802ab(struct flashchip *flash, uint8_t *buf)
} }
/* erase block by block and write block by block; this is the most secure way */ /* erase block by block and write block by block; this is the most secure way */
if (erase_82802ab_block(flash, i * page_size, page_size)) { if (erase_block_82802ab(flash, i * page_size, page_size)) {
fprintf(stderr, "ERASE FAILED!\n"); fprintf(stderr, "ERASE FAILED!\n");
return -1; return -1;
} }
......
...@@ -41,7 +41,7 @@ CPPFLAGS += -I/usr/local/include ...@@ -41,7 +41,7 @@ CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib LDFLAGS += -L/usr/local/lib
endif endif
CHIP_OBJS = jedec.o stm50flw0x0x.o w39v040c.o w39v080fa.o sharplhf00l04.o w29ee011.o \ CHIP_OBJS = jedec.o stm50flw0x0x.o w39v040c.o w39v080fa.o w29ee011.o \
sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \ sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \
sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o
......
...@@ -57,10 +57,11 @@ int spi_aai_write(struct flashchip *flash, uint8_t *buf); ...@@ -57,10 +57,11 @@ int spi_aai_write(struct flashchip *flash, uint8_t *buf);
uint8_t wait_82802ab(chipaddr bios); uint8_t wait_82802ab(chipaddr bios);
int probe_82802ab(struct flashchip *flash); int probe_82802ab(struct flashchip *flash);
int erase_82802ab(struct flashchip *flash); int erase_82802ab(struct flashchip *flash);
int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int pagesize); int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize);
int write_82802ab(struct flashchip *flash, uint8_t *buf); int write_82802ab(struct flashchip *flash, uint8_t *buf);
void print_82802ab_status(uint8_t status); void print_status_82802ab(uint8_t status);
void write_page_82802ab(chipaddr bios, uint8_t *src, chipaddr dst, int page_size); void write_page_82802ab(chipaddr bios, uint8_t *src, chipaddr dst, int page_size);
int unlock_82802ab(struct flashchip *flash);
/* jedec.c */ /* jedec.c */
uint8_t oddparity(uint8_t val); uint8_t oddparity(uint8_t val);
...@@ -92,10 +93,6 @@ void write_page_m29f400bt(chipaddr bios, uint8_t *src, ...@@ -92,10 +93,6 @@ void write_page_m29f400bt(chipaddr bios, uint8_t *src,
int unlock_49fl00x(struct flashchip *flash); int unlock_49fl00x(struct flashchip *flash);
int lock_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 */ /* sst28sf040.c */
int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen); 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 erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size);
...@@ -124,11 +121,8 @@ int unlock_winbond_fwhub(struct flashchip *flash); ...@@ -124,11 +121,8 @@ int unlock_winbond_fwhub(struct flashchip *flash);
int probe_w29ee011(struct flashchip *flash); int probe_w29ee011(struct flashchip *flash);
/* stm50flw0x0x.c */ /* 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_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 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__ */ #endif /* !__CHIPDRIVERS_H__ */
...@@ -2328,9 +2328,10 @@ struct flashchip flashchips[] = { ...@@ -2328,9 +2328,10 @@ struct flashchip flashchips[] = {
{4 * 1024, 2}, {4 * 1024, 2},
{112 * 1024, 1}, {112 * 1024, 1},
}, },
.block_erase = erase_82802ab_block, .block_erase = erase_block_82802ab,
}, },
}, },
.unlock = unlock_82802ab,
.write = NULL, .write = NULL,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -2355,9 +2356,10 @@ struct flashchip flashchips[] = { ...@@ -2355,9 +2356,10 @@ struct flashchip flashchips[] = {
{4 * 1024, 2}, {4 * 1024, 2},
{8 * 1024, 1}, {8 * 1024, 1},
}, },
.block_erase = erase_82802ab_block, .block_erase = erase_block_82802ab,
}, },
}, },
.unlock = unlock_82802ab,
.write = NULL, .write = NULL,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -2377,9 +2379,10 @@ struct flashchip flashchips[] = { ...@@ -2377,9 +2379,10 @@ struct flashchip flashchips[] = {
{ {
{ {
.eraseblocks = { {64 * 1024, 8} }, .eraseblocks = { {64 * 1024, 8} },
.block_erase = erase_82802ab_block, .block_erase = erase_block_82802ab,
}, },
}, },
.unlock = unlock_82802ab,
.write = write_82802ab, .write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -2393,16 +2396,17 @@ struct flashchip flashchips[] = { ...@@ -2393,16 +2396,17 @@ struct flashchip flashchips[] = {
.total_size = 512, .total_size = 512,
.page_size = 64 * 1024, .page_size = 64 * 1024,
.feature_bits = FEATURE_REGISTERMAP, .feature_bits = FEATURE_REGISTERMAP,
.tested = TEST_OK_PRW, .tested = TEST_OK_PR,
.probe = probe_82802ab, .probe = probe_82802ab,
.probe_timing = TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */ .probe_timing = TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */
.block_erasers = .block_erasers =
{ {
{ {
.eraseblocks = { {64 * 1024, 8} }, .eraseblocks = { {64 * 1024, 8} },
.block_erase = erase_82802ab_block, .block_erase = erase_block_82802ab,
}, },
}, },
.unlock = unlock_82802ab,
.write = write_82802ab, .write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -2416,16 +2420,17 @@ struct flashchip flashchips[] = { ...@@ -2416,16 +2420,17 @@ struct flashchip flashchips[] = {
.total_size = 1024, .total_size = 1024,
.page_size = 64 * 1024, .page_size = 64 * 1024,
.feature_bits = FEATURE_REGISTERMAP, .feature_bits = FEATURE_REGISTERMAP,
.tested = TEST_OK_PRW, .tested = TEST_OK_PR,
.probe = probe_82802ab, .probe = probe_82802ab,
.probe_timing = TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */ .probe_timing = TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */
.block_erasers = .block_erasers =
{ {
{ {
.eraseblocks = { {64 * 1024, 16} }, .eraseblocks = { {64 * 1024, 16} },
.block_erase = erase_82802ab_block, .block_erase = erase_block_82802ab,
}, },
}, },
.unlock = unlock_82802ab,
.write = write_82802ab, .write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -3453,7 +3458,7 @@ struct flashchip flashchips[] = { ...@@ -3453,7 +3458,7 @@ struct flashchip flashchips[] = {
{64 * 1024, 15}, {64 * 1024, 15},
{8 * 1024, 8} {8 * 1024, 8}
}, },
.block_erase = erase_lhf00l04_block, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { .eraseblocks = {
{1024 * 1024, 1} {1024 * 1024, 1}
...@@ -3461,7 +3466,8 @@ struct flashchip flashchips[] = { ...@@ -3461,7 +3466,8 @@ struct flashchip flashchips[] = {
.block_erase = NULL, /* 30 D0, only in A/A mux mode */ .block_erase = NULL, /* 30 D0, only in A/A mux mode */
}, },
}, },
.write = write_lhf00l04, .unlock = unlock_82802ab,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -4994,13 +5000,14 @@ struct flashchip flashchips[] = { ...@@ -4994,13 +5000,14 @@ struct flashchip flashchips[] = {
.block_erase = NULL, .block_erase = NULL,
}, { }, {
.eraseblocks = { {64 * 1024, 8}, }, .eraseblocks = { {64 * 1024, 8}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {512 * 1024, 1} }, .eraseblocks = { {512 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5028,13 +5035,14 @@ struct flashchip flashchips[] = { ...@@ -5028,13 +5035,14 @@ struct flashchip flashchips[] = {
.block_erase = NULL, .block_erase = NULL,
}, { }, {
.eraseblocks = { {64 * 1024, 8}, }, .eraseblocks = { {64 * 1024, 8}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {512 * 1024, 1} }, .eraseblocks = { {512 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5062,13 +5070,14 @@ struct flashchip flashchips[] = { ...@@ -5062,13 +5070,14 @@ struct flashchip flashchips[] = {
.block_erase = NULL, .block_erase = NULL,
}, { }, {
.eraseblocks = { {64 * 1024, 16}, }, .eraseblocks = { {64 * 1024, 16}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {1024 * 1024, 1} }, .eraseblocks = { {1024 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5096,13 +5105,14 @@ struct flashchip flashchips[] = { ...@@ -5096,13 +5105,14 @@ struct flashchip flashchips[] = {
.block_erase = NULL, .block_erase = NULL,
}, { }, {
.eraseblocks = { {64 * 1024, 16}, }, .eraseblocks = { {64 * 1024, 16}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {1024 * 1024, 1} }, .eraseblocks = { {1024 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5127,13 +5137,14 @@ struct flashchip flashchips[] = { ...@@ -5127,13 +5137,14 @@ struct flashchip flashchips[] = {
{8 * 1024, 2}, {8 * 1024, 2},
{16 * 1024, 1}, {16 * 1024, 1},
}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {256 * 1024, 1} }, .eraseblocks = { {256 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5153,13 +5164,14 @@ struct flashchip flashchips[] = { ...@@ -5153,13 +5164,14 @@ struct flashchip flashchips[] = {
{ {
{ {
.eraseblocks = { {64 * 1024, 32}, }, .eraseblocks = { {64 * 1024, 32}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {2 * 1024 * 1024, 1} }, .eraseblocks = { {2 * 1024 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5172,20 +5184,21 @@ struct flashchip flashchips[] = { ...@@ -5172,20 +5184,21 @@ struct flashchip flashchips[] = {
.total_size = 512, .total_size = 512,
.page_size = 64 * 1024, .page_size = 64 * 1024,
.feature_bits = FEATURE_REGISTERMAP, .feature_bits = FEATURE_REGISTERMAP,
.tested = TEST_OK_PRW, .tested = TEST_OK_PR,
.probe = probe_82802ab, .probe = probe_82802ab,
.probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */
.block_erasers = .block_erasers =
{ {
{ {
.eraseblocks = { {64 * 1024, 8}, }, .eraseblocks = { {64 * 1024, 8}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {512 * 1024, 1} }, .eraseblocks = { {512 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5198,20 +5211,21 @@ struct flashchip flashchips[] = { ...@@ -5198,20 +5211,21 @@ struct flashchip flashchips[] = {
.total_size = 1024, .total_size = 1024,
.page_size = 64 * 1024, .page_size = 64 * 1024,
.feature_bits = FEATURE_REGISTERMAP, .feature_bits = FEATURE_REGISTERMAP,
.tested = TEST_OK_PRW, .tested = TEST_OK_PR,
.probe = probe_82802ab, .probe = probe_82802ab,
.probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */
.block_erasers = .block_erasers =
{ {
{ {
.eraseblocks = { {64 * 1024, 16}, }, .eraseblocks = { {64 * 1024, 16}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {1024 * 1024, 1} }, .eraseblocks = { {1024 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
...@@ -5237,13 +5251,14 @@ struct flashchip flashchips[] = { ...@@ -5237,13 +5251,14 @@ struct flashchip flashchips[] = {
{8 * 1024, 2}, {8 * 1024, 2},
{16 * 1024, 1}, {16 * 1024, 1},
}, },
.block_erase = erase_block_stm50flw0x0x, .block_erase = erase_block_82802ab,
}, { }, {
.eraseblocks = { {2 * 1024 * 1024, 1} }, .eraseblocks = { {2 * 1024 * 1024, 1} },
.block_erase = erase_chip_stm50flw0x0x, .block_erase = erase_chip_stm50flw0x0x,
} }
}, },
.write = write_stm50flw0x0x, .unlock = unlock_stm50flw0x0x,
.write = write_82802ab,
.read = read_memmapped, .read = read_memmapped,
}, },
......
...@@ -36,7 +36,7 @@ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsign ...@@ -36,7 +36,7 @@ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsign
chip_writeb(0x50, bios); chip_writeb(0x50, bios);
printf("Erase at 0x%lx\n", bios); printf("Erase at 0x%lx\n", bios);
status = wait_82802ab(flash->virtual_memory); status = wait_82802ab(flash->virtual_memory);
print_82802ab_status(status); print_status_82802ab(status);
// clear write protect // clear write protect
printf("write protect is at 0x%lx\n", (wrprotect)); printf("write protect is at 0x%lx\n", (wrprotect));
printf("write protect is 0x%x\n", chip_readb(wrprotect)); printf("write protect is 0x%x\n", chip_readb(wrprotect));
...@@ -49,7 +49,7 @@ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsign ...@@ -49,7 +49,7 @@ int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsign
programmer_delay(10); programmer_delay(10);
// now let's see what the register is // now let's see what the register is
status = wait_82802ab(flash->virtual_memory); status = wait_82802ab(flash->virtual_memory);
print_82802ab_status(status); print_status_82802ab(status);
printf("DONE BLOCK 0x%x\n", blockaddr); printf("DONE BLOCK 0x%x\n", blockaddr);
if (check_erased_range(flash, blockaddr, blocklen)) { if (check_erased_range(flash, blockaddr, blocklen)) {
......
...@@ -33,26 +33,6 @@ ...@@ -33,26 +33,6 @@
#include "flashchips.h" #include "flashchips.h"
#include "chipdrivers.h" #include "chipdrivers.h"
static void wait_stm50flw0x0x(chipaddr bios)
{
chip_writeb(0x70, bios);
if ((chip_readb(bios) & 0x80) == 0) { // it's busy
while ((chip_readb(bios) & 0x80) == 0) ;
}
// put another command to get out of status register mode
chip_writeb(0x90, bios);
programmer_delay(10);
chip_readb(bios); // Read device ID (to make sure?)
// this is needed to jam it out of "read id" mode
chip_writeb(0xAA, bios + 0x5555);
chip_writeb(0x55, bios + 0x2AAA);
chip_writeb(0xF0, bios + 0x5555);
}
/* /*
* claus.gindhart@kontron.com * claus.gindhart@kontron.com
* The ST M50FLW080B and STM50FLW080B chips have to be unlocked, * The ST M50FLW080B and STM50FLW080B chips have to be unlocked,
...@@ -101,25 +81,16 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset) ...@@ -101,25 +81,16 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
return 0; return 0;
} }
int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize) int unlock_stm50flw0x0x(struct flashchip *flash)
{ {
chipaddr bios = flash->virtual_memory + block; int i;
// 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);
if (check_erased_range(flash, block, blocksize)) { for (i = 0; i < flash->total_size; i+= flash->page_size) {
fprintf(stderr, "ERASE FAILED!\n"); if(unlock_block_stm50flw0x0x(flash, i)) {
return -1; fprintf(stderr, "UNLOCK FAILED!\n");
return -1;
}
} }
printf("DONE BLOCK 0x%x\n", block);
return 0; return 0;
} }
...@@ -136,7 +107,7 @@ int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsi ...@@ -136,7 +107,7 @@ int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsi
chip_writeb(0xd0, bios); chip_writeb(0xd0, bios);
programmer_delay(10); programmer_delay(10);
wait_stm50flw0x0x(flash->virtual_memory); wait_82802ab(flash->virtual_memory);
if (check_erased_range(flash, sector, sectorsize)) { if (check_erased_range(flash, sector, sectorsize)) {
fprintf(stderr, "ERASE FAILED!\n"); fprintf(stderr, "ERASE FAILED!\n");
...@@ -147,122 +118,33 @@ int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsi ...@@ -147,122 +118,33 @@ int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsi
return 0; return 0;
} }
int write_page_stm50flw0x0x(chipaddr bios, uint8_t *src, int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
chipaddr dst, int page_size)
{
int i, rc = 0;
chipaddr d = dst;
uint8_t *s = src;
/* transfer data from source to destination */
for (i = 0; i < page_size; i++) {
chip_writeb(0x40, dst);
chip_writeb(*src++, dst++);
wait_stm50flw0x0x(bios);
}
/* claus.gindhart@kontron.com
* TODO
* I think, that verification is not required, but
* i leave it in anyway
*/
dst = d;
src = s;
for (i = 0; i < page_size; i++) {
if (chip_readb(dst) != *src) {
rc = -1;
break;
}
dst++;
src++;
}
if (rc) {
fprintf(stderr, " page 0x%lx failed!\n",
(d - bios) / page_size);
}
return rc;
}
/* I simply erase block by block
* I Chip This is not the fastest way, but it works
*/
int erase_stm50flw0x0x(struct flashchip *flash)
{ {
int i; int i;
int total_size = flash->total_size * 1024; int total_size = flash->total_size * 1024;
int page_size = flash->page_size; int page_size = flash->page_size;
printf("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);
if (unlock_block_stm50flw0x0x(flash, i * page_size)) {
fprintf(stderr, "UNLOCK FAILED!\n");
return -1;
}
if (erase_block_stm50flw0x0x(flash, i * page_size, page_size)) {
fprintf(stderr, "ERASE FAILED!\n");
return -1;
}
}
printf("\n");
return 0;
}
int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
{
if ((addr != 0) || (blocklen != flash->total_size * 1024)) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
msg_cerr("%s called with incorrect arguments\n", msg_cerr("%s called with incorrect arguments\n",
__func__); __func__);
return -1; return -1;
} }
return erase_stm50flw0x0x(flash);
}
int write_stm50flw0x0x(struct flashchip *flash, uint8_t * buf)
{
int i, rc = 0;
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("Erasing page:\n");
printf("Could not allocate memory!\n"); for (i = 0; i < total_size / page_size; i++) {
exit(1);
}
printf("Programming page: \n");
for (i = 0; (i < total_size / page_size) && (rc == 0); i++) {
printf 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"); ("\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); printf("%04d at address: 0x%08x ", i, i * page_size);
//if (unlock_block_stm50flw0x0x(flash, i * page_size)) {
/* Auto Skip Blocks, which already contain the desired data // fprintf(stderr, "UNLOCK FAILED!\n");
* Faster, because we only write, what has changed // return -1;
* More secure, because blocks, which are excluded //}
* (with the exclude or layout feature) if (erase_block_82802ab(flash, i * page_size, page_size)) {
* are not erased and rewritten; data is retained also fprintf(stderr, "ERASE FAILED!\n");
* in sudden power off situations return -1;
*/
chip_readn(tmpbuf, bios + i * page_size, page_size);
if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) {
printf("SKIPPED\n");
continue;
} }
rc = unlock_block_stm50flw0x0x(flash, i * page_size);
if (!rc)
rc = erase_block_stm50flw0x0x(flash, i * page_size, page_size);
if (!rc)
write_page_stm50flw0x0x(bios, buf + i * page_size,
bios + i * page_size, page_size);
} }
printf("\n"); printf("\n");
free(tmpbuf);
return rc; return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment