summaryrefslogtreecommitdiff
path: root/chip/lm4/system.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-03-04 10:35:25 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-14 03:22:37 +0000
commit90ef8b700629381ac62aae4f87612ef84b32cb35 (patch)
treef708bd83c0ac30b46f2bf3a5d79991cb4d80c64d /chip/lm4/system.c
parent911da8c150d9d38b9a9f14453098bd1e0f838b49 (diff)
downloadchrome-ec-90ef8b700629381ac62aae4f87612ef84b32cb35.tar.gz
lm4: stm32: Store panic data in backup registers on hard reset
On hard reset / hibernate, RAM will be erased and panic data will normally be lost. When software panic data saving is enabled, try to save this data just before hard reset and restore it when we come back up. BUG=chrome-os-partner:37380 TEST=Manual on Samus with WP + SW sync enabled. Boot AP, then run "crash divzero" on console. After hard reset, verify that "panicinfo" dumps data and shows divzero exception code. BRANCH=Samus Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I9516dd4b6db12ef35e512cc4710f9b97d7e663cb Reviewed-on: https://chromium-review.googlesource.com/255912 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/lm4/system.c')
-rw-r--r--chip/lm4/system.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/chip/lm4/system.c b/chip/lm4/system.c
index 78db1b38a3..38cde27e1c 100644
--- a/chip/lm4/system.c
+++ b/chip/lm4/system.c
@@ -10,6 +10,7 @@
#include "console.h"
#include "cpu.h"
#include "host_command.h"
+#include "panic.h"
#include "registers.h"
#include "system.h"
#include "task.h"
@@ -18,9 +19,14 @@
/* Indices for hibernate data registers */
enum hibdata_index {
- HIBDATA_INDEX_SCRATCHPAD, /* General-purpose scratchpad */
- HIBDATA_INDEX_WAKE, /* Wake reasons for hibernate */
- HIBDATA_INDEX_SAVED_RESET_FLAGS /* Saved reset flags */
+ HIBDATA_INDEX_SCRATCHPAD, /* General-purpose scratchpad */
+ HIBDATA_INDEX_WAKE, /* Wake reasons for hibernate */
+ HIBDATA_INDEX_SAVED_RESET_FLAGS, /* Saved reset flags */
+#ifdef CONFIG_SOFTWARE_PANIC
+ HIBDATA_INDEX_SAVED_PANIC_REASON, /* Saved panic reason */
+ HIBDATA_INDEX_SAVED_PANIC_INFO, /* Saved panic data */
+ HIBDATA_INDEX_SAVED_PANIC_EXCEPTION /* Saved panic exception code */
+#endif
};
/* Flags for HIBDATA_INDEX_WAKE */
@@ -385,6 +391,10 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds)
void system_pre_init(void)
{
uint32_t hibctl;
+#ifdef CONFIG_SOFTWARE_PANIC
+ uint32_t reason, info;
+ uint8_t exception;
+#endif
/*
* Enable clocks to the hibernation module in run, sleep,
@@ -441,6 +451,19 @@ void system_pre_init(void)
check_reset_cause();
+#ifdef CONFIG_SOFTWARE_PANIC
+ /* Restore then clear saved panic reason */
+ reason = hibdata_read(HIBDATA_INDEX_SAVED_PANIC_REASON);
+ info = hibdata_read(HIBDATA_INDEX_SAVED_PANIC_INFO);
+ exception = hibdata_read(HIBDATA_INDEX_SAVED_PANIC_EXCEPTION);
+ if (reason || info || exception) {
+ panic_set_reason(reason, info, exception);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_REASON, 0);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_INFO, 0);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_EXCEPTION, 0);
+ }
+#endif
+
/* Initialize bootcfg if needed */
if (LM4_SYSTEM_BOOTCFG != CONFIG_BOOTCFG_VALUE) {
/* read-modify-write */
@@ -473,6 +496,17 @@ void system_reset(int flags)
hibdata_write(HIBDATA_INDEX_SAVED_RESET_FLAGS, save_flags);
if (flags & SYSTEM_RESET_HARD) {
+#ifdef CONFIG_SOFTWARE_PANIC
+ uint32_t reason, info;
+ uint8_t exception;
+
+ /* Panic data will be wiped by hard reset, so save it */
+ panic_get_reason(&reason, &info, &exception);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_REASON, reason);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_INFO, info);
+ hibdata_write(HIBDATA_INDEX_SAVED_PANIC_EXCEPTION, exception);
+#endif
+
/*
* Bounce through hibernate to trigger a hard reboot. Do
* not wake on wake pin, since we need the full duration.