[U-Boot] [PATCH v4 5/8] main: Use autoconf for boot_delay code

Simon Glass sjg at chromium.org
Mon Jun 17 16:44:57 CEST 2013


Convert this function and its children to use autoconf instead of #ifdef.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v4:
- Rebase on current master

Changes in v3:
- Simplify code for finding out bootdelay from config or environment

Changes in v2: None

 common/main.c  | 74 +++++++++++++++++++++++++---------------------------------
 include/menu.h |  2 --
 2 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/common/main.c b/common/main.c
index dba6cee..fc55e06 100644
--- a/common/main.c
+++ b/common/main.c
@@ -302,52 +302,42 @@ static void process_fdt_options(const void *blob)
 
 static void process_boot_delay(void)
 {
-	char *s;
-	int bootdelay;
-#ifdef CONFIG_BOOTCOUNT_LIMIT
 	unsigned long bootcount = 0;
 	unsigned long bootlimit = 0;
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
-
-#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 */
-
-	s = getenv ("bootdelay");
-	bootdelay = s ? (int)simple_strtol(s, NULL, 10) : autoconf_bootdelay();
-
-#ifdef CONFIG_OF_CONTROL
-	bootdelay = fdtdec_get_config_int(gd->fdt_blob, "bootdelay",
-			bootdelay);
-#endif
+	const char *s;
+	int bootdelay;
+
+	if (autoconf_bootcount_limit()) {
+		bootcount = bootcount_load();
+		bootcount++;
+		bootcount_store(bootcount);
+		setenv_ulong("bootcount", bootcount);
+		bootlimit = getenv_ulong("bootlimit", 10, 0);
+	}
 
+	bootdelay = getenv_ulong("bootdelay", 10, autoconf_bootdelay());
+
+	if (autoconf_of_control()) {
+		bootdelay = fdtdec_get_config_int(gd->fdt_blob, "bootdelay",
+						  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");
+	}
 	if (autoconf_of_control()) {
 		char *env;
 
@@ -370,24 +360,24 @@ static void process_boot_delay(void)
 	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
+		int prev;
+
+		/* disable Control C checking */
+		if (autoconf_autoboot_keyed())
+			prev = disable_ctrlc(1);
 
 		run_command_list(s, -1, 0);
 
-#ifdef CONFIG_AUTOBOOT_KEYED
-		disable_ctrlc(prev);	/* restore Control C checking */
-#endif
+		/* restore Control C checking */
+		if (autoconf_autoboot_keyed())
+			disable_ctrlc(prev);
 	}
 
-#ifdef CONFIG_MENUKEY
-	if (menukey == CONFIG_MENUKEY) {
+	if (autoconf_menukey() && menukey == autoconf_menukey()) {
 		s = getenv("menucmd");
 		if (s)
 			run_command_list(s, -1, 0);
 	}
-#endif /* CONFIG_MENUKEY */
 }
 
 void main_loop(void)
diff --git a/include/menu.h b/include/menu.h
index d8200ee..bcc3ec4 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -31,7 +31,5 @@ int menu_destroy(struct menu *m);
 void menu_display_statusline(struct menu *m);
 int menu_default_choice(struct menu *m, void **choice);
 
-#if defined(CONFIG_MENU_SHOW)
 int menu_show(int bootdelay);
-#endif
 #endif /* __MENU_H__ */
-- 
1.8.3



More information about the U-Boot mailing list