[U-Boot] [RFC PATCH v2 06/15] main: Use autoconf for boot retry feature
Simon Glass
sjg at chromium.org
Sun Feb 24 18:26:04 CET 2013
Change this feature to use autoconf instead of #ifdef.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2: None
common/main.c | 74 ++++++++++++++++++++++++++---------------------------------
1 file changed, 33 insertions(+), 41 deletions(-)
diff --git a/common/main.c b/common/main.c
index 0df7992..c00c5bd 100644
--- a/common/main.c
+++ b/common/main.c
@@ -71,17 +71,11 @@ static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
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 = 0; /* must be set, default is instant timeout */
static int retry_time = -1; /* -1 so can call readline before main_loop */
-#endif
#define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk())
-#ifndef CONFIG_BOOT_RETRY_MIN
-#define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
-#endif
-
#ifdef CONFIG_MODEM_SUPPORT
int do_mdm_init = 0;
extern void mdm_init(void); /* defined in board.c */
@@ -181,11 +175,10 @@ static int abortboot_keyed(int bootdelay)
delaykey[i].retry ? "delay" : "stop");
# endif
-# ifdef CONFIG_BOOT_RETRY_TIME
- /* don't retry auto boot */
- if (! delaykey[i].retry)
+ /* don't retry auto boot? */
+ if (autoconf_boot_retry_time() &&
+ !delaykey[i].retry)
retry_time = -1;
-# endif
abort = 1;
}
}
@@ -374,9 +367,8 @@ static void process_boot_delay(void)
#if defined(CONFIG_MENU_SHOW)
bootdelay = menu_show(bootdelay);
#endif
-# ifdef CONFIG_BOOT_RETRY_TIME
- init_cmd_timeout ();
-# endif /* CONFIG_BOOT_RETRY_TIME */
+ if (autoconf_boot_retry_time())
+ init_cmd_timeout();
#ifdef CONFIG_POST
if (gd->flags & GD_FLG_POSTFAIL) {
@@ -509,14 +501,12 @@ void main_loop(void)
for (;;);
#else
for (;;) {
-#ifdef CONFIG_BOOT_RETRY_TIME
- if (rc >= 0) {
+ if (autoconf_boot_retry_time() && rc >= 0) {
/* Saw enough of a valid command to
* restart the timeout.
*/
reset_cmd_timeout();
}
-#endif
len = readline (CONFIG_SYS_PROMPT);
flag = 0; /* assume no special flags for now */
@@ -524,19 +514,16 @@ void main_loop(void)
strcpy (lastcommand, console_buffer);
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
-#ifdef CONFIG_BOOT_RETRY_TIME
- else if (len == -2) {
+ else if (autoconf_boot_retry_time() && len == -2) {
/* -2 means timed out, retry autoboot
*/
- puts ("\nTimed out waiting for command\n");
-# ifdef CONFIG_RESET_TO_RETRY
+ puts("\nTimed out waiting for command\n");
/* Reinit board to run initialization code again */
- do_reset (NULL, 0, 0, NULL);
-# else
- return; /* retry autoboot */
-# endif
+ if (autoconf_reset_to_retry())
+ do_reset(NULL, 0, 0, NULL);
+ else
+ return; /* retry autoboot */
}
-#endif
if (len == -1)
puts ("<INTERRUPT>\n");
@@ -551,6 +538,10 @@ void main_loop(void)
#endif /*CONFIG_SYS_HUSH_PARSER*/
}
+/*
+ * Use ifdef here for the benefit of those archs not using
+ * -ffunction-sections, since these functions are exported.
+ */
#ifdef CONFIG_BOOT_RETRY_TIME
/***************************************************************************
* initialize command line timeout
@@ -558,14 +549,15 @@ void main_loop(void)
void init_cmd_timeout(void)
{
char *s = getenv ("bootretry");
+ int retry_min;
if (s != NULL)
retry_time = (int)simple_strtol(s, NULL, 10);
else
- retry_time = CONFIG_BOOT_RETRY_TIME;
+ retry_time = autoconf_boot_retry_time();
- if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
- retry_time = CONFIG_BOOT_RETRY_MIN;
+ if (retry_time >= 0 retry_time < autoconf_boot_retry_min())
+ retry_time = autoconf_boot_retry_min();
}
/***************************************************************************
@@ -787,13 +779,13 @@ 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();
+ if (autoconf_boot_retry_time()) {
+ while (!tstc()) { /* while no incoming data */
+ if (retry_time >= 0 && get_ticks() > endtime)
+ return -2; /* timed out */
+ WATCHDOG_RESET();
+ }
}
-#endif
if (first && timeout) {
uint64_t etime = endtick(timeout);
@@ -1065,14 +1057,14 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
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();
+ if (autoconf_boot_retry_time()) {
+ while (!tstc()) { /* while no incoming data */
+ if (retry_time >= 0 && get_ticks() > endtime)
+ return -2; /* timed out */
+ WATCHDOG_RESET();
+ }
}
-#endif
- WATCHDOG_RESET(); /* Trigger watchdog, if needed */
+ WATCHDOG_RESET(); /* Trigger watchdog, if needed */
#ifdef CONFIG_SHOW_ACTIVITY
while (!tstc()) {
--
1.8.1.3
More information about the U-Boot
mailing list