summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2014-04-10 20:01:30 -0600
committerTom Rini <trini@ti.com>2014-05-29 17:48:21 -0400
commit0098e179e1afacb3cf595c67a98b8739dc7edcde (patch)
treec19140ef37a8f86d6ccd5d2a065239f09cf09121 /common
parent30354978ff470470c15caea2566b61b5792ad277 (diff)
downloadu-boot-0098e179e1afacb3cf595c67a98b8739dc7edcde.tar.gz
u-boot-0098e179e1afacb3cf595c67a98b8739dc7edcde.tar.bz2
u-boot-0098e179e1afacb3cf595c67a98b8739dc7edcde.zip
Move bootretry code into bootretry.c and clean up
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>
Diffstat (limited to 'common')
-rw-r--r--common/Makefile5
-rw-r--r--common/autoboot.c1
-rw-r--r--common/bootretry.c59
-rw-r--r--common/cli_hush.c1
-rw-r--r--common/cli_readline.c60
-rw-r--r--common/cli_simple.c1
-rw-r--r--common/cmd_i2c.c1
-rw-r--r--common/cmd_mem.c1
-rw-r--r--common/cmd_pci.c1
9 files changed, 75 insertions, 55 deletions
diff --git a/common/Makefile b/common/Makefile
index 81721f9b38..391a8d6230 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -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
diff --git a/common/autoboot.c b/common/autoboot.c
index 6933e3fc46..5f8d9c3445 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -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
index 0000000000..12653c00d0
--- /dev/null
+++ b/common/bootretry.c
@@ -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;
+}
diff --git a/common/cli_hush.c b/common/cli_hush.c
index a612bfbef5..d6544ae631 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -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 */
diff --git a/common/cli_readline.c b/common/cli_readline.c
index df446b8c83..9a9fb35b71 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -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
diff --git a/common/cli_simple.c b/common/cli_simple.c
index 3039cfcca1..5b7e2ce7d5 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -10,6 +10,7 @@
*/
#include <common.h>
+#include <bootretry.h>
#include <cli.h>
#include <linux/ctype.h>
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 7158b5a2db..4fa12138c3 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -66,6 +66,7 @@
*/
#include <common.h>
+#include <bootretry.h>
#include <cli.h>
#include <command.h>
#include <edid.h>
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 15a4b84efd..9bd7c0eedb 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -12,6 +12,7 @@
*/
#include <common.h>
+#include <bootretry.h>
#include <cli.h>
#include <command.h>
#ifdef CONFIG_HAS_DATAFLASH
diff --git a/common/cmd_pci.c b/common/cmd_pci.c
index 1ed55cedb1..180b35ab0f 100644
--- a/common/cmd_pci.c
+++ b/common/cmd_pci.c
@@ -14,6 +14,7 @@
*/
#include <common.h>
+#include <bootretry.h>
#include <cli.h>
#include <command.h>
#include <asm/processor.h>