From b00bf851cdaada874b7c66c6913d0cef0798fcbf Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 19 Jan 2018 12:24:21 -0800 Subject: [PATCH] ec_sync: Commit NVRAM updates before battery cutoff Battery cutoff may cause the entire system to lose power, which means that any uncommitted nvram updates will be lost. This can leave us in a battery cutoff loop, where we never completely clear the BATTERY_CUTOFF_REQUEST flag before actually cutting off power. The only way to escape this potential cutoff loop is if we manage to cleanly exit to vb2_kernel_cleanup(), where we perform a similar commit. But this requires us to retain power for some time after VbExEcBatteryCutOff(). BRANCH=none BUG=b:70176744 TEST=`crossystem battery_cutoff_request=1` on scarlet, then reboot; see battery cutoff; plug in AC and observe whether we reliably boot on first attach Change-Id: I1acf3aaeaf76f97f7603f79dbfef7a24a96f36dc Signed-off-by: Brian Norris Reviewed-on: https://chromium-review.googlesource.com/876783 Reviewed-by: Philip Chen Reviewed-by: Julius Werner --- firmware/lib/ec_sync.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/lib/ec_sync.c b/firmware/lib/ec_sync.c index d63ce4b7c2..83ad8025d1 100644 --- a/firmware/lib/ec_sync.c +++ b/firmware/lib/ec_sync.c @@ -473,6 +473,8 @@ VbError_t ec_sync_phase3(struct vb2_context *ctx) 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); VbExEcBatteryCutOff(); return VBERROR_SHUTDOWN_REQUESTED; }