From: Johannes Schneider <johannes.schneider@leica-geosystems.com>
To: barebox@lists.infradead.org, s.hauer@pengutronix.de
Cc: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Subject: [PATCH v2] common: add custom autoboot_abort_key
Date: Sat, 2 Nov 2024 15:43:42 +0100 [thread overview]
Message-ID: <20241102144342.2464331-1-johannes.schneider@leica-geosystems.com> (raw)
Extend the autoboot_abort_key handling to alow custom
abort keys.
Allowed values to set in the env/nv/autoboot_abort_key
are any single ascii charater corresponding to the desired keyboard
key, or the strings 'any' or 'ctrl-c'
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
common/startup.c | 53 ++++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/common/startup.c b/common/startup.c
index 47b70a7..125bcf1 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -93,11 +93,7 @@ static int load_environment(void)
}
environment_initcall(load_environment);
-static int global_autoboot_abort_key;
-static const char * const global_autoboot_abort_keys[] = {
- "any",
- "ctrl-c",
-};
+static char *global_autoboot_abort_key;
static int global_autoboot_timeout = 3;
static const char * const global_autoboot_states[] = {
@@ -187,24 +183,22 @@ enum autoboot_state do_autoboot_countdown(void)
menu_exists = stat(MENUFILE, &s) == 0;
if (menu_exists) {
- printf("\nHit m for menu or %s to stop autoboot: ",
- global_autoboot_abort_keys[global_autoboot_abort_key]);
abortkeys = "m";
- } else {
- printf("\nHit %s to stop autoboot: ",
- global_autoboot_abort_keys[global_autoboot_abort_key]);
}
- switch (global_autoboot_abort_key) {
- case 0:
+ if (!global_autoboot_abort_key ||
+ !strcmp(global_autoboot_abort_key, "any"))
flags |= CONSOLE_COUNTDOWN_ANYKEY;
- break;
- case 1:
+ else if (!strcmp(global_autoboot_abort_key, "ctrl-c"))
flags |= CONSOLE_COUNTDOWN_CTRLC;
- break;
- default:
- break;
- }
+ else
+ abortkeys = xasprintf("%s%s",
+ (abortkeys)?abortkeys:"",
+ global_autoboot_abort_key);
+
+ printf("\nHit %s%s to stop autoboot: ",
+ (menu_exists)?"m for menu or ":"",
+ (global_autoboot_abort_key)?global_autoboot_abort_key:"any");
command_slice_release();
ret = console_countdown(global_autoboot_timeout, flags, abortkeys,
@@ -221,12 +215,27 @@ enum autoboot_state do_autoboot_countdown(void)
return autoboot_state;
}
+static int autoboot_abort_key_set(struct param_d *p, void *priv)
+{
+ if (!strcmp(global_autoboot_abort_key, "any"))
+ return 0;
+ if (!strcmp(global_autoboot_abort_key, "ctrl-c"))
+ return 0;
+
+ if (strlen(global_autoboot_abort_key) != 1)
+ return -EINVAL;
+
+ return 0;
+}
+
static int register_autoboot_vars(void)
{
- globalvar_add_simple_enum("autoboot_abort_key",
+ dev_add_param_string(&global_device,
+ "autoboot_abort_key",
+ autoboot_abort_key_set,
+ NULL,
&global_autoboot_abort_key,
- global_autoboot_abort_keys,
- ARRAY_SIZE(global_autoboot_abort_keys));
+ NULL);
globalvar_add_simple_int("autoboot_timeout",
&global_autoboot_timeout, "%u");
globalvar_add_simple_enum("autoboot",
@@ -402,6 +411,6 @@ void shutdown_barebox(void)
BAREBOX_MAGICVAR(global.autoboot,
"Autoboot state. Possible values: countdown (default), abort, menu, boot");
BAREBOX_MAGICVAR(global.autoboot_abort_key,
- "Which key allows to interrupt autoboot. Possible values: any, ctrl-c");
+ "Which key allows to interrupt autoboot. Possible values: 'any', 'ctrl-c' or any other single ascii character.");
BAREBOX_MAGICVAR(global.autoboot_timeout,
"Timeout before autoboot starts in seconds");
--
2.43.0
next reply other threads:[~2024-11-02 14:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-02 14:43 Johannes Schneider [this message]
2024-11-04 11:54 ` Sascha Hauer
2024-11-04 11:55 ` Sascha Hauer
2024-11-04 12:55 ` SCHNEIDER Johannes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241102144342.2464331-1-johannes.schneider@leica-geosystems.com \
--to=johannes.schneider@leica-geosystems.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox