summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2012-08-31 10:57:49 -0700
committerGerrit <chrome-bot@google.com>2012-09-05 10:03:16 -0700
commitf7291a50b8055f9ec0c69d79c2d5f2a881b53df8 (patch)
tree24cd1d65fa081ffc7237aa78fa8b775fa046486d
parente1f4dfc0826fc35ace68324a6ff1d1f109a37264 (diff)
downloadchrome-ec-f7291a50b8055f9ec0c69d79c2d5f2a881b53df8.tar.gz
stm32: Squeeze fakewp backup register for VbNvContext
We squeeze 2 bytes out of fakewp backup register so that we would have full 16 bytes for VbNvContext. As fakewp will go away real soon and it needs just 1 bits, we move it to saved reset flags register's most significant bit, which is currently unused. Signed-off-by: Che-Liang Chiou <clchiou@chromium.org> BRANCH=snow BUG=chrome-os-partner:10660,13094 TEST=manual Make sure reset flags are still preserved: 1. reset with keyboard. flags -> reset-pin 2. trigger watchdog reset. flags -> reset-pin watchdog 3. 'reboot soft preserve' flags -> reset-pin watchdog soft 4. trigger watchdog reset. flags -> reset-pin watchdog 5. 'reboot soft' flags -> reset-pin soft Make sure fakewp is still preserved: 1. 'flashinfo' -> no flags 2. 'fakewp 1' -> 'wp_gpio_asserted' 3. 'flashwp enable' -> 'wp_gpio_asserted ro_at_boot' 4. 'reboot' -> 'wp_gpio_asserted ro_at_boot ro_now' 5. 'fakewp 0' -> 'ro_at_boot ro_now' 6. 'reboot' -> 'ro_at_boot' 7. 'fakewp 1' -> 'wp_gpio_asserted ro_at_boot' 8. 'flashwp rw' -> 'wp_gpio_asserted ro_at_boot rw_at_boot' 9. 'reboot' -> 'wp_gpio_asserted ro_at_boot ro_now rw_at_boot rw_now' 10.'flashwp disable'-> error 7 11.'flashwp norw' -> 'wp_gpio_asserted ro_at_boot ro_now rw_now' 12.'reboot' -> 'wp_gpio_asserted ro_at_boot ro_now' Change-Id: Ibb7dc8aa224d3226bbaac217e494565e448b5858 Reviewed-on: https://gerrit.chromium.org/gerrit/32041 Commit-Ready: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/stm32/system.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/chip/stm32/system.c b/chip/stm32/system.c
index 74e81d5a70..f5f7dff73d 100644
--- a/chip/stm32/system.c
+++ b/chip/stm32/system.c
@@ -9,16 +9,16 @@
#include "registers.h"
#include "system.h"
#include "task.h"
+#include "util.h"
#include "version.h"
#include "watchdog.h"
+/* TODO: Fake WP is stored at most significant bit of saved reset flags to save
+ * space. Remove it when we have real write protect pin */
+
enum bkpdata_index {
BKPDATA_INDEX_SCRATCHPAD, /* General-purpose scratchpad */
BKPDATA_INDEX_SAVED_RESET_FLAGS,/* Saved reset flags */
- BKPDATA_INDEX_FAKE_WP, /* Fake write-protect pin */
- /* TODO: Remove this when we have real
- * write protect pin.
- */
};
@@ -55,12 +55,15 @@ static void check_reset_cause(void)
uint32_t raw_cause = STM32_RCC_CSR;
uint32_t pwr_status = STM32_PWR_CSR;
+ uint32_t fake_wp = flags & 0x8000;
+ flags &= ~0x8000;
+
/* Clear the hardware reset cause by setting the RMVF bit */
STM32_RCC_CSR |= 1 << 24;
/* Clear SBF in PWR_CSR */
STM32_PWR_CR |= 1 << 3;
/* Clear saved reset flags */
- bkpdata_write(BKPDATA_INDEX_SAVED_RESET_FLAGS, 0);
+ bkpdata_write(BKPDATA_INDEX_SAVED_RESET_FLAGS, 0 | fake_wp);
if (raw_cause & 0x60000000) {
/* IWDG or WWDG
@@ -140,9 +143,16 @@ void system_reset(int flags)
{
uint32_t save_flags = 0;
+ uint32_t fake_wp =
+ bkpdata_read(BKPDATA_INDEX_SAVED_RESET_FLAGS) & 0x8000;
+
/* Disable interrupts to avoid task swaps during reboot */
interrupt_disable();
+ /* TODO: Check if a collision between reset flags and fake wp occurred.
+ * Remove this when we have real write protect pin. */
+ ASSERT(!(system_get_reset_flags() & 0x8000));
+
/* Save current reset reasons if necessary */
if (flags & SYSTEM_RESET_PRESERVE_FLAGS)
save_flags = system_get_reset_flags() | RESET_FLAG_PRESERVED;
@@ -154,7 +164,7 @@ void system_reset(int flags)
if (flags & SYSTEM_RESET_HARD)
save_flags |= RESET_FLAG_HARD;
- bkpdata_write(BKPDATA_INDEX_SAVED_RESET_FLAGS, save_flags);
+ bkpdata_write(BKPDATA_INDEX_SAVED_RESET_FLAGS, save_flags | fake_wp);
if (flags & SYSTEM_RESET_HARD) {
/* Ask the watchdog to trigger a hard reboot */
@@ -210,12 +220,22 @@ const char *system_get_chip_revision(void)
/* TODO: crosbug.com/p/12036 */
int system_set_fake_wp(int val)
{
- return bkpdata_write(BKPDATA_INDEX_FAKE_WP, (uint16_t)val);
+ uint16_t flags = bkpdata_read(BKPDATA_INDEX_SAVED_RESET_FLAGS);
+
+ if (val)
+ flags |= 0x8000;
+ else
+ flags &= ~0x8000;
+
+ return bkpdata_write(BKPDATA_INDEX_SAVED_RESET_FLAGS, flags);
}
/* TODO: crosbug.com/p/12036 */
int system_get_fake_wp(void)
{
- return bkpdata_read(BKPDATA_INDEX_FAKE_WP);
+ if (bkpdata_read(BKPDATA_INDEX_SAVED_RESET_FLAGS) & 0x8000)
+ return 1;
+ else
+ return 0;
}