David Hendricks has uploaded this change for review. ( https://review.coreboot.org/28685
Change subject: Add CLI option to include a numeric range ......................................................................
Add CLI option to include a numeric range
This adds an option, --range, which allows the user to specify a numeric range directly on the command-line.
Change-Id: Ie2691051984bdeac128354c09bbe72aa05ef7401 Signed-off-by: David Hendricks dhendricks@fb.com --- M cli_classic.c M flash.h M layout.c 3 files changed, 49 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/85/28685/1
diff --git a/cli_classic.c b/cli_classic.c index 119c6f8..b98be48 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -55,6 +55,7 @@ " -l | --layout <layoutfile> read ROM layout from <layoutfile>\n" " --ifd read layout from an Intel Firmware Descriptor\n" " -i | --image <name> only flash image <name> from flash layout\n" + " --range start:end include numeric range\n" " -o | --output <logfile> log output to <logfile>\n" " --flash-contents <ref-file> assume flash contents to be <ref-file>\n" " -L | --list-supported print supported devices\n" @@ -97,7 +98,7 @@ struct flashctx *fill_flash; const char *name; int namelen, opt, i, j; - int startchip = -1, chipcount = 0, option_index = 0, force = 0, ifd = 0; + int startchip = -1, chipcount = 0, option_index = 0, force = 0, ifd = 0, include_range = 0; #if CONFIG_PRINT_WIKI == 1 int list_supported_wiki = 0; #endif @@ -108,6 +109,7 @@ enum { OPTION_IFD = 0x0100, OPTION_FLASH_CONTENTS, + OPTION_INCLUDE_RANGE, }; int ret = 0;
@@ -125,6 +127,7 @@ {"layout", 1, NULL, 'l'}, {"ifd", 0, NULL, OPTION_IFD}, {"image", 1, NULL, 'i'}, + {"range", 1, NULL, OPTION_INCLUDE_RANGE}, {"flash-contents", 1, NULL, OPTION_FLASH_CONTENTS}, {"list-supported", 0, NULL, 'L'}, {"list-supported-wiki", 0, NULL, 'z'}, @@ -239,6 +242,14 @@ } ifd = 1; break; + case OPTION_INCLUDE_RANGE: + tempstr = strdup(optarg); + if (include_numeric_range(get_global_layout(), tempstr)) { + free(tempstr); + cli_classic_abort_usage(); + } + include_range = 1; + break; case 'i': tempstr = strdup(optarg); if (register_include_arg(tempstr)) { @@ -552,7 +563,7 @@ goto out_shutdown; }
- if (layoutfile) { + if (layoutfile || include_range) { layout = get_global_layout(); } else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) || process_include_args(layout))) { diff --git a/flash.h b/flash.h index 01ff5cd..735cd21 100644 --- a/flash.h +++ b/flash.h @@ -388,6 +388,7 @@ /* layout.c */ int register_include_arg(char *name); int read_romlayout(const char *name); +int include_numeric_range(struct flashrom_layout *const l, const char *str); int normalize_romentries(const struct flashctx *flash); void layout_cleanup(void);
diff --git a/layout.c b/layout.c index fa66238..49dcba0 100644 --- a/layout.c +++ b/layout.c @@ -101,6 +101,41 @@ } #endif
+int include_numeric_range(struct flashrom_layout *const l, const char *str) +{ + char *tstr1, *tstr2; + char *orig = strdup(str); + int ret = 1; + + if (num_include_args >= MAX_ROMLAYOUT) { + msg_gerr("Maximum number of ROM images (%i) in layout " + "file reached.\n", MAX_ROMLAYOUT); + goto free_ret; + } + + tstr1 = strtok((char *)str, ":"); + tstr2 = strtok(NULL, ":"); + if (!tstr1 || !tstr2) { + msg_gerr("Error parsing included range argument: "%s"\n", str); + goto free_ret; + } + + l->entries[l->num_entries].start = strtol(tstr1, (char **)NULL, 16); + l->entries[l->num_entries].end = strtol(tstr2, (char **)NULL, 16); + l->entries[l->num_entries].included = 1; + + memset(l->entries[l->num_entries].name, 0, sizeof(l->entries[l->num_entries].name)); + strncpy(l->entries[l->num_entries].name, orig, sizeof(l->entries[l->num_entries].name)); + msg_gdbg("romlayout %08x - %08x named %s\n", l->entries[l->num_entries].start, + l->entries[l->num_entries].end, l->entries[l->num_entries].name); + + l->num_entries++; + ret = 0; +free_ret: + free(orig); + return ret; +} + /* returns the index of the entry (or a negative value if it is not found) */ static int find_include_arg(const char *const name) {