]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Move bootretry code into bootretry.c and clean up
authorSimon Glass <sjg@chromium.org>
Fri, 11 Apr 2014 02:01:30 +0000 (20:01 -0600)
committerTom Rini <trini@ti.com>
Thu, 29 May 2014 21:48:21 +0000 (17:48 -0400)
This code is only used by one board, so it seems a shame to clutter up
the readline code with it. Move it into its own file.

Signed-off-by: Simon Glass <sjg@chromium.org>
13 files changed:
board/hymod/hymod.c
board/hymod/input.c
common/Makefile
common/autoboot.c
common/bootretry.c [new file with mode: 0644]
common/cli_hush.c
common/cli_readline.c
common/cli_simple.c
common/cmd_i2c.c
common/cmd_mem.c
common/cmd_pci.c
include/bootretry.h [new file with mode: 0644]
include/common.h

index 55ffd676cf5907946c3ca1bd5eff611dca38f3dd..f6990e929f975898952263ed1bd05ab4fa3ec7ee 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <mpc8260.h>
 #include <mpc8260_irq.h>
index 59ad6aa3ed92a97f9369111de6d4ef4719d43048..2f857c06ae92683bd515fedaf60db2ac5f408d3a 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 
 int
index 81721f9b389cd863df93637ca605aae1b7821008..391a8d6230a3ebb68cdeb3259971055377dac745 100644 (file)
@@ -29,6 +29,11 @@ ifdef CONFIG_BOOTDELAY
 obj-y += autoboot.o
 endif
 
+# This option is not just y/n - it can have a numeric value
+ifdef CONFIG_BOOT_RETRY_TIME
+obj-y += bootretry.o
+endif
+
 # boards
 obj-$(CONFIG_SYS_GENERIC_BOARD) += board_f.o
 obj-$(CONFIG_SYS_GENERIC_BOARD) += board_r.o
index 6933e3fc469e256d82a10145db46860dd3b0a6ef..5f8d9c3445cdc6e7c873e7e9822254f901a05d6f 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <fdtdec.h>
 #include <menu.h>
diff --git a/common/bootretry.c b/common/bootretry.c
new file mode 100644 (file)
index 0000000..12653c0
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <bootretry.h>
+#include <cli.h>
+#include <errno.h>
+#include <watchdog.h>
+
+#ifndef CONFIG_BOOT_RETRY_MIN
+#define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
+#endif
+
+static uint64_t endtime;  /* must be set, default is instant timeout */
+static int      retry_time = -1; /* -1 so can call readline before main_loop */
+
+/***************************************************************************
+ * initialize command line timeout
+ */
+void init_cmd_timeout(void)
+{
+       char *s = getenv("bootretry");
+
+       if (s != NULL)
+               retry_time = (int)simple_strtol(s, NULL, 10);
+       else
+               retry_time = CONFIG_BOOT_RETRY_TIME;
+
+       if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
+               retry_time = CONFIG_BOOT_RETRY_MIN;
+}
+
+/***************************************************************************
+ * reset command line timeout to retry_time seconds
+ */
+void reset_cmd_timeout(void)
+{
+       endtime = endtick(retry_time);
+}
+
+int bootretry_tstc_timeout(void)
+{
+       while (!tstc()) {       /* while no incoming data */
+               if (retry_time >= 0 && get_ticks() > endtime)
+                       return -ETIMEDOUT;
+               WATCHDOG_RESET();
+       }
+
+       return 0;
+}
+
+void bootretry_dont_retry(void)
+{
+       retry_time = -1;
+}
index a612bfbef51e7b806ea22c19c6288ef256b12eb0..d6544ae63111fc034c2cba57b0f1fddfc25c6254 100644 (file)
@@ -79,6 +79,7 @@
 #include <malloc.h>         /* malloc, free, realloc*/
 #include <linux/ctype.h>    /* isalpha, isdigit */
 #include <common.h>        /* readline */
+#include <bootretry.h>
 #include <cli.h>
 #include <cli_hush.h>
 #include <command.h>        /* find_cmd */
index df446b8c8362e998c3279d799fd2a3adcbb10f58..9a9fb35b712b09c8a9a416796c6df1ea27c7f1a0 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <watchdog.h>
 
@@ -18,17 +19,8 @@ DECLARE_GLOBAL_DATA_PTR;
 static const char erase_seq[] = "\b \b";       /* erase sequence */
 static const char   tab_seq[] = "        ";    /* used to expand TABs */
 
-#ifdef CONFIG_BOOT_RETRY_TIME
-static uint64_t endtime;      /* must be set, default is instant timeout */
-static int      retry_time = -1; /* -1 so can call readline before main_loop */
-#endif
-
 char console_buffer[CONFIG_SYS_CBSIZE + 1];    /* console I/O buffer   */
 
-#ifndef CONFIG_BOOT_RETRY_MIN
-#define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
-#endif
-
 static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
 {
        char *s;
@@ -267,13 +259,8 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
                cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
 
        while (1) {
-#ifdef CONFIG_BOOT_RETRY_TIME
-               while (!tstc()) {       /* while no incoming data */
-                       if (retry_time >= 0 && get_ticks() > endtime)
-                               return -2;      /* timed out */
-                       WATCHDOG_RESET();
-               }
-#endif
+               if (bootretry_tstc_timeout())
+                       return -2;      /* timed out */
                if (first && timeout) {
                        uint64_t etime = endtick(timeout);
 
@@ -539,13 +526,8 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
        col = plen;
 
        for (;;) {
-#ifdef CONFIG_BOOT_RETRY_TIME
-               while (!tstc()) {       /* while no incoming data */
-                       if (retry_time >= 0 && get_ticks() > endtime)
-                               return -2;      /* timed out */
-                       WATCHDOG_RESET();
-               }
-#endif
+               if (bootretry_tstc_timeout())
+                       return -2;      /* timed out */
                WATCHDOG_RESET();       /* Trigger watchdog, if needed */
 
 #ifdef CONFIG_SHOW_ACTIVITY
@@ -637,35 +619,3 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
        }
 #endif
 }
-
-#ifdef CONFIG_BOOT_RETRY_TIME
-/***************************************************************************
- * initialize command line timeout
- */
-void init_cmd_timeout(void)
-{
-       char *s = getenv("bootretry");
-
-       if (s != NULL)
-               retry_time = (int)simple_strtol(s, NULL, 10);
-       else
-               retry_time =  CONFIG_BOOT_RETRY_TIME;
-
-       if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
-               retry_time = CONFIG_BOOT_RETRY_MIN;
-}
-
-/***************************************************************************
- * reset command line timeout to retry_time seconds
- */
-void reset_cmd_timeout(void)
-{
-       endtime = endtick(retry_time);
-}
-
-void bootretry_dont_retry(void)
-{
-       retry_time = -1;
-}
-
-#endif
index 3039cfcca1fe73d0a0615a64133916cd092742cd..5b7e2ce7d53a832a71edd7a8ad5f38f1bf7cb899 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <linux/ctype.h>
 
index 7158b5a2db1164c81afd2f560a92bc1293781c0f..4fa12138c357a785c5622c6b969e8a59cbaf6bf8 100644 (file)
@@ -66,6 +66,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <command.h>
 #include <edid.h>
index 15a4b84efdc95f1f8374673fadac592e4fa64124..9bd7c0eedb93d89cf444836a04654861d77b0c8b 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <command.h>
 #ifdef CONFIG_HAS_DATAFLASH
index 1ed55cedb16e13800b8b08c7b7d7e6cfdc260c02..180b35ab0f777fe4f822d8f100a66267c9c99310 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <bootretry.h>
 #include <cli.h>
 #include <command.h>
 #include <asm/processor.h>
diff --git a/include/bootretry.h b/include/bootretry.h
new file mode 100644 (file)
index 0000000..025c29d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __bootretry_h
+#define __bootretry_h
+
+#ifdef CONFIG_BOOT_RETRY_TIME
+/**
+ * bootretry_tstc_timeout() - ensure we get a keypress before timeout
+ *
+ * Check for a keypress repeatedly, resetting the watchdog each time. If a
+ * keypress is not received within the command timeout, return an error.
+ *
+ * @return 0 if a key is received in time, -ETIMEDOUT if not
+ */
+int bootretry_tstc_timeout(void);
+#else
+static inline int bootretry_tstc_timeout(void)
+{
+       return 0;
+}
+#endif
+
+void init_cmd_timeout(void);
+void reset_cmd_timeout(void);
+
+#endif
index 75cb525f3ecfea7bb17284be42e4cebb887870b3..91745cf790fa1b7cf3f555491c6583f1455e3995 100644 (file)
@@ -286,8 +286,6 @@ int run_command(const char *cmd, int flag);
  * @return 0 on success, or != 0 on error.
  */
 int run_command_list(const char *cmd, int len, int flag);
-void   init_cmd_timeout(void);
-void   reset_cmd_timeout(void);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */