Edward O'Callaghan has uploaded this change for review.
flashrom.c: Reduce the prog global state machine
programmer_init() no longer needs to set a full ref to the programmer
handle. A few cases of needing the programmer name and if it is a
internal type are required however a 'const char *' and 'bool' type
are much easier to reason about as well as mitigates going backwards
with patches that attempt to use the 'programmer' state via the global.
Change-Id: I93dfe09fe877acd32c4f22665921544ccd9323f6
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M flashrom.c
1 file changed, 25 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/03/70603/1
diff --git a/flashrom.c b/flashrom.c
index 4f9bf7d..59533d2 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -36,7 +36,9 @@
const char flashrom_version[] = FLASHROM_VERSION;
-static const struct programmer_entry *programmer = NULL;
+// TODO: Remove global state.
+static const char *g_programmer_name = NULL;
+static bool g_programmer_type = false;
/*
* Programmers supporting multiple buses can have differing size limits on
@@ -132,7 +134,10 @@
msg_perr("Invalid programmer specified!\n");
return -1;
}
- programmer = prog;
+ g_programmer_name = prog->name;
+#if CONFIG_INTERNAL == 1
+ g_programmer_type = prog == &programmer_internal;
+#endif
/* Initialize all programmer specific data. */
/* Default to unlimited decode sizes. */
max_rom_decode = (const struct decode_sizes) {
@@ -996,7 +1001,7 @@
msg_cinfo("mapped at physical address 0x%0*" PRIxPTR ".\n",
PRIxPTR_WIDTH, flash->physical_memory);
else
- msg_cinfo("on %s.\n", programmer->name);
+ msg_cinfo("on %s.\n", g_programmer_name);
/* Flash registers may more likely not be mapped if the chip was forced.
* Lock info may be stored in registers, so avoid lock info printing. */
@@ -1480,11 +1485,7 @@
static bool is_internal_programmer()
{
-#if CONFIG_INTERNAL == 1
- return programmer == &programmer_internal;
-#else
- return false;
-#endif
+ return g_programmer_type;
}
static void nonfatal_help_message(void)
To view, visit change 70603. To unsubscribe, or for help writing mail filters, visit settings.