summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Garrett <dgarrett@google.com>2012-01-24 18:36:03 -0800
committerGerrit <chrome-bot@google.com>2012-01-26 15:22:39 -0800
commit0fc95946347a3318b41372aa8e2a4509a384e92b (patch)
treedc9f96bb743f6be00cba3657377aaea8e4ecedf8
parentbf020a0d4db68897058503767067567565450dde (diff)
downloadvboot-0fc95946347a3318b41372aa8e2a4509a384e92b.tar.gz
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>
-rw-r--r--Makefile3
-rw-r--r--utility/Makefile16
-rw-r--r--utility/dump_kernel_config.c104
-rw-r--r--utility/dump_kernel_config_main.c102
-rw-r--r--utility/include/dump_kernel_config.h19
5 files changed, 142 insertions, 102 deletions
diff --git a/Makefile b/Makefile
index d8ee8392..f8144b51 100644
--- a/Makefile
+++ b/Makefile
@@ -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
# found in the LICENSE file.
@@ -83,6 +83,7 @@ endif
export BUILD ?= ${TOP}/build
export FWLIB = ${BUILD}/vboot_fw.a
export HOSTLIB = ${BUILD}/vboot_host.a
+export DUMPKERNELCONFIGLIB = ${BUILD}/dump_kernel_config.a
ifeq ($(FIRMWARE_ARCH),)
SUBDIRS = firmware host utility cgpt tests tests/tpm_lite
diff --git a/utility/Makefile b/utility/Makefile
index b53ee572..e0a0f221 100644
--- a/utility/Makefile
+++ b/utility/Makefile
@@ -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
# found in the LICENSE file.
@@ -45,7 +45,7 @@ endif
TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES))
ALL_DEPS = $(addsuffix .d,${TARGET_BINS})
-all: $(TARGET_BINS)
+all: $(TARGET_BINS) $(DUMPKERNELCONFIGLIB)
${BUILD_ROOT}/crossystem: crossystem_main.c $(LIBS)
$(CC) $(CFLAGS) $< -o $@ $(LIBS)
@@ -53,8 +53,16 @@ ${BUILD_ROOT}/crossystem: crossystem_main.c $(LIBS)
${BUILD_ROOT}/dumpRSAPublicKey: dumpRSAPublicKey.c
$(CC) $(CFLAGS) $< -o $@ -lcrypto
-${BUILD_ROOT}/dump_kernel_config: dump_kernel_config.c $(LIBS)
- $(CC) $(CFLAGS) $< -o $@ $(LIBS) -lcrypto
+${BUILD_ROOT}/dump_kernel_config: dump_kernel_config_main.c \
+ $(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
$(CXX) -DWITH_UTIL_MAIN $(CFLAGS) $< -o $@
diff --git a/utility/dump_kernel_config.c b/utility/dump_kernel_config.c
index 720cc85d..d2658f6f 100644
--- a/utility/dump_kernel_config.c
+++ b/utility/dump_kernel_config.c
@@ -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
* found in the LICENSE file.
*
* Exports the kernel commandline from a given partition/image.
*/
-#include <getopt.h>
-#include <inttypes.h> /* For uint64_t */
+#include "dump_kernel_config.h"
+
#include <stdio.h>
-#include <stdlib.h>
#include <sys/mman.h>
-#include <unistd.h>
#include "host_common.h"
#include "kernel_blob.h"
-#include "vboot_common.h"
-
-
-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;
-}
+uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
+ uint64_t kernel_body_load_address) {
-static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
- uint64_t kernel_body_load_address) {
VbKeyBlockHeader* key_block;
VbKernelPreambleHeader* preamble;
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);
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;
uint8_t* buf;
long file_size = 0;
@@ -112,70 +89,3 @@ static void* MapFile(const char *filename, size_t *size) {
fclose(f);
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;
-}
diff --git a/utility/dump_kernel_config_main.c b/utility/dump_kernel_config_main.c
new file mode 100644
index 00000000..7b8f237f
--- /dev/null
+++ b/utility/dump_kernel_config_main.c
@@ -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;
+}
diff --git a/utility/include/dump_kernel_config.h b/utility/include/dump_kernel_config.h
new file mode 100644
index 00000000..c6f9b2b6
--- /dev/null
+++ b/utility/include/dump_kernel_config.h
@@ -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_