futility: Split help for "sign" command into parts

The help message for the sign command is much too long. This
breaks it into several subcategories.

BUG=none
BRANCH=none
TEST=make runtests

futility help sign
futility help sign pubkey
futility help sign fwblob
futility help sign bios
futility help sign vmlinuz
futility help sign kernel

Change-Id: I3e12b2cfdfb17a77c171f925a53748efb1d6c440
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/260496
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Bill Richardson
2015-03-09 19:39:19 -07:00
committed by ChromeOS Commit Bot
parent eee1b3d227
commit 4dc1575ba1
6 changed files with 173 additions and 74 deletions

View File

@@ -611,7 +611,7 @@ static void show_type(char *filename)
err = futil_file_type(filename, &type);
switch (err) {
case FILE_ERR_NONE:
printf("%s:\t%s\n", filename, futil_file_type_str(type));
printf("%s:\t%s\n", filename, futil_file_type_name(type));
break;
case FILE_ERR_DIR:
printf("%s:\t%s\n", filename, "directory");

View File

@@ -515,19 +515,7 @@ int futil_cb_sign_end(struct futil_traverse_state_s *state)
return state->errors;
}
static const char usage[] = "\n"
"Usage: " MYNAME " %s [PARAMS] INFILE [OUTFILE]\n"
"\n"
"Where INFILE is a\n"
"\n"
" public key (.vbpubk); OUTFILE is a keyblock\n"
" raw firmware blob (FW_MAIN_A/B); OUTFILE is a VBLOCK_A/B\n"
" complete firmware image (bios.bin)\n"
" raw linux kernel; OUTFILE is a kernel partition image\n"
" kernel partition image (/dev/sda2, /dev/mmcblk0p2)\n";
static const char usage_pubkey[] = "\n"
"-----------------------------------------------------------------\n"
"To sign a public key / create a new keyblock:\n"
"\n"
"Required PARAMS:\n"
@@ -547,10 +535,10 @@ static const char usage_pubkey[] = "\n"
" -f|--flags NUM Flags specifying use conditions\n"
" --pem_external PROGRAM"
" External program to compute the signature\n"
" (requires a PEM signing key)\n";
" (requires a PEM signing key)\n"
"\n";
static const char usage_fw_main[] = "\n"
"-----------------------------------------------------------------\n"
"To sign a raw firmware blob (FW_MAIN_A/B):\n"
"\n"
"Required PARAMS:\n"
@@ -565,10 +553,10 @@ static const char usage_fw_main[] = "\n"
"\n"
"Optional PARAMS:\n"
" -f|--flags NUM The preamble flags value"
" (default is 0)\n";
" (default is 0)\n"
"\n";
static const char usage_bios[] = "\n"
"-----------------------------------------------------------------\n"
"To sign a complete firmware image (bios.bin):\n"
"\n"
"Required PARAMS:\n"
@@ -592,10 +580,10 @@ static const char usage_bios[] = "\n"
" unchanged, or 0 if unknown)\n"
" -d|--loemdir DIR Local OEM output vblock directory\n"
" -l|--loemid STRING Local OEM vblock suffix\n"
" [--outfile] OUTFILE Output firmware image\n";
" [--outfile] OUTFILE Output firmware image\n"
"\n";
static const char usage_new_kpart[] = "\n"
"-----------------------------------------------------------------\n"
"To create a new kernel partition image (/dev/sda2, /dev/mmcblk0p2):\n"
"\n"
"Required PARAMS:\n"
@@ -619,10 +607,10 @@ static const char usage_new_kpart[] = "\n"
" (default 0x%x)\n"
" --vblockonly Emit just the vblock (requires a\n"
" distinct outfile)\n"
" -f|--flags NUM The preamble flags value\n";
" -f|--flags NUM The preamble flags value\n"
"\n";
static const char usage_old_kpart[] = "\n"
"-----------------------------------------------------------------\n"
"To resign an existing kernel partition (/dev/sda2, /dev/mmcblk0p2):\n"
"\n"
"Required PARAMS:\n"
@@ -644,14 +632,54 @@ static const char usage_old_kpart[] = "\n"
" -f|--flags NUM The preamble flags value\n"
"\n";
static const char usage[] = "\n"
"Usage: " MYNAME " %s [PARAMS] INFILE [OUTFILE]\n"
"\n"
"The following signing operations are supported:\n"
"\n"
" INFILE OUTFILE\n"
" public key (.vbpubk) keyblock\n"
" raw firmware blob (FW_MAIN_A/B) firmware preamble (VBLOCK_A/B)\n"
" full firmware image (bios.bin) same, or signed in-place\n"
" raw linux kernel (vmlinuz) kernel partition image\n"
" kernel partition (/dev/sda2) same, or signed in-place\n"
"\n"
"For more information, use \"" MYNAME " %s help TYPE\",\n"
"where TYPE is one of:\n\n %s %s %s %s %s\n\n";
static void print_help(int argc, char *argv[])
{
printf(usage, argv[0]);
printf(usage_pubkey, kNumAlgorithms - 1);
puts(usage_fw_main);
printf(usage_bios, option.version);
printf(usage_new_kpart, option.kloadaddr, option.padding);
printf(usage_old_kpart, option.padding);
enum futil_file_type type = FILE_TYPE_UNKNOWN;
if (argc > 1 && futil_str_to_file_type(argv[1], &type))
switch (type) {
case FILE_TYPE_PUBKEY:
printf(usage_pubkey, kNumAlgorithms - 1);
return;
case FILE_TYPE_RAW_FIRMWARE:
puts(usage_fw_main);
return;
case FILE_TYPE_BIOS_IMAGE:
printf(usage_bios, option.version);
return;
case FILE_TYPE_RAW_KERNEL:
printf(usage_new_kpart, option.kloadaddr,
option.padding);
return;
case FILE_TYPE_KERN_PREAMBLE:
printf(usage_old_kpart, option.padding);
return;
default:
break;
}
printf(usage, argv[0], argv[0],
futil_file_type_name(FILE_TYPE_PUBKEY),
futil_file_type_name(FILE_TYPE_RAW_FIRMWARE),
futil_file_type_name(FILE_TYPE_BIOS_IMAGE),
futil_file_type_name(FILE_TYPE_RAW_KERNEL),
futil_file_type_name(FILE_TYPE_KERN_PREAMBLE));
}
enum no_short_opts {
@@ -712,6 +740,7 @@ static int do_sign(int argc, char *argv[])
enum futil_file_type type;
int inout_file_count = 0;
int mapping;
int helpind = 0;
opterr = 0; /* quiet, you */
while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) {
@@ -859,8 +888,8 @@ static int do_sign(int argc, char *argv[])
option.pem_external = optarg;
break;
case OPT_HELP:
print_help(argc, argv);
return !!errorcnt;
helpind = optind - 1;
break;
case '?':
if (optopt)
@@ -883,6 +912,16 @@ static int do_sign(int argc, char *argv[])
}
}
if (helpind) {
/* Skip all the options we've already parsed */
optind--;
argv[optind] = argv[0];
argc -= optind;
argv += optind;
print_help(argc, argv);
return !!errorcnt;
}
/* If we don't have an input file already, we need one */
if (!infile) {
if (argc - optind <= 0) {
@@ -916,7 +955,7 @@ static int do_sign(int argc, char *argv[])
type = FILE_TYPE_RAW_FIRMWARE;
}
Debug("type=%s\n", futil_file_type_str(type));
Debug("type=%s\n", futil_file_type_name(type));
/* Check the arguments for the type of thing we want to sign */
switch (type) {
@@ -990,7 +1029,7 @@ static int do_sign(int argc, char *argv[])
break;
case FILE_TYPE_CHROMIUMOS_DISK:
fprintf(stderr, "Signing a %s is not yet supported\n",
futil_file_type_str(type));
futil_file_type_desc(type));
errorcnt++;
break;
default:

View File

@@ -19,31 +19,58 @@
#include "gbb_header.h"
/* Human-readable strings */
static const char * const type_strings[] = {
"unknown",
"VbPublicKey",
"VbKeyBlock",
"VbFirmwarePreamble",
"GBB",
"Chrome OS BIOS image",
"Cr-48 Chrome OS BIOS image",
"VbKernelPreamble",
"raw firmware",
"raw kernel",
"chromiumos disk image",
"VbPrivateKey",
"vb21 public key",
"vb21 private key",
"RSA private key",
static const struct {
const char * const name;
const char * const desc;
} type_strings[] = {
#define FILE_TYPE(A, B, C) {B, C},
#include "file_type.inc"
#undef FILE_TYPE
};
BUILD_ASSERT(ARRAY_SIZE(type_strings) == NUM_FILE_TYPES);
const char * const futil_file_type_str(enum futil_file_type type)
const char * const futil_file_type_name(enum futil_file_type type)
{
if ((int) type < 0 || type >= NUM_FILE_TYPES)
type = FILE_TYPE_UNKNOWN;
return type_strings[type];
return type_strings[type].name;
}
const char * const futil_file_type_desc(enum futil_file_type type)
{
if ((int) type < 0 || type >= NUM_FILE_TYPES)
type = FILE_TYPE_UNKNOWN;
return type_strings[type].desc;
}
/* Name to enum. Returns true on success. */
int futil_file_str_to_type(const char *str, enum futil_file_type *tptr)
{
int i;
for (i = 0; i < NUM_FILE_TYPES; i++)
if (!strcasecmp(str, type_strings[i].name)) {
if (tptr)
*tptr = i;
return 1;
}
if (tptr)
*tptr = FILE_TYPE_UNKNOWN;
return 0;
}
/* Print the list of type names and exit with the given value. */
void print_file_types_and_exit(int retval)
{
int i;
printf("\nValid file types are:\n\n");
for (i = 0; i < NUM_FILE_TYPES; i++)
printf(" %-20s%s\n", type_strings[i].name,
type_strings[i].desc);
printf("\n");
exit(retval);
}
/* Try these in order so we recognize the larger objects first */
@@ -57,6 +84,21 @@ enum futil_file_type (*recognizers[])(uint8_t *buf, uint32_t len) = {
&recognize_pem,
};
int futil_str_to_file_type(const char *str, enum futil_file_type *type)
{
int i;
for (i = 0; i < NUM_FILE_TYPES; i++)
if (!strcasecmp(str, type_strings[i].name))
break;
if (i < NUM_FILE_TYPES) {
*type = i;
return 1;
}
return 0;
}
/* Try to figure out what we're looking at */
enum futil_file_type futil_file_type_buf(uint8_t *buf, uint32_t len)
{

View File

@@ -8,30 +8,25 @@
/* What type of things do I know how to handle? */
enum futil_file_type {
FILE_TYPE_UNKNOWN,
FILE_TYPE_PUBKEY, /* VbPublicKey */
FILE_TYPE_KEYBLOCK, /* VbKeyBlockHeader */
FILE_TYPE_FW_PREAMBLE, /* VbFirmwarePreambleHeader */
FILE_TYPE_GBB, /* GoogleBinaryBlockHeader */
FILE_TYPE_BIOS_IMAGE, /* Chrome OS BIOS image */
FILE_TYPE_OLD_BIOS_IMAGE, /* Old Chrome OS BIOS image */
FILE_TYPE_KERN_PREAMBLE, /* VbKernelPreambleHeader */
/* These are FILE_TYPE_UNKNOWN, but we've been told more about them */
FILE_TYPE_RAW_FIRMWARE, /* FW_MAIN_A, etc. */
FILE_TYPE_RAW_KERNEL, /* vmlinuz, *.uimg, etc. */
FILE_TYPE_CHROMIUMOS_DISK, /* At least it has a GPT */
FILE_TYPE_PRIVKEY, /* VbPrivateKey */
FILE_TYPE_VB2_PUBKEY, /* struct vb2_public_key */
FILE_TYPE_VB2_PRIVKEY, /* struct vb2_private_key */
FILE_TYPE_PEM, /* RSA .pem file */
#define FILE_TYPE(A, B, C) FILE_TYPE_ ## A,
#include "file_type.inc"
#undef FILE_TYPE
NUM_FILE_TYPES
};
/* Names for them */
const char * const futil_file_type_str(enum futil_file_type type);
/* Short name for file types */
const char * const futil_file_type_name(enum futil_file_type type);
/* Description of file type */
const char * const futil_file_type_desc(enum futil_file_type type);
/* Name to enum. Returns true on success. */
int futil_file_str_to_type(const char *str, enum futil_file_type *tptr);
/* Print the list of type names and exit with the given value. */
void print_file_types_and_exit(int retval);
/* Lookup an type by name. Return true on success */
int futil_str_to_file_type(const char *str, enum futil_file_type *type);
/*
* This tries to match the buffer content to one of the known file types.

23
futility/file_type.inc Normal file
View File

@@ -0,0 +1,23 @@
/* -*- mode:c -*-
*
* Copyright 2015 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* enum --type desc */
FILE_TYPE(UNKNOWN, "unknown", "not something we know about")
FILE_TYPE(PUBKEY, "pubkey", "VbPublicKey (.vbpubk)")
FILE_TYPE(KEYBLOCK, "keyblock", "VbKeyBlock")
FILE_TYPE(FW_PREAMBLE, "fw_pre", "VbFirmwarePreamble (VBLOCK_A/B)")
FILE_TYPE(GBB, "gbb", "GBB")
FILE_TYPE(BIOS_IMAGE, "bios", "Chrome OS BIOS image")
FILE_TYPE(OLD_BIOS_IMAGE, "oldbios", "Cr-48 Chrome OS BIOS image")
FILE_TYPE(KERN_PREAMBLE, "kernel", "kernel preamble/partition")
FILE_TYPE(RAW_FIRMWARE, "fwblob", "raw firmware blob (FW_MAIN_A/B)")
FILE_TYPE(RAW_KERNEL, "vmlinuz", "raw linux kernel")
FILE_TYPE(CHROMIUMOS_DISK, "disk_img", "chromiumos disk image")
FILE_TYPE(PRIVKEY, "prikey", "VbPrivateKey (.vbprivk)")
FILE_TYPE(VB2_PUBKEY, "pubkey21", "vb21 public key (.vbpubk2)")
FILE_TYPE(VB2_PRIVKEY, "prikey21", "vb21 private key (.vbprik2)")
FILE_TYPE(PEM, "pem", "RSA private key (.pem)")

View File

@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
if (!test_case[i].file) {
printf("%sWarning: No test for file type %d (%s)%s\n",
COL_YELLOW, test_case[i].type,
futil_file_type_str(test_case[i].type),
futil_file_type_name(test_case[i].type),
COL_STOP);
continue;
}
@@ -80,14 +80,14 @@ int main(int argc, char *argv[])
snprintf(status, sizeof(status),
"File type %d (%s): examined",
test_case[i].type,
futil_file_type_str(test_case[i].type));
futil_file_type_name(test_case[i].type));
TEST_EQ(FILE_ERR_NONE, futil_file_type(filename, &type),
status);
snprintf(status, sizeof(status),
"File type %d (%s) identified",
test_case[i].type,
futil_file_type_str(test_case[i].type));
futil_file_type_name(test_case[i].type));
TEST_EQ(type, test_case[i].type, status);
}