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