Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67091 )
Change subject: flashrom.c: Make 'chip_to_probe' a param to probe_flash() ......................................................................
flashrom.c: Make 'chip_to_probe' a param to probe_flash()
Apart from the very bespoke case of 'probe_w29ee011()' the override 'chip_to_probe' name is a nature parameter to 'probe_flash()'. However we can deal with w29ee011 by providing a probe specific validation function to check if the chip can indeed be overriden.
TEST=`./flashrom -p internal --flash-name`.
Change-Id: Ifcdace07ea2135d83dea92cfa5c6bec8d7ddf05d Signed-off-by: Edward O'Callaghan quasisec@google.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/67091 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Felix Singer felixsinger@posteo.net Reviewed-by: Anastasia Klimchuk aklm@chromium.org --- M cli_classic.c M flashrom.c M include/chipdrivers.h M include/flash.h M libflashrom.c M w29ee011.c 6 files changed, 49 insertions(+), 18 deletions(-)
Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Anastasia Klimchuk: Looks good to me, approved
diff --git a/cli_classic.c b/cli_classic.c index b66094c..574afff 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -646,6 +646,7 @@ char *pparam = NULL; struct layout_include_args *include_args = NULL; char *wp_region = NULL; + const char *chip_to_probe = NULL;
/* * Safety-guard against a user who has (mistakenly) closed @@ -977,7 +978,7 @@ for (j = 0; j < registered_master_count; j++) { startchip = 0; while (chipcount < (int)ARRAY_SIZE(flashes)) { - startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0); + startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0, chip_to_probe); if (startchip == -1) break; chipcount++; @@ -1020,7 +1021,7 @@ "chip, using the first one.\n"); for (j = 0; j < registered_master_count; j++) { mst = ®istered_masters[j]; - startchip = probe_flash(mst, 0, &flashes[0], 1); + startchip = probe_flash(mst, 0, &flashes[0], 1, chip_to_probe); if (startchip != -1) break; } diff --git a/flashrom.c b/flashrom.c index 694e2c5..db4dd7d 100644 --- a/flashrom.c +++ b/flashrom.c @@ -35,7 +35,6 @@ #include "chipdrivers.h"
const char flashrom_version[] = FLASHROM_VERSION; -const char *chip_to_probe = NULL;
static const struct programmer_entry *programmer = NULL;
@@ -824,7 +823,7 @@ return NULL; }
-int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force) +int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force, const char *const chip_to_probe) { const struct flashchip *chip; enum chipbustype buses_common; @@ -864,6 +863,10 @@ if (force) break;
+ if (probe_func == &probe_w29ee011) + if (!w29ee011_can_override(flash->chip->name, chip_to_probe)) + goto notfound; + if (probe_func(flash) != 1) goto notfound;
diff --git a/include/chipdrivers.h b/include/chipdrivers.h index 61d43c9..470d1fe 100644 --- a/include/chipdrivers.h +++ b/include/chipdrivers.h @@ -195,6 +195,7 @@
/* w29ee011.c */ int probe_w29ee011(struct flashctx *flash); +bool w29ee011_can_override(const char *const chip_name, const char *const override_chip);
/* stm50.c */ int erase_sector_stm50(struct flashctx *flash, unsigned int block, unsigned int blocksize); diff --git a/include/flash.h b/include/flash.h index 2ba235d..da200ea 100644 --- a/include/flash.h +++ b/include/flash.h @@ -475,13 +475,12 @@
/* flashrom.c */ extern const char flashrom_version[]; -extern const char *chip_to_probe; char *flashbuses_to_text(enum chipbustype bustype); int map_flash(struct flashctx *flash); void unmap_flash(struct flashctx *flash); int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int erase_flash(struct flashctx *flash); -int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force); +int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force, const char *const chip_to_probe); int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len); void emergency_help_message(void); void print_version(void); diff --git a/libflashrom.c b/libflashrom.c index cbc6243..c83c1bd 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -221,8 +221,6 @@ int i, ret = 2; struct flashrom_flashctx second_flashctx = { 0, };
- chip_to_probe = chip_name; /* chip_to_probe is global in flashrom.c */ - *flashctx = malloc(sizeof(**flashctx)); if (!*flashctx) return 1; @@ -230,10 +228,10 @@
for (i = 0; i < registered_master_count; ++i) { int flash_idx = -1; - if (!ret || (flash_idx = probe_flash(®istered_masters[i], 0, *flashctx, 0)) != -1) { + if (!ret || (flash_idx = probe_flash(®istered_masters[i], 0, *flashctx, 0, chip_name)) != -1) { ret = 0; /* We found one chip, now check that there is no second match. */ - if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0) != -1) { + if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0, chip_name) != -1) { flashrom_layout_release(second_flashctx.default_layout); free(second_flashctx.chip); ret = 3; diff --git a/w29ee011.c b/w29ee011.c index 62d7a0f..234b865 100644 --- a/w29ee011.c +++ b/w29ee011.c @@ -15,9 +15,24 @@ */
#include <string.h> +#include <stdbool.h> + #include "flash.h" #include "chipdrivers.h"
+bool w29ee011_can_override(const char *const chip_name, const char *const override_chip) +{ + if (!override_chip || strcmp(override_chip, chip_name)) { + msg_cdbg("Old Winbond W29* probe method disabled because " + "the probing sequence puts the AMIC A49LF040A in " + "a funky state. Use 'flashrom -c %s' if you " + "have a board with such a chip.\n", chip_name); + return false; + } + + return true; +} + /* According to the Winbond W29EE011, W29EE012, W29C010M, W29C011A * datasheets this is the only valid probe function for those chips. */ @@ -26,14 +41,6 @@ chipaddr bios = flash->virtual_memory; uint8_t id1, id2;
- if (!chip_to_probe || strcmp(chip_to_probe, flash->chip->name)) { - msg_cdbg("Old Winbond W29* probe method disabled because " - "the probing sequence puts the AMIC A49LF040A in " - "a funky state. Use 'flashrom -c %s' if you " - "have a board with such a chip.\n", flash->chip->name); - return 0; - } - /* Issue JEDEC Product ID Entry command */ chip_writeb(flash, 0xAA, bios + 0x5555); programmer_delay(flash, 10);