summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2015-03-05 13:49:36 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-23 08:59:03 +0000
commit096b0c7adc63d38dd68480577f9643e916360a2b (patch)
treed7179b6ecf9deb7200654d269b4843a697146818
parent84d4e85a393f8b0fb26a3c00d335fe8751d40a47 (diff)
downloadvboot-096b0c7adc63d38dd68480577f9643e916360a2b.tar.gz
futility: change longhelp functions to take multiple args
Some of the help messages are getting pretty long. We should allow each command to provide additional help details only when asked. BUG=none BRANCH=none TEST=make runtests I also compared the help messages for all commands, both before and after this change to ensure that nothing was different. Change-Id: Ibe92ec80f99d286886fe020c9d826a5a05556471 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/260494 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/261756 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--futility/cmd_create.c6
-rw-r--r--futility/cmd_dump_fmap.c37
-rw-r--r--futility/cmd_dump_kernel_config.c8
-rw-r--r--futility/cmd_gbb_utility.c18
-rw-r--r--futility/cmd_load_fmap.c10
-rw-r--r--futility/cmd_pcr.c10
-rw-r--r--futility/cmd_show.c12
-rw-r--r--futility/cmd_sign.c8
-rw-r--r--futility/cmd_vbutil_firmware.c8
-rw-r--r--futility/cmd_vbutil_kernel.c10
-rw-r--r--futility/cmd_vbutil_key.c10
-rw-r--r--futility/cmd_vbutil_keyblock.c8
-rw-r--r--futility/futility.c2
-rw-r--r--futility/futility.h2
14 files changed, 73 insertions, 76 deletions
diff --git a/futility/cmd_create.c b/futility/cmd_create.c
index db668b2c..6138f428 100644
--- a/futility/cmd_create.c
+++ b/futility/cmd_create.c
@@ -51,12 +51,12 @@ static const struct option long_opts[] = {
{NULL, 0, 0, 0}
};
-static void print_help(const char *progname)
+static void print_help(int argc, char *argv[])
{
struct vb2_text_vs_enum *entry;
printf("\n"
-"Usage: " MYNAME " %s [options] <INFILE> [<BASENAME>]\n", progname);
+"Usage: " MYNAME " %s [options] <INFILE> [<BASENAME>]\n", argv[0]);
printf("\n"
"Create a keypair from an RSA key (.pem file).\n"
"\n"
@@ -362,7 +362,7 @@ static int do_create(int argc, char *argv[])
}
if (errorcnt) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c
index 1c233fda..e57bbf7c 100644
--- a/futility/cmd_dump_fmap.c
+++ b/futility/cmd_dump_fmap.c
@@ -24,13 +24,12 @@ enum { FMT_NORMAL, FMT_PRETTY, FMT_FLASHROM, FMT_HUMAN };
static int opt_extract;
static int opt_format = FMT_NORMAL;
static int opt_overlap;
-static char *progname;
static void *base_of_rom;
static size_t size_of_rom;
static int opt_gaps;
/* Return 0 if successful */
-static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[])
+static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
{
int i, retval = 0;
char buf[80]; /* DWR: magic number */
@@ -120,21 +119,21 @@ static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[])
FILE *fp = fopen(outname, "wb");
if (!fp) {
fprintf(stderr, "%s: can't open %s: %s\n",
- progname, outname, strerror(errno));
+ argv[0], outname, strerror(errno));
retval = 1;
} else if (!ah->area_size) {
fprintf(stderr,
"%s: section %s has zero size\n",
- progname, buf);
+ argv[0], buf);
} else if (ah->area_offset + ah->area_size >
size_of_rom) {
fprintf(stderr, "%s: section %s is larger"
- " than the image\n", progname, buf);
+ " than the image\n", argv[0], buf);
retval = 1;
} else if (1 != fwrite(base_of_rom + ah->area_offset,
ah->area_size, 1, fp)) {
fprintf(stderr, "%s: can't write %s: %s\n",
- progname, buf, strerror(errno));
+ argv[0], buf, strerror(errno));
retval = 1;
} else {
if (FMT_NORMAL == opt_format)
@@ -407,9 +406,9 @@ static const char usage[] =
"Specify one or more NAMEs to dump only those sections.\n"
"\n";
-static void print_help(const char *name)
+static void print_help(int argc, char *argv[])
{
- printf(usage, name);
+ printf(usage, argv[0]);
}
static int do_dump_fmap(int argc, char *argv[])
@@ -421,8 +420,6 @@ static int do_dump_fmap(int argc, char *argv[])
const FmapHeader *fmap;
int retval = 1;
- progname = argv[0];
-
opterr = 0; /* quiet, you */
while ((c = getopt(argc, argv, ":xpFhH")) != -1) {
switch (c) {
@@ -444,12 +441,12 @@ static int do_dump_fmap(int argc, char *argv[])
break;
case '?':
fprintf(stderr, "%s: unrecognized switch: -%c\n",
- progname, optopt);
+ argv[0], optopt);
errorcnt++;
break;
case ':':
fprintf(stderr, "%s: missing argument to -%c\n",
- progname, optopt);
+ argv[0], optopt);
errorcnt++;
break;
default:
@@ -459,20 +456,20 @@ static int do_dump_fmap(int argc, char *argv[])
}
if (errorcnt || optind >= argc) {
- print_help(progname);
+ print_help(argc, argv);
return 1;
}
if (0 != stat(argv[optind], &sb)) {
fprintf(stderr, "%s: can't stat %s: %s\n",
- progname, argv[optind], strerror(errno));
+ argv[0], argv[optind], strerror(errno));
return 1;
}
fd = open(argv[optind], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s: can't open %s: %s\n",
- progname, argv[optind], strerror(errno));
+ argv[0], argv[optind], strerror(errno));
return 1;
}
@@ -480,7 +477,7 @@ static int do_dump_fmap(int argc, char *argv[])
mmap(0, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (base_of_rom == (char *)-1) {
fprintf(stderr, "%s: can't mmap %s: %s\n",
- progname, argv[optind], strerror(errno));
+ argv[0], argv[optind], strerror(errno));
close(fd);
return 1;
}
@@ -498,15 +495,15 @@ static int do_dump_fmap(int argc, char *argv[])
(uint32_t) ((char *)fmap - (char *)base_of_rom));
/* fallthrough */
default:
- retval =
- dump_fmap(fmap, argc - optind - 1,
- argv + optind + 1);
+ retval = normal_fmap(fmap,
+ argc - optind - 1,
+ argv + optind + 1);
}
}
if (0 != munmap(base_of_rom, sb.st_size)) {
fprintf(stderr, "%s: can't munmap %s: %s\n",
- progname, argv[optind], strerror(errno));
+ argv[0], argv[optind], strerror(errno));
return 1;
}
diff --git a/futility/cmd_dump_kernel_config.c b/futility/cmd_dump_kernel_config.c
index fad7e292..d1a91fdc 100644
--- a/futility/cmd_dump_kernel_config.c
+++ b/futility/cmd_dump_kernel_config.c
@@ -23,10 +23,10 @@ static const struct option long_opts[] = {
};
/* Print help and return error */
-static void PrintHelp(const char *progname)
+static void print_help(int argc, char *argv[])
{
printf("\nUsage: " MYNAME " %s [--kloadaddr ADDRESS] "
- "KERNEL_PARTITION\n\n", progname);
+ "KERNEL_PARTITION\n\n", argv[0]);
}
static int do_dump_kernel_config(int argc, char *argv[])
@@ -68,7 +68,7 @@ static int do_dump_kernel_config(int argc, char *argv[])
infile = argv[optind];
if (parse_error) {
- PrintHelp(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -90,4 +90,4 @@ static int do_dump_kernel_config(int argc, char *argv[])
DECLARE_FUTIL_COMMAND(dump_kernel_config, do_dump_kernel_config,
VBOOT_VERSION_ALL,
"Prints the kernel command line",
- PrintHelp);
+ print_help);
diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c
index 65d5f938..1053eb2a 100644
--- a/futility/cmd_gbb_utility.c
+++ b/futility/cmd_gbb_utility.c
@@ -18,7 +18,7 @@
#include "futility.h"
#include "gbb_header.h"
-static void print_help(const char *prog)
+static void print_help(int argc, char *argv[])
{
printf("\n"
"Usage: " MYNAME " %s [-g|-s|-c] [OPTIONS] "
@@ -53,7 +53,7 @@ static void print_help(const char *prog)
" %s --set --hwid='New Model' -k key.bin"
" bios.bin newbios.bin\n"
" %s -c 0x100,0x1000,0x03DE80,0x1000 gbb.blob\n\n",
- prog, prog, prog, prog);
+ argv[0], argv[0], argv[0], argv[0]);
}
enum {
@@ -444,7 +444,7 @@ static int do_gbb_utility(int argc, char *argv[])
/* Problems? */
if (errorcnt) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -453,7 +453,7 @@ static int do_gbb_utility(int argc, char *argv[])
case DO_GET:
if (argc - optind < 1) {
fprintf(stderr, "\nERROR: missing input filename\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
} else {
infile = argv[optind++];
@@ -505,7 +505,7 @@ static int do_gbb_utility(int argc, char *argv[])
case DO_SET:
if (argc - optind < 1) {
fprintf(stderr, "\nERROR: missing input filename\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
infile = argv[optind++];
@@ -514,12 +514,12 @@ static int do_gbb_utility(int argc, char *argv[])
if (sel_hwid && !opt_hwid) {
fprintf(stderr, "\nERROR: missing new HWID value\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
if (sel_flags && (!opt_flags || !*opt_flags)) {
fprintf(stderr, "\nERROR: missing new flags value\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -610,7 +610,7 @@ static int do_gbb_utility(int argc, char *argv[])
if (argc - optind < 1) {
fprintf(stderr,
"\nERROR: missing output filename\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
outfile = argv[optind++];
@@ -621,7 +621,7 @@ static int do_gbb_utility(int argc, char *argv[])
fprintf(stderr,
"\nERROR: unable to parse creation spec (%s)\n",
opt_create);
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
if (!errorcnt)
diff --git a/futility/cmd_load_fmap.c b/futility/cmd_load_fmap.c
index cd81b303..7522759d 100644
--- a/futility/cmd_load_fmap.c
+++ b/futility/cmd_load_fmap.c
@@ -39,9 +39,9 @@ static const char usage[] = "\n"
" " MYNAME " %s bios.bin RO_VPD:/dev/zero VBLOCK_B:/dev/urandom\n"
"\n";
-static void help_and_quit(const char *prog)
+static void print_help(int argc, char *argv[])
{
- printf(usage, prog, prog);
+ printf(usage, argv[0], argv[0]);
}
static const struct option long_opts[] = {
@@ -123,7 +123,7 @@ static int do_load_fmap(int argc, char *argv[])
}
if (errorcnt) {
- help_and_quit(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -131,7 +131,7 @@ static int do_load_fmap(int argc, char *argv[])
fprintf(stderr,
"You must specify an input file"
" and at least one AREA:file argument\n");
- help_and_quit(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -201,4 +201,4 @@ done_file:
DECLARE_FUTIL_COMMAND(load_fmap, do_load_fmap,
VBOOT_VERSION_ALL,
"Replace the contents of specified FMAP areas",
- help_and_quit);
+ print_help);
diff --git a/futility/cmd_pcr.c b/futility/cmd_pcr.c
index ef44453e..0de234dc 100644
--- a/futility/cmd_pcr.c
+++ b/futility/cmd_pcr.c
@@ -33,9 +33,9 @@ static const char usage[] = "\n"
"'b5 27 91 12 6f 96 a2 1a 8b a4 d5 11 c6 f2 5a 1c 1e b6 dc 9e'\n"
"\n";
-static void help_and_quit(const char *prog)
+static void print_help(int argc, char *argv[])
{
- printf(usage, prog, prog, prog);
+ printf(usage, argv[0], argv[0], argv[0]);
}
static int parse_hex(uint8_t *val, const char *str)
@@ -136,13 +136,13 @@ static int do_pcr(int argc, char *argv[])
}
if (errorcnt) {
- help_and_quit(argv[0]);
+ print_help(argc, argv);
return 1;
}
if (argc - optind < 1 + opt_init) {
fprintf(stderr, "You must extend at least one DIGEST\n");
- help_and_quit(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -184,4 +184,4 @@ static int do_pcr(int argc, char *argv[])
DECLARE_FUTIL_COMMAND(pcr, do_pcr,
VBOOT_VERSION_ALL,
"Simulate a TPM PCR extension operation",
- help_and_quit);
+ print_help);
diff --git a/futility/cmd_show.c b/futility/cmd_show.c
index aa0ac6bc..660bbcb2 100644
--- a/futility/cmd_show.c
+++ b/futility/cmd_show.c
@@ -579,15 +579,15 @@ static const char usage[] = "\n"
"%s"
"\n";
-static void print_help(const char *prog)
+static void print_help(int argc, char *argv[])
{
- if (strcmp(prog, "verify"))
- printf(usage, prog,
+ if (strcmp(argv[0], "verify"))
+ printf(usage, argv[0],
" public key (.vbpubk)\n",
" --strict "
"Fail unless all signatures are valid\n");
else
- printf(usage, prog, "",
+ printf(usage, argv[0], "",
"\nIt will fail unless all signatures are valid\n");
}
@@ -688,13 +688,13 @@ static int do_show(int argc, char *argv[])
}
if (errorcnt) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
if (argc - optind < 1) {
fprintf(stderr, "ERROR: missing input filename\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index 0c428bf9..104fa2e1 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -596,7 +596,7 @@ static const char usage_bios[] = "\n"
static const char usage_new_kpart[] = "\n"
"-----------------------------------------------------------------\n"
- "To create a new kernel parition image (/dev/sda2, /dev/mmcblk0p2):\n"
+ "To create a new kernel partition image (/dev/sda2, /dev/mmcblk0p2):\n"
"\n"
"Required PARAMS:\n"
" -s|--signprivate FILE.vbprivk"
@@ -623,7 +623,7 @@ static const char usage_new_kpart[] = "\n"
static const char usage_old_kpart[] = "\n"
"-----------------------------------------------------------------\n"
- "To resign an existing kernel parition (/dev/sda2, /dev/mmcblk0p2):\n"
+ "To resign an existing kernel partition (/dev/sda2, /dev/mmcblk0p2):\n"
"\n"
"Required PARAMS:\n"
" -s|--signprivate FILE.vbprivk"
@@ -644,9 +644,9 @@ static const char usage_old_kpart[] = "\n"
" -f|--flags NUM The preamble flags value\n"
"\n";
-static void print_help(const char *prog)
+static void print_help(int argc, char *argv[])
{
- printf(usage, prog);
+ printf(usage, argv[0]);
printf(usage_pubkey, kNumAlgorithms - 1);
puts(usage_fw_main);
printf(usage_bios, option.version);
diff --git a/futility/cmd_vbutil_firmware.c b/futility/cmd_vbutil_firmware.c
index 4f748e86..ce2f0a61 100644
--- a/futility/cmd_vbutil_firmware.c
+++ b/futility/cmd_vbutil_firmware.c
@@ -46,7 +46,7 @@ static const struct option long_opts[] = {
};
/* Print help and return error */
-static void print_help(const char *prog)
+static void print_help(int argc, char *argv[])
{
printf("\nUsage: " MYNAME " %s <--vblock|--verify> <file> [OPTIONS]\n"
"\n"
@@ -71,7 +71,7 @@ static void print_help(const char *prog)
"For '--verify <file>', optional OPTIONS are:\n"
" --kernelkey <file>"
" Write the kernel subkey to this file\n\n",
- prog);
+ argv[0]);
}
/* Create a firmware .vblock */
@@ -368,7 +368,7 @@ static int do_vbutil_firmware(int argc, char *argv[])
}
if (parse_error) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -380,7 +380,7 @@ static int do_vbutil_firmware(int argc, char *argv[])
return Verify(filename, signpubkey, fv_file, kernelkey_file);
default:
fprintf(stderr, "Must specify a mode.\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
}
diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c
index ab5c8d7f..635acdc4 100644
--- a/futility/cmd_vbutil_kernel.c
+++ b/futility/cmd_vbutil_kernel.c
@@ -148,9 +148,9 @@ static const char usage[] =
/* Print help and return error */
-static void print_help(const char *progname)
+static void print_help(int argc, char *argv[])
{
- printf(usage, progname, progname, progname, progname);
+ printf(usage, argv[0], argv[0], argv[0], argv[0]);
}
@@ -381,7 +381,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
}
if (parse_error) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -568,7 +568,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
fprintf(stderr,
"USE: vbutil_kernel --get-vmlinuz <file> "
"--vmlinuz-out <file>\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -642,7 +642,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
fprintf(stderr,
"You must specify a mode: "
"--pack, --repack, --verify, or --get-vmlinuz\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_vbutil_key.c b/futility/cmd_vbutil_key.c
index de9f97ff..cfc21b7f 100644
--- a/futility/cmd_vbutil_key.c
+++ b/futility/cmd_vbutil_key.c
@@ -38,7 +38,7 @@ static const struct option long_opts[] = {
{NULL, 0, 0, 0}
};
-static void print_help(const char *progname)
+static void print_help(int argc, char *argv[])
{
int i;
@@ -51,7 +51,7 @@ static void print_help(const char *progname)
"(required for .keyb,\n"
" ignored for .pem)\n"
" --algorithm <number> "
- "Signing algorithm to use with key:\n", progname);
+ "Signing algorithm to use with key:\n", argv[0]);
for (i = 0; i < kNumAlgorithms; i++) {
printf(" %d = (%s)\n",
@@ -63,7 +63,7 @@ static void print_help(const char *progname)
"\n"
" Optional parameters:\n"
" --copyto <file> "
- "Write a copy of the key to this file.\n\n", progname);
+ "Write a copy of the key to this file.\n\n", argv[0]);
}
/* Pack a .keyb file into a .vbpubk, or a .pem into a .vbprivk */
@@ -218,7 +218,7 @@ static int do_vbutil_key(int argc, char *argv[])
}
if (parse_error) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -229,7 +229,7 @@ static int do_vbutil_key(int argc, char *argv[])
return Unpack(infile, outfile);
default:
printf("Must specify a mode.\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
}
diff --git a/futility/cmd_vbutil_keyblock.c b/futility/cmd_vbutil_keyblock.c
index 64a1760b..738ad4a2 100644
--- a/futility/cmd_vbutil_keyblock.c
+++ b/futility/cmd_vbutil_keyblock.c
@@ -71,9 +71,9 @@ static const char usage[] =
" --datapubkey <file>"
" Write the data public key to this file.\n\n";
-static void print_help(const char *progname)
+static void print_help(int argc, char *argv[])
{
- printf(usage, progname);
+ printf(usage, argv[0]);
}
/* Pack a .keyblock */
@@ -313,7 +313,7 @@ static int do_vbutil_keyblock(int argc, char *argv[])
}
if (parse_error) {
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
@@ -326,7 +326,7 @@ static int do_vbutil_keyblock(int argc, char *argv[])
return Unpack(filename, datapubkey, signpubkey);
default:
printf("Must specify a mode.\n");
- print_help(argv[0]);
+ print_help(argc, argv);
return 1;
}
}
diff --git a/futility/futility.c b/futility/futility.c
index e11cbadf..2a7b6bcf 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -227,7 +227,7 @@ static int do_help(int argc, char *argv[])
if (cmd) {
printf("\n%s - %s\n", argv[1], cmd->shorthelp);
if (cmd->longhelp)
- cmd->longhelp(argv[1]);
+ cmd->longhelp(argc - 1, argv + 1);
return 0;
}
}
diff --git a/futility/futility.h b/futility/futility.h
index 550e381e..c28f40e6 100644
--- a/futility/futility.h
+++ b/futility/futility.h
@@ -48,7 +48,7 @@ struct futil_cmd_t {
int (*const handler) (int argc, char **argv);
enum vboot_version version;
const char *const shorthelp;
- void (*longhelp) (const char *cmd);
+ void (*longhelp) (int argc, char *argv[]); /* argv[0] is the command */
};
/* Macro to define a command */