From 0037fb8dfcd7136d40e608ad9973331bd82d9a80 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Fri, 1 Dec 2017 11:16:58 -0800 Subject: [PATCH] system: Log PC and task id on watchdog For debug, in common code let's log the watchdog PC and task id as our SW panic params. BUG=chromium:790006 BRANCH=none TEST=manually test scarlet rev2 from a1-a3, b1-b2: (a1) Add 'while(1);' in button ISR (a2) Boot and press the button (a3) When watchdog is triggeried, check with 'panicinfo' that saved R5 is the PC for button ISR. (b1) 'crash watchdog' in EC console (b2) Check with 'panicinfo' that CONSOLE task id is saved in EXCEPTION and PC is saved in R5. Change-Id: I64d2fcf594dd24b0951e002ab8e80ebcac2d1def Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/803618 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Vincent Palatin --- chip/npcx/watchdog.c | 14 -------------- common/system.c | 17 ++++++++++++----- core/cortex-m/watchdog.c | 3 +++ core/cortex-m0/watchdog.c | 4 ++++ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/chip/npcx/watchdog.c b/chip/npcx/watchdog.c index 1036523996..4b43a09db2 100644 --- a/chip/npcx/watchdog.c +++ b/chip/npcx/watchdog.c @@ -59,7 +59,6 @@ static uint8_t watchdog_count(void) void __keep watchdog_check(uint32_t excep_lr, uint32_t excep_sp) { int wd_cnt; - uint32_t panic_info; /* Clear timeout status for event */ SET_BIT(NPCX_ITCTS(ITIM_WDG_NO), NPCX_ITCTS_TO_STS); @@ -79,19 +78,6 @@ void __keep watchdog_check(uint32_t excep_lr, uint32_t excep_sp) watchdog_trace(excep_lr, excep_sp); cflush(); - /* - * Log the panic PC if watchdog occurred in exception context - * or the watchdog task # otherwise. - */ - panic_info = ((excep_lr & 0xf) == 1) ? - ((uint32_t *)excep_sp)[6] : task_get_current(); - /* - * panic_reboot() will be called by software_panic(), so this - * typically will not return, and panic reason will appear - * as "soft". - */ - software_panic(PANIC_SW_WATCHDOG, panic_info); - /* Trigger watchdog immediately */ system_watchdog_reset(); } diff --git a/common/system.c b/common/system.c index fcd7e0d795..48c26776b9 100644 --- a/common/system.c +++ b/common/system.c @@ -788,12 +788,19 @@ void system_common_pre_init(void) #ifdef CONFIG_SOFTWARE_PANIC /* - * Log panic cause if watchdog caused reset. This - * must happen before calculating jump_data address - * because it might change panic pointer. + * Log panic cause if watchdog caused reset and panic cause + * was not already logged. This must happen before calculating + * jump_data address because it might change panic pointer. */ - if (system_get_reset_flags() & RESET_FLAG_WATCHDOG) - panic_set_reason(PANIC_SW_WATCHDOG, 0, 0); + if (system_get_reset_flags() & RESET_FLAG_WATCHDOG) { + uint32_t reason; + uint32_t info; + uint8_t exception; + + panic_get_reason(&reason, &info, &exception); + if (reason != PANIC_SW_WATCHDOG) + panic_set_reason(PANIC_SW_WATCHDOG, 0, 0); + } #endif /* diff --git a/core/cortex-m/watchdog.c b/core/cortex-m/watchdog.c index 6a047e662b..a67903df62 100644 --- a/core/cortex-m/watchdog.c +++ b/core/cortex-m/watchdog.c @@ -25,6 +25,9 @@ void __keep watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) stack = (uint32_t *)psp; } + panic_set_reason(PANIC_SW_WATCHDOG, stack[6], + (excep_lr & 0xf) == 1 ? 0xff : task_get_current()); + panic_printf("### WATCHDOG PC=%08x / LR=%08x / pSP=%08x ", stack[6], stack[5], psp); if ((excep_lr & 0xf) == 1) diff --git a/core/cortex-m0/watchdog.c b/core/cortex-m0/watchdog.c index a4e34d51bf..3d53b4979c 100644 --- a/core/cortex-m0/watchdog.c +++ b/core/cortex-m0/watchdog.c @@ -25,6 +25,10 @@ void watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) stack = (uint32_t *)psp; } + /* Log PC. If we were in task context, log task id too. */ + panic_set_reason(PANIC_SW_WATCHDOG, stack[6], + (excep_lr & 0xf) == 1 ? 0xff : task_get_current()); + panic_printf("### WATCHDOG PC=%08x / LR=%08x / pSP=%08x ", stack[6], stack[5], psp); if ((excep_lr & 0xf) == 1)