Author: stefanct Date: Fri Aug 8 10:33:01 2014 New Revision: 1840 URL: http://flashrom.org/trac/flashrom/changeset/1840
Log: Unify non-shifted and shifted JEDEC access.
Some Parallel bus chips have a 16-bit mode and an 8-bit mode. They use normal JEDEC addresses for 16-bit mode and shifted addresses (by 1 bit) for 8-bit mode. Some programmers can access them in 16-bit mode, but on all flashrom-supported programmers so far, we access them in 8-bit mode. This means we have to shift the addresses but apart from the addresses we can share the code.
This patch makes this possible by checking the chip's FEATURE_ADDR_SHIFTED flag in common JEDEC functions and applying the right addresses respectively.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net Signed-off-by: Stefan Tauner stefan.tauner@alumni.tuwien.ac.at Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Deleted: trunk/m29f400bt.c Modified: trunk/82802ab.c trunk/Makefile trunk/chipdrivers.h trunk/en29lv640b.c trunk/flashchips.c trunk/jedec.c
Modified: trunk/82802ab.c ============================================================================== --- trunk/82802ab.c Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/82802ab.c Fri Aug 8 10:33:01 2014 (r1840) @@ -44,7 +44,7 @@ { chipaddr bios = flash->virtual_memory; uint8_t id1, id2, flashcontent1, flashcontent2; - int shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED) != 0; + int shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED) ? 1 : 0;
/* Reset to get a clean state */ chip_writeb(flash, 0xFF, bios);
Modified: trunk/Makefile ============================================================================== --- trunk/Makefile Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/Makefile Fri Aug 8 10:33:01 2014 (r1840) @@ -351,7 +351,7 @@ # Flash chip drivers and bus support infrastructure.
CHIP_OBJS = jedec.o stm50.o w39.o w29ee011.o \ - sst28sf040.o m29f400bt.o 82802ab.o \ + sst28sf040.o 82802ab.o \ sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o spi25_statusreg.o \ opaque.o sfdp.o en29lv640b.o at45db.o
Modified: trunk/chipdrivers.h ============================================================================== --- trunk/chipdrivers.h Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/chipdrivers.h Fri Aug 8 10:33:01 2014 (r1840) @@ -155,10 +155,6 @@ int printlock_regspace2_block_eraser_0(struct flashctx *flash); int printlock_regspace2_block_eraser_1(struct flashctx *flash);
-/* m29f400bt.c */ -int probe_m29f400bt(struct flashctx *flash); -int write_m29f400bt(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); - /* sst28sf040.c */ int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, unsigned int blocklen); int erase_sector_28sf040(struct flashctx *flash, unsigned int address, unsigned int sector_size); @@ -197,8 +193,6 @@
/* en29lv640b.c */ int probe_en29lv640b(struct flashctx *flash); -int erase_block_shifted_jedec(struct flashctx *flash, unsigned int start, unsigned int len); -int erase_chip_block_shifted_jedec(struct flashctx *flash, unsigned int start, unsigned int len); int write_en29lv640b(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
#endif /* !__CHIPDRIVERS_H__ */
Modified: trunk/en29lv640b.c ============================================================================== --- trunk/en29lv640b.c Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/en29lv640b.c Fri Aug 8 10:33:01 2014 (r1840) @@ -85,51 +85,3 @@
return 0; } - -static int erase_chip_shifted_jedec(struct flashctx *flash) -{ - chipaddr bios = flash->virtual_memory; - - chip_writeb(flash, 0xAA, bios + 0xAAA); - chip_writeb(flash, 0x55, bios + 0x555); - chip_writeb(flash, 0x80, bios + 0xAAA); - - chip_writeb(flash, 0xAA, bios + 0xAAA); - chip_writeb(flash, 0x55, bios + 0x555); - chip_writeb(flash, 0x10, bios + 0xAAA); - - programmer_delay(10); - toggle_ready_jedec(flash, bios); - - /* FIXME: Check the status register for errors. */ - return 0; -} - -int erase_block_shifted_jedec(struct flashctx *flash, unsigned int start, unsigned int len) -{ - chipaddr bios = flash->virtual_memory; - chipaddr dst = bios + start; - - chip_writeb(flash, 0xAA, bios + 0xAAA); - chip_writeb(flash, 0x55, bios + 0x555); - chip_writeb(flash, 0x80, bios + 0xAAA); - - chip_writeb(flash, 0xAA, bios + 0xAAA); - chip_writeb(flash, 0x55, bios + 0x555); - chip_writeb(flash, 0x30, dst); - - programmer_delay(10); - toggle_ready_jedec(flash, bios); - - /* FIXME: Check the status register for errors. */ - return 0; -} - -int erase_chip_block_shifted_jedec(struct flashctx *flash, unsigned int address, unsigned int blocklen) -{ - if ((address != 0) || (blocklen != flash->chip->total_size * 1024)) { - msg_cerr("%s called with incorrect arguments\n", __func__); - return -1; - } - return erase_chip_shifted_jedec(flash); -}
Modified: trunk/flashchips.c ============================================================================== --- trunk/flashchips.c Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/flashchips.c Fri Aug 8 10:33:01 2014 (r1840) @@ -4869,7 +4869,7 @@ .model_id = EON_EN29LV640B, .total_size = 8192, .page_size = 8192, - .feature_bits = 0, + .feature_bits = FEATURE_ADDR_SHIFTED, .tested = TEST_OK_PREW, .probe = probe_en29lv640b, .probe_timing = TIMING_ZERO, /* Datasheet has no timing info specified */ @@ -4880,10 +4880,10 @@ {8 * 1024, 8}, {64 * 1024, 127}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_block_jedec, }, { .eraseblocks = { {8 * 1024 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, }, }, .write = write_en29lv640b, @@ -5078,10 +5078,10 @@ .model_id = FUJITSU_MBM29F400BC, .total_size = 512, .page_size = 64 * 1024, - .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_EITHER_RESET, + .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_ADDR_2AA | FEATURE_EITHER_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, /* routine doesn't use probe_timing (m29f400bt.c) */ + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -5091,13 +5091,13 @@ {32 * 1024, 1}, {64 * 1024, 7}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_sector_jedec, }, { .eraseblocks = { {512 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, }, }, - .write = write_m29f400bt, + .write = write_jedec_1, .read = read_memmapped, .voltage = {4750, 5250}, /* 4.75-5.25V for type -55, others 4.5-5.5V */ }, @@ -5110,10 +5110,10 @@ .model_id = FUJITSU_MBM29F400TC, .total_size = 512, .page_size = 64 * 1024, - .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_EITHER_RESET, + .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_ADDR_AAA | FEATURE_EITHER_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, /* routine doesn't use probe_timing (m29f400bt.c) */ + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -5123,13 +5123,13 @@ {8 * 1024, 2}, {16 * 1024, 1}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_sector_jedec, }, { .eraseblocks = { {512 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, }, }, - .write = write_m29f400bt, + .write = write_jedec_1, .read = read_memmapped, .voltage = {4750, 5250}, /* 4.75-5.25V for type -55, others 4.5-5.5V */ }, @@ -5144,8 +5144,8 @@ .page_size = 0, .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_SHORT_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -5155,13 +5155,13 @@ {32 * 1024, 1}, {64 * 1024, 31}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_block_jedec, }, { .eraseblocks = { {2048 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, }, }, - .write = write_m29f400bt, /* Supports a fast mode too */ + .write = write_jedec_1, /* Supports a fast mode too */ .read = read_memmapped, .voltage = {3000, 3600}, /* 3.0-3.6V for type -70, others 2.7-3.6V */ }, @@ -5176,8 +5176,8 @@ .page_size = 0, .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_SHORT_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -5187,13 +5187,13 @@ {8 * 1024, 2}, {16 * 1024, 1}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_block_jedec, }, { .eraseblocks = { {2048 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, }, }, - .write = write_m29f400bt, /* Supports a fast mode too */ + .write = write_jedec_1, /* Supports a fast mode too */ .read = read_memmapped, .voltage = {3000, 3600}, /* 3.0-3.6V for type -70, others 2.7-3.6V */ }, @@ -12178,10 +12178,10 @@ .model_id = ST_M29F400BB, .total_size = 512, .page_size = 64 * 1024, - .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_EITHER_RESET, + .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_ADDR_2AA | FEATURE_EITHER_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, /* routine doesn't use probe_timing (m29f400bt.c) */ + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -12191,13 +12191,13 @@ {32 * 1024, 1}, {64 * 1024, 7}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_sector_jedec, }, { .eraseblocks = { {512 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, } }, - .write = write_m29f400bt, + .write = write_jedec_1, .read = read_memmapped, .voltage = {4500, 5500}, }, @@ -12210,10 +12210,10 @@ .model_id = ST_M29F400BT, .total_size = 512, .page_size = 64 * 1024, - .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_EITHER_RESET, + .feature_bits = FEATURE_ADDR_SHIFTED | FEATURE_ADDR_2AA | FEATURE_EITHER_RESET, .tested = TEST_UNTESTED, - .probe = probe_m29f400bt, - .probe_timing = TIMING_IGNORED, /* routine doesn't use probe_timing (m29f400bt.c) */ + .probe = probe_jedec, + .probe_timing = 10, // FIXME: check datasheet. Using the 10 us from probe_m29f400bt .block_erasers = { { @@ -12223,13 +12223,13 @@ {8 * 1024, 2}, {16 * 1024, 1}, }, - .block_erase = erase_block_shifted_jedec, + .block_erase = erase_sector_jedec, }, { .eraseblocks = { {512 * 1024, 1} }, - .block_erase = erase_chip_block_shifted_jedec, + .block_erase = erase_chip_block_jedec, } }, - .write = write_m29f400bt, + .write = write_jedec_1, .read = read_memmapped, .voltage = {4500, 5500}, },
Modified: trunk/jedec.c ============================================================================== --- trunk/jedec.c Wed Aug 6 17:09:15 2014 (r1839) +++ trunk/jedec.c Fri Aug 8 10:33:01 2014 (r1840) @@ -4,7 +4,7 @@ * Copyright (C) 2000 Silicon Integrated System Corporation * Copyright (C) 2006 Giampiero Giancipoli gianci@email.it * Copyright (C) 2006 coresystems GmbH info@coresystems.de - * Copyright (C) 2007, 2011 Carl-Daniel Hailfinger + * Copyright (C) 2007-2012 Carl-Daniel Hailfinger * Copyright (C) 2009 Sean Nelson audiohacked@gmail.com * Copyright (C) 2014 Stefan Tauner * @@ -116,9 +116,11 @@ static void start_program_jedec_common(const struct flashctx *flash, unsigned int mask) { chipaddr bios = flash->virtual_memory; - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); - chip_writeb(flash, 0xA0, bios + (0x5555 & mask)); + bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED); + + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); + chip_writeb(flash, 0xA0, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); }
int probe_jedec_29gl(struct flashctx *flash) @@ -174,6 +176,7 @@ { chipaddr bios = flash->virtual_memory; const struct flashchip *chip = flash->chip; + bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED); uint8_t id1, id2; uint32_t largeid1, largeid2; uint32_t flashcontent1, flashcontent2; @@ -203,31 +206,31 @@ /* Reset chip to a clean slate */ if ((chip->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET) { - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_exit) programmer_delay(10); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); if (probe_timing_exit) programmer_delay(10); } - chip_writeb(flash, 0xF0, bios + (0x5555 & mask)); + chip_writeb(flash, 0xF0, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_exit) programmer_delay(probe_timing_exit);
/* Issue JEDEC Product ID Entry command */ - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_enter) programmer_delay(10); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); if (probe_timing_enter) programmer_delay(10); - chip_writeb(flash, 0x90, bios + (0x5555 & mask)); + chip_writeb(flash, 0x90, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_enter) programmer_delay(probe_timing_enter);
/* Read product ID */ - id1 = chip_readb(flash, bios); - id2 = chip_readb(flash, bios + 0x01); + id1 = chip_readb(flash, bios + (0x00 << shifted)); + id2 = chip_readb(flash, bios + (0x01 << shifted)); largeid1 = id1; largeid2 = id2;
@@ -246,14 +249,14 @@ /* Issue JEDEC Product ID Exit command */ if ((chip->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET) { - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_exit) programmer_delay(10); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); if (probe_timing_exit) programmer_delay(10); } - chip_writeb(flash, 0xF0, bios + (0x5555 & mask)); + chip_writeb(flash, 0xF0, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); if (probe_timing_exit) programmer_delay(probe_timing_exit);
@@ -262,8 +265,8 @@ msg_cdbg(", id1 parity violation");
/* Read the product ID location again. We should now see normal flash contents. */ - flashcontent1 = chip_readb(flash, bios); - flashcontent2 = chip_readb(flash, bios + 0x01); + flashcontent1 = chip_readb(flash, bios + (0x00 << shifted)); + flashcontent2 = chip_readb(flash, bios + (0x01 << shifted));
/* Check if it is a continuation ID, this should be a while loop. */ if (flashcontent1 == 0x7F) { @@ -294,21 +297,23 @@ unsigned int pagesize, unsigned int mask) { chipaddr bios = flash->virtual_memory; + bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED); unsigned int delay_us = 0; + if(flash->chip->probe_timing != TIMING_ZERO) delay_us = 10;
/* Issue the Sector Erase command */ - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x80, bios + (0x5555 & mask)); + chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us);
- chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); chip_writeb(flash, 0x30, bios + page); programmer_delay(delay_us); @@ -324,21 +329,23 @@ unsigned int blocksize, unsigned int mask) { chipaddr bios = flash->virtual_memory; + bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED); unsigned int delay_us = 0; + if(flash->chip->probe_timing != TIMING_ZERO) delay_us = 10;
/* Issue the Sector Erase command */ - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x80, bios + (0x5555 & mask)); + chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us);
- chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); chip_writeb(flash, 0x50, bios + block); programmer_delay(delay_us); @@ -353,23 +360,25 @@ static int erase_chip_jedec_common(struct flashctx *flash, unsigned int mask) { chipaddr bios = flash->virtual_memory; + bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED); unsigned int delay_us = 0; + if(flash->chip->probe_timing != TIMING_ZERO) delay_us = 10;
/* Issue the JEDEC Chip Erase command */ - chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x80, bios + (0x5555 & mask)); + chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us);
- chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); + chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); + chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask)); programmer_delay(delay_us); - chip_writeb(flash, 0x10, bios + (0x5555 & mask)); + chip_writeb(flash, 0x10, bios + ((shifted ? 0x2AAA : 0x5555) & mask)); programmer_delay(delay_us);
toggle_ready_jedec_slow(flash, bios);