battery cutoff: Move cutoff handling from EC sync to kernel load

Currently, battery cutoff is handled at the end of a successful EC
software sync.  Now that auxiliary firmware sync is separate from the
EC, this patch moves it back to after both EC and auxfw updates are
successful, to ensure all firmware is up-to-date before entering ship
mode.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I96bea22667ebf45b446a26d84de96e52f3d289a5
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1889430
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Tim Wawrzynczak 2019-10-29 21:07:19 -06:00 committed by Commit Bot
parent c8333506d4
commit 14128c66d5
2 changed files with 28 additions and 33 deletions

View File

@ -448,35 +448,6 @@ static vb2_error_t ec_sync_phase2(struct vb2_context *ctx)
return sync_ec(ctx);
}
/**
* EC sync, phase 3
*
* This completes EC sync and handles battery cutoff if needed.
*
* @param ctx Vboot2 context
* @return VB2_SUCCESS or non-zero error code.
*/
static vb2_error_t ec_sync_phase3(struct vb2_context *ctx)
{
/* EC verification (and possibly updating / jumping) is done */
vb2_error_t rv = vb2ex_ec_vboot_done(ctx);
if (rv)
return rv;
/* Check if we need to cut-off battery. This must be done after EC
* firmware updating and before kernel started. */
if (vb2_nv_get(ctx, VB2_NV_BATTERY_CUTOFF_REQUEST)) {
VB2_DEBUG("Request to cut-off battery\n");
vb2_nv_set(ctx, VB2_NV_BATTERY_CUTOFF_REQUEST, 0);
/* May lose power immediately, so commit our update now. */
vb2_nv_commit(ctx);
vb2ex_ec_battery_cutoff();
return VBERROR_SHUTDOWN_REQUESTED;
}
return VB2_SUCCESS;
}
vb2_error_t vb2api_ec_sync(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
@ -509,8 +480,8 @@ vb2_error_t vb2api_ec_sync(struct vb2_context *ctx)
if (rv)
return rv;
/* Phase 3; Completes sync and handles battery cutoff */
rv = ec_sync_phase3(ctx);
/* Phase 3; Let the platform know that EC software sync is now done */
rv = vb2ex_ec_vboot_done(ctx);
if (rv)
return rv;

View File

@ -50,6 +50,26 @@ void vb2_nv_commit(struct vb2_context *ctx)
VbExNvStorageWrite(ctx->nvdata);
}
static vb2_error_t handle_battery_cutoff(struct vb2_context *ctx)
{
/*
* Check if we need to cut-off battery. This should be done after EC
* FW and Aux FW are updated, and before the kernel is started. This
* is to make sure all firmware is up-to-date before shipping (which
* is the typical use-case for cutoff).
*/
if (vb2_nv_get(ctx, VB2_NV_BATTERY_CUTOFF_REQUEST)) {
VB2_DEBUG("Request to cut-off battery\n");
vb2_nv_set(ctx, VB2_NV_BATTERY_CUTOFF_REQUEST, 0);
/* May lose power immediately, so commit our update now. */
vb2_nv_commit(ctx);
vb2ex_ec_battery_cutoff();
return VBERROR_SHUTDOWN_REQUESTED;
}
return VB2_SUCCESS;
}
uint32_t vb2_get_fwmp_flags(void)
{
return fwmp.flags;
@ -367,8 +387,8 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
VB2_DEBUG("GBB flags are %#x\n", vb2_get_gbb(ctx)->flags);
/*
* Do EC software sync unless we're in recovery mode. This has UI but
* it's just a single non-interactive WAIT screen.
* Do EC and Aux FW software sync unless we're in recovery mode. This
* has UI but it's just a single non-interactive WAIT screen.
*/
if (!(ctx->flags & VB2_CONTEXT_RECOVERY_MODE)) {
rv = vb2api_ec_sync(ctx);
@ -378,6 +398,10 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
rv = vb2api_auxfw_sync(ctx);
if (rv)
goto VbSelectAndLoadKernel_exit;
rv = handle_battery_cutoff(ctx);
if (rv)
goto VbSelectAndLoadKernel_exit;
}
/* Select boot path */