On 1/18/10 6:34 PM, Carl-Daniel Hailfinger wrote:

I might add that reviewing this one was more difficult because it used
standard 3 lines of context and it was not obvious to which chips the
patch belonged.

Sorry, about that! I really need to fix my git config to use 7 or 9 lines of context.

Convert ST to block erasers:
ST M25P05-A
ST M25P05.RES
ST M25P10-A
ST M25P10.RES
ST M25P20
ST M25P40
ST M25P40-old
ST M25P80
ST M25P16
ST M25P32
ST M25P64
ST M25P128
ST M29F002B
ST M29F002T/NT
ST M29F040B
ST M29F400BT
ST M29W010B
ST M29W040B
ST M50FLW040A
ST M50FLW040B
ST M50FLW080A
ST M50FLW080B
ST M50FW002
ST M50FW016
ST M50FW040
ST M50FW080
ST M50LPW116

Add erase_chip_stm50flw0x0x to stm50flw0x0x.c
Add copyright to stm50flw0x0x.c
Fix block sizes and counts
Omit M50FLW0x0x mixed sector/block eraser
Convert the used 82802ab functions to their stm50flw0x0x equivalents
Fix incorrect sizes as found by Carl-Daniel.

Signed-off-by: Sean Nelson <[email protected]>

diff --git a/chipdrivers.h b/chipdrivers.h
index 496aa7e..6e2edc6 100644
--- a/chipdrivers.h
+++ b/chipdrivers.h
@@ -161,12 +161,15 @@ int write_winbond_fwhub(struct flashchip *flash, uint8_t 
*buf);
 /* w29ee011.c */
 int probe_w29ee011(struct flashchip *flash);
 
 /* w49f002u.c */
 int write_49f002(struct flashchip *flash, uint8_t *buf);
 
 /* 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);
 
 #endif /* !__CHIPDRIVERS_H__ */
diff --git a/flashchips.c b/flashchips.c
index 0803dd0..69c0d0c 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -4185,19 +4185,29 @@ struct flashchip flashchips[] = {
                .name           = "M25P05-A",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P05A,
                .total_size     = 64,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {32 * 1024, 2} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {64 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        /* The ST M25P05 is a bit of a problem. It has the same ID as the
         * ST M25P05-A in RES mode, but supports only 128 byte writes instead
         * of 256 byte writes. We rely heavily on the fact that probe_spi_res
         * only is successful if RDID does not work.
         */
@@ -4206,424 +4216,710 @@ struct flashchip flashchips[] = {
                .name           = "M25P05.RES",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P05_RES,
                .total_size     = 64,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_res,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {32 * 1024, 2} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {64 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_1, /* 128 */
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P10-A",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P10A,
                .total_size     = 128,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {32 * 1024, 4} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {128 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        /* The ST M25P10 has the same problem as the M25P05. */
        {
                .vendor         = "ST",
                .name           = "M25P10.RES",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P10_RES,
                .total_size     = 128,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_res,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {32 * 1024, 4} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {128 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_1, /* 128 */
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P20",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P20,
                .total_size     = 256,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 4} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {256 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P40",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P40,
                .total_size     = 512,
                .page_size      = 256,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P40-old",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P40_RES,
                .total_size     = 512,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_res,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P80",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P80,
                .total_size     = 1024,
                .page_size      = 256,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 16} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {1024 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P16",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P16,
                .total_size     = 2048,
                .page_size      = 256,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 32} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {2 * 1024 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P32",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P32,
                .total_size     = 4096,
                .page_size      = 256,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 64} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {4 * 1024 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P64",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P64,
                .total_size     = 8192,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 128} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {8 * 1024 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M25P128",
                .bustype        = CHIP_BUSTYPE_SPI,
                .manufacture_id = ST_ID,
                .model_id       = ST_M25P128,
                .total_size     = 16384,
                .page_size      = 256,
                .tested         = TEST_UNTESTED,
                .probe          = probe_spi_rdid,
                .probe_timing   = TIMING_ZERO,
-               .erase          = spi_chip_erase_c7,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {256 * 1024, 64} },
+                               .block_erase = spi_block_erase_d8,
+                       }, {
+                               .eraseblocks = { {16 * 1024 * 1024, 1} },
+                               .block_erase = spi_block_erase_c7,
+                       }
+               },
                .write          = spi_chip_write_256,
                .read           = spi_chip_read,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29F002B",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29F002B,
                .total_size     = 256,
                .page_size      = 64 * 1024,
                .tested         = TEST_UNTESTED,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_ZERO,  /* Datasheet has no timing info 
specified */
-               .erase          = erase_m29f002,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = {
+                                       {16 * 1024, 1},
+                                       {8 * 1024, 2},
+                                       {32 * 1024, 1},
+                                       {64 * 1024, 3},
+                               },
+                               .block_erase = erase_sector_jedec,
+                       }, {
+                               .eraseblocks = { {256 * 1024, 1} },
+                               .block_erase = erase_chip_block_jedec,
+                       }
+               },
                .write          = write_m29f002b,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29F002T/NT",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29F002T,
                .total_size     = 256,
                .page_size      = 64 * 1024,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_ZERO,  /* Datasheet has no timing info 
specified */
-               .erase          = erase_m29f002,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = {
+                                       {64 * 1024, 3},
+                                       {32 * 1024, 1},
+                                       {8 * 1024, 2},
+                                       {16 * 1024, 1},
+                               },
+                               .block_erase = erase_sector_jedec,
+                       }, {
+                               .eraseblocks = { {256 * 1024, 1} },
+                               .block_erase = erase_chip_block_jedec,
+                       }
+               },
                .write          = write_m29f002t,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29F040B",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29F040B,
                .total_size     = 512,
                .page_size      = 64 * 1024,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_29f040b,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (am29f040b.c) */
-               .erase          = erase_29f040b,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8}, },
+                               .block_erase = erase_sector_29f040b,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = erase_chip_29f040b,
+                       }
+               },
                .write          = write_29f040b,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29F400BT",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29F400BT,
                .total_size     = 512,
                .page_size      = 64 * 1024,
                .tested         = TEST_UNTESTED,
                .probe          = probe_m29f400bt,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (m29f400bt.c) */
-               .erase          = erase_m29f400bt,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = {
+                                       {64 * 1024, 7},
+                                       {32 * 1024, 1},
+                                       {8 * 1024, 2},
+                                       {16 * 1024, 1},
+                               },
+                               .block_erase = block_erase_m29f400bt,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = block_erase_chip_m29f400bt,
+                       }
+               },
                .write          = write_coreboot_m29f400bt,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29W010B",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29W010B,
                .total_size     = 128,
                .page_size      = 16 * 1024,
                .tested         = TEST_UNTESTED,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_ZERO,  /* Datasheet has no timing info 
specified */
-               .erase          = erase_chip_jedec,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {16 * 1024, 8}, },
+                               .block_erase = erase_sector_jedec,
+                       }, {
+                               .eraseblocks = { {128 * 1024, 1} },
+                               .block_erase = erase_chip_block_jedec,
+                       }
+               },
                .write          = write_jedec,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "ST",
                .name           = "M29W040B",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = ST_ID,
                .model_id       = ST_M29W040B,
                .total_size     = 512,
                .page_size      = 64 * 1024,
                .tested         = TEST_UNTESTED,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_ZERO,  /* Datasheet has no timing info 
specified */
-               .erase          = erase_chip_jedec,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8}, },
+                               .block_erase = erase_sector_jedec,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = erase_chip_block_jedec,
+                       }
+               },
                .write          = write_jedec,
                .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_jedec,
                .probe_timing   = TIMING_FIXME,
-               .erase          = erase_stm50flw0x0x,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
                .write          = write_stm50flw0x0x,
                .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,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_FIXME,
-               .erase          = erase_stm50flw0x0x,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
                .write          = write_stm50flw0x0x,
                .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_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_FIXME,
-               .erase          = erase_stm50flw0x0x,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 16}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {1024 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
                .write          = write_stm50flw0x0x,
                .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,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_FIXME,
-               .erase          = erase_stm50flw0x0x,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 16}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {1024 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
                .write          = write_stm50flw0x0x,
                .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,
                .tested         = TEST_UNTESTED,
                .probe          = probe_49lfxxxc,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (sst49lfxxxc.c) */
                .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = {
+                                       {64 * 1024, 3},
+                                       {32 * 1024, 1},
+                                       {8 * 1024, 2},
+                                       {16 * 1024, 1},
+                               },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {256 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
                .write          = NULL,
                .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,
                .tested         = TEST_UNTESTED,
                .probe          = probe_82802ab,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (82802ab.c) */
-               .erase          = erase_82802ab,
-               .write          = write_82802ab,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 32}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {2 * 1024 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
+               .write          = write_stm50flw0x0x,
                .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,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_82802ab,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (82802ab.c) */
-               .erase          = erase_82802ab,
-               .write          = write_82802ab,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 8}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {512 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
+               .write          = write_stm50flw0x0x,
                .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,
-               .tested         = TEST_OK_PREW,
+               .tested         = TEST_OK_PRW,
                .probe          = probe_82802ab,
                .probe_timing   = TIMING_IGNORED, /* routine don't use 
probe_timing (82802ab.c) */
-               .erase          = erase_82802ab,
-               .write          = write_82802ab,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = { {64 * 1024, 16}, },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {1024 * 1024, 1} },
+                               .block_erase = erase_chip_stm50flw0x0x,
+                       }
+               },
+               .write          = write_stm50flw0x0x,
                .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,
                .tested         = TEST_UNTESTED,
                .probe          = probe_jedec,
                .probe_timing   = TIMING_ZERO,  /* Datasheet has no timing info 
specified */
-               .erase          = erase_chip_jedec,
+               .erase          = NULL,
+               .block_erasers  =
+               {
+                       {
+                               .eraseblocks = {
+                                       {4 * 1024, 16},
+                                       {64 * 1024, 30},
+                                       {32 * 1024, 1},
+                                       {8 * 1024, 2},
+                                       {16 * 1024, 1},
+                               },
+                               .block_erase = erase_block_stm50flw0x0x,
+                       }, {
+                               .eraseblocks = { {2 * 1024 * 1024, 1} },
+                               .block_erase = erase_chip_block_jedec,
+                       }
+               },
                .write          = write_jedec,
                .read           = read_memmapped,
        },
 
        {
                .vendor         = "SyncMOS",
                .name           = "S29C31004T",
                .bustype        = CHIP_BUSTYPE_PARALLEL,
                .manufacture_id = SYNCMOS_ID,
diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c
index e90bbd2..3b56436 100644
--- a/stm50flw0x0x.c
+++ b/stm50flw0x0x.c
@@ -1,13 +1,14 @@
 /*
  * This file is part of the flashrom project.
  *
  * Copyright (C) 2008 Claus Gindhart <[email protected]>
+ * Copyright (C) 2009 Sean Nelson <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -93,37 +94,60 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int 
offset)
                if (chip_readb(wrprotect + offset) != unlock_sector) {
                        printf("Cannot unlock sector @ 0x%x\n", offset);
                        return -1;
                }
        }
 
        return 0;
 }
 
-int erase_block_stm50flw0x0x(struct flashchip *flash, int offset)
+int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, 
unsigned int blocksize)
 {
-       chipaddr bios = flash->virtual_memory + offset;
+       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);
 
-       if (check_erased_range(flash, offset, flash->page_size)) {
+       if (check_erased_range(flash, block, blocksize)) {
                fprintf(stderr, "ERASE FAILED!\n");
                return -1;
        }
-       printf("DONE BLOCK 0x%x\n", offset);
+       printf("DONE BLOCK 0x%x\n", block);
+
+       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);
+       // now start it
+       chip_writeb(0x32, bios);
+       chip_writeb(0xd0, bios);
+       programmer_delay(10);
+
+       wait_stm50flw0x0x(flash->virtual_memory);
+
+       if (check_erased_range(flash, sector, sectorsize)) {
+               fprintf(stderr, "ERASE FAILED!\n");
+               return -1;
+       }
+       printf("DONE BLOCK 0x%x\n", sector);
 
        return 0;
 }
 
 int write_page_stm50flw0x0x(chipaddr bios, uint8_t *src,
                            chipaddr dst, int page_size)
 {
        int i, rc = 0;
        chipaddr d = dst;
@@ -172,28 +196,38 @@ int erase_stm50flw0x0x(struct flashchip *flash)
        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)) {
+               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)) {
+               msg_cerr("%s called with incorrect arguments\n",
+                       __func__);
+               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) {
@@ -215,19 +249,19 @@ int write_stm50flw0x0x(struct flashchip *flash, uint8_t * 
buf)
                 */
                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);
+                       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");
        free(tmpbuf);
 
        return rc;
 }
_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to