summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-06-20 14:33:00 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-09 01:30:48 +0000
commit782990277ac7d6730db4c43c2b5632de93396921 (patch)
treea7c6c3d332e4e89d4ccdbb6ced0b269dda13022d
parentf8f807a5ef00e8d5360fc2c9093bd0b5da8c0507 (diff)
downloadvboot-782990277ac7d6730db4c43c2b5632de93396921.tar.gz
Split libvboot_host.a into external and local libraries.
We've been creating and linking against a library called "libvboot_host.a" for two different reasons. The main purpose is to build the vboot_reference tools found in the utility/ directory. But there are some external userspace programs that would also like to use some functions in this library. This change establishes libvboot_host.a as the library for use by external userspace programs only, and creates a new libvboot_util.a library that's only used inside this source tree to build the vboot utilities. BUG=chromium:231567 BRANCH=ToT TEST=manual Build and run the local tests: make runalltests make clean Build Link firmware and all the utilities: emerge-link chromeos-base/vboot_reference \ sys-boot/depthcharge \ sys-boot/coreboot \ chromeos-base/chromeos-ec \ chromeos-base/chromeos-firmware-link \ chromeos-base/chromeos-cryptohome \ chromeos-base/update_engine \ chromeos-base/chromeos-installer \ chromeos-base/chromeos-login \ chromeos-base/verity Build Lumpy utilities, which include the 32-bit cros_installer: emerge-lumpy chromeos-base/vboot_reference \ chromeos-base/chromeos-login \ chromeos-base/verity \ chromeos-base/update_engine \ chromeos-base/chromeos-installer \ chromeos-base/chromeos-cryptohome Change-Id: Ie81ff1f74a6356cb8fab7d98471139d7758c4f19 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/207016 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--Makefile126
-rw-r--r--cgpt/cgpt_common.c36
-rw-r--r--cgpt/cgpt_show.c36
-rw-r--r--firmware/lib/vboot_nvstorage.c80
-rw-r--r--firmware/lib/vboot_nvstorage_rollback.c92
-rw-r--r--host/lib/host_misc.c10
-rw-r--r--host/lib/include/host_misc.h3
-rw-r--r--host/lib/include/util_misc.h16
-rw-r--r--host/lib/util_misc.c26
-rw-r--r--host/linktest/extern.c50
-rw-r--r--host/linktest/main.c5
-rw-r--r--utility/vbutil_firmware.c1
-rw-r--r--utility/vbutil_kernel.c1
-rw-r--r--utility/vbutil_key.c1
-rw-r--r--utility/vbutil_keyblock.c1
15 files changed, 319 insertions, 165 deletions
diff --git a/Makefile b/Makefile
index 2fb59cc8..dff0a386 100644
--- a/Makefile
+++ b/Makefile
@@ -237,7 +237,9 @@ else
INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
endif
-# Firmware library. TODO: Do we still need to export this?
+# Firmware library, used by the other firmware components (depthcharge,
+# coreboot, etc.). It doesn't need exporting to some other place; they'll build
+# this source tree locally and link to it directly.
FWLIB = ${BUILD}/vboot_fw.a
# Smaller firmware library. TODO: Do we still need to export this?
@@ -252,6 +254,7 @@ VBINIT_SRCS = \
firmware/lib/vboot_api_init.c \
firmware/lib/vboot_common_init.c \
firmware/lib/vboot_nvstorage.c \
+ firmware/lib/vboot_nvstorage_rollback.c \
firmware/lib/region-init.c \
# Additional firmware library sources needed by VbSelectFirmware() call
@@ -348,10 +351,10 @@ endif
ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
-# Library to build the utilities. "HOST" mostly means "userspace".
-HOSTLIB = ${BUILD}/libvboot_host.a
+# Intermediate library for the vboot_reference utilities to link against.
+UTILLIB = ${BUILD}/libvboot_util.a
-HOSTLIB_SRCS = \
+UTILLIB_SRCS = \
cgpt/cgpt_create.c \
cgpt/cgpt_add.c \
cgpt/cgpt_boot.c \
@@ -370,37 +373,63 @@ HOSTLIB_SRCS = \
host/lib/host_key.c \
host/lib/host_keyblock.c \
host/lib/host_misc.c \
+ host/lib/util_misc.c \
host/lib/host_signature.c \
host/lib/signature_digest.c \
utility/dump_kernel_config_lib.c
+UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
+ALL_OBJS += ${UTILLIB_OBJS}
+
+# Externally exported library for some target userspace apps to link with
+# (cryptohome, updater, etc.)
+HOSTLIB = ${BUILD}/libvboot_host.a
+
+HOSTLIB_SRCS = \
+ cgpt/cgpt_add.c \
+ cgpt/cgpt_boot.c \
+ cgpt/cgpt_common.c \
+ cgpt/cgpt_create.c \
+ cgpt/cgpt_prioritize.c \
+ cgpt/flash_ts_drv.c \
+ firmware/lib/cgptlib/cgptlib_internal.c \
+ firmware/lib/cgptlib/crc32.c \
+ firmware/lib/cgptlib/mtdlib.c \
+ firmware/lib/crc8.c \
+ firmware/lib/flash_ts.c \
+ firmware/lib/tpm_lite/tlcl.c \
+ firmware/lib/utility_string.c \
+ firmware/lib/vboot_nvstorage.c \
+ firmware/stub/tpm_lite_stub.c \
+ firmware/stub/utility_stub.c \
+ firmware/stub/vboot_api_stub_init.c \
+ host/arch/${ARCH}/lib/crossystem_arch.c \
+ host/lib/crossystem.c \
+ host/lib/host_misc.c \
+ utility/dump_kernel_config_lib.c
+
HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
ALL_OBJS += ${HOSTLIB_OBJS}
-# Might need this too.
-CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
-
# Sigh. For historical reasons, the autoupdate installer must sometimes be a
# 32-bit executable, even when everything else is 64-bit. But it only needs a
# few functions, so let's just build those.
TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
TINYHOSTLIB_SRCS = \
- cgpt/cgpt_create.c \
cgpt/cgpt_add.c \
cgpt/cgpt_boot.c \
- cgpt/cgpt_show.c \
- cgpt/cgpt_repair.c \
- cgpt/cgpt_prioritize.c \
cgpt/cgpt_common.c \
+ cgpt/cgpt_create.c \
+ cgpt/cgpt_prioritize.c \
cgpt/flash_ts_drv.c \
+ firmware/lib/cgptlib/cgptlib_internal.c \
+ firmware/lib/cgptlib/crc32.c \
firmware/lib/cgptlib/mtdlib.c \
firmware/lib/flash_ts.c \
- utility/dump_kernel_config_lib.c \
- firmware/lib/cgptlib/crc32.c \
- firmware/lib/cgptlib/cgptlib_internal.c \
firmware/lib/utility_string.c \
- firmware/stub/utility_stub.c
+ firmware/stub/utility_stub.c \
+ utility/dump_kernel_config_lib.c
TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
@@ -657,7 +686,7 @@ all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
# Host targets
.PHONY: host_stuff
-host_stuff: hostlib cgpt utils futil tests
+host_stuff: utillib cgpt utils futil hostlib tests
.PHONY: clean
clean:
@@ -754,24 +783,43 @@ ${FWLIB2}: ${FWLIB2_OBJS}
${Q}ar qc $@ $^
# ----------------------------------------------------------------------------
-# Host library
-
-
-# Link tests
-${BUILD}/host/linktest/main: ${HOSTLIB}
-${BUILD}/host/linktest/main: LIBS = ${HOSTLIB}
-ALL_OBJS += ${BUILD}/host/linktest/main.o
-
-.PHONY: hostlib
-hostlib: ${BUILD}/host/linktest/main
+# Host library(s)
-${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
+# Link tests for local utilities
+${BUILD}/host/linktest/main: ${UTILLIB}
+${BUILD}/host/linktest/main: INCLUDES += \
-Ihost/include \
-Ihost/arch/${ARCH}/include \
-Ihost/lib/include
+${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
+ALL_OBJS += ${BUILD}/host/linktest/main.o
+
+.PHONY: utillib
+utillib: ${UTILLIB} \
+ ${BUILD}/host/linktest/main
# TODO: better way to make .a than duplicating this recipe each time?
-${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
+${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
+ @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
+ ${Q}rm -f $@
+ @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
+ ${Q}ar qc $@ $^
+
+
+# Link tests for external repos
+${BUILD}/host/linktest/extern: ${HOSTLIB}
+${BUILD}/host/linktest/extern: INCLUDES += -Ihost/include
+${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
+${BUILD}/host/linktest/extern: LDLIBS += -static
+ALL_OBJS += ${BUILD}/host/linktest/extern.o
+
+.PHONY: hostlib
+hostlib: ${HOSTLIB} \
+ ${BUILD}/host/linktest/extern
+
+# TODO: better way to make .a than duplicating this recipe each time?
+${HOSTLIB}: INCLUDES += -Ihost/include -Ihost/lib/include
+${HOSTLIB}: ${HOSTLIB_OBJS}
@$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
${Q}rm -f $@
@$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
@@ -783,6 +831,7 @@ ${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
tinyhostlib: ${TINYHOSTLIB}
${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
+${TINYHOSTLIB}: INCLUDES += -Ihost/include -Ihost/lib/include
${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
@$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
${Q}rm -f $@
@@ -800,7 +849,7 @@ ${CGPT_OBJS}: INCLUDES += -Ihost/include
${CGPT}: LDFLAGS += -static
${CGPT}: LDLIBS += -luuid
-${CGPT}: ${CGPT_OBJS} ${HOSTLIB}
+${CGPT}: ${CGPT_OBJS} ${UTILLIB}
@$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
@@ -828,8 +877,8 @@ utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
-${UTIL_BINS} ${UTIL_BINS_STATIC}: ${HOSTLIB}
-${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${HOSTLIB}
+${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
+${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
.PHONY: utils_install
utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
@@ -874,12 +923,12 @@ futil_install: ${FUTIL_BIN}
ln -sf futility "${F_DIR}/$$prog"; done
# TODO(wfrichar): This will need some refactoring (crbug.com/228932)
-${BUILD}/futility/% ${HOSTLIB}: INCLUDES += \
+${BUILD}/futility/% ${UTILLIB}: INCLUDES += \
-Ihost/include \
-Ihost/arch/${ARCH}/include \
-Ihost/lib/include
-${FUTIL_STATIC_BIN} ${FUTIL_BIN}: ${HOSTLIB}
-${FUTIL_STATIC_BIN} ${FUTIL_BIN}: LIBS = ${HOSTLIB}
+${FUTIL_STATIC_BIN} ${FUTIL_BIN}: ${UTILLIB}
+${FUTIL_STATIC_BIN} ${FUTIL_BIN}: LIBS = ${UTILLIB}
# ----------------------------------------------------------------------------
# Utility to generate TLCL structure definition header file.
@@ -903,9 +952,9 @@ update_tlcl_structures: ${BUILD}/utility/tlcl_generator
.PHONY: tests
tests: ${TEST_BINS}
-${TEST_BINS}: ${HOSTLIB} ${TESTLIB}
+${TEST_BINS}: ${UTILLIB} ${TESTLIB}
${TEST_BINS}: INCLUDES += -Itests
-${TEST_BINS}: LIBS = ${HOSTLIB} ${TESTLIB}
+${TEST_BINS}: LIBS = ${UTILLIB} ${TESTLIB}
${TESTLIB}: ${TESTLIB_OBJS}
@$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
@@ -955,6 +1004,8 @@ ${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
# Some utilities need external crypto functions
+CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
+
${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
@@ -1157,6 +1208,9 @@ endif
# ${BUILD}/tests/firmware_rollback_tests
# ${BUILD}/tests/kernel_rollback_tests
+.PHONY: runalltests
+runalltests: runtests runfutiltests runlongtests
+
# Code coverage
.PHONY: coverage_init
coverage_init: test_setup
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index c8a069a4..ff3ae696 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -1162,6 +1162,42 @@ uint8_t RepairHeader(GptData *gpt, const uint32_t valid_headers) {
return 0;
}
+int CgptGetNumNonEmptyPartitions(CgptShowParams *params) {
+ struct drive drive;
+ int gpt_retval;
+ int retval;
+
+ if (params == NULL)
+ return CGPT_FAILED;
+
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDONLY))
+ return CGPT_FAILED;
+
+ if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
+ Error("GptSanityCheck() returned %d: %s\n",
+ gpt_retval, GptError(gpt_retval));
+ retval = CGPT_FAILED;
+ goto done;
+ }
+
+ params->num_partitions = 0;
+ int numEntries = GetNumberOfEntries(&drive);
+ int i;
+ for(i = 0; i < numEntries; i++) {
+ GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, i);
+ if (GuidIsZero(&entry->type))
+ continue;
+
+ params->num_partitions++;
+ }
+
+ retval = CGPT_OK;
+
+done:
+ DriveClose(&drive, 0);
+ return retval;
+}
+
int GuidEqual(const Guid *guid1, const Guid *guid2) {
return (0 == memcmp(guid1, guid2, sizeof(Guid)));
}
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 082a5c73..a2b7c951 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -219,42 +219,6 @@ void EntriesDetails(struct drive *drive, const int secondary, int raw) {
}
}
-int CgptGetNumNonEmptyPartitions(CgptShowParams *params) {
- struct drive drive;
- int gpt_retval;
- int retval;
-
- if (params == NULL)
- return CGPT_FAILED;
-
- if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDONLY))
- return CGPT_FAILED;
-
- if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
- Error("GptSanityCheck() returned %d: %s\n",
- gpt_retval, GptError(gpt_retval));
- retval = CGPT_FAILED;
- goto done;
- }
-
- params->num_partitions = 0;
- int numEntries = GetNumberOfEntries(&drive);
- int i;
- for(i = 0; i < numEntries; i++) {
- GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, i);
- if (GuidIsZero(&entry->type))
- continue;
-
- params->num_partitions++;
- }
-
- retval = CGPT_OK;
-
-done:
- DriveClose(&drive, 0);
- return retval;
-}
-
int MtdShow(struct drive *drive, CgptShowParams *params) {
if (params->partition) { // show single partition
if (params->partition > GetNumberOfEntries(drive)) {
diff --git a/firmware/lib/vboot_nvstorage.c b/firmware/lib/vboot_nvstorage.c
index 3c5d1e27..5476e85b 100644
--- a/firmware/lib/vboot_nvstorage.c
+++ b/firmware/lib/vboot_nvstorage.c
@@ -7,10 +7,8 @@
*/
#include "sysincludes.h"
-
#include "crc8.h"
#include "utility.h"
-#include "rollback_index.h"
#include "vboot_common.h"
#include "vboot_nvstorage.h"
@@ -343,81 +341,3 @@ int VbNvSet(VbNvContext *context, VbNvParam param, uint32_t value)
context->regenerate_crc = 1;
return 0;
}
-
-/* These are the fields of the nvram that we want to back up. */
-static const VbNvParam backup_params[] = {
- VBNV_KERNEL_FIELD,
- VBNV_LOCALIZATION_INDEX,
- VBNV_DEV_BOOT_USB,
- VBNV_DEV_BOOT_LEGACY,
- VBNV_DEV_BOOT_SIGNED_ONLY,
-};
-
-/* We can't back things up if there isn't enough storage. */
-BUILD_ASSERT(VBNV_BLOCK_SIZE <= BACKUP_NV_SIZE);
-
-int RestoreNvFromBackup(VbNvContext *vnc)
-{
- VbNvContext bvnc;
- uint32_t value;
- int i;
-
- VBDEBUG(("TPM: %s()\n", __func__));
-
- if (TPM_SUCCESS != RollbackBackupRead(bvnc.raw))
- return 1;
-
- VbNvSetup(&bvnc);
- if (bvnc.regenerate_crc) {
- VBDEBUG(("TPM: Oops, backup is no good.\n"));
- return 1;
- }
-
- for (i = 0; i < ARRAY_SIZE(backup_params); i++) {
- VbNvGet(&bvnc, backup_params[i], &value);
- VbNvSet(vnc, backup_params[i], value);
- }
-
- /* VbNvTeardown(&bvnc); is not needed. We're done with it. */
- return 0;
-}
-
-int SaveNvToBackup(VbNvContext *vnc)
-{
- VbNvContext bvnc;
- uint32_t value;
- int i;
-
- VBDEBUG(("TPM: %s()\n", __func__));
-
- /* Read it first. No point in writing the same data. */
- if (TPM_SUCCESS != RollbackBackupRead(bvnc.raw))
- return 1;
-
- VbNvSetup(&bvnc);
- VBDEBUG(("TPM: existing backup is %s\n",
- bvnc.regenerate_crc ? "bad" : "good"));
-
- for (i = 0; i < ARRAY_SIZE(backup_params); i++) {
- VbNvGet(vnc, backup_params[i], &value);
- VbNvSet(&bvnc, backup_params[i], value);
- }
-
- VbNvTeardown(&bvnc);
-
- if (!bvnc.raw_changed) {
- VBDEBUG(("TPM: Nothing's changed, not writing backup\n"));
- /* Clear the request flag, since we're happy. */
- VbNvSet(vnc, VBNV_BACKUP_NVRAM_REQUEST, 0);
- return 0;
- }
-
- if (TPM_SUCCESS == RollbackBackupWrite(bvnc.raw)) {
- /* Clear the request flag if we wrote successfully too */
- VbNvSet(vnc, VBNV_BACKUP_NVRAM_REQUEST, 0);
- return 0;
- }
-
- VBDEBUG(("TPM: Sorry, couldn't write backup.\n"));
- return 1;
-}
diff --git a/firmware/lib/vboot_nvstorage_rollback.c b/firmware/lib/vboot_nvstorage_rollback.c
new file mode 100644
index 00000000..8e67812d
--- /dev/null
+++ b/firmware/lib/vboot_nvstorage_rollback.c
@@ -0,0 +1,92 @@
+/* Copyright (c) 2014 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.
+ */
+
+/* Non-volatile storage routines.
+ */
+#include "sysincludes.h"
+
+#include "crc8.h"
+#include "utility.h"
+#include "vboot_common.h"
+#include "vboot_nvstorage.h"
+#include "rollback_index.h"
+
+/* These are the fields of the nvram that we want to back up. */
+static const VbNvParam backup_params[] = {
+ VBNV_KERNEL_FIELD,
+ VBNV_LOCALIZATION_INDEX,
+ VBNV_DEV_BOOT_USB,
+ VBNV_DEV_BOOT_LEGACY,
+ VBNV_DEV_BOOT_SIGNED_ONLY,
+};
+
+/* We can't back things up if there isn't enough storage. */
+BUILD_ASSERT(VBNV_BLOCK_SIZE <= BACKUP_NV_SIZE);
+
+int RestoreNvFromBackup(VbNvContext *vnc)
+{
+ VbNvContext bvnc;
+ uint32_t value;
+ int i;
+
+ VBDEBUG(("TPM: %s()\n", __func__));
+
+ if (TPM_SUCCESS != RollbackBackupRead(bvnc.raw))
+ return 1;
+
+ VbNvSetup(&bvnc);
+ if (bvnc.regenerate_crc) {
+ VBDEBUG(("TPM: Oops, backup is no good.\n"));
+ return 1;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(backup_params); i++) {
+ VbNvGet(&bvnc, backup_params[i], &value);
+ VbNvSet(vnc, backup_params[i], value);
+ }
+
+ /* VbNvTeardown(&bvnc); is not needed. We're done with it. */
+ return 0;
+}
+
+int SaveNvToBackup(VbNvContext *vnc)
+{
+ VbNvContext bvnc;
+ uint32_t value;
+ int i;
+
+ VBDEBUG(("TPM: %s()\n", __func__));
+
+ /* Read it first. No point in writing the same data. */
+ if (TPM_SUCCESS != RollbackBackupRead(bvnc.raw))
+ return 1;
+
+ VbNvSetup(&bvnc);
+ VBDEBUG(("TPM: existing backup is %s\n",
+ bvnc.regenerate_crc ? "bad" : "good"));
+
+ for (i = 0; i < ARRAY_SIZE(backup_params); i++) {
+ VbNvGet(vnc, backup_params[i], &value);
+ VbNvSet(&bvnc, backup_params[i], value);
+ }
+
+ VbNvTeardown(&bvnc);
+
+ if (!bvnc.raw_changed) {
+ VBDEBUG(("TPM: Nothing's changed, not writing backup\n"));
+ /* Clear the request flag, since we're happy. */
+ VbNvSet(vnc, VBNV_BACKUP_NVRAM_REQUEST, 0);
+ return 0;
+ }
+
+ if (TPM_SUCCESS == RollbackBackupWrite(bvnc.raw)) {
+ /* Clear the request flag if we wrote successfully too */
+ VbNvSet(vnc, VBNV_BACKUP_NVRAM_REQUEST, 0);
+ return 0;
+ }
+
+ VBDEBUG(("TPM: Sorry, couldn't write backup.\n"));
+ return 1;
+}
diff --git a/host/lib/host_misc.c b/host/lib/host_misc.c
index 77466864..110feee0 100644
--- a/host/lib/host_misc.c
+++ b/host/lib/host_misc.c
@@ -114,13 +114,3 @@ int WriteFile(const char* filename, const void *data, uint64_t size) {
fclose(f);
return 0;
}
-
-void PrintPubKeySha1Sum(VbPublicKey* key) {
- uint8_t* buf = ((uint8_t *)key) + key->key_offset;
- uint64_t buflen = key->key_size;
- uint8_t* digest = DigestBuf(buf, buflen, SHA1_DIGEST_ALGORITHM);
- int i;
- for (i=0; i<SHA1_DIGEST_SIZE; i++)
- printf("%02x", digest[i]);
- free(digest);
-}
diff --git a/host/lib/include/host_misc.h b/host/lib/include/host_misc.h
index 22b31415..9bfa721d 100644
--- a/host/lib/include/host_misc.h
+++ b/host/lib/include/host_misc.h
@@ -43,7 +43,4 @@ int ReadFileBit(const char* filename, int bitmask);
* Returns 0 if success, 1 if error. */
int WriteFile(const char* filename, const void *data, uint64_t size);
-/* Prints the sha1sum of the given VbPublicKey to stdout. */
-void PrintPubKeySha1Sum(VbPublicKey* key);
-
#endif /* VBOOT_REFERENCE_HOST_MISC_H_ */
diff --git a/host/lib/include/util_misc.h b/host/lib/include/util_misc.h
new file mode 100644
index 00000000..788929de
--- /dev/null
+++ b/host/lib/include/util_misc.h
@@ -0,0 +1,16 @@
+/* Copyright (c) 2014 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.
+ *
+ * Host-side misc functions for verified boot.
+ */
+
+#ifndef VBOOT_REFERENCE_UTIL_MISC_H_
+#define VBOOT_REFERENCE_UTIL_MISC_H_
+
+#include "vboot_struct.h"
+
+/* Prints the sha1sum of the given VbPublicKey to stdout. */
+void PrintPubKeySha1Sum(VbPublicKey* key);
+
+#endif /* VBOOT_REFERENCE_UTIL_MISC_H_ */
diff --git a/host/lib/util_misc.c b/host/lib/util_misc.c
new file mode 100644
index 00000000..09df8eef
--- /dev/null
+++ b/host/lib/util_misc.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 2014 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.
+ *
+ * Miscellaneous functions for userspace vboot utilities.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "cryptolib.h"
+#include "host_common.h"
+#include "util_misc.h"
+#include "vboot_common.h"
+
+void PrintPubKeySha1Sum(VbPublicKey* key) {
+ uint8_t* buf = ((uint8_t *)key) + key->key_offset;
+ uint64_t buflen = key->key_size;
+ uint8_t* digest = DigestBuf(buf, buflen, SHA1_DIGEST_ALGORITHM);
+ int i;
+ for (i=0; i<SHA1_DIGEST_SIZE; i++)
+ printf("%02x", digest[i]);
+ free(digest);
+}
diff --git a/host/linktest/extern.c b/host/linktest/extern.c
new file mode 100644
index 00000000..46b5ddac
--- /dev/null
+++ b/host/linktest/extern.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 2014 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.
+ */
+
+/*
+ * This tests for the presence of those functions actually used by userspace
+ * apps that are not part of firmware or vboot_reference.
+ */
+
+#include "crossystem.h"
+#include "tlcl.h"
+#include "vboot_host.h"
+
+/* TODO(crbug.com/318536) */
+const char* progname = "";
+const char* command = "";
+void (*uuid_generator)(uint8_t* buffer) = NULL;
+
+int main(void)
+{
+ /* crossystem.h */
+ VbGetSystemPropertyInt(0);
+ VbGetSystemPropertyString(0, 0, 0);
+ VbSetSystemPropertyInt(0, 0);
+
+ /* tlcl.h */
+ TlclGetOwnership(0);
+ TlclGetRandom(0, 0, 0);
+ TlclLibClose();
+ TlclLibInit();
+ TlclRead(0, 0, 0);
+
+ /* vboot_host.h */
+ CgptAdd(0);
+ CgptBoot(0);
+ CgptCreate(0);
+ CgptGetBootPartitionNumber(0);
+ CgptGetNumNonEmptyPartitions(0);
+ CgptGetPartitionDetails(0);
+ CgptPrioritize(0);
+ CgptSetAttributes(0);
+ FindKernelConfig(0, 0);
+ GuidEqual(0, 0);
+ GuidIsZero(0);
+ GuidToStr(0, 0, 0);
+ StrToGuid(0, 0);
+
+ return 0;
+}
diff --git a/host/linktest/main.c b/host/linktest/main.c
index 1f3dfecc..56ab21cd 100644
--- a/host/linktest/main.c
+++ b/host/linktest/main.c
@@ -2,6 +2,11 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
+/*
+ * This tests for the presence of functions used by vboot_reference utilities.
+ */
+
#include <stdio.h>
#include "host_common.h"
diff --git a/utility/vbutil_firmware.c b/utility/vbutil_firmware.c
index f6a547d6..f11d7b54 100644
--- a/utility/vbutil_firmware.c
+++ b/utility/vbutil_firmware.c
@@ -15,6 +15,7 @@
#include "cryptolib.h"
#include "host_common.h"
#include "kernel_blob.h"
+#include "util_misc.h"
#include "vboot_common.h"
diff --git a/utility/vbutil_kernel.c b/utility/vbutil_kernel.c
index 24a2ba6c..5fed77ac 100644
--- a/utility/vbutil_kernel.c
+++ b/utility/vbutil_kernel.c
@@ -23,6 +23,7 @@
#include "cryptolib.h"
#include "host_common.h"
#include "kernel_blob.h"
+#include "util_misc.h"
#include "vboot_common.h"
/* Global opts */
diff --git a/utility/vbutil_key.c b/utility/vbutil_key.c
index 18e37a22..3d9dfc4a 100644
--- a/utility/vbutil_key.c
+++ b/utility/vbutil_key.c
@@ -14,6 +14,7 @@
#include "cryptolib.h"
#include "host_common.h"
+#include "util_misc.h"
#include "vboot_common.h"
diff --git a/utility/vbutil_keyblock.c b/utility/vbutil_keyblock.c
index a26d7a99..17614580 100644
--- a/utility/vbutil_keyblock.c
+++ b/utility/vbutil_keyblock.c
@@ -13,6 +13,7 @@
#include "cryptolib.h"
#include "host_common.h"
+#include "util_misc.h"
#include "vboot_common.h"