[Concept,04/24] panic: Provide a way to poweroff on panic
Commit Message
From: Simon Glass <sjg@chromium.org>
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 <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
lib/Kconfig | 8 ++++++++
lib/panic.c | 8 ++++++++
2 files changed, 16 insertions(+)
@@ -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
@@ -13,6 +13,9 @@
#if !defined(CONFIG_PANIC_HANG)
#include <command.h>
#endif
+#if defined(CONFIG_PANIC_POWEROFF)
+#include <sysreset.h>
+#endif
#include <linux/delay.h>
#include <stdio.h>
@@ -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 */