summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-10-14 10:05:43 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-15 23:56:27 +0000
commitf8fd63f135b5922900ceeb345857070e814f8877 (patch)
treed93f66806f14465810b263e30d49a3e610430acf
parent847eb1ec44aa43c761799b522b0449bdfc31269a (diff)
downloadchrome-ec-f8fd63f135b5922900ceeb345857070e814f8877.tar.gz
Fix incorrect valid and writable flash flags
The valid and writable flags the EC sends back to the AP are incorrect. They are a little bit different on differnt chips, so let's move it to flash physical layer. This is not any causing problem, but we should fix this. BUG=chrome-os-partner:32745 TEST=make buildall BRANCH=samus Change-Id: Ibcda5ae770f5ea02cde094490997a5bc447df88f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222661 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/host/flash.c26
-rw-r--r--chip/lm4/flash.c26
-rw-r--r--chip/stm32/flash-stm32f.c26
-rw-r--r--chip/stm32/flash-stm32f0.c27
-rw-r--r--chip/stm32/flash-stm32l.c26
-rw-r--r--common/flash.c20
-rw-r--r--include/flash.h15
7 files changed, 149 insertions, 17 deletions
diff --git a/chip/host/flash.c b/chip/host/flash.c
index 892e4067a9..2be40b37df 100644
--- a/chip/host/flash.c
+++ b/chip/host/flash.c
@@ -118,6 +118,32 @@ int flash_physical_protect_now(int all)
return EC_SUCCESS;
}
+uint32_t flash_physical_get_valid_flags(void)
+{
+ return EC_FLASH_PROTECT_RO_AT_BOOT |
+ EC_FLASH_PROTECT_RO_NOW |
+ EC_FLASH_PROTECT_ALL_NOW;
+}
+
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
+{
+ uint32_t ret = 0;
+
+ /* If RO protection isn't enabled, its at-boot state can be changed. */
+ if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
+ ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
+
+ /*
+ * If entire flash isn't protected at this boot, it can be enabled if
+ * the WP GPIO is asserted.
+ */
+ if (!(cur_flags & EC_FLASH_PROTECT_ALL_NOW) &&
+ (cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
+ ret |= EC_FLASH_PROTECT_ALL_NOW;
+
+ return ret;
+}
+
int flash_pre_init(void)
{
uint32_t prot_flags;
diff --git a/chip/lm4/flash.c b/chip/lm4/flash.c
index c6b676d87b..dd9474f51d 100644
--- a/chip/lm4/flash.c
+++ b/chip/lm4/flash.c
@@ -204,6 +204,32 @@ int flash_physical_protect_now(int all)
return EC_SUCCESS;
}
+uint32_t flash_physical_get_valid_flags(void)
+{
+ return EC_FLASH_PROTECT_RO_AT_BOOT |
+ EC_FLASH_PROTECT_RO_NOW |
+ EC_FLASH_PROTECT_ALL_NOW;
+}
+
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
+{
+ uint32_t ret = 0;
+
+ /* If RO protection isn't enabled, its at-boot state can be changed. */
+ if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
+ ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
+
+ /*
+ * If entire flash isn't protected at this boot, it can be enabled if
+ * the WP GPIO is asserted.
+ */
+ if (!(cur_flags & EC_FLASH_PROTECT_ALL_NOW) &&
+ (cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
+ ret |= EC_FLASH_PROTECT_ALL_NOW;
+
+ return ret;
+}
+
/*****************************************************************************/
/* High-level APIs */
diff --git a/chip/stm32/flash-stm32f.c b/chip/stm32/flash-stm32f.c
index 68e6b7a8e6..299d40d5c1 100644
--- a/chip/stm32/flash-stm32f.c
+++ b/chip/stm32/flash-stm32f.c
@@ -67,6 +67,32 @@ int flash_physical_protect_now(int all)
}
}
+uint32_t flash_physical_get_valid_flags(void)
+{
+ return EC_FLASH_PROTECT_RO_AT_BOOT |
+ EC_FLASH_PROTECT_RO_NOW |
+ EC_FLASH_PROTECT_ALL_NOW;
+}
+
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
+{
+ uint32_t ret = 0;
+
+ /* If RO protection isn't enabled, its at-boot state can be changed. */
+ if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
+ ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
+
+ /*
+ * If entire flash isn't protected at this boot, it can be enabled if
+ * the WP GPIO is asserted.
+ */
+ if (!(cur_flags & EC_FLASH_PROTECT_ALL_NOW) &&
+ (cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
+ ret |= EC_FLASH_PROTECT_ALL_NOW;
+
+ return ret;
+}
+
int flash_physical_restore_state(void)
{
uint32_t reset_flags = system_get_reset_flags();
diff --git a/chip/stm32/flash-stm32f0.c b/chip/stm32/flash-stm32f0.c
index bbf3574c21..85e65c6ac4 100644
--- a/chip/stm32/flash-stm32f0.c
+++ b/chip/stm32/flash-stm32f0.c
@@ -42,3 +42,30 @@ int flash_physical_restore_state(void)
/* Nothing to restore */
return 0;
}
+
+uint32_t flash_physical_get_valid_flags(void)
+{
+ return EC_FLASH_PROTECT_RO_AT_BOOT |
+ EC_FLASH_PROTECT_ALL_AT_BOOT |
+ EC_FLASH_PROTECT_RO_NOW |
+ EC_FLASH_PROTECT_ALL_NOW;
+}
+
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
+{
+ uint32_t ret = 0;
+
+ /* If RO protection isn't enabled, its at-boot state can be changed. */
+ if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
+ ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
+
+ /*
+ * RW at-boot state can be set if WP GPIO is asserted and can always
+ * be cleared.
+ */
+ if (cur_flags & (EC_FLASH_PROTECT_ALL_AT_BOOT |
+ EC_FLASH_PROTECT_GPIO_ASSERTED))
+ ret |= EC_FLASH_PROTECT_ALL_AT_BOOT;
+
+ return ret;
+}
diff --git a/chip/stm32/flash-stm32l.c b/chip/stm32/flash-stm32l.c
index 98f46565a3..106e436c80 100644
--- a/chip/stm32/flash-stm32l.c
+++ b/chip/stm32/flash-stm32l.c
@@ -400,6 +400,32 @@ int flash_physical_protect_now(int all)
}
}
+uint32_t flash_physical_get_valid_flags(void)
+{
+ return EC_FLASH_PROTECT_RO_AT_BOOT |
+ EC_FLASH_PROTECT_RO_NOW |
+ EC_FLASH_PROTECT_ALL_NOW;
+}
+
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
+{
+ uint32_t ret = 0;
+
+ /* If RO protection isn't enabled, its at-boot state can be changed. */
+ if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
+ ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
+
+ /*
+ * If entire flash isn't protected at this boot, it can be enabled if
+ * the WP GPIO is asserted.
+ */
+ if (!(cur_flags & EC_FLASH_PROTECT_ALL_NOW) &&
+ (cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
+ ret |= EC_FLASH_PROTECT_ALL_NOW;
+
+ return ret;
+}
+
int flash_pre_init(void)
{
uint32_t reset_flags = system_get_reset_flags();
diff --git a/common/flash.c b/common/flash.c
index 15af5cd1e8..b6001751d5 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -624,23 +624,9 @@ static int flash_command_protect(struct host_cmd_handler_args *args)
r->valid_flags =
EC_FLASH_PROTECT_GPIO_ASSERTED |
EC_FLASH_PROTECT_ERROR_STUCK |
- EC_FLASH_PROTECT_RO_AT_BOOT |
- EC_FLASH_PROTECT_RO_NOW |
- EC_FLASH_PROTECT_ALL_NOW |
- EC_FLASH_PROTECT_ERROR_INCONSISTENT;
- r->writable_flags = 0;
-
- /* If RO protection isn't enabled, its at-boot state can be changed. */
- if (!(r->flags & EC_FLASH_PROTECT_RO_NOW))
- r->writable_flags |= EC_FLASH_PROTECT_RO_AT_BOOT;
-
- /*
- * If entire flash isn't protected at this boot, it can be enabled if
- * the WP GPIO is asserted.
- */
- if (!(r->flags & EC_FLASH_PROTECT_ALL_NOW) &&
- (r->flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
- r->writable_flags |= EC_FLASH_PROTECT_ALL_NOW;
+ EC_FLASH_PROTECT_ERROR_INCONSISTENT |
+ flash_physical_get_valid_flags();
+ r->writable_flags = flash_physical_get_writable_flags(r->flags);
args->response_size = sizeof(*r);
diff --git a/include/flash.h b/include/flash.h
index 0c6e11c429..a77d5a1cb2 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -110,6 +110,21 @@ int flash_physical_force_reload(void);
*/
int flash_physical_restore_state(void);
+/**
+ * Return the valid flash protect flags.
+ *
+ * @return a combination of EC_FLASH_PROTECT_* flags from ec_commands.h
+ */
+uint32_t flash_physical_get_valid_flags(void);
+
+/**
+ * Return the writable flash protect flags.
+ *
+ * @param cur_flags The current flash protect flags.
+ * @return a combination of EC_FLASH_PROTECT_* flags from ec_commands.h
+ */
+uint32_t flash_physical_get_writable_flags(uint32_t cur_flags);
+
/*****************************************************************************/
/* Low-level common code for use by flash modules. */