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

dummyflasher.c: Get rid of get_data_from_context()

Relying on the global state 'dummy_buses_supported' to
determine the member master struct [mst.par or mst.spi]
is both buggy and ultimately unnecessary. It became
apparent after commit 4eef651ff503f81b77 just how fragile
this really was as the 'defaults' simultaneously selected
both buses causing get_data_from_context() to fall-though
however memory happened to workout by chance due to the
union. With the member master structs now being struct
fields the subtle bug is more apparent.

BUG=none
BRANCH=none
TEST=`./flashrom -r /tmp/fwupdater.apnSQQ -p dummy:emulate=VARIABLE_SIZE,image=test_update.sh.tmp.emu,size=8388608`

Change-Id: I07a34faf50ff0679cb3d6bc683142f82160010b1
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/54907
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Sam McNally <sammc@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Edward O'Callaghan 2021-05-25 20:51:16 +10:00 committed by Edward O'Callaghan
parent 52c0275c70
commit 0282a83ac6

View File

@ -103,18 +103,6 @@ static const uint8_t sfdp_table[] = {
#endif #endif
#endif #endif
static enum chipbustype dummy_buses_supported = BUS_NONE;
static struct emu_data* get_data_from_context(const struct flashctx *flash)
{
if (dummy_buses_supported & BUS_NONSPI)
return (struct emu_data *)flash->mst->par.data;
else if (dummy_buses_supported & BUS_SPI)
return (struct emu_data *)flash->mst->spi.data;
return NULL; /* buses was set to BUS_NONE. */
}
void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len) void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
{ {
msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n", msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
@ -688,7 +676,7 @@ int dummy_init(void)
/* Convert the parameters to lowercase. */ /* Convert the parameters to lowercase. */
tolower_string(bustext); tolower_string(bustext);
dummy_buses_supported = BUS_NONE; enum chipbustype dummy_buses_supported = BUS_NONE;
if (strstr(bustext, "parallel")) { if (strstr(bustext, "parallel")) {
dummy_buses_supported |= BUS_PARALLEL; dummy_buses_supported |= BUS_PARALLEL;
msg_pdbg("Enabling support for %s flash.\n", "parallel"); msg_pdbg("Enabling support for %s flash.\n", "parallel");
@ -1041,7 +1029,7 @@ dummy_init_out:
int probe_variable_size(struct flashctx *flash) int probe_variable_size(struct flashctx *flash)
{ {
unsigned int i; unsigned int i;
const struct emu_data *emu_data = get_data_from_context(flash); const struct emu_data *emu_data = flash->mst->spi.data;
/* Skip the probing if we don't emulate this chip. */ /* Skip the probing if we don't emulate this chip. */
if (!emu_data || emu_data->emu_chip != EMULATE_VARIABLE_SIZE) if (!emu_data || emu_data->emu_chip != EMULATE_VARIABLE_SIZE)