diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-03-26 16:29:10 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-03-31 06:28:14 +0000 |
commit | 453ecd19560af8efe3e518ba745dc6e8bfecac90 (patch) | |
tree | b9f9e2f3f59e9a90c69d989cd9c853ec60e1a8b3 /futility/cmd_sign.c | |
parent | 6ea2f72d0356a73915b736a5ef3498ac06a50770 (diff) | |
download | vboot-453ecd19560af8efe3e518ba745dc6e8bfecac90.tar.gz |
futility: add --type arg to show and sign commands
This allows the user to manually specify the type of an input
file, since not all file types can be reliably identified.
This also adds a test to ensure that futility doesn't coredump if
you give it the wrong type (although I'm sure it's not exhaustive).
BUG=chromium:231574
BRANCH=none
TEST=make runtests
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: I9d909305d9989fe7299e744c585de380109cf8cd
Reviewed-on: https://chromium-review.googlesource.com/262895
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/cmd_sign.c')
-rw-r--r-- | futility/cmd_sign.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c index cae08b2e..98a197e0 100644 --- a/futility/cmd_sign.c +++ b/futility/cmd_sign.c @@ -57,11 +57,13 @@ static struct local_data_s { int pem_algo_specified; uint32_t pem_algo; char *pem_external; + enum futil_file_type type; } option = { .version = 1, .arch = ARCH_UNSPECIFIED, .kloadaddr = CROS_32BIT_ENTRY_ADDR, .padding = 65536, + .type = FILE_TYPE_UNKNOWN, }; @@ -748,6 +750,7 @@ enum no_short_opts { OPT_PEM_SIGNPRIV, OPT_PEM_ALGO, OPT_PEM_EXTERNAL, + OPT_TYPE, OPT_HELP, }; @@ -775,6 +778,7 @@ static const struct option long_opts[] = { {"pem_signpriv", 1, NULL, OPT_PEM_SIGNPRIV}, {"pem_algo", 1, NULL, OPT_PEM_ALGO}, {"pem_external", 1, NULL, OPT_PEM_EXTERNAL}, + {"type", 1, NULL, OPT_TYPE}, {"vblockonly", 0, &option.vblockonly, 1}, {"help", 0, NULL, OPT_HELP}, {NULL, 0, NULL, 0}, @@ -790,7 +794,6 @@ static int do_sign(int argc, char *argv[]) uint8_t *buf; uint32_t buf_len; char *e = 0; - enum futil_file_type type; int inout_file_count = 0; int mapping; int helpind = 0; @@ -940,6 +943,15 @@ static int do_sign(int argc, char *argv[]) case OPT_PEM_EXTERNAL: option.pem_external = optarg; break; + case OPT_TYPE: + if (!futil_str_to_file_type(optarg, &option.type)) { + if (!strcasecmp("help", optarg)) + print_file_types_and_exit(errorcnt); + fprintf(stderr, + "Invalid --type \"%s\"\n", optarg); + errorcnt++; + } + break; case OPT_HELP: helpind = optind - 1; break; @@ -994,24 +1006,25 @@ static int do_sign(int argc, char *argv[]) } /* What are we looking at? */ - if (futil_file_type(infile, &type)) { + if (option.type == FILE_TYPE_UNKNOWN && + futil_file_type(infile, &option.type)) { errorcnt++; goto done; } /* We may be able to infer the type based on the other args */ - if (type == FILE_TYPE_UNKNOWN) { + if (option.type == FILE_TYPE_UNKNOWN) { if (option.bootloader_data || option.config_data || option.arch != ARCH_UNSPECIFIED) - type = FILE_TYPE_RAW_KERNEL; + option.type = FILE_TYPE_RAW_KERNEL; else if (option.kernel_subkey || option.fv_specified) - type = FILE_TYPE_RAW_FIRMWARE; + option.type = FILE_TYPE_RAW_FIRMWARE; } - Debug("type=%s\n", futil_file_type_name(type)); + Debug("type=%s\n", futil_file_type_name(option.type)); /* Check the arguments for the type of thing we want to sign */ - switch (type) { + switch (option.type) { case FILE_TYPE_PUBKEY: option.create_new_outfile = 1; if (option.signprivate && option.pem_signpriv) { @@ -1063,7 +1076,7 @@ static int do_sign(int argc, char *argv[]) break; default: fprintf(stderr, "Unable to sign type %s\n", - futil_file_type_name(type)); + futil_file_type_name(option.type)); errorcnt++; } @@ -1124,7 +1137,7 @@ static int do_sign(int argc, char *argv[]) goto done; } - errorcnt += futil_file_type_sign(type, infile, buf, buf_len); + errorcnt += futil_file_type_sign(option.type, infile, buf, buf_len); errorcnt += futil_unmap_file(ifd, MAP_RW, buf, buf_len); |