Bundle up the utilities methods used in dump_kernel_config and

export them as a library to be used by post installer programs.

A matching change to vboot_reference-9999.ebuild is also required.

TEST=Built, verified library symbols with nm on x86-mario, amd64-generic.
BUG=chromium-os:25381

Change-Id: Icb23838a8cd804e0c66718c6d4d60f639ee6b72f
Reviewed-on: https://gerrit.chromium.org/gerrit/14770
Commit-Ready: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
This commit is contained in:
Don Garrett
2012-01-24 18:36:03 -08:00
committed by Gerrit
parent bf020a0d4d
commit 0fc9594634
5 changed files with 142 additions and 102 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. # 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 # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
@@ -83,6 +83,7 @@ endif
export BUILD ?= ${TOP}/build export BUILD ?= ${TOP}/build
export FWLIB = ${BUILD}/vboot_fw.a export FWLIB = ${BUILD}/vboot_fw.a
export HOSTLIB = ${BUILD}/vboot_host.a export HOSTLIB = ${BUILD}/vboot_host.a
export DUMPKERNELCONFIGLIB = ${BUILD}/dump_kernel_config.a
ifeq ($(FIRMWARE_ARCH),) ifeq ($(FIRMWARE_ARCH),)
SUBDIRS = firmware host utility cgpt tests tests/tpm_lite SUBDIRS = firmware host utility cgpt tests tests/tpm_lite

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. # 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 # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
@@ -45,7 +45,7 @@ endif
TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES)) TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES))
ALL_DEPS = $(addsuffix .d,${TARGET_BINS}) ALL_DEPS = $(addsuffix .d,${TARGET_BINS})
all: $(TARGET_BINS) all: $(TARGET_BINS) $(DUMPKERNELCONFIGLIB)
${BUILD_ROOT}/crossystem: crossystem_main.c $(LIBS) ${BUILD_ROOT}/crossystem: crossystem_main.c $(LIBS)
$(CC) $(CFLAGS) $< -o $@ $(LIBS) $(CC) $(CFLAGS) $< -o $@ $(LIBS)
@@ -53,8 +53,16 @@ ${BUILD_ROOT}/crossystem: crossystem_main.c $(LIBS)
${BUILD_ROOT}/dumpRSAPublicKey: dumpRSAPublicKey.c ${BUILD_ROOT}/dumpRSAPublicKey: dumpRSAPublicKey.c
$(CC) $(CFLAGS) $< -o $@ -lcrypto $(CC) $(CFLAGS) $< -o $@ -lcrypto
${BUILD_ROOT}/dump_kernel_config: dump_kernel_config.c $(LIBS) ${BUILD_ROOT}/dump_kernel_config: dump_kernel_config_main.c \
$(CC) $(CFLAGS) $< -o $@ $(LIBS) -lcrypto $(DUMPKERNELCONFIGLIB)
$(CC) $(CFLAGS) $< -o $@ $(LIBS) $(DUMPKERNELCONFIGLIB) -lcrypto
${BUILD_ROOT}/dump_kernel_config.o: dump_kernel_config.c
$(CC) $(CFLAGS) -c $< -o $@
$(DUMPKERNELCONFIGLIB): ${BUILD_ROOT}/dump_kernel_config.o
rm -f $@
ar qc $@ $^
${BUILD_ROOT}/gbb_utility: gbb_utility.cc ${BUILD_ROOT}/gbb_utility: gbb_utility.cc
$(CXX) -DWITH_UTIL_MAIN $(CFLAGS) $< -o $@ $(CXX) -DWITH_UTIL_MAIN $(CFLAGS) $< -o $@

View File

@@ -1,44 +1,21 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* 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 * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
* Exports the kernel commandline from a given partition/image. * Exports the kernel commandline from a given partition/image.
*/ */
#include <getopt.h> #include "dump_kernel_config.h"
#include <inttypes.h> /* For uint64_t */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
#include "host_common.h" #include "host_common.h"
#include "kernel_blob.h" #include "kernel_blob.h"
#include "vboot_common.h"
uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
uint64_t kernel_body_load_address) {
enum {
OPT_KLOADADDR = 1000,
};
static struct option long_opts[] = {
{ "kloadaddr", 1, 0, OPT_KLOADADDR },
{ NULL, 0, 0, 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 uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
uint64_t kernel_body_load_address) {
VbKeyBlockHeader* key_block; VbKeyBlockHeader* key_block;
VbKernelPreambleHeader* preamble; VbKernelPreambleHeader* preamble;
struct linux_kernel_params *params; struct linux_kernel_params *params;
@@ -77,10 +54,10 @@ static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
VbExError("cmdline is outside of the memory blob: %x\n", offset); VbExError("cmdline is outside of the memory blob: %x\n", offset);
return NULL; return NULL;
} }
return (uint8_t *)(blob + offset); return blob + offset;
} }
static void* MapFile(const char *filename, size_t *size) { void* MapFile(const char* filename, size_t *size) {
FILE* f; FILE* f;
uint8_t* buf; uint8_t* buf;
long file_size = 0; long file_size = 0;
@@ -112,70 +89,3 @@ static void* MapFile(const char *filename, size_t *size) {
fclose(f); fclose(f);
return buf; return buf;
} }
int main(int argc, char* argv[]) {
uint8_t* blob;
size_t blob_size;
char* infile = NULL;
uint8_t *config = NULL;
uint64_t kernel_body_load_address = CROS_32BIT_ENTRY_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) {
VbExError("Must specify filename\n");
return 1;
}
/* Map the kernel image blob. */
blob = MapFile(infile, &blob_size);
if (!blob) {
VbExError("Error reading input file\n");
return 1;
}
config = find_kernel_config(blob, (uint64_t)blob_size,
kernel_body_load_address);
if (!config) {
VbExError("Error parsing input file\n");
munmap(blob, blob_size);
return 1;
}
printf("%.*s", CROS_CONFIG_SIZE, config);
munmap(blob, blob_size);
return 0;
}

View File

@@ -0,0 +1,102 @@
/* 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 "dump_kernel_config.h"
#include <getopt.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include "kernel_blob.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[]) {
uint8_t* blob;
size_t blob_size;
char* infile = NULL;
uint8_t *config = NULL;
uint64_t kernel_body_load_address = CROS_32BIT_ENTRY_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) {
VbExError("Must specify filename\n");
return 1;
}
/* Map the kernel image blob. */
blob = MapFile(infile, &blob_size);
if (!blob) {
VbExError("Error reading input file\n");
return 1;
}
config = find_kernel_config(blob, (uint64_t)blob_size,
kernel_body_load_address);
if (!config) {
VbExError("Error parsing input file\n");
munmap(blob, blob_size);
return 1;
}
printf("%.*s", CROS_CONFIG_SIZE, config);
munmap(blob, blob_size);
return 0;
}

View File

@@ -0,0 +1,19 @@
/* 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.
*/
#ifndef DUMP_KERNEL_CONFIG_UTILITY_H_
#define DUMP_KERNEL_CONFIG_UTILITY_H_
#include <inttypes.h>
#include <stdlib.h>
uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
uint64_t kernel_body_load_address);
void* MapFile(const char* filename, size_t *size);
#endif // DUMP_KERNEL_CONFIG_UTILITY_H_