[U-Boot] [RFC PATCH v2 05/15] main: Move boot_delay code into its own function

Joe Hershberger joe.hershberger at gmail.com
Sun Feb 24 21:20:07 CET 2013


HI Simon,

On Sun, Feb 24, 2013 at 11:26 AM, Simon Glass <sjg at chromium.org> wrote:
> Move this code into its own function, since it clutters up main_loop().
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> Changes in v2: None
>
>  common/main.c | 155 ++++++++++++++++++++++++++++++----------------------------
>  1 file changed, 79 insertions(+), 76 deletions(-)
>
> diff --git a/common/main.c b/common/main.c
> index 1e12e55..0df7992 100644
> --- a/common/main.c
> +++ b/common/main.c
> @@ -91,7 +91,6 @@ extern void mdm_init(void); /* defined in board.c */
>   * Watch for 'delay' seconds for autoboot stop or autoboot delay string.
>   * returns: 0 -  no key string, allow autoboot 1 - got key string, abort
>   */
> -#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
>  static int abortboot_keyed(int bootdelay)
>  {
>         int abort = 0;
> @@ -273,7 +272,6 @@ static int abortboot(int bootdelay)
>         else
>                 return abortboot_normal(bootdelay);
>  }
> -#endif /* CONFIG_BOOTDELAY >= 0  */
>
>  /*
>   * Runs the given boot command securely.  Specifically:
> @@ -289,8 +287,7 @@ static int abortboot(int bootdelay)
>   * printing the error message to console.
>   */
>
> -#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) && \
> -       defined(CONFIG_OF_CONTROL)
> +#ifdef CONFIG_OF_CONTROL
>  static void secure_boot_cmd(char *cmd)
>  {
>         cmd_tbl_t *cmdtp;
> @@ -331,46 +328,33 @@ static void process_fdt_options(const void *blob)
>
>         /* Add an env variable to point to a kernel payload, if available */
>         addr = fdtdec_get_config_int(gd->fdt_blob, "kernel-offset", 0);
> -       if (addr)
> -               setenv_addr("kernaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr));
> +       if (addr) {
> +               setenv_addr("kernaddr",
> +                           (void *)(autoconf_sys_text_base() + addr));
> +       }
>
>         /* Add an env variable to point to a root disk, if available */
>         addr = fdtdec_get_config_int(gd->fdt_blob, "rootdisk-offset", 0);
> -       if (addr)
> -               setenv_addr("rootaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr));
> +       if (addr) {
> +               setenv_addr("rootaddr",
> +                           (void *)(autoconf_sys_text_base() + addr));
> +       }
>  }
>  #endif /* CONFIG_OF_CONTROL */
>
> -
> -/****************************************************************************/
> -
> -void main_loop (void)
> +static void process_boot_delay(void)
>  {
> -#ifndef CONFIG_SYS_HUSH_PARSER
> -       static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
> -       int len;
> -       int rc = 1;
> -       int flag;
> -#endif
> -#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) && \
> -               defined(CONFIG_OF_CONTROL)
> -       char *env;
> -#endif
> -#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
> -       char *s;
> -       int bootdelay;
> -#endif
> -#ifdef CONFIG_PREBOOT
> -       char *p;
> -#endif
>  #ifdef CONFIG_BOOTCOUNT_LIMIT
>         unsigned long bootcount = 0;
>         unsigned long bootlimit = 0;
>         char *bcs;
>         char bcs_set[16];
>  #endif /* CONFIG_BOOTCOUNT_LIMIT */
> -
> -       bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
> +#ifdef CONFIG_OF_CONTROL
> +       char *env;
> +#endif
> +       char *s;
> +       int bootdelay;
>
>  #ifdef CONFIG_BOOTCOUNT_LIMIT
>         bootcount = bootcount_load();
> @@ -382,51 +366,8 @@ void main_loop (void)
>         bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0;
>  #endif /* CONFIG_BOOTCOUNT_LIMIT */
>
> -#ifdef CONFIG_MODEM_SUPPORT
> -       debug ("DEBUG: main_loop:   do_mdm_init=%d\n", do_mdm_init);
> -       if (do_mdm_init) {
> -               char *str = strdup(getenv("mdm_cmd"));
> -               setenv ("preboot", str);  /* set or delete definition */
> -               if (str != NULL)
> -                       free (str);
> -               mdm_init(); /* wait for modem connection */
> -       }
> -#endif  /* CONFIG_MODEM_SUPPORT */
> -
> -#ifdef CONFIG_VERSION_VARIABLE
> -       {
> -               setenv ("ver", version_string);  /* set version variable */
> -       }
> -#endif /* CONFIG_VERSION_VARIABLE */
> -
> -#ifdef CONFIG_SYS_HUSH_PARSER
> -       u_boot_hush_start ();
> -#endif
> -
> -#if defined(CONFIG_HUSH_INIT_VAR)
> -       hush_init_var ();
> -#endif
> -
> -#ifdef CONFIG_PREBOOT
> -       if ((p = getenv ("preboot")) != NULL) {
> -# ifdef CONFIG_AUTOBOOT_KEYED
> -               int prev = disable_ctrlc(1);    /* disable Control C checking */
> -# endif
> -
> -               run_command_list(p, -1, 0);
> -
> -# ifdef CONFIG_AUTOBOOT_KEYED
> -               disable_ctrlc(prev);    /* restore Control C checking */
> -# endif
> -       }
> -#endif /* CONFIG_PREBOOT */
> -
> -       if (autoconf_update_tftp())
> -               update_tftp(0UL);
> -
> -#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
>         s = getenv ("bootdelay");
> -       bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
> +       bootdelay = s ? (int)simple_strtol(s, NULL, 10) : autoconf_bootdelay();
>
>         debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
>
> @@ -491,7 +432,69 @@ void main_loop (void)
>                         run_command_list(s, -1, 0);
>         }
>  #endif /* CONFIG_MENUKEY */
> -#endif /* CONFIG_BOOTDELAY */
> +}
> +
> +/****************************************************************************/
> +
> +void main_loop(void)
> +{
> +#ifndef CONFIG_SYS_HUSH_PARSER
> +       static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
> +       int len;
> +       int rc = 1;
> +       int flag;
> +#endif
> +#ifdef CONFIG_PREBOOT
> +       char *p;
> +#endif
> +
> +       bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
> +
> +#ifdef CONFIG_MODEM_SUPPORT
> +       debug("DEBUG: main_loop:   do_mdm_init=%d\n", do_mdm_init);
> +       if (do_mdm_init) {
> +               char *str = strdup(getenv("mdm_cmd"));
> +               setenv("preboot", str);  /* set or delete definition */
> +               if (str != NULL)
> +                       free(str);
> +               mdm_init(); /* wait for modem connection */
> +       }
> +#endif  /* CONFIG_MODEM_SUPPORT */
> +
> +#ifdef CONFIG_VERSION_VARIABLE
> +       {
> +               setenv("ver", version_string);  /* set version variable */
> +       }
> +#endif /* CONFIG_VERSION_VARIABLE */
> +
> +#ifdef CONFIG_SYS_HUSH_PARSER
> +       u_boot_hush_start();
> +#endif
> +
> +#if defined(CONFIG_HUSH_INIT_VAR)
> +       hush_init_var();
> +#endif
> +
> +#ifdef CONFIG_PREBOOT
> +       p = getenv("preboot");
> +       if (p) {
> +# ifdef CONFIG_AUTOBOOT_KEYED
> +               int prev = disable_ctrlc(1);    /* disable Control C checking */
> +# endif
> +
> +               run_command_list(p, -1, 0);
> +
> +# ifdef CONFIG_AUTOBOOT_KEYED
> +               disable_ctrlc(prev);    /* restore Control C checking */
> +# endif
> +       }
> +#endif /* CONFIG_PREBOOT */
> +
> +       if (autoconf_update_tftp())
> +               update_tftp(0UL);
> +
> +       if (autoconf_has_bootdelay() && autoconf_bootdelay() >= 0)
> +               process_boot_delay();
>
>  #if defined CONFIG_OF_CONTROL
>         set_working_fdt_addr((void *)gd->fdt_blob);
> --
> 1.8.1.3
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


Reviewed-by: Joe Hershberger <joe.hershberger at ni.com>


More information about the U-Boot mailing list