summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJani Nikula <jani.nikula@intel.com>2016-05-03 11:29:43 +0300
committerJani Nikula <jani.nikula@intel.com>2016-05-12 13:58:47 +0300
commit8a06cc12382dc999a32198d4fdf37a1e5ba6c436 (patch)
treed15617ff8799862b4841b504ac9e0e7a6088403b /tools
parent1272b9cd20895533f765ed030fe57282ece6ae48 (diff)
tools/intel_bios_reader: add command line option parsing and --file parameter
Keep positional parameter support for entering filename for backwards compatibility. Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/intel_bios_reader.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
index 66f21df5..b424b17e 100644
--- a/tools/intel_bios_reader.c
+++ b/tools/intel_bios_reader.c
@@ -27,6 +27,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1370,13 +1371,22 @@ static void dump_section(const struct bdb_header *bdb, int section_id, int size)
printf("\n");
}
+enum opt {
+ OPT_UNKNOWN = '?',
+ OPT_END = -1,
+ OPT_FILE,
+};
+
int main(int argc, char **argv)
{
uint8_t *VBIOS;
+ int index;
+ enum opt opt;
int fd;
struct vbt_header *vbt = NULL;
int vbt_off, bdb_off, i;
- const char *filename = "bios";
+ const char *filename = NULL;
+ const char *toolname = argv[0];
struct stat finfo;
int size;
struct bdb_block *block;
@@ -1384,16 +1394,41 @@ int main(int argc, char **argv)
char signature[17];
char *devid_string;
- if (argc != 2) {
- printf("usage: %s <rom file>\n", argv[0]);
- return 1;
+ static struct option options[] = {
+ { "file", required_argument, NULL, OPT_FILE },
+ { 0 }
+ };
+
+ for (opt = 0; opt != OPT_END; ) {
+ opt = getopt_long(argc, argv, "", options, &index);
+
+ switch (opt) {
+ case OPT_FILE:
+ filename = optarg;
+ break;
+ case OPT_END:
+ break;
+ case OPT_UNKNOWN:
+ return EXIT_FAILURE;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (!filename) {
+ if (argc == 1) {
+ /* for backwards compatibility */
+ filename = argv[0];
+ } else {
+ printf("usage: %s --file=<rom file>\n", toolname);
+ return EXIT_FAILURE;
+ }
}
if ((devid_string = getenv("DEVICE")))
devid = strtoul(devid_string, NULL, 0);
- filename = argv[1];
-
fd = open(filename, O_RDONLY);
if (fd == -1) {
printf("Couldn't open \"%s\": %s\n", filename, strerror(errno));