Martin L Roth has submitted this change. ( https://review.coreboot.org/c/coreboot/+/66553 )
(
6 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: util/amdfwtool/amdfwread: Fix incorrect option index ......................................................................
util/amdfwtool/amdfwread: Fix incorrect option index
index I/O argument to getopt_long is not the index to argv. Instead it is an index into the optlong array corresponding to the parsed option. Also getopt() uses a global variable optind to track the index of the next argument to be processed. Use the optindex variable as an index to extract the filename from argv.
BUG=None TEST=Build and use amdfwread to read the Soft-fuse bits from Guybrush BIOS image. Observed no changes before and after the changes.
Change-Id: I33c74a0c8e12c5af76954524cf7294b7541d286b Signed-off-by: Karthikeyan Ramasubramanian kramasub@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/66553 Reviewed-by: Robert Zieba robertzieba@google.com Reviewed-by: Raul Rangel rrangel@chromium.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M util/amdfwtool/amdfwread.c 1 file changed, 29 insertions(+), 6 deletions(-)
Approvals: build bot (Jenkins): Verified Raul Rangel: Looks good to me, approved Robert Zieba: Looks good to me, but someone else must approve
diff --git a/util/amdfwtool/amdfwread.c b/util/amdfwtool/amdfwread.c index 1a95c5c..c9da3d8 100644 --- a/util/amdfwtool/amdfwread.c +++ b/util/amdfwtool/amdfwread.c @@ -179,19 +179,18 @@ char *fw_file = NULL;
int selected_functions = 0; - int index = 0; while (1) { - int opt = getopt_long(argc, argv, optstring, long_options, &index); + int opt = getopt_long(argc, argv, optstring, long_options, NULL);
if (opt == -1) { - index++; - if (index >= argc) { - /* Print usage if we didn't get any arguments */ + if (optind != (argc - 1)) { + /* Print usage if one and only one option i.e. filename is + not found. */ print_usage(); return 0; }
- fw_file = argv[index]; + fw_file = argv[optind]; break; }