summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2018-01-02 12:32:16 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-09 14:14:16 -0800
commit39427240693b31942f89385d3b01083fea1b0678 (patch)
treee1a8dad5e269bd8f6b1530ab307841b486957b47
parent46b7e0dae409ad83797a0b2feff314417bbb7b1c (diff)
downloadvboot-39427240693b31942f89385d3b01083fea1b0678.tar.gz
ec_sync: Use vboot2 context instead of cparams
Copy sync-related flags from cparams / vboot1 shared data to the equivalent vboot2 structs. This removes the need for ec_sync to access the old structs, which are on their way out. No change in functionality. BUG=chromium:611535 BRANCH=none TEST=make -j runtests; build bob firmware and boot it Change-Id: I50ee76cf275a7fba894c2ec2c3dd83b9a8d91b53 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/852489 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
-rw-r--r--firmware/2lib/include/2api.h36
-rw-r--r--firmware/lib/ec_sync.c50
-rw-r--r--firmware/lib/ec_sync_all.c10
-rw-r--r--firmware/lib/include/ec_sync.h23
-rw-r--r--firmware/lib/vboot_api_kernel.c17
-rw-r--r--tests/ec_sync_tests.c6
6 files changed, 84 insertions, 58 deletions
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index 21865783..97b5cca6 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -118,7 +118,10 @@ enum vb2_context_flags {
*/
VB2_CONTEXT_ALLOW_KERNEL_ROLL_FORWARD = (1 << 11),
- /* Boot optimistically: don't touch failure counters */
+ /*
+ * Boot optimistically: don't touch failure counters. Caller may set
+ * this flag when initializing the context.
+ */
VB2_CONTEXT_NOFAIL_BOOT = (1 << 12),
/*
@@ -130,8 +133,37 @@ enum vb2_context_flags {
*/
VB2_CONTEXT_SECDATA_WANTS_REBOOT = (1 << 13),
- /* Boot is S3->S0 resume, not S5->S0 normal boot */
+ /*
+ * Boot is S3->S0 resume, not S5->S0 normal boot. Caller may set this
+ * flag when initializing the context.
+ */
VB2_CONTEXT_S3_RESUME = (1 << 14),
+
+ /*
+ * System supports EC software sync. Caller may set this flag at any
+ * time before calling VbSelectAndLoadKernel().
+ */
+ VB2_CONTEXT_EC_SYNC_SUPPORTED = (1 << 15),
+
+ /*
+ * EC software sync is slow to update; warning screen should be
+ * displayed. Caller may set this flag at any time before calling
+ * VbSelectAndLoadKernel().
+ */
+ VB2_CONTEXT_EC_SYNC_SLOW = (1 << 16),
+
+ /*
+ * EC firmware supports early firmware selection; two EC images exist,
+ * and EC may have already verified and jumped to EC-RW prior to EC
+ * software sync.
+ */
+ VB2_CONTEXT_EC_EFS = (1 << 17),
+
+ /*
+ * Software write protect for the RO firmware was enabled at boot.
+ * Caller may set this flag when initializing the context.
+ */
+ VB2_CONTEXT_SW_WP_ENABLED = (1 << 18),
};
/*
diff --git a/firmware/lib/ec_sync.c b/firmware/lib/ec_sync.c
index 77b5741e..d63ce4b7 100644
--- a/firmware/lib/ec_sync.c
+++ b/firmware/lib/ec_sync.c
@@ -32,7 +32,7 @@
((devidx) ? VB2_SD_FLAG_ECSYNC_PD_RW : VB2_SD_FLAG_ECSYNC_EC_RW))
/* PD doesn't support RW A/B */
-#define RW_AB(devidx) ((devidx) ? 0 : VBSD_EC_EFS)
+#define RW_AB(devidx) ((devidx) ? 0 : VB2_CONTEXT_EC_EFS)
static void request_recovery(struct vb2_context *ctx, uint32_t recovery_request)
{
@@ -236,13 +236,10 @@ static VbError_t check_ec_active(struct vb2_context *ctx, int devidx)
* @param devidx Which device (EC=0, PD=1)
* @return VBERROR_SUCCESS, or non-zero if error.
*/
-static VbError_t sync_one_ec(struct vb2_context *ctx, int devidx,
- VbCommonParams *cparams)
+static VbError_t sync_one_ec(struct vb2_context *ctx, int devidx)
{
- VbSharedDataHeader *shared =
- (VbSharedDataHeader *)cparams->shared_data_blob;
struct vb2_shared_data *sd = vb2_get_sd(ctx);
- int is_rw_ab = shared->flags & RW_AB(devidx);
+ int is_rw_ab = ctx->flags & RW_AB(devidx);
int rv;
const enum VbSelectFirmware_t select_rw = is_rw_ab ?
@@ -339,14 +336,12 @@ static VbError_t sync_one_ec(struct vb2_context *ctx, int devidx,
return rv;
}
-VbError_t ec_sync_phase1(struct vb2_context *ctx, VbCommonParams *cparams)
+VbError_t ec_sync_phase1(struct vb2_context *ctx)
{
- VbSharedDataHeader *shared =
- (VbSharedDataHeader *)cparams->shared_data_blob;
struct vb2_shared_data *sd = vb2_get_sd(ctx);
/* Reasons not to do sync at all */
- if (!(shared->flags & VBSD_EC_SOFTWARE_SYNC))
+ if (!(ctx->flags & VB2_CONTEXT_EC_SYNC_SUPPORTED))
return VBERROR_SUCCESS;
if (sd->gbb_flags & VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC)
return VBERROR_SUCCESS;
@@ -377,7 +372,7 @@ VbError_t ec_sync_phase1(struct vb2_context *ctx, VbCommonParams *cparams)
* separately.
*/
if (vb2_nv_get(ctx, VB2_NV_TRY_RO_SYNC) &&
- !(shared->flags & VBSD_BOOT_FIRMWARE_WP_ENABLED) &&
+ !(ctx->flags & VB2_CONTEXT_SW_WP_ENABLED) &&
check_ec_hash(ctx, 0, VB_SELECT_FIRMWARE_READONLY)) {
return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
}
@@ -391,39 +386,34 @@ VbError_t ec_sync_phase1(struct vb2_context *ctx, VbCommonParams *cparams)
*/
if ((sd->flags & VB2_SD_FLAG_ECSYNC_RW) &&
(sd->flags & VB2_SD_FLAG_ECSYNC_IN_RW) &&
- !(shared->flags & VBSD_EC_EFS)) {
+ !(ctx->flags & VB2_CONTEXT_EC_EFS)) {
return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
}
return VBERROR_SUCCESS;
}
-int ec_will_update_slowly(struct vb2_context *ctx, VbCommonParams *cparams)
+int ec_will_update_slowly(struct vb2_context *ctx)
{
- VbSharedDataHeader *shared =
- (VbSharedDataHeader *)cparams->shared_data_blob;
struct vb2_shared_data *sd = vb2_get_sd(ctx);
return ((sd->flags & VB2_SD_FLAG_ECSYNC_ANY) &&
- (shared->flags & VBSD_EC_SLOW_UPDATE));
+ (ctx->flags & VB2_CONTEXT_EC_SYNC_SLOW));
}
/**
* determine if we can update the EC
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @return boolean (true iff we can update the EC)
*/
-static int ec_sync_allowed(struct vb2_context *ctx, VbCommonParams *cparams)
+static int ec_sync_allowed(struct vb2_context *ctx)
{
- VbSharedDataHeader *shared =
- (VbSharedDataHeader *)cparams->shared_data_blob;
struct vb2_shared_data *sd = vb2_get_sd(ctx);
/* Reasons not to do sync at all */
- if (!(shared->flags & VBSD_EC_SOFTWARE_SYNC))
+ if (!(ctx->flags & VB2_CONTEXT_EC_SYNC_SUPPORTED))
return 0;
if (sd->gbb_flags & VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC)
return 0;
@@ -433,13 +423,12 @@ static int ec_sync_allowed(struct vb2_context *ctx, VbCommonParams *cparams)
}
VbError_t ec_sync_check_aux_fw(struct vb2_context *ctx,
- VbCommonParams *cparams,
VbAuxFwUpdateSeverity_t *severity)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
/* If we're not updating the EC, skip aux fw syncs as well */
- if (!ec_sync_allowed(ctx, cparams) ||
+ if (!ec_sync_allowed(ctx) ||
(sd->gbb_flags & VB2_GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC)) {
*severity = VB_AUX_FW_NO_UPDATE;
return VBERROR_SUCCESS;
@@ -447,13 +436,13 @@ VbError_t ec_sync_check_aux_fw(struct vb2_context *ctx,
return VbExCheckAuxFw(severity);
}
-VbError_t ec_sync_phase2(struct vb2_context *ctx, VbCommonParams *cparams)
+VbError_t ec_sync_phase2(struct vb2_context *ctx)
{
- if (!ec_sync_allowed(ctx, cparams))
+ if (!ec_sync_allowed(ctx))
return VBERROR_SUCCESS;
/* Handle updates and jumps for EC */
- VbError_t retval = sync_one_ec(ctx, 0, cparams);
+ VbError_t retval = sync_one_ec(ctx, 0);
if (retval != VBERROR_SUCCESS)
return retval;
@@ -461,7 +450,7 @@ VbError_t ec_sync_phase2(struct vb2_context *ctx, VbCommonParams *cparams)
/* Handle updates and jumps for PD */
struct vb2_shared_data *sd = vb2_get_sd(ctx);
if (!(sd->gbb_flags & VB2_GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC)) {
- retval = sync_one_ec(ctx, 1, cparams);
+ retval = sync_one_ec(ctx, 1);
if (retval != VBERROR_SUCCESS)
return retval;
}
@@ -470,13 +459,12 @@ VbError_t ec_sync_phase2(struct vb2_context *ctx, VbCommonParams *cparams)
return VBERROR_SUCCESS;
}
-VbError_t ec_sync_phase3(struct vb2_context *ctx, VbCommonParams *cparams)
+VbError_t ec_sync_phase3(struct vb2_context *ctx)
{
- VbSharedDataHeader *shared =
- (VbSharedDataHeader *)cparams->shared_data_blob;
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
/* EC verification (and possibly updating / jumping) is done */
- VbError_t rv = VbExEcVbootDone(!!shared->recovery_reason);
+ VbError_t rv = VbExEcVbootDone(!!sd->recovery_reason);
if (rv)
return rv;
diff --git a/firmware/lib/ec_sync_all.c b/firmware/lib/ec_sync_all.c
index 1d9c7f71..a756bbcf 100644
--- a/firmware/lib/ec_sync_all.c
+++ b/firmware/lib/ec_sync_all.c
@@ -24,13 +24,13 @@ VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
VbAuxFwUpdateSeverity_t fw_update;
VbError_t rv;
- rv = ec_sync_check_aux_fw(ctx, cparams, &fw_update);
+ rv = ec_sync_check_aux_fw(ctx, &fw_update);
if (rv)
return rv;
/* Phase 1; this determines if we need an update */
- VbError_t phase1_rv = ec_sync_phase1(ctx, cparams);
- int need_wait_screen = ec_will_update_slowly(ctx, cparams) ||
+ VbError_t phase1_rv = ec_sync_phase1(ctx);
+ int need_wait_screen = ec_will_update_slowly(ctx) ||
(fw_update == VB_AUX_FW_SLOW_UPDATE);
/*
@@ -61,7 +61,7 @@ VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
}
/* Phase 2; Applies update and/or jumps to the correct EC image */
- rv = ec_sync_phase2(ctx, cparams);
+ rv = ec_sync_phase2(ctx);
if (rv)
return rv;
@@ -89,7 +89,7 @@ VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
}
/* Phase 3; Completes sync and handles battery cutoff */
- rv = ec_sync_phase3(ctx, cparams);
+ rv = ec_sync_phase3(ctx);
if (rv)
return rv;
diff --git a/firmware/lib/include/ec_sync.h b/firmware/lib/include/ec_sync.h
index 78b08a20..f95b500f 100644
--- a/firmware/lib/include/ec_sync.h
+++ b/firmware/lib/include/ec_sync.h
@@ -20,13 +20,11 @@ struct VbCommonParams;
* whether any updates are necessary.
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @return VBERROR_SUCCESS, VBERROR_EC_REBOOT_TO_RO_REQUIRED if the EC must
* reboot back to its RO code to continue EC sync, or other non-zero error
* code.
*/
-VbError_t ec_sync_phase1(struct vb2_context *ctx,
- struct VbCommonParams *cparams);
+VbError_t ec_sync_phase1(struct vb2_context *ctx);
/**
* Returns non-zero if the EC will perform a slow update during phase 2.
@@ -35,23 +33,19 @@ VbError_t ec_sync_phase1(struct vb2_context *ctx,
* ec_sync_phase2().
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @return non-zero if a slow update will be done; zero if no update or a
* fast update.
*/
-int ec_will_update_slowly(struct vb2_context *ctx,
- struct VbCommonParams *cparams);
+int ec_will_update_slowly(struct vb2_context *ctx);
/**
* Check if auxiliary firmware blobs need to be updated.
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @param severity VB_AUX_FW_{NO,FAST,SLOW}_UPDATE
* @return VBERROR_SUCCESS or non-zero error code.
*/
VbError_t ec_sync_check_aux_fw(struct vb2_context *ctx,
- struct VbCommonParams *cparams,
VbAuxFwUpdateSeverity_t *severity);
/**
@@ -64,13 +58,11 @@ VbError_t ec_sync_check_aux_fw(struct vb2_context *ctx,
* warning screen before calling phase 2.
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @return VBERROR_SUCCESS, VBERROR_EC_REBOOT_TO_RO_REQUIRED if the EC must
* reboot back to its RO code to continue EC sync, or other non-zero error
* code.
*/
-VbError_t ec_sync_phase2(struct vb2_context *ctx,
- struct VbCommonParams *cparams);
+VbError_t ec_sync_phase2(struct vb2_context *ctx);
/**
* EC sync, phase 3
@@ -78,10 +70,9 @@ VbError_t ec_sync_phase2(struct vb2_context *ctx,
* This completes EC sync and handles battery cutoff if needed.
*
* @param ctx Vboot2 context
- * @param cparams Vboot common params
* @return VBERROR_SUCCESS or non-zero error code.
*/
-VbError_t ec_sync_phase3(struct vb2_context *ctx, VbCommonParams *cparams);
+VbError_t ec_sync_phase3(struct vb2_context *ctx);
/**
* Sync all EC devices to expected versions.
@@ -89,11 +80,9 @@ VbError_t ec_sync_phase3(struct vb2_context *ctx, VbCommonParams *cparams);
* This is a high-level function which calls the functions above.
*
* @param ctx Vboot context
- * @param devidx EC device index to sync
- * @param cparams Common vboot params
+ * @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, struct VbCommonParams *cparams);
#endif /* VBOOT_REFERENCE_EC_SYNC_H_ */
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index fd0556b5..44b537d9 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -268,11 +268,28 @@ static VbError_t vb2_kernel_setup(VbCommonParams *cparams,
VbExNvStorageRead(ctx.nvdata);
vb2_nv_init(&ctx);
+ /* Translate vboot1 flags back to vboot2 */
if (shared->recovery_reason)
ctx.flags |= VB2_CONTEXT_RECOVERY_MODE;
if (shared->flags & VBSD_BOOT_DEV_SWITCH_ON)
ctx.flags |= VB2_CONTEXT_DEVELOPER_MODE;
+ /*
+ * The following flags are set by depthcharge.
+ *
+ * TODO: Some of these are set at compile-time, so could be #defines
+ * instead of flags. That would save on firmware image size because
+ * features that won't be used in an image could be compiled out.
+ */
+ if (shared->flags & VBSD_EC_SOFTWARE_SYNC)
+ ctx.flags |= VB2_CONTEXT_EC_SYNC_SUPPORTED;
+ if (shared->flags & VBSD_EC_SLOW_UPDATE)
+ ctx.flags |= VB2_CONTEXT_EC_SYNC_SLOW;
+ if (shared->flags & VBSD_EC_EFS)
+ ctx.flags |= VB2_CONTEXT_EC_EFS;
+ if (shared->flags & VBSD_BOOT_FIRMWARE_SW_WP_ENABLED)
+ ctx.flags |= VB2_CONTEXT_SW_WP_ENABLED;
+
ctx.workbuf_size = VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE +
VB2_WORKBUF_ALIGN;
diff --git a/tests/ec_sync_tests.c b/tests/ec_sync_tests.c
index 8f09af0d..bdf24d35 100644
--- a/tests/ec_sync_tests.c
+++ b/tests/ec_sync_tests.c
@@ -80,13 +80,13 @@ static void ResetMocks(void)
memset(&ctx, 0, sizeof(ctx));
ctx.workbuf = workbuf;
ctx.workbuf_size = sizeof(workbuf);
+ ctx.flags = VB2_CONTEXT_EC_SYNC_SUPPORTED;
vb2_init_context(&ctx);
vb2_nv_init(&ctx);
sd = vb2_get_sd(&ctx);
memset(&shared_data, 0, sizeof(shared_data));
VbSharedDataInit(shared, sizeof(shared_data));
- shared->flags = VBSD_EC_SOFTWARE_SYNC;
mock_in_rw = 0;
ec_ro_protected = 0;
@@ -307,7 +307,7 @@ static void VbSoftwareSyncTest(void)
TEST_EQ(ec_ro_updated, 1, " ec ro updated");
ResetMocks();
- shared->flags |= VBSD_BOOT_FIRMWARE_WP_ENABLED;
+ ctx.flags |= VB2_CONTEXT_SW_WP_ENABLED;
vb2_nv_set(&ctx, VB2_NV_TRY_RO_SYNC, 1);
mock_ec_rw_hash[0]++;
mock_ec_ro_hash[0]++;
@@ -365,7 +365,7 @@ static void VbSoftwareSyncTest(void)
ResetMocks();
mock_ec_rw_hash[0]++;
- shared->flags |= VBSD_EC_SLOW_UPDATE;
+ ctx.flags |= VB2_CONTEXT_EC_SYNC_SLOW;
test_ssync(0, 0, "Slow update");
TEST_EQ(screens_displayed[0], VB_SCREEN_WAIT, " wait screen");