futility: cleanup help functions for sign command

Just rearranging some internal functions and args.

BUG=none
BRANCH=none
TEST=make runtests

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Ib7d3ab358543c549c670b1cd2715f1b670da2001
Reviewed-on: https://chromium-review.googlesource.com/262897
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Bill Richardson
2015-03-26 16:32:02 -07:00
committed by ChromeOS Commit Bot
parent 1e35c3a511
commit 08d52b9bf5

View File

@@ -575,6 +575,11 @@ static const char usage_pubkey[] = "\n"
" External program to compute the signature\n" " External program to compute the signature\n"
" (requires a PEM signing key)\n" " (requires a PEM signing key)\n"
"\n"; "\n";
static void print_help_pubkey(int argc, char *argv[])
{
printf(usage_pubkey, kNumAlgorithms - 1);
}
static const char usage_fw_main[] = "\n" static const char usage_fw_main[] = "\n"
"To sign a raw firmware blob (FW_MAIN_A/B):\n" "To sign a raw firmware blob (FW_MAIN_A/B):\n"
@@ -593,6 +598,10 @@ static const char usage_fw_main[] = "\n"
" -f|--flags NUM The preamble flags value" " -f|--flags NUM The preamble flags value"
" (default is 0)\n" " (default is 0)\n"
"\n"; "\n";
static void print_help_raw_firmware(int argc, char *argv[])
{
puts(usage_fw_main);
}
static const char usage_bios[] = "\n" static const char usage_bios[] = "\n"
"To sign a complete firmware image (bios.bin):\n" "To sign a complete firmware image (bios.bin):\n"
@@ -620,6 +629,10 @@ static const char usage_bios[] = "\n"
" -l|--loemid STRING Local OEM vblock suffix\n" " -l|--loemid STRING Local OEM vblock suffix\n"
" [--outfile] OUTFILE Output firmware image\n" " [--outfile] OUTFILE Output firmware image\n"
"\n"; "\n";
static void print_help_bios_image(int argc, char *argv[])
{
printf(usage_bios, sign_option.version);
}
static const char usage_new_kpart[] = "\n" static const char usage_new_kpart[] = "\n"
"To create a new kernel partition image (/dev/sda2, /dev/mmcblk0p2):\n" "To create a new kernel partition image (/dev/sda2, /dev/mmcblk0p2):\n"
@@ -647,6 +660,10 @@ static const char usage_new_kpart[] = "\n"
" distinct outfile)\n" " distinct outfile)\n"
" -f|--flags NUM The preamble flags value\n" " -f|--flags NUM The preamble flags value\n"
"\n"; "\n";
static void print_help_raw_kernel(int argc, char *argv[])
{
printf(usage_new_kpart, sign_option.kloadaddr, sign_option.padding);
}
static const char usage_old_kpart[] = "\n" static const char usage_old_kpart[] = "\n"
"To resign an existing kernel partition (/dev/sda2, /dev/mmcblk0p2):\n" "To resign an existing kernel partition (/dev/sda2, /dev/mmcblk0p2):\n"
@@ -669,8 +686,20 @@ static const char usage_old_kpart[] = "\n"
" distinct OUTFILE)\n" " distinct OUTFILE)\n"
" -f|--flags NUM The preamble flags value\n" " -f|--flags NUM The preamble flags value\n"
"\n"; "\n";
static void print_help_kern_preamble(int argc, char *argv[])
{
printf(usage_old_kpart, sign_option.padding);
}
static const char usage[] = "\n" static void (*help_type[NUM_FILE_TYPES])(int argc, char *argv[]) = {
[FILE_TYPE_PUBKEY] = &print_help_pubkey,
[FILE_TYPE_RAW_FIRMWARE] = &print_help_raw_firmware,
[FILE_TYPE_BIOS_IMAGE] = &print_help_bios_image,
[FILE_TYPE_RAW_KERNEL] = &print_help_raw_kernel,
[FILE_TYPE_KERN_PREAMBLE] = &print_help_kern_preamble,
};
static const char usage_default[] = "\n"
"Usage: " MYNAME " %s [PARAMS] INFILE [OUTFILE]\n" "Usage: " MYNAME " %s [PARAMS] INFILE [OUTFILE]\n"
"\n" "\n"
"The following signing operations are supported:\n" "The following signing operations are supported:\n"
@@ -682,42 +711,30 @@ static const char usage[] = "\n"
" raw linux kernel (vmlinuz) kernel partition image\n" " raw linux kernel (vmlinuz) kernel partition image\n"
" kernel partition (/dev/sda2) same, or signed in-place\n" " kernel partition (/dev/sda2) same, or signed in-place\n"
"\n" "\n"
"For more information, use \"" MYNAME " %s help TYPE\",\n" "For more information, use \"" MYNAME " help %s TYPE\",\n"
"where TYPE is one of:\n\n %s %s %s %s %s\n\n"; "where TYPE is one of:\n\n";
static void print_help_default(int argc, char *argv[])
{
enum futil_file_type type;
printf(usage_default, argv[0], argv[0]);
for (type = 0; type < NUM_FILE_TYPES; type++)
if (help_type[type])
printf(" %s", futil_file_type_name(type));
printf("\n\n");
}
static void print_help(int argc, char *argv[]) static void print_help(int argc, char *argv[])
{ {
enum futil_file_type type = FILE_TYPE_UNKNOWN; enum futil_file_type type = FILE_TYPE_UNKNOWN;
if (argc > 1 && futil_str_to_file_type(argv[1], &type)) if (argc > 1)
switch (type) { futil_str_to_file_type(argv[1], &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, sign_option.version);
return;
case FILE_TYPE_RAW_KERNEL:
printf(usage_new_kpart, sign_option.kloadaddr,
sign_option.padding);
return;
case FILE_TYPE_KERN_PREAMBLE:
printf(usage_old_kpart, sign_option.padding);
return;
default:
break;
}
printf(usage, argv[0], argv[0], if (help_type[type])
futil_file_type_name(FILE_TYPE_PUBKEY), help_type[type](argc, argv);
futil_file_type_name(FILE_TYPE_RAW_FIRMWARE), else
futil_file_type_name(FILE_TYPE_BIOS_IMAGE), print_help_default(argc, argv);
futil_file_type_name(FILE_TYPE_RAW_KERNEL),
futil_file_type_name(FILE_TYPE_KERN_PREAMBLE));
} }
enum no_short_opts { enum no_short_opts {
@@ -1064,9 +1081,8 @@ static int do_sign(int argc, char *argv[])
"arch"); "arch");
break; break;
default: default:
fprintf(stderr, "Unable to sign type %s\n", /* Anything else we don't care */
futil_file_type_name(sign_option.type)); break;
errorcnt++;
} }
Debug("infile=%s\n", infile); Debug("infile=%s\n", infile);