diff options
author | Wealian Liao <whliao@nuvoton.corp-partner.google.com> | 2021-10-15 16:45:47 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-03 01:29:43 +0000 |
commit | 3e8e219853490156968579a71ce42dffddb05415 (patch) | |
tree | 431fcbb0a5218494d51f6b825ec604499a377cea /chip/npcx/flash.c | |
parent | fc78be657fbfc913ac5cd2441b566fd7de7b9fda (diff) | |
download | chrome-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>
Diffstat (limited to 'chip/npcx/flash.c')
-rw-r--r-- | chip/npcx/flash.c | 21 |
1 files changed, 15 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 */ |