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
This commit is contained in:
Randall Spangler
2013-01-11 10:55:11 -08:00
committed by ChromeBot
parent 5d9bbf2bbd
commit 17f8d34109
22 changed files with 211 additions and 237 deletions

View File

@@ -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 $@ $<

View File

@@ -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);

View File

@@ -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. */

View File

@@ -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

View File

@@ -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;
}
/* 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;
/* 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;
}
void* MapFile(const char* filename, size_t *size) {
FILE* f;
uint8_t* buf;
long file_size = 0;
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;
f = fopen(filename, "rb");
if (!f) {
VBDEBUG(("Unable to open file %s\n", filename));
return NULL;
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;
}
}
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 (file_size <= 0) {
fclose(f);
return NULL;
}
*size = (size_t) file_size;
if (parse_error)
return PrintHelp();
/* 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;
if (!infile || !*infile) {
VbExError("Must specify filename\n");
return 1;
}
fclose(f);
return buf;
/* 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,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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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