summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/lib/vboot_api_kernel.c41
-rw-r--r--tests/vboot_api_kernel4_tests.c7
-rw-r--r--tests/vboot_api_kernel5_tests.c7
3 files changed, 16 insertions, 39 deletions
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index c08ca131..11a16595 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -26,7 +26,6 @@
/* Global variables */
static struct RollbackSpaceFwmp fwmp;
static LoadKernelParams lkp;
-static uint8_t *unaligned_workbuf;
#ifdef CHROMEOS_ENVIRONMENT
/* Global variable accessors for unit tests */
@@ -224,6 +223,12 @@ static VbError_t vb2_kernel_setup(struct vb2_context *ctx,
VbCommonParams *cparams,
VbSelectAndLoadKernelParams *kparams)
{
+ if (VB2_SUCCESS != vb2_init_context(ctx)) {
+ VB2_DEBUG("Can't init vb2_context\n");
+ VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
+ return VBERROR_INIT_SHARED_DATA;
+ }
+
VbSharedDataHeader *shared =
(VbSharedDataHeader *)cparams->shared_data_blob;
@@ -255,31 +260,6 @@ static VbError_t vb2_kernel_setup(struct vb2_context *ctx,
VbExNvStorageRead(ctx->nvdata);
vb2_nv_init(ctx);
- ctx->workbuf_size = VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE +
- VB2_WORKBUF_ALIGN;
-
- unaligned_workbuf = ctx->workbuf = malloc(ctx->workbuf_size);
- if (!unaligned_workbuf) {
- VB2_DEBUG("Can't allocate work buffer\n");
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
- if (VB2_SUCCESS != vb2_align(&ctx->workbuf, &ctx->workbuf_size,
- VB2_WORKBUF_ALIGN,
- VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE)) {
- VB2_DEBUG("Can't align work buffer\n");
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
- if (VB2_SUCCESS != vb2_init_context(ctx)) {
- VB2_DEBUG("Can't init vb2_context\n");
- free(unaligned_workbuf);
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
struct vb2_shared_data *sd = vb2_get_sd(ctx);
sd->recovery_reason = shared->recovery_reason;
@@ -381,15 +361,6 @@ static void vb2_kernel_cleanup(struct vb2_context *ctx, VbCommonParams *cparams)
VbSharedDataHeader *shared =
(VbSharedDataHeader *)cparams->shared_data_blob;
- /*
- * Clean up vboot context.
- *
- * TODO: This should propagate up to higher levels
- */
-
- /* Free buffers */
- free(unaligned_workbuf);
-
vb2_nv_commit(ctx);
/* Stop timer */
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index ab9d557f..cb2179d5 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -25,6 +25,7 @@
#include "vboot_struct.h"
/* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
static struct vb2_context ctx_nvram_backend;
static VbCommonParams cparams;
@@ -59,9 +60,11 @@ static void ResetMocks(void)
gbb.minor_version = GBB_MINOR_VER;
gbb.flags = 0;
- /* ctx.workbuf will be allocated and initialized by
- * VbSelectAndLoadKernel. */
+ /* ctx.workbuf will be initialized by VbSelectAndLoadKernel. */
memset(&ctx, 0, sizeof(ctx));
+ ctx.workbuf = workbuf;
+ ctx.workbuf_size = sizeof(workbuf);
+ vb2_init_context(&ctx);
/*
* ctx_nvram_backend is only used as an NVRAM backend (see
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index 65899aec..8d3281be 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -27,6 +27,7 @@
#include "vboot_struct.h"
/* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
static struct vb2_context ctx_nvram_backend;
static VbCommonParams cparams;
@@ -67,9 +68,11 @@ static void ResetMocks(void)
gbb->rootkey_offset = sizeof(*gbb);
gbb->rootkey_size = sizeof(VbPublicKey);
- /* ctx.workbuf will be allocated and initialized by
- * VbVerifyMemoryBootImage. */
+ /* ctx.workbuf will be initialized by VbVerifyMemoryBootImage. */
memset(&ctx, 0, sizeof(ctx));
+ ctx.workbuf = workbuf;
+ ctx.workbuf_size = sizeof(workbuf);
+ vb2_init_context(&ctx);
/*
* ctx_nvram_backend is only used as an NVRAM backend (see