firmware: Include vb1 shared data in vb2 struct

Currently, firmware verification uses entirely vb2 structs, including
vb2_shared_data.  This goes through an ugly translation to the old vb1
VbSharedData to pass it to depthcharge.  The vboot kernel verification
maintains an equally ugly translation back to the vb2 struct
internally.

Eventually, we want to get rid of all that and use vb2 all the way
down to what crossystem picks up from the OS.

But before we can do that, we need to finish translating kernel
verification code to use the new vb2 structs.  This is a step on that
path, using vb2_shared_data equivalents where present and hiding the
old vb1 shared data struct as a member of vb2_shared_data so at least
the vboot functions don't need to pass around cparams to get at it.

This will be followed by more CLs which convert more vboot internals
to use vb2 structs directly, and eventually coreboot/depthcharge CLs
which pass the vb2 structs from firmware verification directly to
kernel verification.

No change in functionality.

BUG=chromium:611535
BRANCH=none
TEST=make -j runtests; build bob firmware and boot it

Change-Id: I5df8ce81ba3c3ac3f2cb4229db5461757cd89d8d
Reviewed-on: https://chromium-review.googlesource.com/852856
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
diff --git a/firmware/2lib/include/2struct.h b/firmware/2lib/include/2struct.h
index 9ae1f54..589e7c9 100644
--- a/firmware/2lib/include/2struct.h
+++ b/firmware/2lib/include/2struct.h
@@ -195,6 +195,12 @@
 	 */
 
 	/*
+	 * Vboot1 shared data header.  This data should eventually get folded
+	 * directly into the kernel portion of this struct.
+	 */
+	struct VbSharedDataHeader *vbsd;
+
+	/*
 	 * Offset and size of packed kernel key in work buffer.  Size is 0 if
 	 * subkey is not stored in the work buffer.  Note that kernel key may
 	 * be inside the firmware preamble.
diff --git a/firmware/lib/ec_sync_all.c b/firmware/lib/ec_sync_all.c
index 9d23629..68e0a9a 100644
--- a/firmware/lib/ec_sync_all.c
+++ b/firmware/lib/ec_sync_all.c
@@ -17,10 +17,10 @@
 #include "vboot_display.h"
 #include "vboot_kernel.h"
 
-VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
+VbError_t ec_sync_all(struct vb2_context *ctx)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	VbAuxFwUpdateSeverity_t fw_update;
 	VbError_t rv;
 
diff --git a/firmware/lib/include/ec_sync.h b/firmware/lib/include/ec_sync.h
index f95b500..573c94c 100644
--- a/firmware/lib/include/ec_sync.h
+++ b/firmware/lib/include/ec_sync.h
@@ -80,9 +80,8 @@
  * This is a high-level function which calls the functions above.
  *
  * @param ctx		Vboot context
- * @param cparams	Vboot common params
  * @return VBERROR_SUCCESS, or non-zero if error.
  */
-VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams);
+VbError_t ec_sync_all(struct vb2_context *ctx);
 
 #endif  /* VBOOT_REFERENCE_EC_SYNC_H_ */
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index b07e533..5bda94f 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -168,8 +168,8 @@
 
 VbError_t VbBootNormal(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	uint32_t max_rollforward = vb2_nv_get(ctx,
 					      VB2_NV_KERNEL_MAX_ROLLFORWARD);
 
@@ -315,10 +315,19 @@
 	sd->recovery_reason = shared->recovery_reason;
 
 	/*
+	 * Save a pointer to the old vboot1 shared data, since we haven't
+	 * finished porting the library to use the new vb2 context and shared
+	 * data.
+	 *
+	 * TODO: replace this with fields directly in vb2 shared data.
+	 */
+	sd->vbsd = shared;
+
+	/*
 	 * If we're in recovery mode just to do memory retraining, all we
 	 * need to do is reboot.
 	 */
-	if (shared->recovery_reason == VB2_RECOVERY_TRAIN_AND_REBOOT) {
+	if (sd->recovery_reason == VB2_RECOVERY_TRAIN_AND_REBOOT) {
 		VB2_DEBUG("Reboot after retraining in recovery.\n");
 		return VBERROR_REBOOT_REQUIRED;
 	}
@@ -346,9 +355,8 @@
 	/* Read kernel version from the TPM.  Ignore errors in recovery mode. */
 	if (RollbackKernelRead(&shared->kernel_version_tpm)) {
 		VB2_DEBUG("Unable to get kernel versions from TPM\n");
-		if (!shared->recovery_reason) {
-			VbSetRecoveryRequest(&ctx,
-					     VB2_RECOVERY_RW_TPM_R_ERROR);
+		if (!(ctx.flags & VB2_CONTEXT_RECOVERY_MODE)) {
+			VbSetRecoveryRequest(&ctx, VB2_RECOVERY_RW_TPM_R_ERROR);
 			return VBERROR_TPM_READ_KERNEL;
 		}
 	}
@@ -360,9 +368,8 @@
 		memset(&fwmp, 0, sizeof(fwmp));
 	} else if (RollbackFwmpRead(&fwmp)) {
 		VB2_DEBUG("Unable to get FWMP from TPM\n");
-		if (!shared->recovery_reason) {
-			VbSetRecoveryRequest(&ctx,
-					     VB2_RECOVERY_RW_TPM_R_ERROR);
+		if (!(ctx.flags & VB2_CONTEXT_RECOVERY_MODE)) {
+			VbSetRecoveryRequest(&ctx, VB2_RECOVERY_RW_TPM_R_ERROR);
 			return VBERROR_TPM_READ_FWMP;
 		}
 	}
@@ -370,11 +377,9 @@
 	return VBERROR_SUCCESS;
 }
 
-static VbError_t vb2_kernel_phase4(VbCommonParams *cparams,
-				   VbSelectAndLoadKernelParams *kparams)
+static VbError_t vb2_kernel_phase4(VbSelectAndLoadKernelParams *kparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(&ctx);
 
 	/* Save disk parameters */
 	kparams->disk_handle = lkp.disk_handle;
@@ -388,8 +393,8 @@
 	       sizeof(kparams->partition_guid));
 
 	/* Lock the kernel versions if not in recovery mode */
-	if (!shared->recovery_reason &&
-	    RollbackKernelLock(shared->recovery_reason)) {
+	if (!(ctx.flags & VB2_CONTEXT_RECOVERY_MODE) &&
+	    RollbackKernelLock(sd->recovery_reason)) {
 		VB2_DEBUG("Error locking kernel versions.\n");
 		VbSetRecoveryRequest(&ctx, VB2_RECOVERY_RW_TPM_L_ERROR);
 		return VBERROR_TPM_LOCK_KERNEL;
@@ -400,8 +405,13 @@
 
 static void vb2_kernel_cleanup(struct vb2_context *ctx, VbCommonParams *cparams)
 {
+	/*
+	 * This must directly access cparams for now because we could have had
+	 * an error setting up the vboot2 context.  In that case
+	 * vb2_shared_data is not available.
+	 */
 	VbSharedDataHeader *shared =
-			(VbSharedDataHeader *)cparams->shared_data_blob;
+		(VbSharedDataHeader *)cparams->shared_data_blob;
 
 	/*
 	 * Clean up vboot context.
@@ -422,9 +432,6 @@
 VbError_t VbSelectAndLoadKernel(VbCommonParams *cparams,
                                 VbSelectAndLoadKernelParams *kparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
-
 	VbError_t retval = vb2_kernel_setup(cparams, kparams);
 	if (retval)
 		goto VbSelectAndLoadKernel_exit;
@@ -433,21 +440,21 @@
 	 * Do EC software sync unless we're in recovery mode. This has UI but
 	 * it's just a single non-interactive WAIT screen.
 	 */
-	if (shared->recovery_reason == VB2_RECOVERY_NOT_REQUESTED) {
-		retval = ec_sync_all(&ctx, cparams);
+	if (!(ctx.flags & VB2_CONTEXT_RECOVERY_MODE)) {
+		retval = ec_sync_all(&ctx);
 		if (retval)
 			goto VbSelectAndLoadKernel_exit;
 	}
 
 	/* Select boot path */
-	if (shared->recovery_reason) {
+	if (ctx.flags & VB2_CONTEXT_RECOVERY_MODE) {
 		/* Recovery boot.  This has UI. */
 		if (kparams->inflags & VB_SALK_INFLAGS_ENABLE_DETACHABLE_UI)
 			retval = VbBootRecoveryMenu(&ctx, cparams);
 		else
 			retval = VbBootRecovery(&ctx, cparams);
 		VbExEcEnteringMode(0, VB_EC_RECOVERY);
-	} else if (shared->flags & VBSD_BOOT_DEV_SWITCH_ON) {
+	} else if (ctx.flags & VB2_CONTEXT_DEVELOPER_MODE) {
 		/* Developer boot.  This has UI. */
 		if (kparams->inflags & VB_SALK_INFLAGS_ENABLE_DETACHABLE_UI)
 			retval = VbBootDeveloperMenu(&ctx, cparams);
@@ -463,7 +470,7 @@
  VbSelectAndLoadKernel_exit:
 
 	if (VBERROR_SUCCESS == retval)
-		retval = vb2_kernel_phase4(cparams, kparams);
+		retval = vb2_kernel_phase4(kparams);
 
 	vb2_kernel_cleanup(&ctx, cparams);
 
@@ -480,8 +487,6 @@
 	VbPublicKey* kernel_subkey = NULL;
 	uint8_t *kbuf;
 	VbKeyBlockHeader *key_block;
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
 	VbKernelPreambleHeader *preamble;
 	uint64_t body_offset;
 	int hash_only = 0;
@@ -494,6 +499,7 @@
 		goto fail;
 
 	struct vb2_shared_data *sd = vb2_get_sd(&ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 
 	if ((boot_image == NULL) || (image_size == 0)) {
 		retval = VBERROR_INVALID_PARAMETER;
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index 3d12244..d3e3a6a 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -276,9 +276,8 @@
 
 VbError_t VbDisplayDebugInfo(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
 	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	char buf[DEBUG_INFO_SIZE] = "";
 	char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
 	char hwid[256];
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index c5030ef..d298e68 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -431,7 +431,8 @@
 VbError_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params,
 		     VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared = cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	VbSharedDataKernelCall *shcall = NULL;
 	struct vb2_packed_key *recovery_key = NULL;
 	int found_partitions = 0;
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 1776e4f..36c7cdf 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -94,8 +94,8 @@
 int VbUserConfirms(struct vb2_context *ctx, VbCommonParams *cparams,
 		   uint32_t confirm_flags)
 {
-	VbSharedDataHeader *shared =
-			(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	uint32_t key;
 	uint32_t key_flags;
 	uint32_t btn;
@@ -162,9 +162,8 @@
 
 VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
 	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 
 	uint32_t disable_dev_boot = 0;
 	uint32_t use_usb = 0;
@@ -399,8 +398,8 @@
 
 static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	uint32_t retval;
 	uint32_t key;
 	int i;
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index aad03a2..a8247a2 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -589,9 +589,8 @@
  */
 VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
 	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 
 	uint32_t use_usb = 0;
 	uint32_t use_legacy = 0;
@@ -897,8 +896,8 @@
  */
 static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams)
 {
-	VbSharedDataHeader *shared =
-		(VbSharedDataHeader *)cparams->shared_data_blob;
+	struct vb2_shared_data *sd = vb2_get_sd(ctx);
+	VbSharedDataHeader *shared = sd->vbsd;
 	uint32_t retval;
 	uint32_t key;
 	uint32_t key_flags;
diff --git a/tests/ec_sync_tests.c b/tests/ec_sync_tests.c
index 8a2ecd8..332290a 100644
--- a/tests/ec_sync_tests.c
+++ b/tests/ec_sync_tests.c
@@ -83,7 +83,9 @@
 	ctx.flags = VB2_CONTEXT_EC_SYNC_SUPPORTED;
 	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
+
 	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
 
 	memset(&shared_data, 0, sizeof(shared_data));
 	VbSharedDataInit(shared, sizeof(shared_data));
@@ -235,7 +237,7 @@
 
 static void test_ssync(VbError_t retval, int recovery_reason, const char *desc)
 {
-	TEST_EQ(ec_sync_all(&ctx, &cparams), retval, desc);
+	TEST_EQ(ec_sync_all(&ctx), retval, desc);
 	TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST),
 		recovery_reason, "  recovery reason");
 }
diff --git a/tests/vboot_api_devmode_tests.c b/tests/vboot_api_devmode_tests.c
index 0a336d9..330a89a 100644
--- a/tests/vboot_api_devmode_tests.c
+++ b/tests/vboot_api_devmode_tests.c
@@ -118,8 +118,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;
 	cparams.gbb = &gbb;
 
@@ -128,7 +126,9 @@
 	ctx.workbuf_size = sizeof(workbuf);
 	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
+
 	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
 
 	memset(&shared_data, 0, sizeof(shared_data));
 	VbSharedDataInit(shared, sizeof(shared_data));
diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c
index 64fca37..04e6466 100644
--- a/tests/vboot_api_kernel2_tests.c
+++ b/tests/vboot_api_kernel2_tests.c
@@ -59,8 +59,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;
 	cparams.gbb = &gbb;
 
@@ -81,7 +79,9 @@
 	ctx.workbuf_size = sizeof(workbuf);
 	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
+
 	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
 
 	shutdown_request_calls_left = -1;
 	audio_looping_calls_left = 30;
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index e239192..07bbfce 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -11,6 +11,7 @@
 
 #include "2sysincludes.h"
 #include "2api.h"
+#include "2misc.h"
 #include "2nvstorage.h"
 #include "ec_sync.h"
 #include "gbb_header.h"
@@ -24,7 +25,9 @@
 #include "vboot_struct.h"
 
 /* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
 static struct vb2_context ctx;
+static struct vb2_shared_data *sd;
 static VbCommonParams cparams;
 static VbSelectAndLoadKernelParams kparams;
 static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
@@ -54,9 +57,15 @@
 	gbb.flags = 0;
 
 	memset(&ctx, 0, sizeof(ctx));
+	ctx.workbuf = workbuf;
+	ctx.workbuf_size = sizeof(workbuf);
+	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
 	vb2_nv_set(&ctx, VB2_NV_KERNEL_MAX_ROLLFORWARD, 0xffffffff);
 
+	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
+
 	memset(&shared_data, 0, sizeof(shared_data));
 	VbSharedDataInit(shared, sizeof(shared_data));
 
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index 2d7c2e7..fc54eb7 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -13,6 +13,7 @@
 #include "2sysincludes.h"
 #include "2api.h"
 #include "2common.h"
+#include "2misc.h"
 #include "2nvstorage.h"
 #include "2rsa.h"
 #include "gbb_header.h"
@@ -26,7 +27,9 @@
 #include "vboot_struct.h"
 
 /* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
 static struct vb2_context ctx;
+static struct vb2_shared_data *sd;
 static VbCommonParams cparams;
 static VbSelectAndLoadKernelParams kparams;
 static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
@@ -63,8 +66,14 @@
 	gbb.flags = 0;
 
 	memset(&ctx, 0, sizeof(ctx));
+	ctx.workbuf = workbuf;
+	ctx.workbuf_size = sizeof(workbuf);
+	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
 
+	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
+
 	memset(&shared_data, 0, sizeof(shared_data));
 	VbSharedDataInit(shared, sizeof(shared_data));
 
diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c
index 3857c68..0e3cc3b 100644
--- a/tests/vboot_detach_menu_tests.c
+++ b/tests/vboot_detach_menu_tests.c
@@ -61,8 +61,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;
 	cparams.gbb = &gbb;
 
@@ -83,7 +81,9 @@
 	ctx.workbuf_size = sizeof(workbuf);
 	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
+
 	sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
 
 	shutdown_request_calls_left = -1;
 	audio_looping_calls_left = 30;
diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c
index e5e0d00..7ddc28e 100644
--- a/tests/vboot_display_tests.c
+++ b/tests/vboot_display_tests.c
@@ -53,8 +53,6 @@
 	mock_localization_count = 3;
 
 	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_data);
 
@@ -78,6 +76,9 @@
 	vb2_init_context(&ctx);
 	vb2_nv_init(&ctx);
 
+	struct vb2_shared_data *sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
+
 	memset(&shared_data, 0, sizeof(shared_data));
 	VbSharedDataInit(shared, sizeof(shared_data));
 
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index d581b37..a591978 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -149,7 +149,6 @@
 	cparams.gbb = gbb;
 	cparams.gbb_data = gbb;
 	cparams.gbb_size = sizeof(gbb_data);
-	cparams.shared_data_blob = shared;
 
 	memset(&lkp, 0, sizeof(lkp));
 	lkp.bytes_per_lba = 512;
@@ -184,6 +183,9 @@
 	ctx.workbuf_size = sizeof(workbuf);
 	vb2_nv_init(&ctx);
 
+	struct vb2_shared_data *sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
+
 	// TODO: more workbuf fields - flags, secdata, secdatak
 }
 
diff --git a/tests/verify_kernel.c b/tests/verify_kernel.c
index 58c01ad..01c4dee 100644
--- a/tests/verify_kernel.c
+++ b/tests/verify_kernel.c
@@ -132,6 +132,9 @@
 		return 1;
 	}
 
+	struct vb2_shared_data *sd = vb2_get_sd(&ctx);
+	sd->vbsd = shared;
+
 	/*
 	 * LoadKernel() cares only about VBNV_DEV_BOOT_SIGNED_ONLY, and only in
 	 * dev mode.  So just use defaults for nv storage.
diff --git a/utility/load_kernel_test.c b/utility/load_kernel_test.c
index 517a13f..481e78c 100644
--- a/utility/load_kernel_test.c
+++ b/utility/load_kernel_test.c
@@ -247,6 +247,9 @@
 	  return 1;
   }
 
+  struct vb2_shared_data *sd = vb2_get_sd(&ctx);
+  sd->vbsd = shared;
+
   /* Call LoadKernel() */
   rv = LoadKernel(&ctx, &lkp, &cparams);
   printf("LoadKernel() returned %d\n", rv);