summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-08-25 23:11:56 +1000
committerAnastasia Klimchuk <aklm@chromium.org>2022-11-06 23:30:33 +0000
commitaf76e447527da609965dff5726696b59d6873d6e (patch)
treea6153ef63056d4501cec684410a28314a4aea7e5
parent39b189077379a6cdd99e5ae20452fa685b94500e (diff)
downloadflashrom-af76e447527da609965dff5726696b59d6873d6e.tar.gz
flashrom-af76e447527da609965dff5726696b59d6873d6e.tar.bz2
flashrom-af76e447527da609965dff5726696b59d6873d6e.zip
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>
-rw-r--r--cli_classic.c5
-rw-r--r--flashrom.c7
-rw-r--r--include/chipdrivers.h1
-rw-r--r--include/flash.h3
-rw-r--r--libflashrom.c6
-rw-r--r--w29ee011.c23
6 files changed, 27 insertions, 18 deletions
diff --git a/cli_classic.c b/cli_classic.c
index b66094ccd..574afff1f 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -646,6 +646,7 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
for (j = 0; j < registered_master_count; j++) {
startchip = 0;
while (chipcount < (int)ARRAY_SIZE(flashes)) {
- startchip = probe_flash(&registered_masters[j], startchip, &flashes[chipcount], 0);
+ startchip = probe_flash(&registered_masters[j], startchip, &flashes[chipcount], 0, chip_to_probe);
if (startchip == -1)
break;
chipcount++;
@@ -1020,7 +1021,7 @@ int main(int argc, char *argv[])
"chip, using the first one.\n");
for (j = 0; j < registered_master_count; j++) {
mst = &registered_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 694e2c5ed..db4dd7d0b 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 @@ static probe_func_t *lookup_probe_func_ptr(const struct flashchip *chip)
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 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
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 61d43c9fa..470d1fe26 100644
--- a/include/chipdrivers.h
+++ b/include/chipdrivers.h
@@ -195,6 +195,7 @@ int printlock_at49f(struct flashctx *flash);
/* 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 2ba235db4..da200ea9a 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -475,13 +475,12 @@ size_t strnlen(const char *str, size_t n);
/* 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 cbc624309..c83c1bd8c 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -221,8 +221,6 @@ int flashrom_flash_probe(struct flashrom_flashctx **const flashctx,
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 @@ int flashrom_flash_probe(struct flashrom_flashctx **const flashctx,
for (i = 0; i < registered_master_count; ++i) {
int flash_idx = -1;
- if (!ret || (flash_idx = probe_flash(&registered_masters[i], 0, *flashctx, 0)) != -1) {
+ if (!ret || (flash_idx = probe_flash(&registered_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(&registered_masters[i], flash_idx + 1, &second_flashctx, 0) != -1) {
+ if (probe_flash(&registered_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 62d7a0f70..234b865c8 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 @@ int probe_w29ee011(struct flashctx *flash)
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);