Re: [U-Boot] [RFC PATCH v2 09/15] main: Use autoconf for boot_delay code

2013-02-25 Thread Simon Glass
Hi Joe,

On Sun, Feb 24, 2013 at 12:40 PM, Joe Hershberger
joe.hershber...@gmail.com wrote:
 Hi Simon,

 On Sun, Feb 24, 2013 at 11:26 AM, Simon Glass s...@chromium.org wrote:
 Convert this function and its children to use autoconf instead of #ifdef.

 Some header files must now be included unconditionally, so remove some of
 the #ifdefs from the header section, and put these header files into the
 right order.

 Signed-off-by: Simon Glass s...@chromium.org
 ---
 Changes in v2: None

  common/main.c  | 104 
 +++--
  include/menu.h |   2 --
  2 files changed, 41 insertions(+), 65 deletions(-)

 diff --git a/common/main.c b/common/main.c
 index 4f11e58..a5d3f82 100644
 --- a/common/main.c
 +++ b/common/main.c
[snip]
 @@ -258,7 +248,6 @@ static int abortboot(int bootdelay)
   * printing the error message to console.
   */

 -#ifdef CONFIG_OF_CONTROL
  static void secure_boot_cmd(char *cmd)
  {
 cmd_tbl_t *cmdtp;
 @@ -311,93 +300,82 @@ static void process_fdt_options(const void *blob)
 (void *)(autoconf_sys_text_base() + addr));
 }
  }
 -#endif /* CONFIG_OF_CONTROL */

  static void process_boot_delay(void)
  {
 -#ifdef CONFIG_BOOTCOUNT_LIMIT
 unsigned long bootcount = 0;
 unsigned long bootlimit = 0;
 -#endif /* CONFIG_BOOTCOUNT_LIMIT */
 -#ifdef CONFIG_OF_CONTROL
 -   char *env;
 -#endif
 -   char *s;
 +   const char *s;
 int bootdelay;

 -#ifdef CONFIG_BOOTCOUNT_LIMIT
 -   bootcount = bootcount_load();
 -   bootcount++;
 -   bootcount_store (bootcount);
 -   setenv_ulong(bootcount, bootcount);
 -   bootlimit = getenv_ulong(bootlimit, 10, 0);
 -#endif /* CONFIG_BOOTCOUNT_LIMIT */
 +   if (autoconf_bootcount_limit()) {
 +   bootcount = bootcount_load();
 +   bootcount++;
 +   bootcount_store(bootcount);
 +   setenv_ulong(bootcount, bootcount);
 +   bootlimit = getenv_ulong(bootlimit, 10, 0);
 +   }

 s = getenv (bootdelay);
 bootdelay = s ? (int)simple_strtol(s, NULL, 10) : 
 autoconf_bootdelay();

 This would look a lot nicer as:
bootdelay = getenv_ulong_def(bootdelay, autoconf_bootdelay());

Yes of course, thank you.

[snip]

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [RFC PATCH v2 09/15] main: Use autoconf for boot_delay code

2013-02-24 Thread Simon Glass
Convert this function and its children to use autoconf instead of #ifdef.

Some header files must now be included unconditionally, so remove some of
the #ifdefs from the header section, and put these header files into the
right order.

Signed-off-by: Simon Glass s...@chromium.org
---
Changes in v2: None

 common/main.c  | 104 +++--
 include/menu.h |   2 --
 2 files changed, 41 insertions(+), 65 deletions(-)

diff --git a/common/main.c b/common/main.c
index 4f11e58..a5d3f82 100644
--- a/common/main.c
+++ b/common/main.c
@@ -31,27 +31,17 @@
 #include watchdog.h
 #include command.h
 #include fdtdec.h
+#include fdt_support.h
 #include malloc.h
+#include menu.h
 #include version.h
-#ifdef CONFIG_MODEM_SUPPORT
-#include malloc.h/* for free() prototype */
-#endif
 
 #ifdef CONFIG_SYS_HUSH_PARSER
 #include hush.h
 #endif
 
-#ifdef CONFIG_OF_CONTROL
-#include fdtdec.h
-#endif
-
-#ifdef CONFIG_OF_LIBFDT
-#include fdt_support.h
-#endif /* CONFIG_OF_LIBFDT */
-
 #include post.h
 #include linux/ctype.h
-#include menu.h
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -258,7 +248,6 @@ static int abortboot(int bootdelay)
  * printing the error message to console.
  */
 
-#ifdef CONFIG_OF_CONTROL
 static void secure_boot_cmd(char *cmd)
 {
cmd_tbl_t *cmdtp;
@@ -311,93 +300,82 @@ static void process_fdt_options(const void *blob)
(void *)(autoconf_sys_text_base() + addr));
}
 }
-#endif /* CONFIG_OF_CONTROL */
 
 static void process_boot_delay(void)
 {
-#ifdef CONFIG_BOOTCOUNT_LIMIT
unsigned long bootcount = 0;
unsigned long bootlimit = 0;
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
-#ifdef CONFIG_OF_CONTROL
-   char *env;
-#endif
-   char *s;
+   const char *s;
int bootdelay;
 
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-   bootcount = bootcount_load();
-   bootcount++;
-   bootcount_store (bootcount);
-   setenv_ulong(bootcount, bootcount);
-   bootlimit = getenv_ulong(bootlimit, 10, 0);
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
+   if (autoconf_bootcount_limit()) {
+   bootcount = bootcount_load();
+   bootcount++;
+   bootcount_store(bootcount);
+   setenv_ulong(bootcount, bootcount);
+   bootlimit = getenv_ulong(bootlimit, 10, 0);
+   }
 
s = getenv (bootdelay);
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : autoconf_bootdelay();
 
debug (### main_loop entered: bootdelay=%d\n\n, bootdelay);
 
-#if defined(CONFIG_MENU_SHOW)
-   bootdelay = menu_show(bootdelay);
-#endif
+   if (autoconf_menu_show())
+   bootdelay = menu_show(bootdelay);
if (autoconf_boot_retry_time())
init_cmd_timeout();
 
-#ifdef CONFIG_POST
-   if (gd-flags  GD_FLG_POSTFAIL) {
+   if (autoconf_post()  (gd-flags  GD_FLG_POSTFAIL)) {
s = getenv(failbootcmd);
-   }
-   else
-#endif /* CONFIG_POST */
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-   if (bootlimit  (bootcount  bootlimit)) {
+   } else if (autoconf_bootcount_limit()  bootlimit 
+   (bootcount  bootlimit)) {
printf (Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n,
(unsigned)bootlimit);
s = getenv (altbootcmd);
-   }
-   else
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
+   } else {
s = getenv (bootcmd);
-#ifdef CONFIG_OF_CONTROL
-   /* Allow the fdt to override the boot command */
-   env = fdtdec_get_config_string(gd-fdt_blob, bootcmd);
-   if (env)
-   s = env;
+   }
+   if (autoconf_of_control()) {
+   char *env;
 
-   process_fdt_options(gd-fdt_blob);
+   /* Allow the fdt to override the boot command */
+   env = fdtdec_get_config_string(gd-fdt_blob, bootcmd);
+   if (env)
+   s = env;
 
-   /*
-* If the bootsecure option was chosen, use secure_boot_cmd().
-* Always use 'env' in this case, since bootsecure requres that the
-* bootcmd was specified in the FDT too.
-*/
-   if (fdtdec_get_config_int(gd-fdt_blob, bootsecure, 0))
-   secure_boot_cmd(env);
+   process_fdt_options(gd-fdt_blob);
 
-#endif /* CONFIG_OF_CONTROL */
+   /*
+   * If the bootsecure option was chosen, use secure_boot_cmd().
+   * Always use 'env' in this case, since bootsecure requres that
+   * the bootcmd was specified in the FDT too.
+   */
+   if (fdtdec_get_config_int(gd-fdt_blob, bootsecure, 0))
+   secure_boot_cmd(env);
+   }
 
debug (### main_loop: bootcmd=\%s\\n, s ? s : UNDEFINED);
 
if (bootdelay != -1  s  !abortboot(bootdelay)) {
-# ifdef CONFIG_AUTOBOOT_KEYED
-   int prev = disable_ctrlc(1);/* disable Control C checking */
-# endif
+   

Re: [U-Boot] [RFC PATCH v2 09/15] main: Use autoconf for boot_delay code

2013-02-24 Thread Joe Hershberger
Hi Simon,

On Sun, Feb 24, 2013 at 11:26 AM, Simon Glass s...@chromium.org wrote:
 Convert this function and its children to use autoconf instead of #ifdef.

 Some header files must now be included unconditionally, so remove some of
 the #ifdefs from the header section, and put these header files into the
 right order.

 Signed-off-by: Simon Glass s...@chromium.org
 ---
 Changes in v2: None

  common/main.c  | 104 
 +++--
  include/menu.h |   2 --
  2 files changed, 41 insertions(+), 65 deletions(-)

 diff --git a/common/main.c b/common/main.c
 index 4f11e58..a5d3f82 100644
 --- a/common/main.c
 +++ b/common/main.c
 @@ -31,27 +31,17 @@
  #include watchdog.h
  #include command.h
  #include fdtdec.h
 +#include fdt_support.h
  #include malloc.h
 +#include menu.h
  #include version.h
 -#ifdef CONFIG_MODEM_SUPPORT
 -#include malloc.h/* for free() prototype */
 -#endif

  #ifdef CONFIG_SYS_HUSH_PARSER
  #include hush.h
  #endif

 -#ifdef CONFIG_OF_CONTROL
 -#include fdtdec.h
 -#endif
 -
 -#ifdef CONFIG_OF_LIBFDT
 -#include fdt_support.h
 -#endif /* CONFIG_OF_LIBFDT */
 -
  #include post.h
  #include linux/ctype.h
 -#include menu.h

  DECLARE_GLOBAL_DATA_PTR;

 @@ -258,7 +248,6 @@ static int abortboot(int bootdelay)
   * printing the error message to console.
   */

 -#ifdef CONFIG_OF_CONTROL
  static void secure_boot_cmd(char *cmd)
  {
 cmd_tbl_t *cmdtp;
 @@ -311,93 +300,82 @@ static void process_fdt_options(const void *blob)
 (void *)(autoconf_sys_text_base() + addr));
 }
  }
 -#endif /* CONFIG_OF_CONTROL */

  static void process_boot_delay(void)
  {
 -#ifdef CONFIG_BOOTCOUNT_LIMIT
 unsigned long bootcount = 0;
 unsigned long bootlimit = 0;
 -#endif /* CONFIG_BOOTCOUNT_LIMIT */
 -#ifdef CONFIG_OF_CONTROL
 -   char *env;
 -#endif
 -   char *s;
 +   const char *s;
 int bootdelay;

 -#ifdef CONFIG_BOOTCOUNT_LIMIT
 -   bootcount = bootcount_load();
 -   bootcount++;
 -   bootcount_store (bootcount);
 -   setenv_ulong(bootcount, bootcount);
 -   bootlimit = getenv_ulong(bootlimit, 10, 0);
 -#endif /* CONFIG_BOOTCOUNT_LIMIT */
 +   if (autoconf_bootcount_limit()) {
 +   bootcount = bootcount_load();
 +   bootcount++;
 +   bootcount_store(bootcount);
 +   setenv_ulong(bootcount, bootcount);
 +   bootlimit = getenv_ulong(bootlimit, 10, 0);
 +   }

 s = getenv (bootdelay);
 bootdelay = s ? (int)simple_strtol(s, NULL, 10) : 
 autoconf_bootdelay();

This would look a lot nicer as:
   bootdelay = getenv_ulong_def(bootdelay, autoconf_bootdelay());


 debug (### main_loop entered: bootdelay=%d\n\n, bootdelay);

 -#if defined(CONFIG_MENU_SHOW)
 -   bootdelay = menu_show(bootdelay);
 -#endif
 +   if (autoconf_menu_show())
 +   bootdelay = menu_show(bootdelay);
 if (autoconf_boot_retry_time())
 init_cmd_timeout();

 -#ifdef CONFIG_POST
 -   if (gd-flags  GD_FLG_POSTFAIL) {
 +   if (autoconf_post()  (gd-flags  GD_FLG_POSTFAIL)) {
 s = getenv(failbootcmd);
 -   }
 -   else
 -#endif /* CONFIG_POST */
 -#ifdef CONFIG_BOOTCOUNT_LIMIT
 -   if (bootlimit  (bootcount  bootlimit)) {
 +   } else if (autoconf_bootcount_limit()  bootlimit 
 +   (bootcount  bootlimit)) {
 printf (Warning: Bootlimit (%u) exceeded. Using 
 altbootcmd.\n,
 (unsigned)bootlimit);
 s = getenv (altbootcmd);
 -   }
 -   else
 -#endif /* CONFIG_BOOTCOUNT_LIMIT */
 +   } else {
 s = getenv (bootcmd);
 -#ifdef CONFIG_OF_CONTROL
 -   /* Allow the fdt to override the boot command */
 -   env = fdtdec_get_config_string(gd-fdt_blob, bootcmd);
 -   if (env)
 -   s = env;
 +   }
 +   if (autoconf_of_control()) {
 +   char *env;

 -   process_fdt_options(gd-fdt_blob);
 +   /* Allow the fdt to override the boot command */
 +   env = fdtdec_get_config_string(gd-fdt_blob, bootcmd);
 +   if (env)
 +   s = env;

 -   /*
 -* If the bootsecure option was chosen, use secure_boot_cmd().
 -* Always use 'env' in this case, since bootsecure requres that the
 -* bootcmd was specified in the FDT too.
 -*/
 -   if (fdtdec_get_config_int(gd-fdt_blob, bootsecure, 0))
 -   secure_boot_cmd(env);
 +   process_fdt_options(gd-fdt_blob);

 -#endif /* CONFIG_OF_CONTROL */
 +   /*
 +   * If the bootsecure option was chosen, use secure_boot_cmd().
 +   * Always use 'env' in this case, since bootsecure requres that
 +   * the bootcmd was specified in the FDT too.
 +   */
 +   if (fdtdec_get_config_int(gd-fdt_blob, bootsecure,