Add support for multikey autoboot stop string
authorPiotr Dymacz <pepe2k@gmail.com>
Thu, 6 Apr 2017 18:10:03 +0000 (20:10 +0200)
committerPiotr Dymacz <pepe2k@gmail.com>
Thu, 6 Apr 2017 18:10:03 +0000 (20:10 +0200)
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
u-boot/common/environment.c
u-boot/common/main.c
u-boot/include/configs/qca9k_common.h

index 722add9c06ae79f49062b2155311fd62b7b4296b..99a7fd1bb8ad2bb267a212d8f82ee3cae5a52a83 100644 (file)
@@ -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
index 31bcd8aa9bbc0477df0d6d1e55c46c5ca7e6366d..04ea3ff15205d86608db21eb13bd59a09137edda 100644 (file)
@@ -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
index a8d708c3cf139479139c6e150c1f7d7887a33cb9..c550812f570fef5f68205bcb4eb308e7ba9336d5 100644 (file)
@@ -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) {
index 7601454e6b111884f0df22aa76d31144642c95ab..360c676eff3e893351861fb8faded3081a2bf65a 100644 (file)
        #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