summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-01-11 10:55:11 -0800
committerChromeBot <chrome-bot@google.com>2013-01-11 16:14:24 -0800
commit17f8d341099120da78a6ca71165834eefb0960ed (patch)
treea43c898fc4b547d45a1b16990d556d894108b612
parent5d9bbf2bbd7b8dfad45d8ddfea6512987736e523 (diff)
downloadvboot-17f8d341099120da78a6ca71165834eefb0960ed.tar.gz
Rename files and defines to simplify makefile.
BUG=chromium-os:26317 BRANCH=none TEST=manual sudo emerge vboot_reference emerge-link vboot_reference chromeos-u-boot chromeos-installer emerge-daisy vboot_reference chromeos-u-boot chromeos-installer Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I8c55ca40f3f0cacf08530ab63c886fe351bcee8e Reviewed-on: https://gerrit.chromium.org/gerrit/41152
-rw-r--r--Makefile96
-rw-r--r--firmware/lib/include/vboot_audio_private.h4
-rw-r--r--firmware/lib/rollback_index.c2
-rw-r--r--tests/tpm_lite/tpmtest_earlyextend.c (renamed from tests/tpm_lite/earlyextend.c)0
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram.c (renamed from tests/tpm_lite/earlynvram.c)0
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram2.c (renamed from tests/tpm_lite/earlynvram2.c)0
-rw-r--r--tests/tpm_lite/tpmtest_enable.c (renamed from tests/tpm_lite/enable.c)0
-rw-r--r--tests/tpm_lite/tpmtest_fastenable.c (renamed from tests/tpm_lite/fastenable.c)0
-rw-r--r--tests/tpm_lite/tpmtest_globallock.c (renamed from tests/tpm_lite/globallock.c)0
-rw-r--r--tests/tpm_lite/tpmtest_redefine_unowned.c (renamed from tests/tpm_lite/redefine_unowned.c)0
-rw-r--r--tests/tpm_lite/tpmtest_spaceperm.c (renamed from tests/tpm_lite/spaceperm.c)0
-rw-r--r--tests/tpm_lite/tpmtest_testsetup.c (renamed from tests/tpm_lite/testsetup.c)0
-rw-r--r--tests/tpm_lite/tpmtest_timing.c (renamed from tests/tpm_lite/timing.c)0
-rw-r--r--tests/tpm_lite/tpmtest_writelimit.c (renamed from tests/tpm_lite/writelimit.c)0
-rw-r--r--utility/bmpblk_utility.cc4
-rw-r--r--utility/crossystem.c (renamed from utility/crossystem_main.c)0
-rw-r--r--utility/dump_kernel_config.c137
-rw-r--r--utility/dump_kernel_config_lib.c88
-rw-r--r--utility/dump_kernel_config_main.c103
-rw-r--r--utility/eficompress.c4
-rw-r--r--utility/efidecompress.c4
-rw-r--r--utility/gbb_utility.cc4
22 files changed, 210 insertions, 236 deletions
diff --git a/Makefile b/Makefile
index b9e47606..03d4938c 100644
--- a/Makefile
+++ b/Makefile
@@ -442,42 +442,17 @@ utils_install : $(UTIL_BINS) $(UTIL_SCRIPTS)
chmod a+rx $(patsubst utility/%,$(DESTDIR)/%,$(UTIL_SCRIPTS))
${BUILD}/utility/dump_kernel_config : LIBS += $(DUMPKERNELCONFIGLIB)
-${BUILD}/utility/dump_kernel_config : $$(LIBS) \
- ${BUILD}/utility/dump_kernel_config_main.o
- @printf " LDdkc $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(LD) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
-
-# TODO: these build as both standalone utils and libs. Make standalone the
-# default so this is less crufty.
-${BUILD}/utility/eficompress.o : CFLAGS += -DSTANDALONE
-${BUILD}/utility/efidecompress.o : CFLAGS += -DSTANDALONE
-
-${BUILD}/utility/eficompress_lib.o : utility/eficompress.c
- @printf " CC $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-${BUILD}/utility/efidecompress_lib.o : utility/efidecompress.c
- @printf " CC $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
# GBB utility needs C++ linker
${BUILD}/utility/gbb_utility : LD = $(CXX)
-${BUILD}/utility/gbb_utility : CFLAGS += -DWITH_UTIL_MAIN
-
-${BUILD}/utility/crossystem : ${BUILD}/utility/crossystem_main.o $$(LIBS)
- @printf " LDcr $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(LD) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LIBS) $(LDLIBS)
-
-# TODO: Why isn't this the default? It's the only time this file is compiled.
-# (gbb_utility, too)
-${BUILD}/utility/bmpblk_utility.o : CFLAGS += -DWITH_UTIL_MAIN
${BUILD}/utility/bmpblk_utility : LD = $(CXX)
${BUILD}/utility/bmpblk_utility : LDLIBS = -llzma -lyaml
${BUILD}/utility/bmpblk_utility : OBJS = \
${BUILD}/utility/bmpblk_util.o \
${BUILD}/utility/image_types.o \
- ${BUILD}/utility/eficompress_lib.o \
- ${BUILD}/utility/efidecompress_lib.o
+ ${BUILD}/utility/eficompress_for_lib.o \
+ ${BUILD}/utility/efidecompress_for_lib.o
${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
@@ -539,10 +514,11 @@ update_tlcl_structures: ${BUILD}/utility/tlcl_generator
# -----------------------------------------------------------------------------
# Library to dump kernel config
+# Used by platform/installer
libdump_kernel_config: $(DUMPKERNELCONFIGLIB)
-$(DUMPKERNELCONFIGLIB) : ${BUILD}/utility/dump_kernel_config.o
+$(DUMPKERNELCONFIGLIB) : ${BUILD}/utility/dump_kernel_config_lib.o
@printf " RM $(subst $(BUILD)/,,$(@))\n"
$(Q)rm -f $@
@printf " AR $(subst $(BUILD)/,,$(@))\n"
@@ -586,23 +562,24 @@ TEST_NAMES += CgptManagerTests
endif
TLCL_TEST_NAMES = \
- earlyextend \
- earlynvram \
- earlynvram2 \
- enable \
- fastenable \
- globallock \
- redefine_unowned \
- spaceperm \
- testsetup \
- timing \
- writelimit
-TEST_NAMES += $(addprefix tpm_lite/tpmtest_,$(TLCL_TEST_NAMES))
+ tpmtest_earlyextend \
+ tpmtest_earlynvram \
+ tpmtest_earlynvram2 \
+ tpmtest_enable \
+ tpmtest_fastenable \
+ tpmtest_globallock \
+ tpmtest_redefine_unowned \
+ tpmtest_spaceperm \
+ tpmtest_testsetup \
+ tpmtest_timing \
+ tpmtest_writelimit
+TEST_NAMES += $(addprefix tpm_lite/,$(TLCL_TEST_NAMES))
TEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES))
ALL_DEPS += $(addsuffix .d,${TEST_BINS})
tests : $(TEST_BINS)
+.PHONY: tests
${TEST_LIB}: \
${BUILD}/tests/test_common.o \
@@ -613,42 +590,23 @@ ${TEST_LIB}: \
@printf " AR $(subst $(BUILD)/,,$(@))\n"
$(Q)ar qc $@ $^
-# Compile rollback_index.c for unit test, so it uses the same implementation
-# as it does in the firmware.
-${BUILD}/tests/rollback_index_for_test.o : CFLAGS += -DROLLBACK_UNITTEST
-${BUILD}/tests/rollback_index_for_test.o : firmware/lib/rollback_index.c
- @printf " CC $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
${BUILD}/tests/rollback_index2_tests: OBJS += \
- ${BUILD}/tests/rollback_index_for_test.o
-
-${BUILD}/tests/vboot_audio_for_test.o : CFLAGS += -DCUSTOM_MUSIC
-${BUILD}/tests/vboot_audio_for_test.o : firmware/lib/vboot_audio.c
- @printf " CC $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ ${BUILD}/firmware/lib/rollback_index_for_test.o
${BUILD}/tests/vboot_audio_tests: OBJS += \
- ${BUILD}/tests/vboot_audio_for_test.o \
+ ${BUILD}/firmware/lib/vboot_audio_for_test.o
cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
-${BUILD}/tests/CgptManagerTests : CFLAGS += -DWITH_UTIL_MAIN $(PC_CFLAGS)
+${BUILD}/tests/CgptManagerTests : CFLAGS += $(PC_CFLAGS)
${BUILD}/tests/CgptManagerTests : LD = $(CXX)
${BUILD}/tests/CgptManagerTests : LDLIBS += -lgtest -lgflags $(PC_LDLIBS)
${BUILD}/tests/CgptManagerTests : LIBS = $(CGPTLIB)
-${BUILD}/tests/rollback_index_test.o : INCLUDES += -I/usr/include
+${BUILD}/tests/rollback_index_test : INCLUDES += -I/usr/include
${BUILD}/tests/rollback_index_test : LIBS += -ltlcl
-# TPM tests have special naming
-# TODO: rename .c files to match test names
${BUILD}/tests/tpm_lite/tpmtest_% : OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
-${BUILD}/tests/tpm_lite/tpmtest_% : ${BUILD}/tests/tpm_lite/%.o $$(OBJS) \
- $$(LIBS)
- @printf " LDtpm $(subst $(BUILD)/,,$(@))\n"
- $(Q)$(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
- $(LIBS) $(LDLIBS)
# TODO: port these tests to new API, if not already eqivalent
# functionality in other tests. These don't even compile at present.
@@ -744,6 +702,18 @@ ${BUILD}/%.o : %.c
@printf " CC $(subst $(BUILD)/,,$(@))\n"
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+# Rules to recompile a single source file for library and test
+# TODO: is there a tidier way to do this?
+${BUILD}/%_for_lib.o : CFLAGS += -DFOR_LIBRARY
+${BUILD}/%_for_lib.o : %.c
+ @printf " CC-for-lib $(subst $(BUILD)/,,$(@))\n"
+ $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+${BUILD}/%_for_test.o : CFLAGS += -DFOR_TEST
+${BUILD}/%_for_test.o : %.c
+ @printf " CC-for-test $(subst $(BUILD)/,,$(@))\n"
+ $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
+# TODO: C++ files don't belong in vboot reference at all. Convert to C.
${BUILD}/%.o : %.cc
@printf " CXX $(subst $(BUILD)/,,$(@))\n"
$(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
diff --git a/firmware/lib/include/vboot_audio_private.h b/firmware/lib/include/vboot_audio_private.h
index e9348f6b..236cc09c 100644
--- a/firmware/lib/include/vboot_audio_private.h
+++ b/firmware/lib/include/vboot_audio_private.h
@@ -40,6 +40,10 @@ struct VbAudioContext {
uint64_t last_time;
};
+#ifdef FOR_TEST
+#define CUSTOM_MUSIC
+#endif
+
#ifdef CUSTOM_MUSIC
void *VbExGetMusicPtr(void);
uint32_t VbExMaxMusicSize(void);
diff --git a/firmware/lib/rollback_index.c b/firmware/lib/rollback_index.c
index a5bc6ae1..ee89d7e6 100644
--- a/firmware/lib/rollback_index.c
+++ b/firmware/lib/rollback_index.c
@@ -17,7 +17,7 @@
#define offsetof(A,B) __builtin_offsetof(A,B)
#endif
-#ifdef ROLLBACK_UNITTEST
+#ifdef FOR_TEST
/* Compiling for unit test, so we need the real implementations of
* rollback functions. The unit test mocks the underlying tlcl
* functions, so this is ok to run on the host. */
diff --git a/tests/tpm_lite/earlyextend.c b/tests/tpm_lite/tpmtest_earlyextend.c
index 837960c1..837960c1 100644
--- a/tests/tpm_lite/earlyextend.c
+++ b/tests/tpm_lite/tpmtest_earlyextend.c
diff --git a/tests/tpm_lite/earlynvram.c b/tests/tpm_lite/tpmtest_earlynvram.c
index fa458338..fa458338 100644
--- a/tests/tpm_lite/earlynvram.c
+++ b/tests/tpm_lite/tpmtest_earlynvram.c
diff --git a/tests/tpm_lite/earlynvram2.c b/tests/tpm_lite/tpmtest_earlynvram2.c
index 2bd2d712..2bd2d712 100644
--- a/tests/tpm_lite/earlynvram2.c
+++ b/tests/tpm_lite/tpmtest_earlynvram2.c
diff --git a/tests/tpm_lite/enable.c b/tests/tpm_lite/tpmtest_enable.c
index 9163ca17..9163ca17 100644
--- a/tests/tpm_lite/enable.c
+++ b/tests/tpm_lite/tpmtest_enable.c
diff --git a/tests/tpm_lite/fastenable.c b/tests/tpm_lite/tpmtest_fastenable.c
index 821658ca..821658ca 100644
--- a/tests/tpm_lite/fastenable.c
+++ b/tests/tpm_lite/tpmtest_fastenable.c
diff --git a/tests/tpm_lite/globallock.c b/tests/tpm_lite/tpmtest_globallock.c
index 96fad9df..96fad9df 100644
--- a/tests/tpm_lite/globallock.c
+++ b/tests/tpm_lite/tpmtest_globallock.c
diff --git a/tests/tpm_lite/redefine_unowned.c b/tests/tpm_lite/tpmtest_redefine_unowned.c
index c54e1178..c54e1178 100644
--- a/tests/tpm_lite/redefine_unowned.c
+++ b/tests/tpm_lite/tpmtest_redefine_unowned.c
diff --git a/tests/tpm_lite/spaceperm.c b/tests/tpm_lite/tpmtest_spaceperm.c
index 71a65218..71a65218 100644
--- a/tests/tpm_lite/spaceperm.c
+++ b/tests/tpm_lite/tpmtest_spaceperm.c
diff --git a/tests/tpm_lite/testsetup.c b/tests/tpm_lite/tpmtest_testsetup.c
index fac1951e..fac1951e 100644
--- a/tests/tpm_lite/testsetup.c
+++ b/tests/tpm_lite/tpmtest_testsetup.c
diff --git a/tests/tpm_lite/timing.c b/tests/tpm_lite/tpmtest_timing.c
index 677b533b..677b533b 100644
--- a/tests/tpm_lite/timing.c
+++ b/tests/tpm_lite/tpmtest_timing.c
diff --git a/tests/tpm_lite/writelimit.c b/tests/tpm_lite/tpmtest_writelimit.c
index 952033cb..952033cb 100644
--- a/tests/tpm_lite/writelimit.c
+++ b/tests/tpm_lite/tpmtest_writelimit.c
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc
index 386d2d44..ea04c222 100644
--- a/utility/bmpblk_utility.cc
+++ b/utility/bmpblk_utility.cc
@@ -630,7 +630,7 @@ namespace vboot_reference {
} // namespace vboot_reference
-#ifdef WITH_UTIL_MAIN
+#ifndef FOR_LIBRARY
//////////////////////////////////////////////////////////////////////////////
// Command line utilities.
@@ -772,4 +772,4 @@ namespace vboot_reference {
return 0;
}
-#endif // WITH_UTIL_MAIN
+#endif // FOR_LIBRARY
diff --git a/utility/crossystem_main.c b/utility/crossystem.c
index 91465002..91465002 100644
--- a/utility/crossystem_main.c
+++ b/utility/crossystem.c
diff --git a/utility/dump_kernel_config.c b/utility/dump_kernel_config.c
index a6989e1c..20a51871 100644
--- a/utility/dump_kernel_config.c
+++ b/utility/dump_kernel_config.c
@@ -5,84 +5,99 @@
* Exports the kernel commandline from a given partition/image.
*/
+
+#include <getopt.h>
#include <stdio.h>
#include <sys/mman.h>
+#include <unistd.h>
#include "dump_kernel_config.h"
-#include "host_common.h"
#include "kernel_blob.h"
#include "vboot_api.h"
-uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
- uint64_t kernel_body_load_address) {
+enum {
+ OPT_KLOADADDR = 1000,
+};
- VbKeyBlockHeader* key_block;
- VbKernelPreambleHeader* preamble;
- uint32_t now = 0;
- uint32_t offset = 0;
+static struct option long_opts[] = {
+ { "kloadaddr", 1, NULL, OPT_KLOADADDR },
+ { NULL, 0, NULL, 0 }
+};
- /* Skip the key block */
- key_block = (VbKeyBlockHeader*)blob;
- now += key_block->key_block_size;
- if (now + blob > blob + blob_size) {
- VbExError("key_block_size advances past the end of the blob\n");
- return NULL;
- }
+/* 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;
+}
- /* Open up the preamble */
- preamble = (VbKernelPreambleHeader*)(blob + now);
- now += preamble->preamble_size;
- if (now + blob > blob + blob_size) {
- VbExError("preamble_size advances past the end of the blob\n");
- return NULL;
- }
+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_NO_ENTRY_ADDR;
+ int parse_error = 0;
+ char *e;
+ int i;
- /* Read body_load_address from preamble if no kernel_body_load_address */
- if (kernel_body_load_address == CROS_NO_ENTRY_ADDR)
- kernel_body_load_address = preamble->body_load_address;
-
- /* The x86 kernels have a pointer to the kernel commandline in the zeropage
- * table, but that's irrelevant for ARM. Both types keep the config blob in
- * the same place, so just go find it. */
- offset = preamble->bootloader_address -
- (kernel_body_load_address + CROS_PARAMS_SIZE +
- CROS_CONFIG_SIZE) + now;
- if (offset > blob_size) {
- VbExError("params are outside of the memory blob: %x\n", offset);
- return NULL;
- }
- return blob + offset;
-}
+ while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) &&
+ !parse_error) {
+ switch (i) {
+ default:
+ case '?':
+ /* Unhandled option */
+ parse_error = 1;
+ break;
-void* MapFile(const char* filename, size_t *size) {
- FILE* f;
- uint8_t* buf;
- long file_size = 0;
+ case 0:
+ /* silently handled option */
+ break;
- f = fopen(filename, "rb");
- if (!f) {
- VBDEBUG(("Unable to open file %s\n", filename));
- return NULL;
+ case OPT_KLOADADDR:
+ kernel_body_load_address = strtoul(optarg, &e, 0);
+ if (!*optarg || (e && *e)) {
+ fprintf(stderr, "Invalid --kloadaddr\n");
+ parse_error = 1;
+ }
+ break;
+ }
}
- fseek(f, 0, SEEK_END);
- file_size = ftell(f);
- rewind(f);
+ if (optind >= argc) {
+ fprintf(stderr, "Expected argument after options\n");
+ parse_error = 1;
+ } else
+ infile = argv[optind];
+
+ if (parse_error)
+ return PrintHelp();
- if (file_size <= 0) {
- fclose(f);
- return NULL;
+ if (!infile || !*infile) {
+ VbExError("Must specify filename\n");
+ return 1;
}
- *size = (size_t) file_size;
-
- /* Uses a host primitive as this is not meant for firmware use. */
- buf = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fileno(f), 0);
- if (buf == MAP_FAILED) {
- VbExError("Failed to mmap the file %s\n", filename);
- fclose(f);
- return NULL;
+
+ /* 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;
}
- fclose(f);
- return buf;
+ printf("%.*s", CROS_CONFIG_SIZE, config);
+ munmap(blob, blob_size);
+ return 0;
}
diff --git a/utility/dump_kernel_config_lib.c b/utility/dump_kernel_config_lib.c
new file mode 100644
index 00000000..a6989e1c
--- /dev/null
+++ b/utility/dump_kernel_config_lib.c
@@ -0,0 +1,88 @@
+/* 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 <stdio.h>
+#include <sys/mman.h>
+
+#include "dump_kernel_config.h"
+#include "host_common.h"
+#include "kernel_blob.h"
+#include "vboot_api.h"
+
+uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
+ uint64_t kernel_body_load_address) {
+
+ VbKeyBlockHeader* key_block;
+ VbKernelPreambleHeader* preamble;
+ uint32_t now = 0;
+ uint32_t offset = 0;
+
+ /* Skip the key block */
+ key_block = (VbKeyBlockHeader*)blob;
+ now += key_block->key_block_size;
+ if (now + blob > blob + blob_size) {
+ VbExError("key_block_size advances past the end of the blob\n");
+ return NULL;
+ }
+
+ /* Open up the preamble */
+ preamble = (VbKernelPreambleHeader*)(blob + now);
+ now += preamble->preamble_size;
+ if (now + blob > blob + blob_size) {
+ VbExError("preamble_size advances past the end of the blob\n");
+ return NULL;
+ }
+
+ /* Read body_load_address from preamble if no kernel_body_load_address */
+ if (kernel_body_load_address == CROS_NO_ENTRY_ADDR)
+ kernel_body_load_address = preamble->body_load_address;
+
+ /* The x86 kernels have a pointer to the kernel commandline in the zeropage
+ * table, but that's irrelevant for ARM. Both types keep the config blob in
+ * the same place, so just go find it. */
+ offset = preamble->bootloader_address -
+ (kernel_body_load_address + CROS_PARAMS_SIZE +
+ CROS_CONFIG_SIZE) + now;
+ if (offset > blob_size) {
+ VbExError("params are outside of the memory blob: %x\n", offset);
+ return NULL;
+ }
+ return blob + offset;
+}
+
+void* MapFile(const char* filename, size_t *size) {
+ FILE* f;
+ uint8_t* buf;
+ long file_size = 0;
+
+ f = fopen(filename, "rb");
+ if (!f) {
+ VBDEBUG(("Unable to open file %s\n", filename));
+ return NULL;
+ }
+
+ fseek(f, 0, SEEK_END);
+ file_size = ftell(f);
+ rewind(f);
+
+ if (file_size <= 0) {
+ fclose(f);
+ return NULL;
+ }
+ *size = (size_t) file_size;
+
+ /* Uses a host primitive as this is not meant for firmware use. */
+ buf = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fileno(f), 0);
+ if (buf == MAP_FAILED) {
+ VbExError("Failed to mmap the file %s\n", filename);
+ fclose(f);
+ return NULL;
+ }
+
+ fclose(f);
+ return buf;
+}
diff --git a/utility/dump_kernel_config_main.c b/utility/dump_kernel_config_main.c
deleted file mode 100644
index 20a51871..00000000
--- a/utility/dump_kernel_config_main.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* 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 "dump_kernel_config.h"
-#include "kernel_blob.h"
-#include "vboot_api.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_NO_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/eficompress.c b/utility/eficompress.c
index b5987006..dfa0d71f 100644
--- a/utility/eficompress.c
+++ b/utility/eficompress.c
@@ -1609,7 +1609,7 @@ Returns:
}
-#ifdef STANDALONE
+#ifndef FOR_LIBRARY
int main(int argc, char *argv[])
{
char *progname;
@@ -1729,4 +1729,4 @@ done1:
return retval;
}
-#endif // STANDALONE
+#endif // FOR_LIBRARY
diff --git a/utility/efidecompress.c b/utility/efidecompress.c
index 5e7e14d7..02587205 100644
--- a/utility/efidecompress.c
+++ b/utility/efidecompress.c
@@ -1008,7 +1008,7 @@ Returns:
}
-#ifdef STANDALONE
+#ifndef FOR_LIBRARY
int main(int argc, char *argv[])
{
char *progname;
@@ -1159,4 +1159,4 @@ done1:
return retval;
}
-#endif // STANDALONE
+#endif // FOR_LIBRARY
diff --git a/utility/gbb_utility.cc b/utility/gbb_utility.cc
index 544e1848..52135d01 100644
--- a/utility/gbb_utility.cc
+++ b/utility/gbb_utility.cc
@@ -475,7 +475,7 @@ bool GoogleBinaryBlockUtil::set_recovery_key(const string &value) {
} // namespace vboot_reference
-#ifdef WITH_UTIL_MAIN
+#ifndef FOR_LIBRARY
///////////////////////////////////////////////////////////////////////
// command line utilities
@@ -870,4 +870,4 @@ int main(int argc, char *argv[]) {
return 0;
}
-#endif // WITH_UTIL_MAIN
+#endif // FOR_LIBRARY