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

tree/: Convert flashchip probe func ptr to enumerate

This forges the way for flashchips.c to be pure declarative
data and lookup functions for dispatch to be pure. This
means that the flashchips data could be extracted out to
be agnostic data of the flashrom code and algorithms.

TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's.

Change-Id: I00aaab9c83f305cd47e78c36d9c2867f2b73c396
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66781
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
This commit is contained in:
Edward O'Callaghan 2022-08-15 12:05:31 +10:00 committed by Felix Singer
parent 74c3e56ec2
commit 10e7a0ebd7
4 changed files with 650 additions and 596 deletions

File diff suppressed because it is too large Load Diff

View File

@ -729,6 +729,38 @@ static int init_default_layout(struct flashctx *flash)
return 0;
}
typedef int (probe_func_t)(struct flashctx *flash);
static probe_func_t *lookup_probe_func_ptr(const struct flashchip *chip)
{
switch (chip->probe) {
case PROBE_JEDEC: return &probe_jedec;
case PROBE_JEDEC_29GL: return &probe_jedec_29gl;
case PROBE_OPAQUE: return &probe_opaque;
case PROBE_EDI_KB9012: return &edi_probe_kb9012;
case PROBE_AT82802AB: return &probe_82802ab;
case PROBE_W29EE011: return &probe_w29ee011;
case PROBE_EN29LV640B: return &probe_en29lv640b;
case PROBE_SPI_AT25F: return &probe_spi_at25f;
case PROBE_SPI_AT45DB: return &probe_spi_at45db;
case PROBE_SPI_BIG_SPANSION: return &probe_spi_big_spansion;
case PROBE_SPI_RDID: return &probe_spi_rdid;
case PROBE_SPI_RDID4: return &probe_spi_rdid4;
case PROBE_SPI_REMS: return &probe_spi_rems;
case PROBE_SPI_RES1: return &probe_spi_res1;
case PROBE_SPI_RES2: return &probe_spi_res2;
case PROBE_SPI_SFDP: return &probe_spi_sfdp;
case PROBE_SPI_ST95: return &probe_spi_st95;
/* default: total function, 0 indicates no probe function set.
* We explicitly do not want a default catch-all case in the switch
* to ensure unhandled enum's are compiler warnings.
*/
case NO_PROBE_FUNC: return NULL;
};
return NULL;
}
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force)
{
const struct flashchip *chip;
@ -745,7 +777,8 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
if (chip->bustype == BUS_SPI && !chip_to_probe && chip->spi_cmd_set != SPI25)
continue;
msg_gdbg("Probing for %s %s, %d kB: ", chip->vendor, chip->name, chip->total_size);
if (!chip->probe && !force) {
probe_func_t *probe_func = lookup_probe_func_ptr(chip);
if (!probe_func && !force) {
msg_gdbg("failed! flashrom has no probe function for this flash chip.\n");
continue;
}
@ -768,7 +801,7 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
if (force)
break;
if (flash->chip->probe(flash) != 1)
if (probe_func(flash) != 1)
goto notfound;
/* If this is the first chip found, accept it.

View File

@ -217,6 +217,27 @@ enum decode_range_func {
};
typedef void (decode_range_func_t)(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
enum probe_func {
NO_PROBE_FUNC = 0, /* 0 indicates no probe function set. */
PROBE_JEDEC = 1,
PROBE_JEDEC_29GL,
PROBE_OPAQUE,
PROBE_EDI_KB9012,
PROBE_AT82802AB,
PROBE_W29EE011,
PROBE_EN29LV640B,
PROBE_SPI_AT25F,
PROBE_SPI_AT45DB,
PROBE_SPI_BIG_SPANSION,
PROBE_SPI_RDID,
PROBE_SPI_RDID4,
PROBE_SPI_REMS,
PROBE_SPI_RES1,
PROBE_SPI_RES2,
PROBE_SPI_SFDP,
PROBE_SPI_ST95,
};
struct flashchip {
const char *vendor;
const char *name;
@ -258,7 +279,7 @@ struct flashchip {
SPI_EDI = 1,
} spi_cmd_set;
int (*probe) (struct flashctx *flash);
enum probe_func probe;
/* Delay after "enter/exit ID mode" commands in microseconds.
* NB: negative values have special meanings, see TIMING_* below.

View File

@ -31,7 +31,7 @@ struct flashchip mock_chip = {
.total_size = 0,
.page_size = 256,
.tested = TEST_BAD_PREW,
.probe = probe_spi_rdid,
.probe = PROBE_SPI_RDID,
.write = NULL,
};