From 5cd0879c3e4a65746204d412218ba5ef8c0c1c83 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 22 Oct 2025 07:27:36 +0100 Subject: [PATCH] panic: Provide a way to poweroff on panic For sandbox it normally doesn't make sense to reset when a panic occurs, since presumably it will just happen again. Add an option to power off instead. Co-developed-by: Claude Signed-off-by: Simon Glass --- lib/Kconfig | 8 ++++++++ lib/panic.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index c45a98313aa..9de4667731e 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -263,6 +263,14 @@ config PANIC_HANG development since you can try to debug the conditions that lead to the situation. +config PANIC_POWEROFF + bool "Power off the system on fatal error" + help + Define this option to power off the system in case of a fatal error, + instead of resetting. This is useful for development and testing to + avoid infinite reset loops when debugging issues like stack smashing. + The system will power off using sysreset. + config REGEX bool "Enable regular expression support" default y if NET diff --git a/lib/panic.c b/lib/panic.c index 0f578b5b513..adc338860a5 100644 --- a/lib/panic.c +++ b/lib/panic.c @@ -13,6 +13,9 @@ #if !defined(CONFIG_PANIC_HANG) #include #endif +#if defined(CONFIG_PANIC_POWEROFF) +#include +#endif #include #include @@ -23,6 +26,11 @@ static void panic_finish(void) putc('\n'); #if defined(CONFIG_PANIC_HANG) hang(); +#elif defined(CONFIG_PANIC_POWEROFF) + flush(); /* flush the panic message before power off */ + + sysreset_walk(SYSRESET_POWER_OFF); + hang(); /* hang if power off fails */ #else flush(); /* flush the panic message before reset */