* [PATCH v2] common: add custom autoboot_abort_key
@ 2024-11-02 14:43 Johannes Schneider
2024-11-04 11:54 ` Sascha Hauer
2024-11-04 11:55 ` Sascha Hauer
0 siblings, 2 replies; 4+ messages in thread
From: Johannes Schneider @ 2024-11-02 14:43 UTC (permalink / raw)
To: barebox, s.hauer; +Cc: Johannes Schneider
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] common: add custom autoboot_abort_key
2024-11-02 14:43 [PATCH v2] common: add custom autoboot_abort_key Johannes Schneider
@ 2024-11-04 11:54 ` Sascha Hauer
2024-11-04 11:55 ` Sascha Hauer
1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-11-04 11:54 UTC (permalink / raw)
To: barebox, Johannes Schneider
On Sat, 02 Nov 2024 15:43:42 +0100, Johannes Schneider wrote:
> 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'
>
> [...]
Applied, thanks!
[1/1] common: add custom autoboot_abort_key
https://git.pengutronix.de/cgit/barebox/commit/?id=8b559bd63205 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] common: add custom autoboot_abort_key
2024-11-02 14:43 [PATCH v2] common: add custom autoboot_abort_key Johannes Schneider
2024-11-04 11:54 ` Sascha Hauer
@ 2024-11-04 11:55 ` Sascha Hauer
2024-11-04 12:55 ` SCHNEIDER Johannes
1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2024-11-04 11:55 UTC (permalink / raw)
To: Johannes Schneider; +Cc: barebox
On Sat, Nov 02, 2024 at 03:43:42PM +0100, Johannes Schneider wrote:
> 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);
This memory is never freed. I converted it into a static array while
applying.
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] 4+ messages in thread
* Re: [PATCH v2] common: add custom autoboot_abort_key
2024-11-04 11:55 ` Sascha Hauer
@ 2024-11-04 12:55 ` SCHNEIDER Johannes
0 siblings, 0 replies; 4+ messages in thread
From: SCHNEIDER Johannes @ 2024-11-04 12:55 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
> Subject: Re: [PATCH v2] common: add custom autoboot_abort_key
>
> This email is not from Hexagon’s Office 365 instance. Please be careful while clicking links, opening attachments, or replying to this email.
>
>
> On Sat, Nov 02, 2024 at 03:43:42PM +0100, Johannes Schneider wrote:
> > 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);
>
> This memory is never freed. I converted it into a static array while
> applying.
>
> Sascha
>
ups :-S
thanks! :-)
gruß
Johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-04 12:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-02 14:43 [PATCH v2] common: add custom autoboot_abort_key Johannes Schneider
2024-11-04 11:54 ` Sascha Hauer
2024-11-04 11:55 ` Sascha Hauer
2024-11-04 12:55 ` SCHNEIDER Johannes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox