[U-Boot] [PATCH v4 3/8] main: Remove CONFIG #ifdefs from the abortboot() code

2013-10-26 Thread Simon Glass
Move this code over to using autoconf. We can add the autoconf values to
the delaykey[] array, and move the code that checks for autoconf values into
the loop.

Also change to using ARRAY_SIZE on delaykey[].

Signed-off-by: Simon Glass s...@chromium.org
Reviewed-by: Joe Hershberger joe.hershber...@ni.com
---
Changes in v4:
- Rebase on current master

Changes in v3: None
Changes in v2: None

 common/main.c | 90 ++-
 1 file changed, 34 insertions(+), 56 deletions(-)

diff --git a/common/main.c b/common/main.c
index 54c5df8..5768a16 100644
--- a/common/main.c
+++ b/common/main.c
@@ -70,15 +70,20 @@ static int abortboot_keyed(int bootdelay)
int abort = 0;
uint64_t etime = endtick(bootdelay);
struct {
-   char* str;
+   const char *str;
u_int len;
int retry;
+   const char *conf;   /* Configuration value */
}
delaykey [] = {
-   { str: getenv (bootdelaykey),  retry: 1 },
-   { str: getenv (bootdelaykey2), retry: 1 },
-   { str: getenv (bootstopkey),   retry: 0 },
-   { str: getenv (bootstopkey2),  retry: 0 },
+   { str: getenv(bootdelaykey),  retry: 1,
+   conf: autoconf_autoboot_delay_str() },
+   { str: getenv(bootdelaykey2), retry: 1,
+   conf: autoconf_autoboot_delay_str2() },
+   { str: getenv(bootstopkey),   retry: 0,
+   conf: autoconf_autoboot_stop_str() },
+   { str: getenv(bootstopkey2),  retry: 0,
+   conf: autoconf_autoboot_stop_str2() },
};
 
char presskey [MAX_DELAY_STOP_STR];
@@ -86,33 +91,15 @@ static int abortboot_keyed(int bootdelay)
u_int presskey_max = 0;
u_int i;
 
-#ifndef CONFIG_ZERO_BOOTDELAY_CHECK
-   if (bootdelay == 0)
+   if (!autoconf_zero_bootdelay_check()  bootdelay == 0)
return 0;
-#endif
 
-#  ifdef CONFIG_AUTOBOOT_PROMPT
-   printf(CONFIG_AUTOBOOT_PROMPT);
-#  endif
-
-#  ifdef CONFIG_AUTOBOOT_DELAY_STR
-   if (delaykey[0].str == NULL)
-   delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_DELAY_STR2
-   if (delaykey[1].str == NULL)
-   delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_STOP_STR
-   if (delaykey[2].str == NULL)
-   delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_STOP_STR2
-   if (delaykey[3].str == NULL)
-   delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2;
-#  endif
-
-   for (i = 0; i  sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
+   if (autoconf_has_autoboot_prompt())
+   printf(autoconf_autoboot_prompt());
+
+   for (i = 0; i  ARRAY_SIZE(delaykey); i++) {
+   if (delaykey[i].conf  !delaykey[i].str)
+   delaykey[i].str = delaykey[i].conf;
delaykey[i].len = delaykey[i].str == NULL ?
0 : strlen (delaykey[i].str);
delaykey[i].len = delaykey[i].len  MAX_DELAY_STOP_STR ?
@@ -142,7 +129,7 @@ static int abortboot_keyed(int bootdelay)
}
}
 
-   for (i = 0; i  sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
+   for (i = 0; i  ARRAY_SIZE(delaykey); i++) {
if (delaykey[i].len  0 
presskey_len = delaykey[i].len 
memcmp (presskey + presskey_len - delaykey[i].len,
@@ -164,45 +151,39 @@ static int abortboot_keyed(int bootdelay)
if (!abort)
debug_bootkeys(key timeout\n);
 
-#ifdef CONFIG_SILENT_CONSOLE
-   if (abort)
+   if (autoconf_silent_console()  abort)
gd-flags = ~GD_FLG_SILENT;
-#endif
 
return abort;
 }
 
 # else /* !defined(CONFIG_AUTOBOOT_KEYED) */
 
-#ifdef CONFIG_MENUKEY
-static int menukey = 0;
-#endif
+static int menukey;
 
 static int abortboot_normal(int bootdelay)
 {
int abort = 0;
unsigned long ts;
 
-#ifdef CONFIG_MENUPROMPT
-   printf(CONFIG_MENUPROMPT);
-#else
-   if (bootdelay = 0)
+   if (autoconf_menuprompt())
+   printf(autoconf_menuprompt());
+   else if (bootdelay = 0)
printf(Hit any key to stop autoboot: %2d , bootdelay);
-#endif
 
-#if defined CONFIG_ZERO_BOOTDELAY_CHECK
/*
-* Check if key already pressed
-* Don't check if bootdelay  0
+* If we need to do a bootdelay check even if bootdelay is 0, do
+* it here, since the loop below will be skipped in this case.
+* We don't do this check if bootdelay  0.
 */
-   if (bootdelay = 0) {
-   if (tstc()) {   /* we got a key press   */
+   if (autoconf_zero_bootdelay_check()  bootdelay = 0) {
+  

[U-Boot] [PATCH v4 3/8] main: Remove CONFIG #ifdefs from the abortboot() code

2013-06-17 Thread Simon Glass
Move this code over to using autoconf. We can add the autoconf values to
the delaykey[] array, and move the code that checks for autoconf values into
the loop.

Also change to using ARRAY_SIZE on delaykey[].

Signed-off-by: Simon Glass s...@chromium.org
Reviewed-by: Joe Hershberger joe.hershber...@ni.com
---
Changes in v4:
- Rebase on current master

Changes in v3: None
Changes in v2: None

 common/main.c | 90 ++-
 1 file changed, 34 insertions(+), 56 deletions(-)

diff --git a/common/main.c b/common/main.c
index 3a143ae..3a4754d 100644
--- a/common/main.c
+++ b/common/main.c
@@ -86,15 +86,20 @@ static int abortboot_keyed(int bootdelay)
int abort = 0;
uint64_t etime = endtick(bootdelay);
struct {
-   char* str;
+   const char *str;
u_int len;
int retry;
+   const char *conf;   /* Configuration value */
}
delaykey [] = {
-   { str: getenv (bootdelaykey),  retry: 1 },
-   { str: getenv (bootdelaykey2), retry: 1 },
-   { str: getenv (bootstopkey),   retry: 0 },
-   { str: getenv (bootstopkey2),  retry: 0 },
+   { str: getenv(bootdelaykey),  retry: 1,
+   conf: autoconf_autoboot_delay_str() },
+   { str: getenv(bootdelaykey2), retry: 1,
+   conf: autoconf_autoboot_delay_str2() },
+   { str: getenv(bootstopkey),   retry: 0,
+   conf: autoconf_autoboot_stop_str() },
+   { str: getenv(bootstopkey2),  retry: 0,
+   conf: autoconf_autoboot_stop_str2() },
};
 
char presskey [MAX_DELAY_STOP_STR];
@@ -102,33 +107,15 @@ static int abortboot_keyed(int bootdelay)
u_int presskey_max = 0;
u_int i;
 
-#ifndef CONFIG_ZERO_BOOTDELAY_CHECK
-   if (bootdelay == 0)
+   if (!autoconf_zero_bootdelay_check()  bootdelay == 0)
return 0;
-#endif
 
-#  ifdef CONFIG_AUTOBOOT_PROMPT
-   printf(CONFIG_AUTOBOOT_PROMPT);
-#  endif
-
-#  ifdef CONFIG_AUTOBOOT_DELAY_STR
-   if (delaykey[0].str == NULL)
-   delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_DELAY_STR2
-   if (delaykey[1].str == NULL)
-   delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_STOP_STR
-   if (delaykey[2].str == NULL)
-   delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR;
-#  endif
-#  ifdef CONFIG_AUTOBOOT_STOP_STR2
-   if (delaykey[3].str == NULL)
-   delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2;
-#  endif
-
-   for (i = 0; i  sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
+   if (autoconf_has_autoboot_prompt())
+   printf(autoconf_autoboot_prompt());
+
+   for (i = 0; i  ARRAY_SIZE(delaykey); i++) {
+   if (delaykey[i].conf  !delaykey[i].str)
+   delaykey[i].str = delaykey[i].conf;
delaykey[i].len = delaykey[i].str == NULL ?
0 : strlen (delaykey[i].str);
delaykey[i].len = delaykey[i].len  MAX_DELAY_STOP_STR ?
@@ -158,7 +145,7 @@ static int abortboot_keyed(int bootdelay)
}
}
 
-   for (i = 0; i  sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
+   for (i = 0; i  ARRAY_SIZE(delaykey); i++) {
if (delaykey[i].len  0 
presskey_len = delaykey[i].len 
memcmp (presskey + presskey_len - delaykey[i].len,
@@ -180,45 +167,39 @@ static int abortboot_keyed(int bootdelay)
if (!abort)
debug_bootkeys(key timeout\n);
 
-#ifdef CONFIG_SILENT_CONSOLE
-   if (abort)
+   if (autoconf_silent_console()  abort)
gd-flags = ~GD_FLG_SILENT;
-#endif
 
return abort;
 }
 
 # else /* !defined(CONFIG_AUTOBOOT_KEYED) */
 
-#ifdef CONFIG_MENUKEY
-static int menukey = 0;
-#endif
+static int menukey;
 
 static int abortboot_normal(int bootdelay)
 {
int abort = 0;
unsigned long ts;
 
-#ifdef CONFIG_MENUPROMPT
-   printf(CONFIG_MENUPROMPT);
-#else
-   if (bootdelay = 0)
+   if (autoconf_menuprompt())
+   printf(autoconf_menuprompt());
+   else if (bootdelay = 0)
printf(Hit any key to stop autoboot: %2d , bootdelay);
-#endif
 
-#if defined CONFIG_ZERO_BOOTDELAY_CHECK
/*
-* Check if key already pressed
-* Don't check if bootdelay  0
+* If we need to do a bootdelay check even if bootdelay is 0, do
+* it here, since the loop below will be skipped in this case.
+* We don't do this check if bootdelay  0.
 */
-   if (bootdelay = 0) {
-   if (tstc()) {   /* we got a key press   */
+   if (autoconf_zero_bootdelay_check()  bootdelay = 0) {
+