Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/73456 )
Change subject: internal: Move laptop_ok into board_cfg ......................................................................
internal: Move laptop_ok into board_cfg
Due to how internal is structured around chipset_flash_enable() entry we need to prepare a crafted programmer_cfg that contains a board_enable substructure with data derived from the board_enable subsystem. While this is certainly not perfection, it does make clear the relationships between board_enable into chipset_flash_enable and subsequently the overall internal programmer initialisation in a RAII fashion at the type level over closure upon global state that is impossible to reason about.
TEST=`$ sudo ./flashrom -p internal --flash-name`.
Change-Id: I459215253845c2af73262943ce91a36464e9eb06 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M board_enable.c M chipset_enable.c M flashrom.c M include/programmer.h M internal.c 5 files changed, 40 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/56/73456/1
diff --git a/board_enable.c b/board_enable.c index f10f5fc..d9af44e 100644 --- a/board_enable.c +++ b/board_enable.c @@ -2293,7 +2293,7 @@ static int p2_whitelist_laptop(struct board_cfg *cfg) { cfg->is_laptop = 1; - laptop_ok = true; + cfg->laptop_ok = true; msg_pdbg("Whitelisted laptop detected.\n"); return 0; } diff --git a/chipset_enable.c b/chipset_enable.c index e1dd6a3..16ef0f4 100644 --- a/chipset_enable.c +++ b/chipset_enable.c @@ -826,7 +826,7 @@
/* Suppress unknown laptop warning if we booted from SPI. */ if (boot_buses & BUS_SPI) - laptop_ok = true; + cfg->bcfg->laptop_ok = true;
return 0; } @@ -971,7 +971,7 @@
/* Suppress unknown laptop warning if we booted from SPI. */ if (!ret && (boot_buses & BUS_SPI)) - laptop_ok = true; + cfg->bcfg->laptop_ok = true;
_freepci_ret: pci_free_dev(spi_dev); @@ -1087,7 +1087,7 @@
/* Suppress unknown laptop warning if we booted from SPI. */ if (boot_buses & BUS_SPI) - laptop_ok = true; + cfg->bcfg->laptop_ok = true;
return 0; } @@ -1676,7 +1676,7 @@
/* Suppress unknown laptop warning if we booted from SPI. */ if (!ret && want_spi) - laptop_ok = true; + cfg->bcfg->laptop_ok = true;
return ret; } diff --git a/flashrom.c b/flashrom.c index 3cf67f1..da46354 100644 --- a/flashrom.c +++ b/flashrom.c @@ -65,10 +65,6 @@ */ static bool may_register_shutdown = false;
-struct programmer_cfg { - char *params; -}; - /* Register a function to be executed on programmer shutdown. * The advantage over atexit() is that you can supply a void pointer which will * be used as parameter to the registered function upon programmer shutdown. diff --git a/include/programmer.h b/include/programmer.h index ec92702..5b304f5 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -30,7 +30,11 @@ USB, OTHER, }; -struct programmer_cfg; +struct board_cfg; +struct programmer_cfg { + char *params; + struct board_cfg *bcfg; +};
struct dev_entry { uint16_t vendor_id; @@ -162,6 +166,7 @@
struct board_cfg { int is_laptop; + bool laptop_ok; };
struct board_match { @@ -267,7 +272,6 @@ #endif
#if CONFIG_INTERNAL == 1 -extern bool laptop_ok; extern bool force_boardmismatch; void probe_superio(void); int register_superio(struct superio s); diff --git a/internal.c b/internal.c index 7f0e0e9..79d6352 100644 --- a/internal.c +++ b/internal.c @@ -27,8 +27,6 @@ #include "hwaccess_x86_io.h" #endif
-bool laptop_ok = false; - bool force_boardmismatch = false;
enum chipbustype internal_buses_supported = BUS_NONE; @@ -108,9 +106,9 @@ }
// FIXME: remove '_' suffix from parameters once global shadowing is fixed. -static void report_nonwl_laptop_detected(int is_laptop, bool laptop_ok_) +static void report_nonwl_laptop_detected(int is_laptop, bool laptop_ok) { - if (is_laptop && !laptop_ok_) { + if (is_laptop && !laptop_ok) { msg_pinfo("========================================================================\n"); if (is_laptop == 1) { msg_pinfo("You seem to be running flashrom on an unknown laptop. Some\n" @@ -159,7 +157,7 @@ return ret;
/* Unconditionally reset global state from previous operation. */ - laptop_ok = false; + bcfg.laptop_ok = false;
/* Default to Parallel/LPC/FWH flash devices. If a known host controller * is found, the host controller init routine sets the @@ -229,13 +227,15 @@ * this isn't a laptop. Board-enables may override this, * non-legacy buses (SPI and opaque atm) are probed anyway. */ - if (bcfg.is_laptop && !(laptop_ok || force_laptop || (not_a_laptop && bcfg.is_laptop == 2))) + if (bcfg.is_laptop && !(bcfg.laptop_ok || force_laptop || (not_a_laptop && bcfg.is_laptop == 2))) internal_buses_supported = BUS_NONE;
/* try to enable it. Failure IS an option, since not all motherboards * really need this to be done, etc., etc. */ - ret = chipset_flash_enable(cfg); + struct programmer_cfg icfg = *cfg; + icfg.bcfg = &bcfg; + ret = chipset_flash_enable(&icfg); if (ret == -2) { msg_perr("WARNING: No chipset found. Flash detection " "will most likely fail.\n"); @@ -259,7 +259,7 @@ internal_par_init(internal_buses_supported);
/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */ - report_nonwl_laptop_detected(bcfg.is_laptop, laptop_ok); + report_nonwl_laptop_detected(bcfg.is_laptop, bcfg.laptop_ok);
ret = 0;