diff options
author | Furquan Shaikh <furquan@google.com> | 2018-09-26 22:07:50 -0700 |
---|---|---|
committer | Martin Roth <martinroth@chromium.org> | 2018-10-01 21:43:52 +0000 |
commit | 6fe43997b5588be82ef64596bab727883ed32927 (patch) | |
tree | d3b208c7b244dd0fe5ca38265b2d8e9a8d54bf48 /chip | |
parent | a891e0804dcd1ed79fe7d2daded3df03b4f6845a (diff) | |
download | chrome-ec-6fe43997b5588be82ef64596bab727883ed32927.tar.gz |
npcx: Check WP_IF for internal flash before writing status register
In case of internal flash, WP_IF needs to be checked to determine if
it is okay to write status register. WP_IF is R/W1S, hence once it is
set, it gets cleared only on core domain reset. Thus, it is necessary
to reboot EC on WP de-assertion before any attempt to write status
register is made.
This change checks to ensure that internal flash is not protected
based on the state of WP_IF bit in DEV_CTL4 before writing status
register.
BUG=b:115983409
BRANCH=None
TEST=Verified following:
1. Attempt to write status register without rebooting EC:
a. Disable WP
b. flashrom -p ec --wp-disable
---> Reports failure back to host
2. Attempt to write status register after rebooting EC:
a. Disable WP
b. Reboot EC
c. flashrom -p ec --wp-disable
---> Reports success and SW WP is successfully disabled.
Change-Id: I2a89ecfc0bed824d5e75110f00b060980627dd33
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1248481
Commit-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Sanna Fnu <fnu.sanna@intel.corp-partner.google.com>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Justin TerAvest <teravest@chromium.org>
(cherry picked from commit 9e67cde50f6f5ecd578e47db612b1a7b9e1e1ff7)
Reviewed-on: https://chromium-review.googlesource.com/1256046
Reviewed-by: Martin Roth <martinroth@chromium.org>
Tested-by: Martin Roth <martinroth@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r-- | chip/npcx/flash.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/chip/npcx/flash.c b/chip/npcx/flash.c index d542dec674..55ad98e14a 100644 --- a/chip/npcx/flash.c +++ b/chip/npcx/flash.c @@ -193,13 +193,18 @@ static uint8_t flash_get_status2(void) } #ifdef NPCX_INT_FLASH_SUPPORT +static int is_int_flash_protected(void) +{ + return IS_BIT_SET(NPCX_DEV_CTL4, NPCX_DEV_CTL4_WP_IF); +} + static void flash_protect_int_flash(int enable) { /* * Please notice the type of WP_IF bit is R/W1S. Once it's set, * only rebooting EC can clear it. */ - if (enable && !IS_BIT_SET(NPCX_DEV_CTL4, NPCX_DEV_CTL4_WP_IF)) + if (enable && !is_int_flash_protected()) SET_BIT(NPCX_DEV_CTL4, NPCX_DEV_CTL4_WP_IF); } #endif @@ -271,6 +276,11 @@ static int flash_set_status_for_prot(int reg1, int reg2) * is deasserted then remove the lock and allow the write. */ if (all_protected) { +#ifdef NPCX_INT_FLASH_SUPPORT + if (is_int_flash_protected()) + return EC_ERROR_ACCESS_DENIED; +#endif + if (flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) return EC_ERROR_ACCESS_DENIED; flash_uma_lock(0); |