From 09d0c2e487653ada95768abe5cb9bfbf8dbfe6bb Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Wed, 25 Jul 2012 15:52:51 -0700 Subject: [PATCH] Handle reboots required to protect/unprotect RW firmware Necessary for updating snow EC BUG=chrome-os-partner:11087 TEST=force an EC update by loading a slightly old EC and then a new BIOS Change-Id: Id00257f8a67c08077a5b396cf120a056a7601671 Signed-off-by: Randall Spangler Reviewed-on: https://gerrit.chromium.org/gerrit/28436 Reviewed-by: Bill Richardson --- firmware/lib/vboot_api_kernel.c | 38 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index c87a05afff..e38a949cf1 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -347,6 +347,18 @@ VbError_t VbBootRecovery(VbCommonParams* cparams, LoadKernelParams* p) { return VBERROR_SUCCESS; } +/* Wrapper around VbExEcProtectRW() which sets recovery reason on error */ +static VbError_t EcProtectRW(void) { + int rv = VbExEcProtectRW(); + + if (rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED) { + VBDEBUG(("VbExEcProtectRW() needs reboot\n")); + } else if (rv != VBERROR_SUCCESS) { + VBDEBUG(("VbExEcProtectRW() returned %d\n", rv)); + VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC); + } + return rv; +} VbError_t VbEcSoftwareSync(VbSharedDataHeader *shared) { int in_rw = 0; @@ -394,12 +406,9 @@ VbError_t VbEcSoftwareSync(VbSharedDataHeader *shared) { } /* Protect the RW flash and stay in EC-RO */ - rv = VbExEcProtectRW(); - if (rv != VBERROR_SUCCESS) { - VBDEBUG(("VbEcSoftwareSync() - VbExEcProtectRW() returned %d\n", rv)); - VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC); - return VBERROR_EC_REBOOT_TO_RO_REQUIRED; - } + rv = EcProtectRW(); + if (rv != VBERROR_SUCCESS) + return rv; rv = VbExEcStayInRO(); if (rv != VBERROR_SUCCESS) { @@ -485,7 +494,13 @@ VbError_t VbEcSoftwareSync(VbSharedDataHeader *shared) { */ rv = VbExEcUpdateRW(expected, expected_size); - if (rv != VBERROR_SUCCESS) { + if (rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED) { + /* Reboot required. May need to unprotect RW before updating, + * or may need to reboot after RW updated. Either way, it's not + * an error requiring recovery mode. */ + VBDEBUG(("VbEcSoftwareSync() - VbExEcUpdateRW() needs reboot\n")); + return rv; + } else if (rv != VBERROR_SUCCESS) { VBDEBUG(("VbEcSoftwareSync() - VbExEcUpdateRW() returned %d\n", rv)); VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC); return VBERROR_EC_REBOOT_TO_RO_REQUIRED; @@ -498,12 +513,9 @@ VbError_t VbEcSoftwareSync(VbSharedDataHeader *shared) { } /* Protect EC-RW flash */ - rv = VbExEcProtectRW(); - if (rv != VBERROR_SUCCESS) { - VBDEBUG(("VbEcSoftwareSync() - VbExEcProtectRW() returned %d\n", rv)); - VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC); - return VBERROR_EC_REBOOT_TO_RO_REQUIRED; - } + rv = EcProtectRW(); + if (rv != VBERROR_SUCCESS) + return rv; /* Tell EC to jump to its RW code */ VBDEBUG(("VbEcSoftwareSync() jumping to EC-RW\n"));