[PATCH v2 005/113] common: add option to poweroff system on failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When developing using Qemu and KASAN/Hardening options enabled, it can
be useful to just terminate Qemu on an error, because a stack trace is
already printed to console and restarting barebox or hanging just
results in the developer having to kill the process.

For this use case, add shutdown as third option besides hang and reset.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 common/Kconfig | 44 ++++++++++++++++++++++++++++++++++----------
 common/misc.c  | 12 ++++++++----
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index d16c8696dad4..cb0fef46ccbe 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -353,16 +353,40 @@ config RELOCATABLE
 	  allowing it to relocate to the end of the available RAM. This
 	  way you have the whole memory in a single piece.
 
-config PANIC_HANG
-	bool "hang the system in case of a fatal error"
-	help
-	  This option enables stop of the system in case of a
-	  fatal error, so that you have to reset it manually.
-	  This is probably NOT a good idea for an embedded
-	  system where you want the system to reboot
-	  automatically as fast as possible, but it may be
-	  useful during development since you can try to debug
-	  the conditions that lead to the situation.
+choice
+	prompt "Configure action on fatal error"
+	default PANIC_RESET
+
+	config PANIC_POWEROFF
+		bool "power off the system"
+		help
+		  This option shuts down the system in case of a
+		  fatal error, so that you have to power it on manually.
+		  This is probably NOT a good idea for an embedded
+		  system where you want the system to reboot
+		  automatically as fast as possible, but it may be
+		  useful in emulation, because the system returns
+		  to parent shell immediately.
+
+	config PANIC_HANG
+		bool "hang the system"
+		help
+		  This option enables stop of the system in case of a
+		  fatal error, so that you have to reset it manually.
+		  This is probably NOT a good idea for an embedded
+		  system where you want the system to reboot
+		  automatically as fast as possible, but it may be
+		  useful during development since you can try to debug
+		  the conditions that lead to the situation.
+
+	config PANIC_RESET
+		bool "reset the system"
+		help
+		  This option enables reset of the system in case of a
+		  fatal error, so you don't have to reset it manually.
+		  This is the recommended configuration in production.
+
+endchoice
 
 config PROMPT
 	string
diff --git a/common/misc.c b/common/misc.c
index e266f0951ee9..04ff4e6eb5c5 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -13,6 +13,7 @@
 #include <led.h>
 #include <of.h>
 #include <restart.h>
+#include <poweroff.h>
 #include <linux/stringify.h>
 
 int errno;
@@ -226,12 +227,15 @@ static void __noreturn do_panic(bool stacktrace, const char *fmt, va_list ap)
 
 	led_trigger(LED_TRIGGER_PANIC, TRIGGER_ENABLE);
 
-	if (IS_ENABLED(CONFIG_PANIC_HANG)) {
+	if (IS_ENABLED(CONFIG_PANIC_HANG))
 		hang();
-	} else {
-		udelay(100000);	/* allow messages to go out */
+
+	udelay(100000);	/* allow messages to go out */
+
+	if (IS_ENABLED(CONFIG_PANIC_POWEROFF))
+		poweroff_machine();
+	else
 		restart_machine();
-	}
 }
 
 void __noreturn panic(const char *fmt, ...)
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux