1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00

tree/: Convert flashchips db to use indirection for erase_block

This paves the way to allow for the conversion of flashchip erase_block
func ptr to enumerate values. This change should be a NOP.

TEST=`diff -u <(objdump -D flashchips.o_bk) <(objdump -D flashchips.o)`.

Change-Id: I122295ec9add0fe0efd27273c9725e5d64f6dbe2
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69131
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Edward O'Callaghan 2022-11-02 12:15:38 +11:00 committed by Edward O'Callaghan
parent 2f0e49c2ab
commit 3c44e12a28
9 changed files with 2007 additions and 1971 deletions

View File

@ -80,7 +80,7 @@ static unsigned int at45db_get_sector_count(struct flashctx *flash)
unsigned int i, j;
unsigned int cnt = 0;
for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
if (flash->chip->block_erasers[i].block_erase == &spi_erase_at45db_sector) {
if (flash->chip->block_erasers[i].block_erase == SPI_ERASE_AT45DB_SECTOR) {
for (j = 0; j < NUM_ERASEREGIONS; j++) {
cnt += flash->chip->block_erasers[i].eraseblocks[j].count;
}

View File

@ -71,7 +71,7 @@ static void atapromise_limit_chip(struct flashchip *chip, size_t rom_size)
for (i = 0; i < NUM_ERASEFUNCTIONS; ++i) {
if (chip->block_erasers[i].eraseblocks[0].size != size) {
chip->block_erasers[i].eraseblocks[0].count = 0;
chip->block_erasers[i].block_erase = NULL;
chip->block_erasers[i].block_erase = NO_BLOCK_ERASE_FUNC;
} else {
chip->block_erasers[i].eraseblocks[0].size = rom_size;
usable_erasers++;

File diff suppressed because it is too large Load Diff

View File

@ -340,18 +340,18 @@ static int check_block_eraser(const struct flashctx *flash, int k, int log)
{
struct block_eraser eraser = flash->chip->block_erasers[k];
if (!eraser.block_erase && !eraser.eraseblocks[0].count) {
if (eraser.block_erase == NO_BLOCK_ERASE_FUNC && !eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("not defined. ");
return 1;
}
if (!eraser.block_erase && eraser.eraseblocks[0].count) {
if (eraser.block_erase == NO_BLOCK_ERASE_FUNC && eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("eraseblock layout is known, but matching "
"block erase function is not implemented. ");
return 1;
}
if (eraser.block_erase && !eraser.eraseblocks[0].count) {
if (eraser.block_erase != NO_BLOCK_ERASE_FUNC && !eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("block erase function found, but "
"eraseblock layout is not defined. ");

View File

@ -268,6 +268,42 @@ enum read_func {
typedef int (read_func_t)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int read_flash(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
#define NO_BLOCK_ERASE_FUNC NULL
#define SPI_BLOCK_ERASE_EMULATION &spi_block_erase_emulation
#define SPI_BLOCK_ERASE_20 &spi_block_erase_20
#define SPI_BLOCK_ERASE_21 &spi_block_erase_21
#define SPI_BLOCK_ERASE_40 &spi_block_erase_40
#define SPI_BLOCK_ERASE_50 &spi_block_erase_50
#define SPI_BLOCK_ERASE_52 &spi_block_erase_52
#define SPI_BLOCK_ERASE_53 &spi_block_erase_53
#define SPI_BLOCK_ERASE_5C &spi_block_erase_5c
#define SPI_BLOCK_ERASE_60 &spi_block_erase_60
#define SPI_BLOCK_ERASE_62 &spi_block_erase_62
#define SPI_BLOCK_ERASE_81 &spi_block_erase_81
#define SPI_BLOCK_ERASE_C4 &spi_block_erase_c4
#define SPI_BLOCK_ERASE_C7 &spi_block_erase_c7
#define SPI_BLOCK_ERASE_D7 &spi_block_erase_d7
#define SPI_BLOCK_ERASE_D8 &spi_block_erase_d8
#define SPI_BLOCK_ERASE_DB &spi_block_erase_db
#define SPI_BLOCK_ERASE_DC &spi_block_erase_dc
#define S25FL_BLOCK_ERASE &s25fl_block_erase
#define S25FS_BLOCK_ERASE_D8 &s25fs_block_erase_d8
#define JEDEC_SECTOR_ERASE &erase_sector_jedec
#define JEDEC_BLOCK_ERASE &erase_block_jedec
#define JEDEC_CHIP_BLOCK_ERASE &erase_chip_block_jedec
#define OPAQUE_ERASE &erase_opaque
#define SPI_ERASE_AT45CS_SECTOR &spi_erase_at45cs_sector
#define SPI_ERASE_AT45DB_BLOCK &spi_erase_at45db_block
#define SPI_ERASE_AT45DB_CHIP &spi_erase_at45db_chip
#define SPI_ERASE_AT45DB_PAGE &spi_erase_at45db_page
#define SPI_ERASE_AT45DB_SECTOR &spi_erase_at45db_sector
#define ERASE_CHIP_28SF040 &erase_chip_28sf040
#define ERASE_SECTOR_28SF040 &erase_sector_28sf040
#define ERASE_BLOCK_82802AB &erase_block_82802ab
#define ERASE_SECTOR_49LFXXXC &erase_sector_49lfxxxc
#define STM50_SECTOR_ERASE &erase_sector_stm50
#define EDI_CHIP_BLOCK_ERASE &edi_chip_block_erase
struct flashchip {
const char *vendor;
const char *name;

4
sfdp.c
View File

@ -83,7 +83,7 @@ static int sfdp_add_uniform_eraser(struct flashchip *chip, uint8_t opcode, uint3
uint32_t total_size = chip->total_size * 1024;
erasefunc_t *erasefn = spi_get_erasefn_from_opcode(opcode);
if (erasefn == NULL || total_size == 0 || block_size == 0 ||
if (erasefn == NO_BLOCK_ERASE_FUNC || total_size == 0 || block_size == 0 ||
total_size % block_size != 0) {
msg_cdbg("%s: invalid input, please report to "
"flashrom@flashrom.org\n", __func__);
@ -101,7 +101,7 @@ static int sfdp_add_uniform_eraser(struct flashchip *chip, uint8_t opcode, uint3
return 1;
}
if (eraser->eraseblocks[0].size != 0 ||
eraser->block_erase != NULL) {
eraser->block_erase != NO_BLOCK_ERASE_FUNC) {
msg_cspew(" Block Eraser %d is already occupied.\n",
i);
continue;

32
spi25.c
View File

@ -622,21 +622,21 @@ static const struct {
erasefunc_t *func;
uint8_t opcode;
} function_opcode_list[] = {
{&spi_block_erase_20, 0x20},
{&spi_block_erase_21, 0x21},
{&spi_block_erase_50, 0x50},
{&spi_block_erase_52, 0x52},
{&spi_block_erase_53, 0x53},
{&spi_block_erase_5c, 0x5c},
{&spi_block_erase_60, 0x60},
{&spi_block_erase_62, 0x62},
{&spi_block_erase_81, 0x81},
{&spi_block_erase_c4, 0xc4},
{&spi_block_erase_c7, 0xc7},
{&spi_block_erase_d7, 0xd7},
{&spi_block_erase_d8, 0xd8},
{&spi_block_erase_db, 0xdb},
{&spi_block_erase_dc, 0xdc},
{SPI_BLOCK_ERASE_20, 0x20},
{SPI_BLOCK_ERASE_21, 0x21},
{SPI_BLOCK_ERASE_50, 0x50},
{SPI_BLOCK_ERASE_52, 0x52},
{SPI_BLOCK_ERASE_53, 0x53},
{SPI_BLOCK_ERASE_5C, 0x5c},
{SPI_BLOCK_ERASE_60, 0x60},
{SPI_BLOCK_ERASE_62, 0x62},
{SPI_BLOCK_ERASE_81, 0x81},
{SPI_BLOCK_ERASE_C4, 0xc4},
{SPI_BLOCK_ERASE_C7, 0xc7},
{SPI_BLOCK_ERASE_D7, 0xd7},
{SPI_BLOCK_ERASE_D8, 0xd8},
{SPI_BLOCK_ERASE_DB, 0xdb},
{SPI_BLOCK_ERASE_DC, 0xdc},
};
erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode)
@ -648,7 +648,7 @@ erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode)
}
msg_cinfo("%s: unknown erase opcode (0x%02x). Please report "
"this at flashrom@flashrom.org\n", __func__, opcode);
return NULL;
return NO_BLOCK_ERASE_FUNC;
}
uint8_t spi_get_opcode_from_erasefn(erasefunc_t *func)

View File

@ -177,19 +177,19 @@ static const struct flashchip chip_W25Q128_V = {
{
{
.eraseblocks = { {4 * 1024, 4096} },
.block_erase = spi_block_erase_20,
.block_erase = SPI_BLOCK_ERASE_20,
}, {
.eraseblocks = { {32 * 1024, 512} },
.block_erase = spi_block_erase_52,
.block_erase = SPI_BLOCK_ERASE_52,
}, {
.eraseblocks = { {64 * 1024, 256} },
.block_erase = spi_block_erase_d8,
.block_erase = SPI_BLOCK_ERASE_D8,
}, {
.eraseblocks = { {16 * 1024 * 1024, 1} },
.block_erase = spi_block_erase_60,
.block_erase = SPI_BLOCK_ERASE_60,
}, {
.eraseblocks = { {16 * 1024 * 1024, 1} },
.block_erase = spi_block_erase_c7,
.block_erase = SPI_BLOCK_ERASE_C7,
}
},
};

View File

@ -72,19 +72,19 @@ static const struct flashchip chip_W25Q128_V = {
{
{
.eraseblocks = { {4 * 1024, 4096} },
.block_erase = spi_block_erase_20,
.block_erase = SPI_BLOCK_ERASE_20,
}, {
.eraseblocks = { {32 * 1024, 512} },
.block_erase = spi_block_erase_52,
.block_erase = SPI_BLOCK_ERASE_52,
}, {
.eraseblocks = { {64 * 1024, 256} },
.block_erase = spi_block_erase_d8,
.block_erase = SPI_BLOCK_ERASE_D8,
}, {
.eraseblocks = { {16 * 1024 * 1024, 1} },
.block_erase = spi_block_erase_60,
.block_erase = SPI_BLOCK_ERASE_60,
}, {
.eraseblocks = { {16 * 1024 * 1024, 1} },
.block_erase = spi_block_erase_c7,
.block_erase = SPI_BLOCK_ERASE_C7,
}
},
.reg_bits =