Matt DeVillier has uploaded this change for review.

View Change

cli_classic: Add option to use first detected chip if multiple found

In many cases, when flashrom detects multiple chips, it is simply unable
to distinguish between similar chips in the same family (eg, W25Q64).
In these instances, we may want to programmatically use the first chip
found, so add a parameter enabling this.

TEST=read flash on google/link with --use-first-chip option, which
previously required specifying the chip using -c.

Change-Id: I0427b1ef80e4eca16623f0fc9119d79f7dd62551
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
---
M cli_classic.c
1 file changed, 20 insertions(+), 8 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/60/85160/1
diff --git a/cli_classic.c b/cli_classic.c
index 8f37019..280e632 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -51,6 +51,7 @@
OPTION_WP_LIST,
OPTION_PROGRESS,
OPTION_SACRIFICE_RATIO,
+ OPTION_USE_FIRST_CHIP
#if CONFIG_RPMC_ENABLED == 1
OPTION_RPMC_READ_DATA,
OPTION_RPMC_WRITE_ROOT_KEY,
@@ -90,6 +91,7 @@
char *referencefile;
const char *chip_to_probe;
int sacrifice_ratio;
+ bool use_first_chip;

#if CONFIG_RPMC_ENABLED == 1
bool rpmc_read_data;
@@ -106,7 +108,7 @@
static void cli_classic_usage(const char *name)
{
printf("Usage: %s [-h|-R|-L|"
- "\n\t-p <programmername>[:<parameters>] [-c <chipname>]\n"
+ "\n\t-p <programmername>[:<parameters>] [-c <chipname>| --use-first-chip]\n"
"\t\t(--flash-name|--flash-size|\n"
"\t\t [-E|-x|(-r|-w|-v) <file>]\n"
"\t\t [(-l <layoutfile>|--ifd| --fmap|--fmap-file <file>) [-i <region>[:<file>]]...]\n"
@@ -128,6 +130,7 @@
" -N | --noverify-all verify included regions only (cf. -i)\n"
" -x | --extract extract regions to files\n"
" -l | --layout <layoutfile> read ROM layout from <layoutfile>\n"
+ " --use-first-chip in cases where multiple chips are detected, use the first one found\n"
" --wp-disable disable write protection\n"
" --wp-enable enable write protection\n"
" --wp-list list supported write protection ranges\n"
@@ -971,6 +974,9 @@
/* It is okay to convert invalid input to 0. */
options->sacrifice_ratio = atoi(optarg);
break;
+ case OPTION_USE_FIRST_CHIP:
+ options->use_first_chip = true;
+ break;
#if CONFIG_RPMC_ENABLED == 1
case OPTION_RPMC_READ_DATA:
options->rpmc_read_data = true;
@@ -1068,6 +1074,7 @@
{"output", 1, NULL, 'o'},
{"progress", 0, NULL, OPTION_PROGRESS},
{"sacrifice-ratio", 1, NULL, OPTION_SACRIFICE_RATIO},
+ {"use-first-chip", 0, NULL, OPTION_USE_FIRST_CHIP},
#if CONFIG_RPMC_ENABLED == 1
{"get-rpmc-status", 0, NULL, OPTION_RPMC_READ_DATA},
{"write-root-key", 0, NULL, OPTION_RPMC_WRITE_ROOT_KEY},
@@ -1196,13 +1203,18 @@
}

if (chipcount > 1) {
- msg_cinfo("Multiple flash chip definitions match the detected chip(s): \"%s\"",
- flashes[0].chip->name);
- for (i = 1; i < chipcount; i++)
- msg_cinfo(", \"%s\"", flashes[i].chip->name);
- msg_cinfo("\nPlease specify which chip definition to use with the -c <chipname> option.\n");
- ret = 1;
- goto out_shutdown;
+ if (options.use_first_chip) {
+ chipcount = 1;
+ startchip = 1;
+ } else {
+ msg_cinfo("Multiple flash chip definitions match the detected chip(s): \"%s\"",
+ flashes[0].chip->name);
+ for (i = 1; i < chipcount; i++)
+ msg_cinfo(", \"%s\"", flashes[i].chip->name);
+ msg_cinfo("\nPlease specify which chip definition to use with the -c <chipname> option.\n");
+ ret = 1;
+ goto out_shutdown;
+ }
} else if (!chipcount) {
msg_cinfo("No EEPROM/flash device found.\n");
if (!options.force || !options.chip_to_probe) {

To view, visit change 85160. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: I0427b1ef80e4eca16623f0fc9119d79f7dd62551
Gerrit-Change-Number: 85160
Gerrit-PatchSet: 1
Gerrit-Owner: Matt DeVillier <matt.devillier@gmail.com>