From 98616d79c6b60c719bc3e37f7f82028e77983d94 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Thu, 4 Jan 2018 16:08:47 -0800 Subject: [PATCH] firmware: Prune down old region API The region API was a way for firmware and kernel verification to get at various blocks of caller-provided data. In practice, we only used it internally as a way to get at parts of the GBB. Prune it down to access only the bits of GBB we still need, from the buffer we already know we have. In the long run we should use the same vb2ex_read_resource() API that vb2 firmware verification does, but that should be done in a follow-up CL since it'll need to be coordinated with support in depthcharge. No change in functionality. BUG=chromium:611535 BRANCH=none TEST=make -j runtests; build bob firmware and boot it Change-Id: I5715cb8d88274164a1a73ed4a56bbd93af46f9bf Signed-off-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/852798 Commit-Ready: ChromeOS CL Exonerator Bot Reviewed-by: Stefan Reinauer --- Makefile | 19 +-- firmware/2lib/include/2struct.h | 5 + firmware/include/gbb_access.h | 36 ++--- firmware/include/region.h | 55 -------- firmware/include/vboot_api.h | 3 - firmware/lib/include/vboot_display.h | 5 +- firmware/lib/include/vboot_kernel.h | 8 +- firmware/lib/region-fw.c | 55 -------- firmware/lib/region-init.c | 100 +++++++++---- firmware/lib/region-kernel.c | 89 ------------ firmware/lib/vboot_api_kernel.c | 24 +--- firmware/lib/vboot_display.c | 14 +- firmware/lib/vboot_kernel.c | 3 +- firmware/lib/vboot_ui.c | 19 ++- firmware/lib/vboot_ui_menu.c | 32 ++--- firmware/stub/vboot_api_stub_region.c | 18 --- tests/ec_sync_tests.c | 8 -- tests/vboot_api_devmode_tests.c | 8 -- tests/vboot_api_kernel2_tests.c | 28 ++-- tests/vboot_api_kernel5_tests.c | 23 +-- tests/vboot_detach_menu_tests.c | 8 -- tests/vboot_display_tests.c | 60 +++----- tests/vboot_kernel_tests.c | 5 +- tests/vboot_region_tests.c | 196 -------------------------- utility/load_kernel_test.c | 2 +- 25 files changed, 188 insertions(+), 635 deletions(-) delete mode 100644 firmware/include/region.h delete mode 100644 firmware/lib/region-fw.c delete mode 100644 firmware/lib/region-kernel.c delete mode 100644 firmware/stub/vboot_api_stub_region.c delete mode 100644 tests/vboot_region_tests.c diff --git a/Makefile b/Makefile index 3c12e79bce..ed73e260b5 100644 --- a/Makefile +++ b/Makefile @@ -318,12 +318,11 @@ BDBLIB = ${BUILD}/bdb.a # Firmware library sources needed by VbInit() call VBINIT_SRCS = \ firmware/lib/vboot_common_init.c \ - firmware/lib/region-init.c \ + firmware/lib/region-init.c # Additional firmware library sources needed by VbSelectFirmware() call VBSF_SRCS = \ - firmware/lib/vboot_common.c \ - firmware/lib/region-fw.c \ + firmware/lib/vboot_common.c # Additional firmware library sources needed by VbSelectAndLoadKernel() call VBSLK_SRCS = \ @@ -339,8 +338,7 @@ VBSLK_SRCS = \ firmware/lib/vboot_display.c \ firmware/lib/vboot_kernel.c \ firmware/lib/vboot_ui.c \ - firmware/lib/vboot_ui_menu.c \ - firmware/lib/region-kernel.c \ + firmware/lib/vboot_ui_menu.c # Code common to both vboot 2.0 (old structs) and 2.1 (new structs) FWLIB2X_SRCS = \ @@ -410,8 +408,7 @@ ifeq (${FIRMWARE_ARCH},) # TODO: split out other stub funcs too VBINIT_SRCS += \ firmware/stub/tpm_lite_stub.c \ - firmware/stub/vboot_api_stub_init.c \ - firmware/stub/vboot_api_stub_region.c + firmware/stub/vboot_api_stub_init.c VBSLK_SRCS += \ firmware/stub/vboot_api_stub.c \ @@ -747,10 +744,6 @@ TEST_NAMES += \ tests/rollback_index2_tests endif -ifdef REGION_READ -TEST_NAMES += tests/vboot_region_tests -endif - TEST_FUTIL_NAMES = \ tests/futility/binary_editor \ tests/futility/test_file_types \ @@ -910,10 +903,6 @@ ${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY ${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA endif -ifdef REGION_READ -${FWLIB_OBJS}: CFLAGS += -DREGION_READ -endif - ifeq (${FIRMWARE_ARCH},) # Disable rollback TPM when compiling locally, since otherwise # load_kernel_test attempts to talk to the TPM. diff --git a/firmware/2lib/include/2struct.h b/firmware/2lib/include/2struct.h index 589e7c9b95..3411de771a 100644 --- a/firmware/2lib/include/2struct.h +++ b/firmware/2lib/include/2struct.h @@ -208,6 +208,11 @@ struct vb2_shared_data { uint32_t workbuf_kernel_key_offset; uint32_t workbuf_kernel_key_size; + /* GBB data and size */ + struct vb2_gbb_header *gbb; + uint32_t gbb_size; + + } __attribute__((packed)); /****************************************************************************/ diff --git a/firmware/include/gbb_access.h b/firmware/include/gbb_access.h index 7b11dc85d1..9b4e0dde7a 100644 --- a/firmware/include/gbb_access.h +++ b/firmware/include/gbb_access.h @@ -10,43 +10,43 @@ #include "vboot_api.h" -struct BmpBlockHeader; -struct ImageInfo; -struct GoogleBinaryBlockHeader; -struct ScreenLayout; +struct vb2_context; struct VbPublicKey; -/** - * Read the GBB header - * - * This accesses the GBB and reads its header. - * - * @param cparams Vboot common parameters - * @param gbb Place to put GBB header - */ -VbError_t VbGbbReadHeader_static(VbCommonParams *cparams, - struct GoogleBinaryBlockHeader *gbb); - /** * Read the root key from the GBB * - * @param cparams Vboot common parameters + * @param ctx Vboot context * @param keyp Returns a pointer to the key. The caller must call * free() on the key when finished with it. * @return VBERROR_... error, VBERROR_SUCCESS on success, */ -VbError_t VbGbbReadRootKey(VbCommonParams *cparams, +VbError_t VbGbbReadRootKey(struct vb2_context *ctx, struct VbPublicKey **keyp); /** * Read the recovery key from the GBB * + * @param ctx Vboot context * @param cparams Vboot common parameters * @param keyp Returns a pointer to the key. The caller must call * free() on the key when finished with it. * @return VBERROR_... error, VBERROR_SUCCESS on success, */ -VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams, +VbError_t VbGbbReadRecoveryKey(struct vb2_context *ctx, struct VbPublicKey **keyp); +/** + * Read the hardware ID from the GBB + * + * @param ctx Vboot context + * @param hwid Place to put HWID, which will be null-terminated + * @param max_size Maximum size of HWID including terminated null + * character (suggest 256). If this size is too small + * then VBERROR_INVALID_PARAMETER is returned. + * @return VBERROR_... error, VBERROR_SUCCESS on success, + */ +VbError_t VbGbbReadHWID(struct vb2_context *ctx, char *hwid, + uint32_t max_size); + #endif diff --git a/firmware/include/region.h b/firmware/include/region.h deleted file mode 100644 index 78e1dba0b0..0000000000 --- a/firmware/include/region.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 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. - * - * Access to portions of the firmware image, perhaps later to be expanded - * to other devices. - */ - -#ifndef VBOOT_REFERENCE_REGION_H_ -#define VBOOT_REFERENCE_REGION_H_ - -#include "bmpblk_header.h" -#include "gbb_header.h" -#include "vboot_api.h" -#include "vboot_struct.h" - -/* The maximum length of a hardware ID */ -#define VB_REGION_HWID_LEN 256 - -/** - * Read data from a region - * - * @param cparams Vboot common parameters - * @param region Region number to read - * @param offset Offset within region to start reading - * @param size Size of data to read - * @param buf Buffer to put the data into - * @return VBERROR_... error, VBERROR_SUCCESS on success, - */ -VbError_t VbRegionReadData(VbCommonParams *cparams, - enum vb_firmware_region region, uint32_t offset, - uint32_t size, void *buf); - -/** - * Check the version of the GBB and print debug information if valid - * - * @param cparams Vboot common parameters - */ -void VbRegionCheckVersion(VbCommonParams *cparams); - -/** - * Read the hardware ID from the GBB - * - * @param cparams Vboot common parameters - * @param hwid Place to put HWID, which will be null-terminated - * @param max_size Maximum size of HWID including terminated null - * character (suggest VB_REGION_HWID_LEN). If this size - * it too small then VBERROR_INVALID_PARAMETER is - * returned. - * @return VBERROR_... error, VBERROR_SUCCESS on success, - */ -VbError_t VbRegionReadHWID(VbCommonParams *cparams, char *hwid, - uint32_t max_size); - -#endif /* VBOOT_REFERENCE_REGION_H_ */ diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h index aa3ba2c974..5edf0a6b67 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -193,9 +193,6 @@ typedef struct VbCommonParams { * the stack. */ void *caller_context; - - /* For internal use of Vboot - do not examine or modify! */ - struct GoogleBinaryBlockHeader *gbb; } VbCommonParams; /* Flags for VbInitParams.flags */ diff --git a/firmware/lib/include/vboot_display.h b/firmware/lib/include/vboot_display.h index 8e6a454630..20066dfa8d 100644 --- a/firmware/lib/include/vboot_display.h +++ b/firmware/lib/include/vboot_display.h @@ -14,9 +14,8 @@ VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force); VbError_t VbDisplayMenu(struct vb2_context *ctx, uint32_t screen, int force, uint32_t selected_index, uint32_t disabled_idx_mask); -VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams); -VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams, - uint32_t key); +VbError_t VbDisplayDebugInfo(struct vb2_context *ctx); +VbError_t VbCheckDisplayKey(struct vb2_context *ctx, uint32_t key); /** * Return a description of the recovery reason code. diff --git a/firmware/lib/include/vboot_kernel.h b/firmware/lib/include/vboot_kernel.h index 2195e0cfe9..3398169029 100644 --- a/firmware/lib/include/vboot_kernel.h +++ b/firmware/lib/include/vboot_kernel.h @@ -16,11 +16,6 @@ struct vb2_context; -/** - * Exported for unit tests only - frees memory used by VbSelectAndLoadKernel() - */ -void VbApiKernelFree(VbCommonParams *cparams); - /** * Attempt loading a kernel from the specified type(s) of disks. * @@ -54,8 +49,7 @@ uint32_t VbTryLoadKernel(struct vb2_context *ctx, VbCommonParams *cparams, * * Returns: 1=yes, 0=no, -1 = shutdown. */ -int VbUserConfirms(struct vb2_context *ctx, VbCommonParams *cparams, - uint32_t confirm_flags); +int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags); /** * Handle a normal boot. diff --git a/firmware/lib/region-fw.c b/firmware/lib/region-fw.c deleted file mode 100644 index 2bc1a690f1..0000000000 --- a/firmware/lib/region-fw.c +++ /dev/null @@ -1,55 +0,0 @@ -/* 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. - * - * High-level firmware API for loading and verifying rewritable firmware. - * (Firmware portion) - */ - -#include "sysincludes.h" - -#include "bmpblk_header.h" -#include "region.h" -#include "gbb_access.h" -#include "gbb_header.h" -#include "load_kernel_fw.h" -#include "utility.h" -#include "vboot_api.h" -#include "vboot_struct.h" - -static VbError_t VbGbbReadKey(VbCommonParams *cparams, uint32_t offset, - VbPublicKey **keyp) -{ - VbPublicKey hdr, *key; - VbError_t ret; - uint32_t size; - - ret = VbRegionReadData(cparams, VB_REGION_GBB, offset, - sizeof(VbPublicKey), &hdr); - if (ret) - return ret; - - /* Deal with a zero-size key (used in testing) */ - size = hdr.key_offset + hdr.key_size; - if (size < sizeof(hdr)) - size = sizeof(hdr); - key = malloc(size); - ret = VbRegionReadData(cparams, VB_REGION_GBB, offset, size, key); - if (ret) { - free(key); - return ret; - } - - *keyp = key; - return VBERROR_SUCCESS; -} - -VbError_t VbGbbReadRootKey(VbCommonParams *cparams, VbPublicKey **keyp) -{ - return VbGbbReadKey(cparams, cparams->gbb->rootkey_offset, keyp); -} - -VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams, VbPublicKey **keyp) -{ - return VbGbbReadKey(cparams, cparams->gbb->recovery_key_offset, keyp); -} diff --git a/firmware/lib/region-init.c b/firmware/lib/region-init.c index 26602b542e..5cfd4edaee 100644 --- a/firmware/lib/region-init.c +++ b/firmware/lib/region-init.c @@ -6,10 +6,11 @@ * (Firmware portion) */ -#include "sysincludes.h" +#include "2sysincludes.h" +#include "2common.h" +#include "2misc.h" -#include "bmpblk_header.h" -#include "region.h" +#include "sysincludes.h" #include "gbb_access.h" #include "gbb_header.h" #include "load_kernel_fw.h" @@ -17,34 +18,83 @@ #include "vboot_api.h" #include "vboot_struct.h" -VbError_t VbRegionReadData(VbCommonParams *cparams, - enum vb_firmware_region region, uint32_t offset, - uint32_t size, void *buf) +VbError_t VbGbbReadData(struct vb2_context *ctx, + uint32_t offset, uint32_t size, void *buf) { + struct vb2_shared_data *sd = vb2_get_sd(ctx); + /* This is the old API, for backwards compatibility */ - if (region == VB_REGION_GBB && cparams->gbb_data) { - if (offset + size > cparams->gbb_size) - return VBERROR_INVALID_GBB; - memcpy(buf, cparams->gbb_data + offset, size); - } else -#ifdef REGION_READ - { - VbError_t ret; + if (!sd->gbb) + return VBERROR_INVALID_GBB; - ret = VbExRegionRead(cparams, region, offset, size, buf); - if (ret) - return ret; - } -#else - return VBERROR_INVALID_GBB; -#endif + if (offset + size > sd->gbb_size) + return VBERROR_INVALID_GBB; + memcpy(buf, ((uint8_t *)sd->gbb) + offset, size); return VBERROR_SUCCESS; } -VbError_t VbGbbReadHeader_static(VbCommonParams *cparams, - GoogleBinaryBlockHeader *gbb) +VbError_t VbGbbReadHWID(struct vb2_context *ctx, char *hwid, uint32_t max_size) { - return VbRegionReadData(cparams, VB_REGION_GBB, 0, - sizeof(GoogleBinaryBlockHeader), gbb); + struct vb2_shared_data *sd = vb2_get_sd(ctx); + + if (!max_size) + return VBERROR_INVALID_PARAMETER; + *hwid = '\0'; + StrnAppend(hwid, "{INVALID}", max_size); + if (!ctx) + return VBERROR_INVALID_GBB; + + if (0 == sd->gbb->hwid_size) { + VB2_DEBUG("VbHWID(): invalid hwid size\n"); + return VBERROR_SUCCESS; /* oddly enough! */ + } + + if (sd->gbb->hwid_size > max_size) { + VB2_DEBUG("VbDisplayDebugInfo(): invalid hwid offset/size\n"); + return VBERROR_INVALID_PARAMETER; + } + + return VbGbbReadData(ctx, sd->gbb->hwid_offset, + sd->gbb->hwid_size, hwid); +} + +static VbError_t VbGbbReadKey(struct vb2_context *ctx, uint32_t offset, + VbPublicKey **keyp) +{ + VbPublicKey hdr, *key; + VbError_t ret; + uint32_t size; + + ret = VbGbbReadData(ctx, offset, sizeof(VbPublicKey), &hdr); + if (ret) + return ret; + + /* Deal with a zero-size key (used in testing) */ + size = hdr.key_offset + hdr.key_size; + if (size < sizeof(hdr)) + size = sizeof(hdr); + key = malloc(size); + ret = VbGbbReadData(ctx, offset, size, key); + if (ret) { + free(key); + return ret; + } + + *keyp = key; + return VBERROR_SUCCESS; +} + +VbError_t VbGbbReadRootKey(struct vb2_context *ctx, VbPublicKey **keyp) +{ + struct vb2_shared_data *sd = vb2_get_sd(ctx); + + return VbGbbReadKey(ctx, sd->gbb->rootkey_offset, keyp); +} + +VbError_t VbGbbReadRecoveryKey(struct vb2_context *ctx, VbPublicKey **keyp) +{ + struct vb2_shared_data *sd = vb2_get_sd(ctx); + + return VbGbbReadKey(ctx, sd->gbb->recovery_key_offset, keyp); } diff --git a/firmware/lib/region-kernel.c b/firmware/lib/region-kernel.c deleted file mode 100644 index 404c189d14..0000000000 --- a/firmware/lib/region-kernel.c +++ /dev/null @@ -1,89 +0,0 @@ -/* 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. - * - * High-level firmware API for loading and verifying rewritable firmware. - * (Firmware portion) - */ - -#include "2sysincludes.h" -#include "2common.h" - -#include "sysincludes.h" -#include "bmpblk_header.h" -#include "region.h" -#include "gbb_access.h" -#include "gbb_header.h" -#include "load_kernel_fw.h" -#include "utility.h" -#include "vboot_api.h" -#include "vboot_struct.h" - -static VbError_t VbRegionReadGbb(VbCommonParams *cparams, uint32_t offset, - uint32_t size, void *buf) -{ - return VbRegionReadData(cparams, VB_REGION_GBB, offset, size, buf); -} - -VbError_t VbRegionReadHWID(VbCommonParams *cparams, char *hwid, - uint32_t max_size) -{ - GoogleBinaryBlockHeader *gbb; - VbError_t ret; - - if (!max_size) - return VBERROR_INVALID_PARAMETER; - *hwid = '\0'; - StrnAppend(hwid, "{INVALID}", max_size); - if (!cparams) - return VBERROR_INVALID_GBB; - - gbb = cparams->gbb; - - if (0 == gbb->hwid_size) { - VB2_DEBUG("VbHWID(): invalid hwid size\n"); - return VBERROR_SUCCESS; /* oddly enough! */ - } - - if (gbb->hwid_size > max_size) { - VB2_DEBUG("VbDisplayDebugInfo(): invalid hwid offset/size\n"); - return VBERROR_INVALID_PARAMETER; - } - ret = VbRegionReadGbb(cparams, gbb->hwid_offset, gbb->hwid_size, hwid); - if (ret) - return ret; - - return VBERROR_SUCCESS; -} - -#define OUTBUF_LEN 128 - -void VbRegionCheckVersion(VbCommonParams *cparams) -{ - GoogleBinaryBlockHeader *gbb; - - if (!cparams) - return; - - gbb = cparams->gbb; - - /* - * If GBB flags is nonzero, complain because that's something that the - * factory MUST fix before shipping. We only have to do this here, - * because it's obvious that something is wrong if we're not displaying - * screens from the GBB. - */ - if (gbb->major_version == GBB_MAJOR_VER && gbb->minor_version >= 1 && - (gbb->flags != 0)) { - uint32_t used = 0; - char outbuf[OUTBUF_LEN]; - - *outbuf = '\0'; - used += StrnAppend(outbuf + used, "gbb.flags is nonzero: 0x", - OUTBUF_LEN - used); - used += Uint64ToString(outbuf + used, OUTBUF_LEN - used, - gbb->flags, 16, 8); - used += StrnAppend(outbuf + used, "\n", OUTBUF_LEN - used); - (void)VbExDisplayDebugInfo(outbuf); - } -} diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index 5bda94f93e..7976170d16 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -16,7 +16,6 @@ #include "gbb_access.h" #include "gbb_header.h" #include "load_kernel_fw.h" -#include "region.h" #include "rollback_index.h" #include "utility.h" #include "vb2_common.h" @@ -234,16 +233,6 @@ VbError_t VbBootNormal(struct vb2_context *ctx, VbCommonParams *cparams) return rv; } -/* This function is also used by tests */ -void VbApiKernelFree(VbCommonParams *cparams) -{ - /* VbSelectAndLoadKernel() always allocates this, tests don't */ - if (cparams->gbb) { - free(cparams->gbb); - cparams->gbb = NULL; - } -} - static VbError_t vb2_kernel_setup(VbCommonParams *cparams, VbSelectAndLoadKernelParams *kparams) { @@ -345,12 +334,10 @@ static VbError_t vb2_kernel_setup(VbCommonParams *cparams, kparams->flags = 0; memset(kparams->partition_guid, 0, sizeof(kparams->partition_guid)); - /* Read GBB header, since we'll needs flags from it */ - cparams->gbb = malloc(sizeof(*cparams->gbb)); - uint32_t retval = VbGbbReadHeader_static(cparams, cparams->gbb); - if (retval) - return retval; - sd->gbb_flags = cparams->gbb->flags; + /* Point to GBB data from cparams */ + sd->gbb = cparams->gbb_data; + sd->gbb_size = cparams->gbb_size; + sd->gbb_flags = sd->gbb->flags; /* Read kernel version from the TPM. Ignore errors in recovery mode. */ if (RollbackKernelRead(&shared->kernel_version_tpm)) { @@ -421,7 +408,6 @@ static void vb2_kernel_cleanup(struct vb2_context *ctx, VbCommonParams *cparams) /* Free buffers */ free(unaligned_workbuf); - VbApiKernelFree(cparams); vb2_nv_commit(ctx); @@ -530,7 +516,7 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams, hash_only = 1; } else { /* Get recovery key. */ - retval = VbGbbReadRecoveryKey(cparams, &kernel_subkey); + retval = VbGbbReadRecoveryKey(&ctx, &kernel_subkey); if (VBERROR_SUCCESS != retval) { VB2_DEBUG("Gbb Read Recovery key failed.\n"); goto fail; diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c index d3e3a6a2e3..ea36c1f1b6 100644 --- a/firmware/lib/vboot_display.c +++ b/firmware/lib/vboot_display.c @@ -15,7 +15,6 @@ #include "bmpblk_font.h" #include "gbb_access.h" #include "gbb_header.h" -#include "region.h" #include "utility.h" #include "vboot_api.h" #include "vboot_common.h" @@ -274,7 +273,7 @@ const char *RecoveryReasonString(uint8_t code) #define DEBUG_INFO_SIZE 512 -VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams) +VbError_t VbDisplayDebugInfo(struct vb2_context *ctx) { struct vb2_shared_data *sd = vb2_get_sd(ctx); VbSharedDataHeader *shared = sd->vbsd; @@ -296,7 +295,7 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams) disp_current_index, disp_disabled_idx_mask); /* Add hardware ID */ - VbRegionReadHWID(cparams, hwid, sizeof(hwid)); + VbGbbReadHWID(ctx, hwid, sizeof(hwid)); used += StrnAppend(buf + used, "HWID: ", DEBUG_INFO_SIZE - used); used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used); @@ -371,7 +370,7 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams) sd->gbb_flags, 16, 8); /* Add sha1sum for Root & Recovery keys */ - ret = VbGbbReadRootKey(cparams, &key); + ret = VbGbbReadRootKey(ctx, &key); if (!ret) { FillInSha1Sum(sha1sum, key); free(key); @@ -381,7 +380,7 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams) DEBUG_INFO_SIZE - used); } - ret = VbGbbReadRecoveryKey(cparams, &key); + ret = VbGbbReadRecoveryKey(ctx, &key); if (!ret) { FillInSha1Sum(sha1sum, key); free(key); @@ -413,8 +412,7 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams) #define MAGIC_WORD "xyzzy" static uint8_t MagicBuffer[MAGIC_WORD_LEN]; -VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams, - uint32_t key) +VbError_t VbCheckDisplayKey(struct vb2_context *ctx, uint32_t key) { int i; @@ -426,7 +424,7 @@ VbError_t VbCheckDisplayKey(struct vb2_context *ctx, VbCommonParams *cparams, if ('\t' == key) { /* Tab = display debug info */ - return VbDisplayDebugInfo(ctx, cparams); + return VbDisplayDebugInfo(ctx); } else if (VB_KEY_LEFT == key || VB_KEY_RIGHT == key || VB_KEY_DOWN == key || VB_KEY_UP == key) { /* Arrow keys = change localization */ diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c index d298e68deb..0200dccf65 100644 --- a/firmware/lib/vboot_kernel.c +++ b/firmware/lib/vboot_kernel.c @@ -16,7 +16,6 @@ #include "2sha.h" #include "cgptlib.h" #include "cgptlib_internal.h" -#include "region.h" #include "gbb_access.h" #include "gbb_header.h" #include "gpt_misc.h" @@ -464,7 +463,7 @@ VbError_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params, struct vb2_packed_key *kernel_subkey; if (kBootRecovery == shcall->boot_mode) { /* Use the recovery key to verify the kernel */ - retval = VbGbbReadRecoveryKey(cparams, + retval = VbGbbReadRecoveryKey(ctx, (VbPublicKey **)&recovery_key); if (VBERROR_SUCCESS != retval) goto load_kernel_exit; diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index 36c7cdf165..93bdf65aa3 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -16,7 +16,6 @@ #include "gbb_access.h" #include "gbb_header.h" #include "load_kernel_fw.h" -#include "region.h" #include "rollback_index.h" #include "utility.h" #include "vb2_common.h" @@ -91,8 +90,7 @@ uint32_t VbTryUsb(struct vb2_context *ctx, VbCommonParams *cparams) #define CONFIRM_KEY_DELAY 20 /* Check confirm screen keys every 20ms */ -int VbUserConfirms(struct vb2_context *ctx, VbCommonParams *cparams, - uint32_t confirm_flags) +int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags) { struct vb2_shared_data *sd = vb2_get_sd(ctx); VbSharedDataHeader *shared = sd->vbsd; @@ -146,7 +144,7 @@ int VbUserConfirms(struct vb2_context *ctx, VbCommonParams *cparams, return 1; } } - VbCheckDisplayKey(ctx, cparams, key); + VbCheckDisplayKey(ctx, key); } VbExSleepMs(CONFIRM_KEY_DELAY); } @@ -216,7 +214,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams) VbExDisplayDebugInfo(dev_disable_msg); /* Ignore space in VbUserConfirms()... */ - switch (VbUserConfirms(ctx, cparams, 0)) { + switch (VbUserConfirms(ctx, 0)) { case 1: VB2_DEBUG("leaving dev-mode\n"); vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1); @@ -278,7 +276,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams) VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_TO_NORM, 0); /* Ignore space in VbUserConfirms()... */ - switch (VbUserConfirms(ctx, cparams, 0)) { + switch (VbUserConfirms(ctx, 0)) { case 1: VB2_DEBUG("leaving dev-mode\n"); vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, @@ -360,7 +358,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams) break; default: VB2_DEBUG("VbBootDeveloper() - pressed key %d\n", key); - VbCheckDisplayKey(ctx, cparams, key); + VbCheckDisplayKey(ctx, key); break; } } while(vb2_audio_looping()); @@ -429,7 +427,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) VB2_DEBUG("VbBootRecovery() waiting for manual recovery\n"); while (1) { key = VbExKeyboardRead(); - VbCheckDisplayKey(ctx, cparams, key); + VbCheckDisplayKey(ctx, key); if (VbWantShutdown(ctx, key)) return VBERROR_SHUTDOWN_REQUESTED; VbExSleepMs(REC_KEY_DELAY); @@ -499,8 +497,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) uint32_t vbc_flags = VB_CONFIRM_SPACE_MEANS_NO | VB_CONFIRM_MUST_TRUST_KEYBOARD; - switch (VbUserConfirms(ctx, cparams, - vbc_flags)) { + switch (VbUserConfirms(ctx, vbc_flags)) { case 1: VB2_DEBUG("Enabling dev-mode...\n"); if (TPM_SUCCESS != SetVirtualDevMode(1)) @@ -524,7 +521,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) break; } } else { - VbCheckDisplayKey(ctx, cparams, key); + VbCheckDisplayKey(ctx, key); } if (VbWantShutdown(ctx, key)) return VBERROR_SHUTDOWN_REQUESTED; diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c index a8247a2c9b..6ca602a782 100644 --- a/firmware/lib/vboot_ui_menu.c +++ b/firmware/lib/vboot_ui_menu.c @@ -14,7 +14,6 @@ #include "gbb_access.h" #include "gbb_header.h" #include "load_kernel_fw.h" -#include "region.h" #include "rollback_index.h" #include "utility.h" #include "vb2_common.h" @@ -245,8 +244,7 @@ static const uint32_t VB_MENU_TO_SCREEN_MAP[] = { VB_SCREEN_TO_NORM_CONFIRMED, }; -VbError_t vb2_draw_current_screen(struct vb2_context *ctx, - VbCommonParams *cparams) { +VbError_t vb2_draw_current_screen(struct vb2_context *ctx) { uint32_t screen; if (current_menu < VB_MENU_COUNT) screen = VB_MENU_TO_SCREEN_MAP[current_menu]; @@ -645,7 +643,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) vb2_set_disabled_idx_mask(shared->flags); /* Show the dev mode warning screen */ - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); /* Get audio/delay context */ vb2_audio_start(ctx); @@ -710,21 +708,21 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) return VBERROR_SUCCESS; } else { /* Show dev mode warning screen again */ - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); } } break; case VB_BUTTON_VOL_UP_SHORT_PRESS: case VB_KEY_UP: vb2_update_selection(key); - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); /* reset 30 second timer */ vb2_audio_start(ctx); break; case VB_BUTTON_VOL_DOWN_SHORT_PRESS: case VB_KEY_DOWN: vb2_update_selection(key); - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); /* reset 30 second timer */ vb2_audio_start(ctx); break; @@ -740,7 +738,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) ret = vb2_update_menu(ctx); vb2_set_disabled_idx_mask(shared->flags); - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); /* Probably shutting down */ if (ret != VBERROR_SUCCESS) { @@ -757,7 +755,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) /* Display debug information */ if (current_menu == VB_MENU_DEV_WARNING && current_menu_idx == VB_WARN_DBG_INFO) { - VbDisplayDebugInfo(ctx, cparams); + VbDisplayDebugInfo(ctx); } /* Boot Legacy mode */ @@ -797,8 +795,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) * Show dev mode warning screen * again */ - vb2_draw_current_screen(ctx, - cparams); + vb2_draw_current_screen(ctx); } } @@ -933,7 +930,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) if (key == VB_BUTTON_POWER_SHORT_PRESS) return VBERROR_SHUTDOWN_REQUESTED; else { - VbCheckDisplayKey(ctx, cparams, key); + VbCheckDisplayKey(ctx, key); if (VbWantShutdownMenu(ctx)) return VBERROR_SHUTDOWN_REQUESTED; } @@ -970,7 +967,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) if (current_menu != VB_MENU_RECOVERY || current_menu_idx != VB_RECOVERY_DBG_INFO) { if (retval == VBERROR_NO_DISK_FOUND) - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); else { VbDisplayScreen(ctx, VB_SCREEN_RECOVERY_NO_GOOD, 0); @@ -1005,7 +1002,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) } vb2_update_selection(key); - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); break; case VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS: /* @@ -1018,7 +1015,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) if (ret != VBERROR_SUCCESS) return ret; vb2_set_disabled_idx_mask(shared->flags); - vb2_draw_current_screen(ctx, cparams); + vb2_draw_current_screen(ctx); } break; case VB_BUTTON_POWER_SHORT_PRESS: @@ -1056,8 +1053,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) * printed. */ if (retval == VBERROR_NO_DISK_FOUND) - vb2_draw_current_screen(ctx, - cparams); + vb2_draw_current_screen(ctx); else { VbDisplayScreen(ctx, VB_SCREEN_RECOVERY_NO_GOOD, 0); @@ -1078,7 +1074,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) /* Display debug information */ if (current_menu == VB_MENU_RECOVERY && current_menu_idx == VB_RECOVERY_DBG_INFO) { - VbDisplayDebugInfo(ctx, cparams); + VbDisplayDebugInfo(ctx); } /* Confirm going into developer mode */ diff --git a/firmware/stub/vboot_api_stub_region.c b/firmware/stub/vboot_api_stub_region.c deleted file mode 100644 index f462fe4ecd..0000000000 --- a/firmware/stub/vboot_api_stub_region.c +++ /dev/null @@ -1,18 +0,0 @@ -/* 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 region API function. - */ - -#include -#include - -#include "vboot_api.h" - -VbError_t VbExRegionRead(VbCommonParams *cparams, - enum vb_firmware_region region, uint32_t offset, - uint32_t size, void *buf) -{ - return VBERROR_SUCCESS; -} diff --git a/tests/ec_sync_tests.c b/tests/ec_sync_tests.c index 332290aead..3dcc6803ee 100644 --- a/tests/ec_sync_tests.c +++ b/tests/ec_sync_tests.c @@ -29,7 +29,6 @@ static VbCommonParams cparams; static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; -static GoogleBinaryBlockHeader gbb; static int mock_in_rw; static VbError_t in_rw_retval; @@ -69,13 +68,6 @@ static void ResetMocks(void) memset(&cparams, 0, sizeof(cparams)); cparams.shared_data_size = sizeof(shared_data); cparams.shared_data_blob = shared_data; - cparams.gbb_data = &gbb; - - memset(&gbb, 0, sizeof(gbb)); - gbb.major_version = GBB_MAJOR_VER; - gbb.minor_version = GBB_MINOR_VER; - gbb.flags = 0; - cparams.gbb = &gbb; memset(&ctx, 0, sizeof(ctx)); ctx.workbuf = workbuf; diff --git a/tests/vboot_api_devmode_tests.c b/tests/vboot_api_devmode_tests.c index 330a89ac37..916cf0689c 100644 --- a/tests/vboot_api_devmode_tests.c +++ b/tests/vboot_api_devmode_tests.c @@ -100,7 +100,6 @@ static struct vb2_context ctx; static struct vb2_shared_data *sd; static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; static VbSharedDataHeader* shared = (VbSharedDataHeader*)shared_data; -static GoogleBinaryBlockHeader gbb; static int current_time; static uint64_t current_ticks; static int current_event; @@ -118,8 +117,6 @@ extern int audio_open_count; static void ResetMocks(void) { memset(&cparams, 0, sizeof(cparams)); - cparams.gbb_data = &gbb; - cparams.gbb = &gbb; memset(&ctx, 0, sizeof(ctx)); ctx.workbuf = workbuf; @@ -134,11 +131,6 @@ static void ResetMocks(void) VbSharedDataInit(shared, sizeof(shared_data)); shared->fw_keyblock_flags = 0xABCDE0; - memset(&gbb, 0, sizeof(gbb)); - gbb.major_version = GBB_MAJOR_VER; - gbb.minor_version = GBB_MINOR_VER; - gbb.flags = 0; - current_ticks = 0; current_time = 0; diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c index 04e6466784..92041207b4 100644 --- a/tests/vboot_api_kernel2_tests.c +++ b/tests/vboot_api_kernel2_tests.c @@ -28,7 +28,6 @@ static VbCommonParams cparams; static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; -static GoogleBinaryBlockHeader gbb; static LoadKernelParams lkp; static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]; static struct vb2_context ctx; @@ -59,13 +58,6 @@ extern struct RollbackSpaceFwmp *VbApiKernelGetFwmp(void); static void ResetMocks(void) { memset(&cparams, 0, sizeof(cparams)); - cparams.gbb_data = &gbb; - cparams.gbb = &gbb; - - memset(&gbb, 0, sizeof(gbb)); - gbb.major_version = GBB_MAJOR_VER; - gbb.minor_version = GBB_MINOR_VER; - gbb.flags = 0; memset(VbApiKernelGetFwmp(), 0, sizeof(struct RollbackSpaceFwmp)); @@ -212,48 +204,48 @@ static void VbUserConfirmsTest(void) ResetMocks(); shutdown_request_calls_left = 1; - TEST_EQ(VbUserConfirms(&ctx, &cparams, 0), -1, "Shutdown requested"); + TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Shutdown requested"); ResetMocks(); mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; - TEST_EQ(VbUserConfirms(&ctx, &cparams, 0), -1, "Shutdown requested"); + TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Shutdown requested"); ResetMocks(); mock_keypress[0] = '\r'; - TEST_EQ(VbUserConfirms(&ctx, &cparams, 0), 1, "Enter"); + TEST_EQ(VbUserConfirms(&ctx, 0), 1, "Enter"); ResetMocks(); mock_keypress[0] = 0x1b; - TEST_EQ(VbUserConfirms(&ctx, &cparams, 0), 0, "Esc"); + TEST_EQ(VbUserConfirms(&ctx, 0), 0, "Esc"); ResetMocks(); mock_keypress[0] = ' '; shutdown_request_calls_left = 1; - TEST_EQ(VbUserConfirms(&ctx, &cparams, VB_CONFIRM_SPACE_MEANS_NO), 0, + TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_SPACE_MEANS_NO), 0, "Space means no"); ResetMocks(); mock_keypress[0] = ' '; shutdown_request_calls_left = 1; - TEST_EQ(VbUserConfirms(&ctx, &cparams, 0), -1, "Space ignored"); + TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Space ignored"); ResetMocks(); mock_keypress[0] = '\r'; mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD; - TEST_EQ(VbUserConfirms(&ctx, &cparams, VB_CONFIRM_MUST_TRUST_KEYBOARD), + TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_MUST_TRUST_KEYBOARD), 1, "Enter with trusted keyboard"); ResetMocks(); mock_keypress[0] = '\r'; /* untrusted */ mock_keypress[1] = ' '; - TEST_EQ(VbUserConfirms(&ctx, &cparams, + TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_SPACE_MEANS_NO | VB_CONFIRM_MUST_TRUST_KEYBOARD), 0, "Untrusted keyboard"); ResetMocks(); mock_switches[0] = VB_INIT_FLAG_REC_BUTTON_PRESSED; - TEST_EQ(VbUserConfirms(&ctx, &cparams, + TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_SPACE_MEANS_NO | VB_CONFIRM_MUST_TRUST_KEYBOARD), 1, "Recovery button"); @@ -265,7 +257,7 @@ static void VbUserConfirmsTest(void) mock_keypress[3] = ' '; mock_switches[0] = VB_INIT_FLAG_REC_BUTTON_PRESSED; mock_switches_are_stuck = 1; - TEST_EQ(VbUserConfirms(&ctx, &cparams, + TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_SPACE_MEANS_NO | VB_CONFIRM_MUST_TRUST_KEYBOARD), 0, "Recovery button stuck"); diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c index fc54eb7acb..a831e7f537 100644 --- a/tests/vboot_api_kernel5_tests.c +++ b/tests/vboot_api_kernel5_tests.c @@ -34,7 +34,8 @@ static VbCommonParams cparams; static VbSelectAndLoadKernelParams kparams; static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; -static GoogleBinaryBlockHeader gbb; +static uint8_t gbb_buf[4096]; +static GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader *)gbb_buf; static uint8_t kernel_buffer[80000]; static int key_block_verify_fail; /* 0=ok, 1=sig, 2=hash */ @@ -55,15 +56,17 @@ static void ResetMocks(void) memset(&cparams, 0, sizeof(cparams)); cparams.shared_data_size = sizeof(shared_data); cparams.shared_data_blob = shared_data; - cparams.gbb_data = &gbb; - cparams.gbb_size = sizeof(gbb); + cparams.gbb_data = gbb_buf; + cparams.gbb_size = sizeof(gbb_buf); memset(&kparams, 0, sizeof(kparams)); - memset(&gbb, 0, sizeof(gbb)); - gbb.major_version = GBB_MAJOR_VER; - gbb.minor_version = GBB_MINOR_VER; - gbb.flags = 0; + memset(gbb_buf, 0, sizeof(gbb_buf)); + gbb->major_version = GBB_MAJOR_VER; + gbb->minor_version = GBB_MINOR_VER; + gbb->flags = 0; + gbb->rootkey_offset = sizeof(*gbb); + gbb->rootkey_size = sizeof(VbPublicKey); memset(&ctx, 0, sizeof(ctx)); ctx.workbuf = workbuf; @@ -223,7 +226,7 @@ static void VerifyMemoryBootImageTest(void) /* Key Block Hash Failure */ ResetMocks(); shared->flags = VBSD_BOOT_DEV_SWITCH_ON; - gbb.flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; + gbb->flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; key_block_verify_fail = 1; TEST_EQ(VbVerifyMemoryBootImage(&cparams, &kparams, kernel_buffer, kernel_buffer_size), @@ -256,7 +259,7 @@ static void VerifyMemoryBootImageTest(void) kbh.key_block_flags = KEY_BLOCK_FLAG_DEVELOPER_0 | KEY_BLOCK_FLAG_RECOVERY_1; copy_kbh(); - gbb.flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; + gbb->flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; shared->flags = VBSD_BOOT_DEV_SWITCH_ON; TEST_EQ(VbVerifyMemoryBootImage(&cparams, &kparams, kernel_buffer, kernel_buffer_size), @@ -269,7 +272,7 @@ static void VerifyMemoryBootImageTest(void) KEY_BLOCK_FLAG_RECOVERY_0; copy_kbh(); shared->flags = VBSD_BOOT_DEV_SWITCH_ON; - gbb.flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; + gbb->flags = GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP; TEST_EQ(VbVerifyMemoryBootImage(&cparams, &kparams, kernel_buffer, kernel_buffer_size), VBERROR_SUCCESS, diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c index 0e3cc3b0ee..db04f6ba37 100644 --- a/tests/vboot_detach_menu_tests.c +++ b/tests/vboot_detach_menu_tests.c @@ -30,7 +30,6 @@ static VbCommonParams cparams; static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; -static GoogleBinaryBlockHeader gbb; static LoadKernelParams lkp; static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]; static struct vb2_context ctx; @@ -61,13 +60,6 @@ extern struct RollbackSpaceFwmp *VbApiKernelGetFwmp(void); static void ResetMocks(void) { memset(&cparams, 0, sizeof(cparams)); - cparams.gbb_data = &gbb; - cparams.gbb = &gbb; - - memset(&gbb, 0, sizeof(gbb)); - gbb.major_version = GBB_MAJOR_VER; - gbb.minor_version = GBB_MINOR_VER; - gbb.flags = 0; memset(VbApiKernelGetFwmp(), 0, sizeof(struct RollbackSpaceFwmp)); diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c index 7ddc28e942..a6d2b9f404 100644 --- a/tests/vboot_display_tests.c +++ b/tests/vboot_display_tests.c @@ -15,9 +15,9 @@ #include "2misc.h" #include "2nvstorage.h" #include "bmpblk_font.h" +#include "gbb_access.h" #include "gbb_header.h" #include "host_common.h" -#include "region.h" #include "test_common.h" #include "vboot_common.h" #include "vboot_display.h" @@ -31,6 +31,7 @@ static char gbb_data[4096 + sizeof(GoogleBinaryBlockHeader)]; static GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader *)gbb_data; static char debug_info[4096]; static struct vb2_context ctx; +struct vb2_shared_data *sd; static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]; static uint32_t mock_localization_count; @@ -55,12 +56,6 @@ static void ResetMocks(void) memset(&cparams, 0, sizeof(cparams)); cparams.gbb_data = gbb; cparams.gbb_size = sizeof(gbb_data); - - /* - * Note, VbApiKernelFree() expects this to be allocated by - * malloc(), so we cannot just assign it staticly. - */ - cparams.gbb = malloc(sizeof(*gbb)); gbb->header_size = sizeof(*gbb); gbb->rootkey_offset = gbb_used; gbb->rootkey_size = 64; @@ -68,7 +63,6 @@ static void ResetMocks(void) gbb->recovery_key_offset = gbb_used; gbb->recovery_key_size = 64; gbb_used += 64; - memcpy(cparams.gbb, gbb, sizeof(*gbb)); memset(&ctx, 0, sizeof(ctx)); ctx.workbuf = workbuf; @@ -76,8 +70,10 @@ static void ResetMocks(void) vb2_init_context(&ctx); vb2_nv_init(&ctx); - struct vb2_shared_data *sd = vb2_get_sd(&ctx); + sd = vb2_get_sd(&ctx); sd->vbsd = shared; + sd->gbb = (struct vb2_gbb_header *)gbb_data; + sd->gbb_size = sizeof(gbb_data); memset(&shared_data, 0, sizeof(shared_data)); VbSharedDataInit(shared, sizeof(shared_data)); @@ -106,7 +102,7 @@ VbError_t VbExDisplayDebugInfo(const char *info_str) /* Test displaying debug info */ static void DebugInfoTest(void) { - char hwid[VB_REGION_HWID_LEN]; + char hwid[256]; int i; /* Recovery string should be non-null for any code */ @@ -115,82 +111,72 @@ static void DebugInfoTest(void) /* HWID should come from the gbb */ ResetMocks(); - VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); + VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "Test HWID"), 0, "HWID"); - VbApiKernelFree(&cparams); ResetMocks(); - cparams.gbb_size = 0; - VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); + sd->gbb_size = 0; + VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID bad gbb"); - VbApiKernelFree(&cparams); ResetMocks(); - cparams.gbb->hwid_size = 0; - VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); + sd->gbb->hwid_size = 0; + VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID missing"); - VbApiKernelFree(&cparams); ResetMocks(); - cparams.gbb->hwid_offset = cparams.gbb_size + 1; - VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); + sd->gbb->hwid_offset = sd->gbb_size + 1; + VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID past end"); - VbApiKernelFree(&cparams); ResetMocks(); - cparams.gbb->hwid_size = cparams.gbb_size; - VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); + sd->gbb->hwid_size = sd->gbb_size; + VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID overflow"); - VbApiKernelFree(&cparams); /* Display debug info */ ResetMocks(); - VbDisplayDebugInfo(&ctx, &cparams); + VbDisplayDebugInfo(&ctx); TEST_NEQ(*debug_info, '\0', "Some debug info was displayed"); - VbApiKernelFree(&cparams); } /* Test display key checking */ static void DisplayKeyTest(void) { ResetMocks(); - VbCheckDisplayKey(&ctx, &cparams, 'q'); + VbCheckDisplayKey(&ctx, 'q'); TEST_EQ(*debug_info, '\0', "DisplayKey q = does nothing"); - VbApiKernelFree(&cparams); ResetMocks(); - VbCheckDisplayKey(&ctx, &cparams, '\t'); + VbCheckDisplayKey(&ctx, '\t'); TEST_NEQ(*debug_info, '\0', "DisplayKey tab = display"); - VbApiKernelFree(&cparams); /* Toggle localization */ ResetMocks(); vb2_nv_set(&ctx, VB2_NV_LOCALIZATION_INDEX, 0); - VbCheckDisplayKey(&ctx, &cparams, VB_KEY_DOWN); + VbCheckDisplayKey(&ctx, VB_KEY_DOWN); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 2, "DisplayKey up"); - VbCheckDisplayKey(&ctx, &cparams, VB_KEY_LEFT); + VbCheckDisplayKey(&ctx, VB_KEY_LEFT); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 1, "DisplayKey left"); - VbCheckDisplayKey(&ctx, &cparams, VB_KEY_RIGHT); + VbCheckDisplayKey(&ctx, VB_KEY_RIGHT); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 2, "DisplayKey right"); - VbCheckDisplayKey(&ctx, &cparams, VB_KEY_UP); + VbCheckDisplayKey(&ctx, VB_KEY_UP); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 0, "DisplayKey up"); - VbApiKernelFree(&cparams); /* Reset localization if localization count is invalid */ ResetMocks(); vb2_nv_set(&ctx, VB2_NV_LOCALIZATION_INDEX, 1); mock_localization_count = 0xffffffff; - VbCheckDisplayKey(&ctx, &cparams, VB_KEY_UP); + VbCheckDisplayKey(&ctx, VB_KEY_UP); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 0, "DisplayKey invalid"); - VbApiKernelFree(&cparams); } int main(void) diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c index a5919780bc..c6798d2ce0 100644 --- a/tests/vboot_kernel_tests.c +++ b/tests/vboot_kernel_tests.c @@ -146,9 +146,6 @@ static void ResetMocks(void) shared->kernel_version_tpm = 0x20001; memset(&cparams, '\0', sizeof(cparams)); - cparams.gbb = gbb; - cparams.gbb_data = gbb; - cparams.gbb_size = sizeof(gbb_data); memset(&lkp, 0, sizeof(lkp)); lkp.bytes_per_lba = 512; @@ -185,6 +182,8 @@ static void ResetMocks(void) struct vb2_shared_data *sd = vb2_get_sd(&ctx); sd->vbsd = shared; + sd->gbb = (struct vb2_gbb_header *)gbb_data; + sd->gbb_size = sizeof(gbb_data); // TODO: more workbuf fields - flags, secdata, secdatak } diff --git a/tests/vboot_region_tests.c b/tests/vboot_region_tests.c deleted file mode 100644 index a08daedefd..0000000000 --- a/tests/vboot_region_tests.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (c) 2011 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. - * - * Tests for vboot region API - */ - -#include -#include -#include -#include - -#include "bmpblk_font.h" -#include "gbb_header.h" -#include "host_common.h" -#include "rollback_index.h" -#include "test_common.h" -#include "vboot_common.h" -#include "vboot_struct.h" - -typedef struct VbNvContext VbNvContext; - -/* Mock data */ -static VbCommonParams cparams; -static VbSelectFirmwareParams fparams; -VbSelectAndLoadKernelParams kparams; -static char gbb_data[4096 + sizeof(GoogleBinaryBlockHeader)]; -static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; -static VbSharedDataHeader* shared = (VbSharedDataHeader*)shared_data; -/* Mock TPM versions */ -static uint32_t mock_tpm_version; -static uint32_t mock_lf_tpm_version; /* TPM version set by LoadFirmware() */ -static uint32_t mock_seen_region; -/* Mock return values, so we can simulate errors */ -static VbError_t mock_lf_retval; - -#define COMPRESSED_SIZE 200 -#define ORIGINAL_SIZE 400 - -/* Reset mock data (for use before each test) */ -static void ResetMocks(void) { - GoogleBinaryBlockHeader *gbb; - BmpBlockHeader *bhdr; - ImageInfo *image_info; - ScreenLayout *layout; - int gbb_used; - - memset(&cparams, 0, sizeof(cparams)); - cparams.shared_data_size = sizeof(shared_data); - cparams.shared_data_blob = shared_data; - - memset(&fparams, 0, sizeof(fparams)); - - memset(gbb_data, 0, sizeof(gbb_data)); - gbb = (GoogleBinaryBlockHeader *)gbb_data; - gbb->major_version = GBB_MAJOR_VER; - gbb->minor_version = GBB_MINOR_VER; - gbb->flags = 0; - gbb_used = sizeof(GoogleBinaryBlockHeader); - - gbb->hwid_offset = gbb_used; - strcpy(gbb_data + gbb->hwid_offset, "Test HWID"); - gbb->hwid_size = strlen(gbb_data + gbb->hwid_offset) + 1; - gbb_used = (gbb_used + gbb->hwid_size + 7) & ~7; - - gbb->bmpfv_offset = gbb_used; - bhdr = (BmpBlockHeader *)(gbb_data + gbb->bmpfv_offset); - gbb->bmpfv_size = sizeof(BmpBlockHeader); - gbb_used = (gbb_used + gbb->bmpfv_size + 7) & ~7; - memcpy(bhdr->signature, BMPBLOCK_SIGNATURE, BMPBLOCK_SIGNATURE_SIZE); - bhdr->major_version = BMPBLOCK_MAJOR_VERSION; - bhdr->minor_version = BMPBLOCK_MINOR_VERSION; - bhdr->number_of_localizations = 3; - bhdr->number_of_screenlayouts = 1; - - layout = (ScreenLayout *)(gbb_data + gbb_used); - gbb_used += sizeof(*layout); - layout->images[0].x = 1; - layout->images[0].image_info_offset = gbb_used - gbb->bmpfv_offset; - - /* First image is uncompressed */ - image_info = (ImageInfo *)(gbb_data + gbb_used); - image_info->format = FORMAT_BMP; - image_info->compressed_size = ORIGINAL_SIZE; - image_info->original_size = ORIGINAL_SIZE; - image_info->compression = COMPRESS_NONE; - gbb_used += sizeof(*image_info); - strcpy(gbb_data + gbb_used, "original"); - gbb_used += ORIGINAL_SIZE; - - /* Second image is compressed */ - layout->images[1].image_info_offset = gbb_used - gbb->bmpfv_offset; - layout->images[1].x = 2; - image_info = (ImageInfo *)(gbb_data + gbb_used); - image_info->format = FORMAT_BMP; - image_info->compressed_size = COMPRESSED_SIZE; - image_info->original_size = ORIGINAL_SIZE; - image_info->compression = COMPRESS_LZMA1; - gbb_used += sizeof(*image_info) + COMPRESSED_SIZE; - - memset(&shared_data, 0, sizeof(shared_data)); - VbSharedDataInit(shared, sizeof(shared_data)); - shared->fw_keyblock_flags = 0xABCDE0; - - mock_tpm_version = mock_lf_tpm_version = 0x20004; - shared->fw_version_tpm_start = mock_tpm_version; - mock_lf_retval = 0; - mock_seen_region = 0; -} - -/****************************************************************************/ -/* Mocked verification functions */ - -VbError_t VbExNvStorageRead(uint8_t* buf) { - return VBERROR_SUCCESS; -} - -VbError_t VbExNvStorageWrite(const uint8_t* buf) { - return VBERROR_SUCCESS; -} - -VbError_t VbExRegionRead(VbCommonParams *cparams, - enum vb_firmware_region region, uint32_t offset, - uint32_t size, void *buf) -{ - if (region != VB_REGION_GBB) - return VBERROR_UNSUPPORTED_REGION; - mock_seen_region |= 1 << region; - if (offset + size > sizeof(gbb_data)) - return VBERROR_REGION_READ_INVALID; - memcpy(buf, gbb_data + offset, size); - return VBERROR_SUCCESS; -} - -VbError_t VbExDisplayImage(uint32_t x, uint32_t y, - void *buffer, uint32_t buffersize) -{ - switch (x) { - case 1: - TEST_STR_EQ(buffer, "original", " uncompressed image"); - break; - case 2: - TEST_STR_EQ(buffer, "decompressed", " compressed image"); - break; - default: - TEST_STR_EQ(buffer, "invalid", " correct image"); - break; - } - return VBERROR_SUCCESS; -} - -VbError_t VbExDecompress(void *inbuf, uint32_t in_size, - uint32_t compression_type, - void *outbuf, uint32_t *out_size) -{ - *out_size = ORIGINAL_SIZE; - strcpy(outbuf, "decompressed"); - return VBERROR_SUCCESS; -} - -int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams, - VbNvContext *vnc) { - shared->fw_version_tpm = mock_lf_tpm_version; - TEST_PTR_NEQ(cparams->gbb, NULL, " GBB allocated"); - return mock_lf_retval; -} - -/****************************************************************************/ - -static void VbRegionReadTest(void) { - /* Should read GBB */ - ResetMocks(); - TEST_TRUE(1, "Normal call"); - TEST_EQ(VbSelectFirmware(&cparams, &fparams), VBERROR_SUCCESS, - " Success"); - TEST_EQ(mock_seen_region, 1 << VB_REGION_GBB, " GBB region"); - TEST_PTR_EQ(cparams.gbb, NULL, " GBB free"); - - ResetMocks(); - TEST_EQ(VbSelectAndLoadKernel(&cparams, &kparams), - VBERROR_NO_DISK_FOUND, "Kernel"); - TEST_PTR_EQ(cparams.gbb, NULL, " GBB free"); - TEST_PTR_EQ(cparams.bmp, NULL, " BMP free"); - - ResetMocks(); - shared->flags |= VBSD_BOOT_DEV_SWITCH_ON; - TEST_EQ(VbSelectAndLoadKernel(&cparams, &kparams), - VBERROR_NO_DISK_FOUND, "Kernel"); -} - -int main(int argc, char* argv[]) -{ - VbRegionReadTest(); - - return gTestSuccess ? 0 : 255; -} diff --git a/utility/load_kernel_test.c b/utility/load_kernel_test.c index 481e78ce4b..da1667b8da 100644 --- a/utility/load_kernel_test.c +++ b/utility/load_kernel_test.c @@ -163,7 +163,7 @@ int main(int argc, char* argv[]) { /* Initialize the GBB */ cparams.gbb_size = sizeof(GoogleBinaryBlockHeader) + key_size; - cparams.gbb = gbb = (GoogleBinaryBlockHeader*)malloc(cparams.gbb_size); + cparams.gbb_data = gbb = (GoogleBinaryBlockHeader*)malloc(cparams.gbb_size); memset(gbb, 0, cparams.gbb_size); memcpy(gbb->signature, GBB_SIGNATURE, GBB_SIGNATURE_SIZE); gbb->major_version = GBB_MAJOR_VER;