summaryrefslogtreecommitdiff
path: root/firmware/lib
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/lib')
-rw-r--r--firmware/lib/region-init.c91
-rw-r--r--firmware/lib/vboot_api_kernel.c17
-rw-r--r--firmware/lib/vboot_display.c59
-rw-r--r--firmware/lib/vboot_kernel.c20
-rw-r--r--firmware/lib/vboot_ui.c1
-rw-r--r--firmware/lib/vboot_ui_menu.c1
6 files changed, 54 insertions, 135 deletions
diff --git a/firmware/lib/region-init.c b/firmware/lib/region-init.c
deleted file mode 100644
index 9e3c2bc3..00000000
--- a/firmware/lib/region-init.c
+++ /dev/null
@@ -1,91 +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 "2misc.h"
-
-#include "sysincludes.h"
-#include "gbb_access.h"
-#include "load_kernel_fw.h"
-#include "utility.h"
-#include "vboot_api.h"
-#include "vboot_struct.h"
-
-static VbError_t VbGbbReadData(struct vb2_context *ctx,
- uint32_t offset, uint32_t size, void *buf)
-{
- if (vb2ex_read_resource(ctx, VB2_RES_GBB, offset, buf, size))
- return VBERROR_INVALID_GBB;
- return VBERROR_SUCCESS;
-}
-
-VbError_t VbGbbReadHWID(struct vb2_context *ctx, char *hwid, uint32_t max_size)
-{
- struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
-
- if (!max_size)
- return VBERROR_INVALID_PARAMETER;
- *hwid = '\0';
- StrnAppend(hwid, "{INVALID}", max_size);
- if (!ctx)
- return VBERROR_INVALID_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;
- }
-
- return VbGbbReadData(ctx, gbb->hwid_offset,
- 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_gbb_header *gbb = vb2_get_gbb(ctx);
-
- return VbGbbReadKey(ctx, gbb->rootkey_offset, keyp);
-}
-
-VbError_t VbGbbReadRecoveryKey(struct vb2_context *ctx, VbPublicKey **keyp)
-{
- struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
-
- return VbGbbReadKey(ctx, gbb->recovery_key_offset, keyp);
-}
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 35f33813..bde6f82e 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -13,7 +13,6 @@
#include "2nvstorage.h"
#include "2rsa.h"
#include "ec_sync.h"
-#include "gbb_access.h"
#include "load_kernel_fw.h"
#include "rollback_index.h"
#include "utility.h"
@@ -463,7 +462,7 @@ VbError_t VbVerifyMemoryBootImage(
VbSelectAndLoadKernelParams *kparams, void *boot_image,
size_t image_size)
{
- VbPublicKey* kernel_subkey = NULL;
+ struct vb2_packed_key *kernel_subkey = NULL;
uint8_t *kbuf;
VbKeyBlockHeader *key_block;
VbKernelPreambleHeader *preamble;
@@ -473,6 +472,9 @@ VbError_t VbVerifyMemoryBootImage(
uint32_t allow_fastboot_full_cap = 0;
struct vb2_workbuf wb;
+ /* Allocate work buffer */
+ vb2_workbuf_from_ctx(ctx, &wb);
+
VbError_t retval = vb2_kernel_setup(ctx, shared, kparams);
if (retval)
goto fail;
@@ -508,7 +510,8 @@ VbError_t VbVerifyMemoryBootImage(
hash_only = 1;
} else {
/* Get recovery key. */
- retval = VbGbbReadRecoveryKey(ctx, &kernel_subkey);
+ retval = vb2_gbb_read_recovery_key(ctx, &kernel_subkey,
+ NULL, &wb);
if (VBERROR_SUCCESS != retval) {
VB2_DEBUG("Gbb Read Recovery key failed.\n");
goto fail;
@@ -518,9 +521,6 @@ VbError_t VbVerifyMemoryBootImage(
/* If we fail at any step, retval returned would be invalid kernel. */
retval = VBERROR_INVALID_KERNEL_FOUND;
- /* Allocate work buffer */
- vb2_workbuf_from_ctx(ctx, &wb);
-
/* Verify the key block. */
key_block = (VbKeyBlockHeader *)kbuf;
struct vb2_keyblock *keyblock2 = (struct vb2_keyblock *)kbuf;
@@ -531,8 +531,7 @@ VbError_t VbVerifyMemoryBootImage(
/* Unpack kernel subkey */
struct vb2_public_key kernel_subkey2;
if (VB2_SUCCESS !=
- vb2_unpack_key(&kernel_subkey2,
- (struct vb2_packed_key *)kernel_subkey)) {
+ vb2_unpack_key(&kernel_subkey2, kernel_subkey)) {
VB2_DEBUG("Unable to unpack kernel subkey\n");
goto fail;
}
@@ -609,8 +608,6 @@ VbError_t VbVerifyMemoryBootImage(
fail:
vb2_kernel_cleanup(ctx);
- if (NULL != kernel_subkey)
- free(kernel_subkey);
return retval;
}
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index 1f80a651..6ef692f7 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -12,7 +12,6 @@
#include "2misc.h"
#include "2nvstorage.h"
#include "2sha.h"
-#include "gbb_access.h"
#include "utility.h"
#include "vboot_api.h"
#include "vboot_common.h"
@@ -274,19 +273,27 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
+ struct vb2_workbuf wb;
VbSharedDataHeader *shared = sd->vbsd;
char buf[DEBUG_INFO_SIZE] = "";
char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
- char hwid[256];
uint32_t used = 0;
- VbPublicKey *key;
- VbError_t ret;
+ int ret;
uint32_t i;
+ vb2_workbuf_from_ctx(ctx, &wb);
+
/* Add hardware ID */
- VbGbbReadHWID(ctx, hwid, sizeof(hwid));
- used += StrnAppend(buf + used, "HWID: ", DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used);
+ {
+ char hwid[VB2_GBB_HWID_MAX_SIZE];
+ uint32_t size = sizeof(hwid);
+ ret = vb2api_gbb_read_hwid(ctx, hwid, &size);
+ if (ret)
+ strcpy(hwid, "{INVALID}");
+ used += StrnAppend(buf + used, "HWID: ",
+ DEBUG_INFO_SIZE - used);
+ used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used);
+ }
/* Add recovery reason and subcode */
i = vb2_nv_get(ctx, VB2_NV_RECOVERY_SUBCODE);
@@ -359,24 +366,30 @@ VbError_t VbDisplayDebugInfo(struct vb2_context *ctx)
gbb->flags, 16, 8);
/* Add sha1sum for Root & Recovery keys */
- ret = VbGbbReadRootKey(ctx, &key);
- if (!ret) {
- FillInSha1Sum(sha1sum, key);
- free(key);
- used += StrnAppend(buf + used, "\ngbb.rootkey: ",
- DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum,
- DEBUG_INFO_SIZE - used);
+ {
+ struct vb2_packed_key *key;
+ struct vb2_workbuf wblocal = wb;
+ ret = vb2_gbb_read_root_key(ctx, &key, NULL, &wblocal);
+ if (!ret) {
+ FillInSha1Sum(sha1sum, (VbPublicKey *)key);
+ used += StrnAppend(buf + used, "\ngbb.rootkey: ",
+ DEBUG_INFO_SIZE - used);
+ used += StrnAppend(buf + used, sha1sum,
+ DEBUG_INFO_SIZE - used);
+ }
}
- ret = VbGbbReadRecoveryKey(ctx, &key);
- if (!ret) {
- FillInSha1Sum(sha1sum, key);
- free(key);
- used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
- DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum,
- DEBUG_INFO_SIZE - used);
+ {
+ struct vb2_packed_key *key;
+ struct vb2_workbuf wblocal = wb;
+ ret = vb2_gbb_read_recovery_key(ctx, &key, NULL, &wblocal);
+ if (!ret) {
+ FillInSha1Sum(sha1sum, (VbPublicKey *)key);
+ used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
+ DEBUG_INFO_SIZE - used);
+ used += StrnAppend(buf + used, sha1sum,
+ DEBUG_INFO_SIZE - used);
+ }
}
/* If we're in dev-mode, show the kernel subkey that we expect, too. */
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 7195bdb0..741890e4 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 "gbb_access.h"
#include "gpt_misc.h"
#include "load_kernel_fw.h"
#include "rollback_index.h"
@@ -309,6 +308,7 @@ enum vb2_load_partition_flags {
* @param params Load-kernel parameters
* @param min_version Minimum kernel version from TPM
* @param shpart Destination for verification results
+ * @param wb Workbuf for data storage
* @return VB2_SUCCESS, or non-zero error code.
*/
static int vb2_load_partition(struct vb2_context *ctx,
@@ -317,10 +317,10 @@ static int vb2_load_partition(struct vb2_context *ctx,
uint32_t flags,
LoadKernelParams *params,
uint32_t min_version,
- VbSharedDataKernelPart *shpart)
+ VbSharedDataKernelPart *shpart,
+ struct vb2_workbuf *wb)
{
- struct vb2_workbuf wblocal;
- vb2_workbuf_from_ctx(ctx, &wblocal);
+ struct vb2_workbuf wblocal = *wb;
/* Allocate kernel header buffer in workbuf */
uint8_t *kbuf = vb2_workbuf_alloc(&wblocal, KBUF_SIZE);
@@ -429,6 +429,7 @@ static int vb2_load_partition(struct vb2_context *ctx,
VbError_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
+ struct vb2_workbuf wb;
VbSharedDataHeader *shared = sd->vbsd;
VbSharedDataKernelCall *shcall = NULL;
struct vb2_packed_key *recovery_key = NULL;
@@ -438,6 +439,8 @@ VbError_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params)
VbError_t retval = VBERROR_UNKNOWN;
int recovery = VB2_RECOVERY_LK_UNSPECIFIED;
+ vb2_workbuf_from_ctx(ctx, &wb);
+
/* Clear output params in case we fail */
params->partition_number = 0;
params->bootloader_address = 0;
@@ -461,8 +464,8 @@ 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(ctx,
- (VbPublicKey **)&recovery_key);
+ retval = vb2_gbb_read_recovery_key(ctx, &recovery_key,
+ NULL, &wb);
if (VBERROR_SUCCESS != retval)
goto load_kernel_exit;
kernel_subkey = recovery_key;
@@ -547,7 +550,8 @@ VbError_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params)
lpflags,
params,
shared->kernel_version_tpm,
- shpart);
+ shpart,
+ &wb);
VbExStreamClose(stream);
if (rv != VB2_SUCCESS) {
@@ -656,8 +660,6 @@ load_kernel_exit:
VBERROR_SUCCESS != retval ?
recovery : VB2_RECOVERY_NOT_REQUESTED);
- free(recovery_key);
-
shcall->return_code = (uint8_t)retval;
return retval;
}
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 7fc7a307..8a990047 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -13,7 +13,6 @@
#include "2nvstorage.h"
#include "2rsa.h"
#include "ec_sync.h"
-#include "gbb_access.h"
#include "load_kernel_fw.h"
#include "rollback_index.h"
#include "tlcl.h"
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index 3fdf77cb..c3268d1e 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -11,7 +11,6 @@
#include "2nvstorage.h"
#include "2rsa.h"
#include "ec_sync.h"
-#include "gbb_access.h"
#include "load_kernel_fw.h"
#include "rollback_index.h"
#include "utility.h"