From 6fe43997b5588be82ef64596bab727883ed32927 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Wed, 26 Sep 2018 22:07:50 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/1248481 Commit-Ready: Furquan Shaikh Tested-by: Sanna Fnu Tested-by: Furquan Shaikh Reviewed-by: Aseda Aboagye Reviewed-by: Jett Rink Reviewed-by: Justin TerAvest (cherry picked from commit 9e67cde50f6f5ecd578e47db612b1a7b9e1e1ff7) Reviewed-on: https://chromium-review.googlesource.com/1256046 Reviewed-by: Martin Roth Tested-by: Martin Roth --- chip/npcx/flash.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'chip') 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); -- cgit v1.2.1