diff --git a/chipdrivers.h b/chipdrivers.h index e7261e0..6ab8dd1 100644 --- a/chipdrivers.h +++ b/chipdrivers.h @@ -166,6 +166,8 @@ 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 write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf); #endif /* !__CHIPDRIVERS_H__ */ diff --git a/flashchips.c b/flashchips.c index 933682d..d151ad4 100644 --- a/flashchips.c +++ b/flashchips.c @@ -3977,7 +3977,17 @@ struct flashchip flashchips[] = { .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, }, @@ -3998,7 +4008,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4014,7 +4034,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4031,7 +4061,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4047,7 +4087,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4060,10 +4110,20 @@ struct flashchip flashchips[] = { .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, }, @@ -4079,7 +4139,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4092,10 +4162,20 @@ struct flashchip flashchips[] = { .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, }, @@ -4108,10 +4188,20 @@ struct flashchip flashchips[] = { .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, }, @@ -4124,10 +4214,20 @@ struct flashchip flashchips[] = { .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, }, @@ -4143,7 +4243,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4159,7 +4269,17 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, - .erase = spi_chip_erase_c7, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { {256 * 1024, 128} }, + .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, }, @@ -4175,7 +4295,22 @@ struct flashchip flashchips[] = { .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, }, @@ -4188,10 +4323,25 @@ struct flashchip flashchips[] = { .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, }, @@ -4204,10 +4354,20 @@ struct flashchip flashchips[] = { .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, }, @@ -4223,7 +4383,22 @@ struct flashchip flashchips[] = { .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, }, @@ -4239,7 +4414,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4255,7 +4440,17 @@ struct flashchip flashchips[] = { .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, }, @@ -4272,7 +4467,25 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_jedec, .probe_timing = TIMING_FIXME, - .erase = erase_stm50flw0x0x, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { + {4 * 1024, 16}, + {4 * 1024, 16}, + {64 * 1024, 5}, + {4 * 1024, 16}, + }, + .block_erase = erase_sector_stm50flw0x0x, + }, { + .eraseblocks = { {64 * 1024, 8}, }, + .block_erase = erase_block_stm50flw0x0x, + }, { + .eraseblocks = { {512 * 1024, 1} }, + .block_erase = erase_chip_stm50flw0x0x, + } + }, .write = write_stm50flw0x0x, .read = read_memmapped, }, @@ -4289,7 +4502,25 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_jedec, .probe_timing = TIMING_FIXME, - .erase = erase_stm50flw0x0x, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { + {4 * 1024, 16}, + {64 * 1024, 5}, + {4 * 1024, 16}, + {4 * 1024, 16}, + }, + .block_erase = erase_sector_stm50flw0x0x, + }, { + .eraseblocks = { {64 * 1024, 8}, }, + .block_erase = erase_block_stm50flw0x0x, + }, { + .eraseblocks = { {512 * 1024, 1} }, + .block_erase = erase_chip_stm50flw0x0x, + } + }, .write = write_stm50flw0x0x, .read = read_memmapped, }, @@ -4303,10 +4534,28 @@ struct flashchip flashchips[] = { .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 = { + {4 * 1024, 16}, + {4 * 1024, 16}, + {64 * 1024, 13}, + {4 * 1024, 16}, + }, + .block_erase = erase_sector_stm50flw0x0x, + }, { + .eraseblocks = { {64 * 1024, 16}, }, + .block_erase = erase_block_stm50flw0x0x, + }, { + .eraseblocks = { {1024 * 1024, 1} }, + .block_erase = erase_chip_stm50flw0x0x, + } + }, .write = write_stm50flw0x0x, .read = read_memmapped, }, @@ -4323,7 +4572,25 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_jedec, .probe_timing = TIMING_FIXME, - .erase = erase_stm50flw0x0x, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { + {4 * 1024, 16}, + {64 * 1024, 13}, + {4 * 1024, 16}, + {4 * 1024, 16}, + }, + .block_erase = erase_sector_stm50flw0x0x, + }, { + .eraseblocks = { {64 * 1024, 16}, }, + .block_erase = erase_block_stm50flw0x0x, + }, { + .eraseblocks = { {1024 * 1024, 1} }, + .block_erase = erase_chip_stm50flw0x0x, + } + }, .write = write_stm50flw0x0x, .read = read_memmapped, }, @@ -4340,6 +4607,21 @@ struct flashchip flashchips[] = { .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 = { {1024 * 1024, 1} }, + .block_erase = erase_chip_stm50flw0x0x, + } + }, .write = NULL, .read = read_memmapped, }, @@ -4355,7 +4637,17 @@ struct flashchip flashchips[] = { .tested = TEST_UNTESTED, .probe = probe_82802ab, .probe_timing = TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */ - .erase = erase_82802ab, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { {64 * 1024, 32}, }, + .block_erase = erase_82802ab_block, + }, { + .eraseblocks = { {2 * 1024 * 1024, 1} }, + .block_erase = erase_82802ab_chip, + } + }, .write = write_82802ab, .read = read_memmapped, }, @@ -4368,10 +4660,20 @@ struct flashchip flashchips[] = { .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, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { {64 * 1024, 8}, }, + .block_erase = erase_82802ab_block, + }, { + .eraseblocks = { {512 * 1024, 1} }, + .block_erase = erase_82802ab_chip, + } + }, .write = write_82802ab, .read = read_memmapped, }, @@ -4384,10 +4686,20 @@ struct flashchip flashchips[] = { .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, + .erase = NULL, + .block_erasers = + { + { + .eraseblocks = { {64 * 1024, 16}, }, + .block_erase = erase_82802ab_block, + }, { + .eraseblocks = { {1024 * 1024, 1} }, + .block_erase = erase_82802ab_chip, + } + }, .write = write_82802ab, .read = read_memmapped, }, @@ -4403,7 +4715,23 @@ struct flashchip flashchips[] = { .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, }, diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c index e90bbd2..a9f8be9 100644 --- a/stm50flw0x0x.c +++ b/stm50flw0x0x.c @@ -2,6 +2,7 @@ * This file is part of the flashrom project. * * Copyright (C) 2008 Claus Gindhart + * Copyright (C) 2009 Sean Nelson * * 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 @@ -99,9 +100,9 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset) 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); @@ -113,11 +114,34 @@ int erase_block_stm50flw0x0x(struct flashchip *flash, int offset) 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; } @@ -188,6 +212,16 @@ int erase_stm50flw0x0x(struct flashchip *flash) 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;