summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2018-09-26 22:07:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-27 19:44:48 -0700
commit9e67cde50f6f5ecd578e47db612b1a7b9e1e1ff7 (patch)
treead926152deb3774399afe9711d4f85039fc69e29 /chip
parentf90282218998398948f3cdcc2f74d0b5fa0ab11e (diff)
downloadchrome-ec-9e67cde50f6f5ecd578e47db612b1a7b9e1e1ff7.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>
Diffstat (limited to 'chip')
-rw-r--r--chip/npcx/flash.c12
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);