From 83c79707400d66706071e6d6037558e531e07412 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Thu, 6 Apr 2017 20:10:03 +0200 Subject: [PATCH] Add support for multikey autoboot stop string This allows to define string (in environment variable 'bootstopkey') used to interrupt autobooting process. It works in similar way as in upstream U-Boot version. If variable is not defined in environment, default approach (any key) will be used. Variable can be also predefined during compilation with CONFIG_AUTOBOOT_STOP_STR define. This closes #136 --- u-boot/common/env_common.c | 3 + u-boot/common/environment.c | 3 + u-boot/common/main.c | 86 ++++++++++++++++++++------- u-boot/include/configs/qca9k_common.h | 4 -- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/u-boot/common/env_common.c b/u-boot/common/env_common.c index 722add9..99a7fd1 100644 --- a/u-boot/common/env_common.c +++ b/u-boot/common/env_common.c @@ -63,6 +63,9 @@ uchar default_environment[] = { #if defined(CONFIG_BOOTCOMMAND) "bootcmd=" CONFIG_BOOTCOMMAND "\0" #endif +#if defined(CONFIG_AUTOBOOT_STOP_STR) + "bootstopkey=" CONFIG_AUTOBOOT_STOP_STR "\0" +#endif #if defined(CONFIG_RAMBOOTCOMMAND) "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" #endif diff --git a/u-boot/common/environment.c b/u-boot/common/environment.c index 31bcd8a..04ea3ff 100644 --- a/u-boot/common/environment.c +++ b/u-boot/common/environment.c @@ -122,6 +122,9 @@ env_t environment __PPCENV__ = { #if defined(CONFIG_BOOTCOMMAND) "bootcmd=" CONFIG_BOOTCOMMAND "\0" #endif +#if defined(CONFIG_AUTOBOOT_STOP_STR) + "bootstopkey=" CONFIG_AUTOBOOT_STOP_STR "\0" +#endif #if defined(CONFIG_RAMBOOTCOMMAND) "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" #endif diff --git a/u-boot/common/main.c b/u-boot/common/main.c index a8d708c..c550812 100644 --- a/u-boot/common/main.c +++ b/u-boot/common/main.c @@ -32,6 +32,8 @@ DECLARE_GLOBAL_DATA_PTR; #endif +#define MAX_STOPSTR_LEN 16 + static char *delete_char(char *buffer, char *p, int *colp, int *np, int plen); static int parse_line(char *, char *[]); @@ -49,7 +51,13 @@ static char tab_seq[] = " "; /* used to expand TABs */ static __inline__ int abortboot(int bootdelay) { int abort = 0; - char stopc; + int tested = 0; + int stopstr_len = 0; + int envstopstr_len = 0; + + char c; + char *envstopstr; + char stopstr[MAX_STOPSTR_LEN] = { 0 }; #if defined(CONFIG_SILENT_CONSOLE) if (gd->flags & GD_FLG_SILENT) { @@ -59,35 +67,71 @@ static __inline__ int abortboot(int bootdelay) } #endif - if (bootdelay > 0) { + if (bootdelay <= 0) + return abort; + + /* Check value of 'bootstopkey' and just ignore it if it's over limit */ + envstopstr = getenv("bootstopkey"); + if (envstopstr) { + envstopstr_len = strlen(envstopstr); + + if (envstopstr_len > MAX_STOPSTR_LEN) + envstopstr = NULL; + } + #if defined(CONFIG_MENUPROMPT) - printf(CONFIG_MENUPROMPT, bootdelay); + printf(CONFIG_MENUPROMPT, bootdelay); #else - printf("Hit any key to stop booting: %2d ", bootdelay); + /* + * Use custom CONFIG_MENUPROMPT if bootstopkey + * string contains nonprintable characters (e.g. ESC) + */ + if (envstopstr) + printf("Enter '%s' to stop booting: %2d", envstopstr, bootdelay); + else + printf("Hit any key to stop booting: %2d", bootdelay); #endif - while ((bootdelay > 0) && (!abort)) { - int i; + while ((bootdelay > 0) && (!abort)) { + int i; - --bootdelay; + --bootdelay; - /* delay 100 * 10ms */ - for (i = 0; !abort && i < 100; ++i) { - /* we got a key press */ - if (tstc()) { - stopc = getc(); - if (stopc != 0) { - abort = 1; - bootdelay = 0; - break; - } - } - udelay(10000); + /* delay 500 * 2 ms */ + for (i = 0; !abort && i < 500; ++i, udelay(2000)) { + if (!tstc() || tested) + continue; + + /* Ignore nulls */ + c = getc(); + if (c == 0) + continue; + + /* Interrupt by any key if bootstopkey isn't used */ + if (!envstopstr) { + abort = 1; + bootdelay = 0; + break; + } + + /* Consume characters up to the strlen(envstopstr) */ + if (stopstr_len < envstopstr_len) + stopstr[stopstr_len++] = c; + + if (stopstr_len == envstopstr_len) { + + if (memcmp(envstopstr, stopstr, + envstopstr_len) == 0) { + abort = 1; + bootdelay = 0; + break; + } else + tested = 1; } - printf("\b\b%d ", bootdelay); } - printf("\n\n"); + printf("\b\b%2d", bootdelay); } + puts("\n\n"); #if defined(CONFIG_SILENT_CONSOLE) if (abort) { diff --git a/u-boot/include/configs/qca9k_common.h b/u-boot/include/configs/qca9k_common.h index 7601454..360c676 100644 --- a/u-boot/include/configs/qca9k_common.h +++ b/u-boot/include/configs/qca9k_common.h @@ -20,10 +20,6 @@ #define CONFIG_BOOTDELAY 1 #endif -#if !defined(CONFIG_MENUPROMPT) - #define CONFIG_MENUPROMPT "Hit any key to stop booting: %2d " -#endif - /* Allow to disable console output, don't display console info */ #define CONFIG_SILENT_CONSOLE 1 #define CFG_CONSOLE_INFO_QUIET 1 -- 2.25.1