1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-06-30 21:52:36 +02:00

cli_classic: Add convenient '--{flash,get}-size' cli opt

We have this in the ChromiumOS fork of flashrom which we rely
on to obtain the current flash chip in use. This ports it for
upstream consumption.

V.2: Constrain number_of_operations to one as per Nico's comment.
V.3: Rename '--get-size' to '--flash-size' however keep old arg as
     'undocumented' for back-compat.
V.4: Add missing --help line.
V.5: Add man page entry.
V.6: Use printf() directly.

Change-Id: I8f002f3b2012aec4d26b0e81456697b9a5de28d6
Signed-off-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/35592
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Edward O'Callaghan
2019-09-23 22:53:14 +10:00
parent 0cd11d8919
commit 7d6b526ef5
2 changed files with 23 additions and 3 deletions

View File

@ -52,6 +52,7 @@ static void cli_classic_usage(const char *name)
" -N | --noverify-all verify included regions only (cf. -i)\n"
" -l | --layout <layoutfile> read ROM layout from <layoutfile>\n"
" --flash-name read out the detected flash name\n"
" --flash-size read out the detected flash size\n"
" --fmap read ROM layout from fmap embedded in ROM\n"
" --fmap-file <fmapfile> read ROM layout from fmap in <fmapfile>\n"
" --ifd read layout from an Intel Firmware Descriptor\n"
@ -102,7 +103,7 @@ int main(int argc, char *argv[])
#if CONFIG_PRINT_WIKI == 1
int list_supported_wiki = 0;
#endif
int flash_name = 0;
int flash_name = 0, flash_size = 0;
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
struct flashrom_layout *layout = NULL;
@ -113,6 +114,7 @@ int main(int argc, char *argv[])
OPTION_FMAP_FILE,
OPTION_FLASH_CONTENTS,
OPTION_FLASH_NAME,
OPTION_FLASH_SIZE,
};
int ret = 0;
@ -134,6 +136,8 @@ int main(int argc, char *argv[])
{"image", 1, NULL, 'i'},
{"flash-contents", 1, NULL, OPTION_FLASH_CONTENTS},
{"flash-name", 0, NULL, OPTION_FLASH_NAME},
{"flash-size", 0, NULL, OPTION_FLASH_SIZE},
{"get-size", 0, NULL, OPTION_FLASH_SIZE}, // (deprecated): back compatibility.
{"list-supported", 0, NULL, 'L'},
{"list-supported-wiki", 0, NULL, 'z'},
{"programmer", 1, NULL, 'p'},
@ -308,6 +312,14 @@ int main(int argc, char *argv[])
}
flash_name = 1;
break;
case OPTION_FLASH_SIZE:
if (++operation_specified > 1) {
fprintf(stderr, "More than one operation "
"specified. Aborting.\n");
cli_classic_abort_usage();
}
flash_size = 1;
break;
case 'L':
if (++operation_specified > 1) {
fprintf(stderr, "More than one operation "
@ -614,7 +626,7 @@ int main(int argc, char *argv[])
goto out_shutdown;
}
if (!(read_it | write_it | verify_it | erase_it | flash_name)) {
if (!(read_it | write_it | verify_it | erase_it | flash_name | flash_size)) {
msg_ginfo("No operations were specified.\n");
goto out_shutdown;
}
@ -630,6 +642,11 @@ int main(int argc, char *argv[])
goto out_shutdown;
}
if (flash_size) {
printf("%d\n", fill_flash->chip->total_size * 1024);
goto out_shutdown;
}
if (layoutfile) {
layout = get_global_layout();
} else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||