summaryrefslogtreecommitdiff
path: root/chip/lm4/flash.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-05-21 12:34:11 -0700
committerChromeBot <chrome-bot@google.com>2013-05-24 16:27:49 -0700
commit1d28ca7cf1d8ec5f552dce7e84123735f6aecb14 (patch)
treece6de03a89cea2fe2f8889fed0175438dbb7e38f /chip/lm4/flash.c
parentb144a584af63891b134c3f789fdd00ac232a9577 (diff)
downloadchrome-ec-1d28ca7cf1d8ec5f552dce7e84123735f6aecb14.tar.gz
Move flash_get_protect() and flash_set_protect() to flash_common.c
Much more flash code is now common between platforms, for more consistent behavior and easier testing. Also change STM32L to use pstate, the same way LM4 and STM32F do. BUG=chrome-os-partner:15613 BRANCH=none TEST=build pit, link, spring; do - flashinfo -> (no flags) - enable WP (via screw or dut-control) - flashinfo -> wp_gpio_asserted - flashwp enable - flashinfo -> wp_gpio_asserted ro_at_boot - flashwp now - flashinfo -> wp_gpio_asserted ro_at_boot all_now (and possibly ro_now) - flashwp disable -> fails - flashinfo -> wp_gpio_asserted ro_at_boot all_now - reboot ap-off - flashinfo -> wp_gpio_asserted ro_at_boot ro_now - disable WP (via screw or dut-control) - reboot - flashinfo -> ro_at_boot - flashwp disable - flashinfo -> (no flags) Change-Id: Iccd098786454ad9b72b4e5f9f312d86819a0c8eb Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/56109
Diffstat (limited to 'chip/lm4/flash.c')
-rw-r--r--chip/lm4/flash.c95
1 files changed, 13 insertions, 82 deletions
diff --git a/chip/lm4/flash.c b/chip/lm4/flash.c
index 2a8e45c1b6..2c5e0f9127 100644
--- a/chip/lm4/flash.c
+++ b/chip/lm4/flash.c
@@ -6,7 +6,6 @@
/* Flash memory module for Chrome EC */
#include "flash.h"
-#include "gpio.h"
#include "registers.h"
#include "switch.h"
#include "system.h"
@@ -177,58 +176,14 @@ int flash_physical_get_protect(int bank)
return (LM4_FLASH_FMPPE[F_BANK(bank)] & F_BIT(bank)) ? 0 : 1;
}
-int flash_physical_get_all_protect_now(void)
-{
- return all_protected;
-}
-
-/*****************************************************************************/
-/* High-level APIs */
-
-uint32_t flash_get_protect(void)
+uint32_t flash_physical_get_protect_flags(void)
{
uint32_t flags = 0;
- int not_protected[2] = {0};
- int i;
/* Read all-protected state from our shadow copy */
- if (flash_physical_get_all_protect_now())
+ if (all_protected)
flags |= EC_FLASH_PROTECT_ALL_NOW;
- /* Read the current persist state from flash */
- if (flash_get_protect_ro_at_boot())
- flags |= EC_FLASH_PROTECT_RO_AT_BOOT;
-
- /* Check if write protect pin is asserted now */
- if (gpio_get_level(GPIO_WP))
- flags |= EC_FLASH_PROTECT_GPIO_ASSERTED;
-
- /* Scan flash protection */
- for (i = 0; i < PHYSICAL_BANKS; i++) {
- /* Is this bank part of RO? */
- int is_ro = ((i >= RO_BANK_OFFSET &&
- i < RO_BANK_OFFSET + RO_BANK_COUNT) ||
- i == PSTATE_BANK);
- int bank_flag = (is_ro ? EC_FLASH_PROTECT_RO_NOW :
- EC_FLASH_PROTECT_ALL_NOW);
-
- if (flash_physical_get_protect(i)) {
- /* At least one bank in the region is protected */
- flags |= bank_flag;
- if (not_protected[is_ro])
- flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
- } else {
- /* But not all banks in the region! */
- not_protected[is_ro] = 1;
- if (flags & bank_flag)
- flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
- }
- }
-
- if ((flags & EC_FLASH_PROTECT_ALL_NOW) &&
- !(flags & EC_FLASH_PROTECT_RO_NOW))
- flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
-
/* Check if blocks were stuck locked at pre-init */
if (stuck_locked)
flags |= EC_FLASH_PROTECT_ERROR_STUCK;
@@ -236,50 +191,26 @@ uint32_t flash_get_protect(void)
return flags;
}
-int flash_set_protect(uint32_t mask, uint32_t flags)
+int flash_physical_protect_now(int all)
{
- int retval = EC_SUCCESS;
- int rv;
-
- /*
- * Process flags we can set. Track the most recent error, but process
- * all flags before returning.
- */
- if (mask & EC_FLASH_PROTECT_RO_AT_BOOT) {
- rv = flash_protect_ro_at_boot(
- flags & EC_FLASH_PROTECT_RO_AT_BOOT);
- if (rv)
- retval = rv;
- }
-
- /*
- * All subsequent flags only work if write protect is enabled (that is,
- * hardware WP flag) *and* RO is protected at boot (software WP flag).
- */
- if ((~flash_get_protect()) & (EC_FLASH_PROTECT_GPIO_ASSERTED |
- EC_FLASH_PROTECT_RO_AT_BOOT))
- return retval;
-
- if ((mask & EC_FLASH_PROTECT_RO_NOW) &&
- (flags & EC_FLASH_PROTECT_RO_NOW)) {
- /* Protect pstate */
- protect_banks(PSTATE_BANK, 1);
-
- /* Protect the read-only section */
- protect_banks(RO_BANK_OFFSET, RO_BANK_COUNT);
- }
-
- if ((mask & EC_FLASH_PROTECT_ALL_NOW) &&
- (flags & EC_FLASH_PROTECT_ALL_NOW)) {
+ if (all) {
/* Protect the entire flash */
all_protected = 1;
protect_banks(0, CONFIG_FLASH_PHYSICAL_SIZE /
CONFIG_FLASH_BANK_SIZE);
+ } else {
+ /* Protect the read-only section and persistent state */
+ protect_banks(RO_BANK_OFFSET, RO_BANK_COUNT);
+ protect_banks(PSTATE_BANK, 1);
}
- return retval;
+ return EC_SUCCESS;
}
+
+/*****************************************************************************/
+/* High-level APIs */
+
int flash_pre_init(void)
{
uint32_t reset_flags = system_get_reset_flags();