diff options
Diffstat (limited to 'futility/cmd_dump_kernel_config.c')
-rw-r--r-- | futility/cmd_dump_kernel_config.c | 129 |
1 files changed, 64 insertions, 65 deletions
diff --git a/futility/cmd_dump_kernel_config.c b/futility/cmd_dump_kernel_config.c index a6e987e2..1bf411b2 100644 --- a/futility/cmd_dump_kernel_config.c +++ b/futility/cmd_dump_kernel_config.c @@ -5,7 +5,6 @@ * Exports the kernel commandline from a given partition/image. */ - #include <getopt.h> #include <stdio.h> #include <sys/mman.h> @@ -15,78 +14,78 @@ #include "vboot_host.h" enum { - OPT_KLOADADDR = 1000, + OPT_KLOADADDR = 1000, }; static const struct option long_opts[] = { - { "kloadaddr", 1, NULL, OPT_KLOADADDR }, - { NULL, 0, NULL, 0 } + {"kloadaddr", 1, NULL, OPT_KLOADADDR}, + {NULL, 0, NULL, 0} }; /* Print help and return error */ -static int PrintHelp(void) { - puts("dump_kernel_config - Prints the kernel command line\n" - "\n" - "Usage: dump_kernel_config [--kloadaddr <ADDRESS>] " - "<image/blockdevice>\n" - "\n" - ""); - return 1; +static int PrintHelp(void) +{ + puts("dump_kernel_config - Prints the kernel command line\n" + "\n" + "Usage: dump_kernel_config [--kloadaddr <ADDRESS>] " + "<image/blockdevice>\n" "\n" ""); + return 1; } -static int do_dump_kernel_config(int argc, char* argv[]) { - char *infile = NULL; - char *config = NULL; - uint64_t kernel_body_load_address = USE_PREAMBLE_LOAD_ADDR; - int parse_error = 0; - char *e; - int i; - - while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) && - !parse_error) { - switch (i) { - default: - case '?': - /* Unhandled option */ - parse_error = 1; - break; - - case 0: - /* silently handled option */ - break; - - case OPT_KLOADADDR: - kernel_body_load_address = strtoul(optarg, &e, 0); - if (!*optarg || (e && *e)) { - fprintf(stderr, "Invalid --kloadaddr\n"); - parse_error = 1; - } - break; - } - } - - if (optind >= argc) { - fprintf(stderr, "Expected argument after options\n"); - parse_error = 1; - } else - infile = argv[optind]; - - if (parse_error) - return PrintHelp(); - - if (!infile || !*infile) { - fprintf(stderr, "Must specify filename\n"); - return 1; - } - - config = FindKernelConfig(infile, kernel_body_load_address); - if (!config) - return 1; - - printf("%s", config); - - free(config); - return 0; +static int do_dump_kernel_config(int argc, char *argv[]) +{ + char *infile = NULL; + char *config = NULL; + uint64_t kernel_body_load_address = USE_PREAMBLE_LOAD_ADDR; + int parse_error = 0; + char *e; + int i; + + while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) && + !parse_error) { + switch (i) { + default: + case '?': + /* Unhandled option */ + parse_error = 1; + break; + + case 0: + /* silently handled option */ + break; + + case OPT_KLOADADDR: + kernel_body_load_address = strtoul(optarg, &e, 0); + if (!*optarg || (e && *e)) { + fprintf(stderr, "Invalid --kloadaddr\n"); + parse_error = 1; + } + break; + } + } + + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + parse_error = 1; + } else + infile = argv[optind]; + + if (parse_error) + return PrintHelp(); + + if (!infile || !*infile) { + fprintf(stderr, "Must specify filename\n"); + return 1; + } + + config = FindKernelConfig(infile, kernel_body_load_address); + if (!config) + return 1; + + printf("%s", config); + + free(config); + return 0; } DECLARE_FUTIL_COMMAND(dump_kernel_config, do_dump_kernel_config, |