mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] common: add custom autoboot_abort_key
@ 2024-09-16 13:53 Johannes Schneider
  2024-10-22  9:53 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schneider @ 2024-09-16 13:53 UTC (permalink / raw)
  To: barebox; +Cc: Johannes Schneider

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@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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] common: add custom autoboot_abort_key
  2024-09-16 13:53 [PATCH] common: add custom autoboot_abort_key Johannes Schneider
@ 2024-10-22  9:53 ` Sascha Hauer
  2024-11-01  5:43   ` SCHNEIDER Johannes
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2024-10-22  9:53 UTC (permalink / raw)
  To: Johannes Schneider; +Cc: barebox

Hi Johannes,

On Mon, Sep 16, 2024 at 03:53:00PM +0200, Johannes Schneider wrote:
> 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."

Having a custom key to stop autoboot is generally fine. Defining the key
at compile time not so.

Instead we could convert autoboot_abort_key from
globalvar_add_simple_enum() to dev_add_param_string(&global_device,...)
the set function could then accept "any", "ctrl-c" or any other single
digit string.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] common: add custom autoboot_abort_key
  2024-10-22  9:53 ` Sascha Hauer
@ 2024-11-01  5:43   ` SCHNEIDER Johannes
  0 siblings, 0 replies; 3+ messages in thread
From: SCHNEIDER Johannes @ 2024-11-01  5:43 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hoi,

> 
> Having a custom key to stop autoboot is generally fine. Defining the key
> at compile time not so.
>

i was at first wondering "then how are we supposed to configure it" but looking
through the code how 'global_autoboot_abort_key=1' for ctrl-c was nowhere to be
found in the codebase, i realized that the <any> is just the
global.autoboot_abort_key no-one ever set to anything else :-D

... and i should have set it up in a way that you'd feed barebox an
env/nv/autoboot_abort_key
with 'any', 'ctrl-c' or the one key -- right?

>
> Instead we could convert autoboot_abort_key from
> globalvar_add_simple_enum() to dev_add_param_string(&global_device,...)
> the set function could then accept "any", "ctrl-c" or any other single
> digit string.
>

got it - i'll rework it and send out a v2 :-)

> Sascha
> 
> --


gruß
Johannes


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-01  5:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-16 13:53 [PATCH] common: add custom autoboot_abort_key Johannes Schneider
2024-10-22  9:53 ` Sascha Hauer
2024-11-01  5:43   ` SCHNEIDER Johannes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox