[PATCH] common: add custom autoboot_abort_key

Johannes Schneider johannes.schneider at leica-geosystems.com
Mon Sep 16 06:53:00 PDT 2024


Add the Kconfig options to select a compile-time custom key(s) that
can be used to enter the console when barebox prompts for:
"Hit <custom_key> to stop autoboot."

This commit also adds the option to set the global autoboot_abort_key's default
value to any of the available ones: 'any', 'ctrl-c' or the new 'custom'.

Signed-off-by: Johannes Schneider <johannes.schneider at leica-geosystems.com>
---
 common/Kconfig   | 34 ++++++++++++++++++++++++++++++++++
 common/startup.c |  8 +++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 4af0225..db9585c 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -408,6 +408,39 @@ config CBSIZE
 	prompt "Buffer size for input from the Console"
 	default 1024
 
+choice
+	prompt "autoboot_abort_key default"
+	help
+		Set the compile time default of global.autoboot_abort_key. Note that it
+		still possible to set the global to a different value during runtime.
+
+	config AUTOBOOT_ABORT_KEY_DEFAULT_ANY
+		bool "any"
+
+	config AUTOBOOT_ABORT_KEY_DEFAULT_CTRL_C
+		bool "ctrl-c"
+
+	config AUTOBOOT_ABORT_KEY_DEFAULT_CUSTOM
+		bool "custom"
+		select AUTOBOOT_ABORT_KEY_CUSTOM
+
+endchoice
+
+config AUTOBOOT_ABORT_KEY_DEFAULT
+	int
+	default 0 if AUTOBOOT_ABORT_KEY_DEFAULT_ANY
+	default 1 if AUTOBOOT_ABORT_KEY_DEFAULT_CTRL_C
+	default 2 if AUTOBOOT_ABORT_KEY_DEFAULT_CUSTOM
+
+config AUTOBOOT_ABORT_KEY_CUSTOM_KEY
+	depends on AUTOBOOT_ABORT_KEY_DEFAULT_CUSTOM
+	prompt "select a custom autoboot_abort_key"
+	string
+	default "c"
+	help
+		Set key to use as autoboot_abort_key.
+		If set to a string, any of the characters can be pressed to abort autoboot.
+
 config FIRMWARE
 	bool
 
diff --git a/common/startup.c b/common/startup.c
index 47b70a7..6b068a8 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -93,10 +93,13 @@ static int load_environment(void)
 }
 environment_initcall(load_environment);
 
-static int global_autoboot_abort_key;
+static int global_autoboot_abort_key = CONFIG_AUTOBOOT_ABORT_KEY_DEFAULT;
 static const char * const global_autoboot_abort_keys[] = {
 	"any",
 	"ctrl-c",
+#if defined CONFIG_AUTOBOOT_ABORT_KEY_CUSTOM_KEY
+	CONFIG_AUTOBOOT_ABORT_KEY_CUSTOM_KEY
+#endif
 };
 static int global_autoboot_timeout = 3;
 
@@ -202,6 +205,11 @@ enum autoboot_state do_autoboot_countdown(void)
 	case 1:
 		flags |= CONSOLE_COUNTDOWN_CTRLC;
 		break;
+#if defined CONFIG_AUTOBOOT_ABORT_KEY_CUSTOM_KEY
+	case 2:
+		abortkeys = xasprintf("%s%s", (abortkeys)?abortkeys:"", CONFIG_AUTOBOOT_ABORT_KEY_CUSTOM_KEY);
+		break;
+#endif
 	default:
 		break;
 	}
-- 
2.43.0




More information about the barebox mailing list