summaryrefslogtreecommitdiff
path: root/common/panic_output.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-02-13 15:29:33 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-02-18 04:53:51 +0000
commitd00847782480e492401ba3bc5a8a8e6f026b08ba (patch)
tree01c42b77ba518cf57e7512affcb833f0df61056f /common/panic_output.c
parent9cb03971f6852fa03df3290e44a8451e01774755 (diff)
downloadchrome-ec-d00847782480e492401ba3bc5a8a8e6f026b08ba.tar.gz
cortex-m*: Save panicinfo on non-exception panics
Make non-exception "software" panics such as stack overflow and assert failure save a panic log. Log the panic type in r4, and misc. panic data in r5 so that panic reasons can be distinguished. BUG=chrome-os-partner:36744 TEST=Manual on samus_pd. Run 'crash divzero' then 'panicinfo' after reboot. Verify that panic info is printed with "r4 :dead6660". Trigger stack overflow, verify that panic info is printed with "r4 :dead6661". BRANCH=Samus Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I5f7a8eb0a5c2ac5799d29bb241deb24fabf38f68 Reviewed-on: https://chromium-review.googlesource.com/249912 Tested-by: Alec Berg <alecaberg@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'common/panic_output.c')
-rw-r--r--common/panic_output.c66
1 files changed, 58 insertions, 8 deletions
diff --git a/common/panic_output.c b/common/panic_output.c
index 4f0f22d00d..af98c5953d 100644
--- a/common/panic_output.c
+++ b/common/panic_output.c
@@ -6,6 +6,7 @@
#include "common.h"
#include "console.h"
#include "cpu.h"
+#include "hooks.h"
#include "host_command.h"
#include "panic.h"
#include "printf.h"
@@ -82,8 +83,11 @@ void panic_reboot(void)
void panic_assert_fail(const char *fname, int linenum)
{
panic_printf("\nASSERTION FAILURE at %s:%d\n", fname, linenum);
-
+#ifdef CONFIG_SOFTWARE_PANIC
+ software_panic(PANIC_SW_ASSERT, linenum);
+#else
panic_reboot();
+#endif
}
#else
void panic_assert_fail(const char *msg, const char *func, const char *fname,
@@ -91,8 +95,11 @@ void panic_assert_fail(const char *msg, const char *func, const char *fname,
{
panic_printf("\nASSERTION FAILURE '%s' in %s() at %s:%d\n",
msg, func, fname, linenum);
-
+#ifdef CONFIG_SOFTWARE_PANIC
+ software_panic(PANIC_SW_ASSERT, linenum);
+#else
panic_reboot();
+#endif
}
#endif
#endif
@@ -108,6 +115,37 @@ struct panic_data *panic_get_data(void)
return pdata_ptr->magic == PANIC_DATA_MAGIC ? pdata_ptr : NULL;
}
+#ifdef CONFIG_SOFTWARE_PANIC
+static void panic_init(void)
+{
+ /* Log panic cause if watchdog caused reset */
+ if (system_get_reset_flags() & RESET_FLAG_WATCHDOG)
+ panic_log_watchdog();
+}
+DECLARE_HOOK(HOOK_INIT, panic_init, HOOK_PRIO_DEFAULT);
+#endif
+
+#ifdef CONFIG_CMD_STACKOVERFLOW
+static void stack_overflow_recurse(int n)
+{
+ ccprintf("+%d", n);
+
+ /*
+ * Force task context switch, since that's where we do stack overflow
+ * checking.
+ */
+ msleep(10);
+
+ stack_overflow_recurse(n+1);
+
+ /*
+ * Do work after the recursion, or else the compiler uses tail-chaining
+ * and we don't actually consume additional stack.
+ */
+ ccprintf("-%d", n);
+}
+#endif /* CONFIG_CMD_STACKOVERFLOW */
+
/*****************************************************************************/
/* Console commands */
@@ -116,14 +154,26 @@ static int command_crash(int argc, char **argv)
if (argc < 2)
return EC_ERROR_PARAM1;
- if (!strcasecmp(argv[1], "divzero")) {
- int a = 1, b = 0;
+ if (!strcasecmp(argv[1], "assert")) {
+ ASSERT(0);
+ } else if (!strcasecmp(argv[1], "divzero")) {
+ int zero = 0;
cflush();
- ccprintf("%08x", a / b);
+ if (argc >= 3 && !strcasecmp(argv[2], "unsigned"))
+ ccprintf("%08x", (unsigned long)1 / zero);
+ else
+ ccprintf("%08x", (long)1 / zero);
+#ifdef CONFIG_CMD_STACKOVERFLOW
+ } else if (!strcasecmp(argv[1], "stack")) {
+ stack_overflow_recurse(1);
+#endif
} else if (!strcasecmp(argv[1], "unaligned")) {
cflush();
ccprintf("%08x", *(int *)0xcdef);
+ } else if (!strcasecmp(argv[1], "watchdog")) {
+ while (1)
+ ;
} else {
return EC_ERROR_PARAM1;
}
@@ -132,9 +182,9 @@ static int command_crash(int argc, char **argv)
return EC_ERROR_UNKNOWN;
}
DECLARE_CONSOLE_COMMAND(crash, command_crash,
- "[divzero | unaligned]",
- "Crash the system (for testing)",
- NULL);
+ "[assert | divzero | stack | unaligned | watchdog] [options]",
+ "Crash the system (for testing)",
+ NULL);
static int command_panicinfo(int argc, char **argv)
{