summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-02-26 11:03:57 -0800
committerChromeBot <chrome-bot@google.com>2013-02-26 12:59:12 -0800
commit93943266c597ad66300445a04afa01270f2b5763 (patch)
treebf7034285aa5679373a0e430945a929a819bcf9e
parentab63d3c20b8be3f610fff454260f02ab1d7c02b6 (diff)
downloadvboot-93943266c597ad66300445a04afa01270f2b5763.tar.gz
Split off modules required for VbInit() and VbSelectFirmware()
This makes it more obvious which modules and VbEx*() functions must be implemented to call these entry points. This change only moves functions between modules and adds two link-test binaries; it doesn't change any functionality. BUG=chromium-os:39262 BRANCH=none TEST=make && make runtests Change-Id: If3edf0b1989b631f0e7ad18de7ccdad8315181b5 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/44076 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--Makefile73
-rw-r--r--firmware/lib/vboot_common.c34
-rw-r--r--firmware/lib/vboot_common_init.c43
-rw-r--r--firmware/linktest/main_vbinit.c13
-rw-r--r--firmware/linktest/main_vbsf.c14
-rw-r--r--firmware/stub/utility_stub.c19
-rw-r--r--firmware/stub/vboot_api_stub.c76
-rw-r--r--firmware/stub/vboot_api_stub_init.c73
-rw-r--r--firmware/stub/vboot_api_stub_sf.c40
9 files changed, 248 insertions, 137 deletions
diff --git a/Makefile b/Makefile
index 30d04fc6..27072451 100644
--- a/Makefile
+++ b/Makefile
@@ -228,12 +228,16 @@ endif
# Firmware library. TODO: Do we still need to export this?
FWLIB = ${BUILD}/vboot_fw.a
-# find lib -iname '*.c' | sort
-FWLIB_SRCS = \
- firmware/lib/cgptlib/cgptlib.c \
- firmware/lib/cgptlib/cgptlib_internal.c \
- firmware/lib/cgptlib/crc32.c \
+# Firmware library sources needed by VbInit() call
+VBINIT_SRCS = \
firmware/lib/crc8.c \
+ firmware/lib/utility.c \
+ firmware/lib/vboot_api_init.c \
+ firmware/lib/vboot_common_init.c \
+ firmware/lib/vboot_nvstorage.c \
+
+# Additional firmware library sources needed by VbSelectFirmware() call
+VBSF_SRCS = \
firmware/lib/cryptolib/padding.c \
firmware/lib/cryptolib/rsa.c \
firmware/lib/cryptolib/rsa_utility.c \
@@ -242,40 +246,60 @@ FWLIB_SRCS = \
firmware/lib/cryptolib/sha512.c \
firmware/lib/cryptolib/sha_utility.c \
firmware/lib/stateful_util.c \
- firmware/lib/utility.c \
- firmware/lib/utility_string.c \
- firmware/lib/vboot_api_init.c \
firmware/lib/vboot_api_firmware.c \
+ firmware/lib/vboot_common.c \
+ firmware/lib/vboot_firmware.c
+
+# Additional firmware library sources needed by VbSelectAndLoadKernel() call
+VBSLK_SRCS = \
+ firmware/lib/cgptlib/cgptlib.c \
+ firmware/lib/cgptlib/cgptlib_internal.c \
+ firmware/lib/cgptlib/crc32.c \
+ firmware/lib/utility_string.c \
firmware/lib/vboot_api_kernel.c \
firmware/lib/vboot_audio.c \
- firmware/lib/vboot_common.c \
firmware/lib/vboot_display.c \
- firmware/lib/vboot_firmware.c \
- firmware/lib/vboot_kernel.c \
- firmware/lib/vboot_nvstorage.c
+ firmware/lib/vboot_kernel.c
# Support real TPM unless BIOS sets MOCK_TPM
ifeq (${MOCK_TPM},)
-FWLIB_SRCS += \
+VBINIT_SRCS += \
firmware/lib/rollback_index.c \
- firmware/lib/tpm_bootmode.c \
firmware/lib/tpm_lite/tlcl.c
+
+VBSF_SRCS += \
+ firmware/lib/tpm_bootmode.c
else
-FWLIB_SRCS += \
+VBINIT_SRCS += \
firmware/lib/mocked_rollback_index.c \
- firmware/lib/mocked_tpm_bootmode.c \
firmware/lib/tpm_lite/mocked_tlcl.c
+
+VBSF_SRCS += \
+ firmware/lib/mocked_tpm_bootmode.c
endif
ifeq (${FIRMWARE_ARCH},)
# Include BIOS stubs in the firmware library when compiling for host
-FWLIB_SRCS += \
+# TODO: split out other stub funcs too
+VBINIT_SRCS += \
firmware/stub/tpm_lite_stub.c \
firmware/stub/utility_stub.c \
+ firmware/stub/vboot_api_stub_init.c
+
+VBSF_SRCS += \
+ firmware/stub/vboot_api_stub_sf.c
+
+VBSLK_SRCS += \
firmware/stub/vboot_api_stub.c \
firmware/stub/vboot_api_stub_disk.c
endif
+VBSF_SRCS += ${VBINIT_SRCS}
+FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
+
+VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
+VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
+
FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
ALL_OBJS += ${FWLIB_OBJS}
@@ -298,7 +322,6 @@ HOSTLIB_SRCS = \
HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
ALL_OBJS += ${HOSTLIB_OBJS}
-
# Link with hostlib by default
LIBS = $(HOSTLIB)
@@ -610,8 +633,20 @@ ifeq (${FIRMWARE_ARCH},)
${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
endif
+# Link tests
+${BUILD}/firmware/linktest/main_vbinit: LIBS =
+${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
+${BUILD}/firmware/linktest/main_vbsf: LIBS =
+${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
+
+.phony: fwlinktest
+fwlinktest: ${FWLIB} \
+ ${BUILD}/firmware/linktest/main_vbinit \
+ ${BUILD}/firmware/linktest/main_vbsf \
+ ${BUILD}/firmware/linktest/main
+
.PHONY: fwlib
-fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,${BUILD}/firmware/linktest/main)
+fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,fwlinktest)
${FWLIB}: ${FWLIB_OBJS}
@printf " RM $(subst ${BUILD}/,,$@)\n"
diff --git a/firmware/lib/vboot_common.c b/firmware/lib/vboot_common.c
index 50a4cff8..3e3375f1 100644
--- a/firmware/lib/vboot_common.c
+++ b/firmware/lib/vboot_common.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 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.
*
@@ -430,38 +430,6 @@ int VerifyKernelPreamble(const VbKernelPreambleHeader *preamble,
return VBOOT_SUCCESS;
}
-int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
-{
- VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
- sizeof(VbSharedDataHeader)));
-
- if (size < sizeof(VbSharedDataHeader)) {
- VBDEBUG(("Not enough data for header.\n"));
- return VBOOT_SHARED_DATA_INVALID;
- }
- if (size < VB_SHARED_DATA_MIN_SIZE) {
- VBDEBUG(("Shared data buffer too small.\n"));
- return VBOOT_SHARED_DATA_INVALID;
- }
-
- if (!header)
- return VBOOT_SHARED_DATA_INVALID;
-
- /* Zero the header */
- Memset(header, 0, sizeof(VbSharedDataHeader));
-
- /* Initialize fields */
- header->magic = VB_SHARED_DATA_MAGIC;
- header->struct_version = VB_SHARED_DATA_VERSION;
- header->struct_size = sizeof(VbSharedDataHeader);
- header->data_size = size;
- header->data_used = sizeof(VbSharedDataHeader);
- header->firmware_index = 0xFF;
-
- /* Success */
- return VBOOT_SUCCESS;
-}
-
uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size)
{
uint64_t offs = header->data_used;
diff --git a/firmware/lib/vboot_common_init.c b/firmware/lib/vboot_common_init.c
new file mode 100644
index 00000000..9d6670ea
--- /dev/null
+++ b/firmware/lib/vboot_common_init.c
@@ -0,0 +1,43 @@
+/* Copyright (c) 2013 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.
+ *
+ * Common functions between firmware and kernel verified boot.
+ * (Firmware portion)
+ */
+
+#include "vboot_api.h"
+#include "vboot_common.h"
+#include "utility.h"
+
+int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
+{
+ VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
+ sizeof(VbSharedDataHeader)));
+
+ if (size < sizeof(VbSharedDataHeader)) {
+ VBDEBUG(("Not enough data for header.\n"));
+ return VBOOT_SHARED_DATA_INVALID;
+ }
+ if (size < VB_SHARED_DATA_MIN_SIZE) {
+ VBDEBUG(("Shared data buffer too small.\n"));
+ return VBOOT_SHARED_DATA_INVALID;
+ }
+
+ if (!header)
+ return VBOOT_SHARED_DATA_INVALID;
+
+ /* Zero the header */
+ Memset(header, 0, sizeof(VbSharedDataHeader));
+
+ /* Initialize fields */
+ header->magic = VB_SHARED_DATA_MAGIC;
+ header->struct_version = VB_SHARED_DATA_VERSION;
+ header->struct_size = sizeof(VbSharedDataHeader);
+ header->data_size = size;
+ header->data_used = sizeof(VbSharedDataHeader);
+ header->firmware_index = 0xFF;
+
+ /* Success */
+ return VBOOT_SUCCESS;
+}
diff --git a/firmware/linktest/main_vbinit.c b/firmware/linktest/main_vbinit.c
new file mode 100644
index 00000000..a3d50196
--- /dev/null
+++ b/firmware/linktest/main_vbinit.c
@@ -0,0 +1,13 @@
+/* Copyright (c) 2013 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.
+ */
+
+#include "vboot_api.h"
+
+int main(void)
+{
+ /* vboot_api.h - entry points INTO vboot_reference */
+ VbInit(0, 0);
+ return 0;
+}
diff --git a/firmware/linktest/main_vbsf.c b/firmware/linktest/main_vbsf.c
new file mode 100644
index 00000000..1a3825a8
--- /dev/null
+++ b/firmware/linktest/main_vbsf.c
@@ -0,0 +1,14 @@
+/* Copyright (c) 2013 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.
+ */
+
+#include "vboot_api.h"
+
+int main(void)
+{
+ /* vboot_api.h - entry points INTO vboot_reference */
+ VbSelectFirmware(0, 0);
+ VbUpdateFirmwareBodyHash(0, 0, 0);
+ return 0;
+}
diff --git a/firmware/stub/utility_stub.c b/firmware/stub/utility_stub.c
index e3ec19be..549ee851 100644
--- a/firmware/stub/utility_stub.c
+++ b/firmware/stub/utility_stub.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 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.
*
@@ -15,18 +15,19 @@
#include <string.h>
#include <sys/time.h>
-
-int Memcmp(const void* src1, const void* src2, size_t n) {
- return memcmp(src1, src2, n);
+int Memcmp(const void *src1, const void *src2, size_t n)
+{
+ return memcmp(src1, src2, n);
}
-
-void* Memcpy(void* dest, const void* src, uint64_t n) {
- return memcpy(dest, src, (size_t)n);
+void *Memcpy(void *dest, const void *src, uint64_t n)
+{
+ return memcpy(dest, src, (size_t)n);
}
-void* Memset(void* d, const uint8_t c, uint64_t n) {
- return memset(d, c, n);
+void *Memset(void *d, const uint8_t c, uint64_t n)
+{
+ return memset(d, c, n);
}
diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c
index c71c38ac..1829764f 100644
--- a/firmware/stub/vboot_api_stub.c
+++ b/firmware/stub/vboot_api_stub.c
@@ -18,66 +18,6 @@
/* disable MSVC warnings on unused arguments */
__pragma(warning (disable: 4100))
-
-/* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
-#define MAX_FMT 255
-static char fmtbuf[MAX_FMT+1];
-
-static const char *fixfmt(const char *format)
-{
- int i;
- for(i=0; i<MAX_FMT && format[i]; i++) {
- fmtbuf[i] = format[i];
- if(format[i] == '%' && format[i+1] == 'L') {
- fmtbuf[i+1] = 'l';
- i++;
- }
- }
- fmtbuf[i] = '\0';
- return fmtbuf;
-}
-
-void VbExError(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "ERROR: ");
- vfprintf(stderr, fixfmt(format), ap);
- va_end(ap);
- exit(1);
-}
-
-void VbExDebug(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "DEBUG: ");
- vfprintf(stderr, fixfmt(format), ap);
- va_end(ap);
-}
-
-void *VbExMalloc(size_t size)
-{
- void *p = malloc(size);
- if (!p) {
- /* Fatal Error. We must abort. */
- abort();
- }
- return p;
-}
-
-void VbExFree(void *ptr)
-{
- free(ptr);
-}
-
-uint64_t VbExGetTimer(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
-}
-
void VbExSleepMs(uint32_t msec)
{
}
@@ -87,22 +27,6 @@ VbError_t VbExBeep(uint32_t msec, uint32_t frequency)
return VBERROR_SUCCESS;
}
-VbError_t VbExNvStorageRead(uint8_t *buf)
-{
- return VBERROR_SUCCESS;
-}
-
-VbError_t VbExNvStorageWrite(const uint8_t *buf)
-{
- return VBERROR_SUCCESS;
-}
-
-VbError_t VbExHashFirmwareBody(VbCommonParams *cparams,
- uint32_t firmware_index)
-{
- return VBERROR_SUCCESS;
-}
-
VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
{
return VBERROR_SUCCESS;
diff --git a/firmware/stub/vboot_api_stub_init.c b/firmware/stub/vboot_api_stub_init.c
new file mode 100644
index 00000000..76a29175
--- /dev/null
+++ b/firmware/stub/vboot_api_stub_init.c
@@ -0,0 +1,73 @@
+/* Copyright (c) 2013 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.
+ *
+ * Stub implementations of firmware-provided API functions.
+ */
+
+#define _STUB_IMPLEMENTATION_
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "vboot_api.h"
+
+/* disable MSVC warnings on unused arguments */
+__pragma(warning (disable: 4100))
+
+/* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
+#define MAX_FMT 255
+static char fmtbuf[MAX_FMT+1];
+
+static const char *fixfmt(const char *format)
+{
+ int i;
+ for(i=0; i<MAX_FMT && format[i]; i++) {
+ fmtbuf[i] = format[i];
+ if(format[i] == '%' && format[i+1] == 'L') {
+ fmtbuf[i+1] = 'l';
+ i++;
+ }
+ }
+ fmtbuf[i] = '\0';
+ return fmtbuf;
+}
+
+void VbExError(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "ERROR: ");
+ vfprintf(stderr, fixfmt(format), ap);
+ va_end(ap);
+ exit(1);
+}
+
+void VbExDebug(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "DEBUG: ");
+ vfprintf(stderr, fixfmt(format), ap);
+ va_end(ap);
+}
+
+uint64_t VbExGetTimer(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
+}
+
+VbError_t VbExNvStorageRead(uint8_t *buf)
+{
+ return VBERROR_SUCCESS;
+}
+
+VbError_t VbExNvStorageWrite(const uint8_t *buf)
+{
+ return VBERROR_SUCCESS;
+}
diff --git a/firmware/stub/vboot_api_stub_sf.c b/firmware/stub/vboot_api_stub_sf.c
new file mode 100644
index 00000000..41a16467
--- /dev/null
+++ b/firmware/stub/vboot_api_stub_sf.c
@@ -0,0 +1,40 @@
+/* Copyright (c) 2013 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.
+ *
+ * Stub implementations of firmware-provided API functions.
+ */
+
+#define _STUB_IMPLEMENTATION_
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "vboot_api.h"
+
+/* disable MSVC warnings on unused arguments */
+__pragma(warning (disable: 4100))
+
+void *VbExMalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (!p) {
+ /* Fatal Error. We must abort. */
+ abort();
+ }
+ return p;
+}
+
+void VbExFree(void *ptr)
+{
+ free(ptr);
+}
+
+VbError_t VbExHashFirmwareBody(VbCommonParams *cparams,
+ uint32_t firmware_index)
+{
+ return VBERROR_SUCCESS;
+}