Files
OpenCellular/utility/dump_kernel_config.c
Bill Richardson 0c3ba249ab Massive refactoring of external header files.
This reduces the number of exported header files to the minimum needed by
the existing userspace utilities and firmware implementations.

BUG=chromium:221544
BRANCH=none
TEST=manual, trybots
CQ-DEPEND=CL:47019,CL:47022,CL:47023

  sudo FEATURES=test emerge vboot_reference
  FEATURES=test emerge-$BOARD \
                vboot_reference \
                chromeos-cryptohome \
                chromeos-installer \
                chromeos-u-boot \
                peach-u-boot \
                depthcharge

Change-Id: I2946cc2dbaf5459a6c5eca92ca57d546498e6d85
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47021
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-04-02 14:12:52 -07:00

90 lines
1.9 KiB
C

/* Copyright (c) 2012 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.
*
* Exports the kernel commandline from a given partition/image.
*/
#include <getopt.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include "vboot_host.h"
enum {
OPT_KLOADADDR = 1000,
};
static struct option long_opts[] = {
{ "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;
}
int main(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;
}