summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWealian Liao <whliao@nuvoton.corp-partner.google.com>2021-10-15 16:45:47 +0800
committerCommit Bot <commit-bot@chromium.org>2021-11-03 01:29:43 +0000
commit3e8e219853490156968579a71ce42dffddb05415 (patch)
tree431fcbb0a5218494d51f6b825ec604499a377cea
parentfc78be657fbfc913ac5cd2441b566fd7de7b9fda (diff)
downloadchrome-ec-3e8e219853490156968579a71ce42dffddb05415.tar.gz
npcx: flash: Fix physical_get_protect_flags()
Protecting status register by /WP works when SRP0 is enabled. The getting protect flags function should check SRP0 & QE for EC_FLASH_PROTECT_ERROR_INCONSISTENT flag. This CL adds the following: 1. SRP0 & QE bits check for npcx flash. 2. EC_FLASH_PROTECT_ERROR_UNKNOWN flag BUG=none BRANCH=none TEST=Protect a range & don't set the SRP0. Check flag by `flashinfo`. Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com> Change-Id: Iae8645aca7b0d9176e625de3656a35e675df3ef2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3246882 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--chip/npcx/flash.c21
-rw-r--r--common/flash.c3
-rw-r--r--include/ec_commands.h2
-rw-r--r--util/ectool.c2
4 files changed, 22 insertions, 6 deletions
diff --git a/chip/npcx/flash.c b/chip/npcx/flash.c
index e468af57f8..0d024ba8d7 100644
--- a/chip/npcx/flash.c
+++ b/chip/npcx/flash.c
@@ -21,7 +21,6 @@
static int all_protected; /* Has all-flash protection been requested? */
static int addr_prot_start;
static int addr_prot_length;
-static uint8_t flag_prot_inconsistent;
/* SR regs aren't readable when UMA lock is on, so save a copy */
static uint8_t saved_sr1;
@@ -627,17 +626,27 @@ int crec_flash_physical_get_protect(int bank)
uint32_t crec_flash_physical_get_protect_flags(void)
{
uint32_t flags = 0;
+ uint8_t sr1 = flash_get_status1();
+ uint8_t sr2 = flash_get_status2();
+ unsigned int start, len;
+ int rv;
/* Check if WP region is protected in status register */
- if (flash_check_prot_reg(WP_BANK_OFFSET*CONFIG_FLASH_BANK_SIZE,
- WP_BANK_COUNT*CONFIG_FLASH_BANK_SIZE))
+ rv = flash_check_prot_reg(WP_BANK_OFFSET * CONFIG_FLASH_BANK_SIZE,
+ WP_BANK_COUNT * CONFIG_FLASH_BANK_SIZE);
+ if (rv == EC_ERROR_ACCESS_DENIED)
flags |= EC_FLASH_PROTECT_RO_AT_BOOT;
+ else if (rv)
+ return EC_FLASH_PROTECT_ERROR_UNKNOWN;
/*
- * TODO: If status register protects a range, but SRP0 is not set,
- * flags should indicate EC_FLASH_PROTECT_ERROR_INCONSISTENT.
+ * If the status register protects a range, but SRP0 is not set, or QE
+ * is set, flags should indicate EC_FLASH_PROTECT_ERROR_INCONSISTENT.
*/
- if (flag_prot_inconsistent)
+ rv = spi_flash_reg_to_protect(sr1, sr2, &start, &len);
+ if (rv)
+ return EC_FLASH_PROTECT_ERROR_UNKNOWN;
+ if (len && (!(sr1 & SPI_FLASH_SR1_SRP0) || (sr2 & SPI_FLASH_SR2_QE)))
flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
/* Read all-protected state from our shadow copy */
diff --git a/common/flash.c b/common/flash.c
index c8f58a82af..ec9f50b711 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -1032,6 +1032,8 @@ static int command_flash_info(int argc, char **argv)
ccputs(" STUCK");
if (flags & EC_FLASH_PROTECT_ERROR_INCONSISTENT)
ccputs(" INCONSISTENT");
+ if (flags & EC_FLASH_PROTECT_ERROR_UNKNOWN)
+ ccputs(" UNKNOWN_ERROR");
#ifdef CONFIG_ROLLBACK
if (flags & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT)
ccputs(" rollback_at_boot");
@@ -1490,6 +1492,7 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args)
EC_FLASH_PROTECT_GPIO_ASSERTED |
EC_FLASH_PROTECT_ERROR_STUCK |
EC_FLASH_PROTECT_ERROR_INCONSISTENT |
+ EC_FLASH_PROTECT_ERROR_UNKNOWN |
crec_flash_physical_get_valid_flags();
r->writable_flags = crec_flash_physical_get_writable_flags(r->flags);
diff --git a/include/ec_commands.h b/include/ec_commands.h
index e317c29e28..a8ea4e31a5 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1768,6 +1768,8 @@ struct ec_params_flash_erase_v1 {
#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
/* Rollback information flash region protected now */
#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
+/* Error - Unknown error */
+#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
/**
diff --git a/util/ectool.c b/util/ectool.c
index 01d3605afd..8d4963c3d5 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1576,6 +1576,8 @@ static void print_flash_protect_flags(const char *desc, uint32_t flags)
printf(" STUCK");
if (flags & EC_FLASH_PROTECT_ERROR_INCONSISTENT)
printf(" INCONSISTENT");
+ if (flags & EC_FLASH_PROTECT_ERROR_UNKNOWN)
+ printf(" UNKNOWN_ERROR");
printf("\n");
}