Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/67476 )
Change subject: flashrom.c: Embed is_internal state within the flashctx ......................................................................
flashrom.c: Embed is_internal state within the flashctx
This avoids a fragil stack pointer check and another reliance upon the 'programmer' handle as a global state.
Change-Id: I25717afc3a8f61ca9f4dfb4bb60d6cb048a2ad37 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M cli_classic.c M flashrom.c M include/flash.h M include/programmer.h M internal.c 5 files changed, 23 insertions(+), 15 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/67476/1
diff --git a/cli_classic.c b/cli_classic.c index dc4a49e..05eee02 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -1004,6 +1004,7 @@ }
fill_flash = &flashes[0]; + fill_flash->is_internal = prog->is_internal;
unsigned int progress_user_data[FLASHROM_PROGRESS_NR]; struct flashrom_progress progress_state = { diff --git a/flashrom.c b/flashrom.c index 402ba94..78897b4 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1298,15 +1298,6 @@ return 0; }
-static bool is_internal_programmer() -{ -#if CONFIG_INTERNAL == 1 - return programmer == &programmer_internal; -#else - return false; -#endif -} - static void nonfatal_help_message(bool is_internal) { msg_gerr("Good, writing to the flash chip apparently didn't do anything.\n"); @@ -1609,7 +1600,7 @@ * knows very well that booting won't work. */ if (ret) - emergency_help_message(is_internal_programmer()); + emergency_help_message(flashctx->is_internal); return ret; }
@@ -1688,7 +1679,7 @@ }
#if CONFIG_INTERNAL == 1 - if (is_internal_programmer() && cb_check_image(newcontents, flash_size) < 0) { + if (flashctx->is_internal && cb_check_image(newcontents, flash_size) < 0) { if (flashctx->flags.force_boardmismatch) { msg_pinfo("Proceeding anyway because user forced us to.\n"); } else { @@ -1741,18 +1732,18 @@ if (!flashctx->chip->read(flashctx, curcontents, 0, flash_size)) { msg_cinfo("done.\n"); if (!memcmp(oldcontents, curcontents, flash_size)) { - nonfatal_help_message(is_internal_programmer()); + nonfatal_help_message(flashctx->is_internal); goto _finalize_ret; } msg_cerr("Apparently at least some data has changed.\n"); } else msg_cerr("Can't even read anymore!\n"); - emergency_help_message(is_internal_programmer()); + emergency_help_message(flashctx->is_internal); goto _finalize_ret; } else { msg_cerr("\n"); } - emergency_help_message(is_internal_programmer()); + emergency_help_message(flashctx->is_internal); goto _finalize_ret; }
@@ -1769,7 +1760,7 @@ /* If we tried to write, and verification now fails, we might have an emergency situation. */ if (ret) - emergency_help_message(is_internal_programmer()); + emergency_help_message(flashctx->is_internal); else msg_cinfo("VERIFIED.\n"); } else { diff --git a/include/flash.h b/include/flash.h index 0d2dc1b..1513674 100644 --- a/include/flash.h +++ b/include/flash.h @@ -357,6 +357,7 @@ /* Progress reporting */ flashrom_progress_callback *progress_callback; struct flashrom_progress *progress_state; + bool is_internal; /* flashctx that belong to an internal programmer have special properties. */ };
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset diff --git a/include/programmer.h b/include/programmer.h index a7cea5e..170accd 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -47,6 +47,7 @@ const struct dev_entry *const dev; const char *const note; } devs; + bool is_internal;
int (*init) (const struct programmer_cfg *cfg);
diff --git a/internal.c b/internal.c index 43aa51b..0af4305 100644 --- a/internal.c +++ b/internal.c @@ -350,4 +350,5 @@ .map_flash_region = physmap, .unmap_flash_region = physunmap, .delay = internal_delay, + .is_internal = true, };