All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 07/16] main: Remove CONFIG #ifdefs from the abortboot() code
Date: Tue, 26 Feb 2013 08:11:00 -0800	[thread overview]
Message-ID: <1361895069-7343-8-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1361895069-7343-1-git-send-email-sjg@chromium.org>

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 <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
---
Changes in v3: None
Changes in v2: None

 common/main.c | 86 ++++++++++++++++++++++-------------------------------------
 1 file changed, 32 insertions(+), 54 deletions(-)

diff --git a/common/main.c b/common/main.c
index 36d8048..e2eb9ec 100644
--- a/common/main.c
+++ b/common/main.c
@@ -90,15 +90,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];
@@ -106,33 +111,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
+	if (autoconf_has_autoboot_prompt())
+		printf(autoconf_autoboot_prompt());
 
-	for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
+	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 ?
@@ -164,7 +151,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,
@@ -189,43 +176,37 @@ static int abortboot_keyed(int bootdelay)
 		puts("key timeout\n");
 #  endif
 
-#ifdef CONFIG_SILENT_CONSOLE
-	if (abort)
+	if (autoconf_silent_console() && abort)
 		gd->flags &= ~GD_FLG_SILENT;
-#endif
 
 	return abort;
 }
 
-#ifdef CONFIG_MENUKEY
 static int menukey = 0;
-#endif
 
 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) {
+		/* Check if key already pressed */
+		if (tstc()) {	/* we got a key press */
 			(void) getc();  /* consume input	*/
 			puts ("\b\b\b 0");
 			abort = 1;	/* don't auto boot	*/
 		}
 	}
-#endif
 
 	while ((bootdelay > 0) && (!abort)) {
 		--bootdelay;
@@ -235,11 +216,10 @@ static int abortboot_normal(int bootdelay)
 			if (tstc()) {	/* we got a key press	*/
 				abort  = 1;	/* don't auto boot	*/
 				bootdelay = 0;	/* no more delay	*/
-# ifdef CONFIG_MENUKEY
-				menukey = getc();
-# else
-				(void) getc();  /* consume input	*/
-# endif
+				if (autoconf_menukey())
+					menukey = getc();
+				else
+					(void) getc();  /* consume input */
 				break;
 			}
 			udelay(10000);
@@ -250,10 +230,8 @@ static int abortboot_normal(int bootdelay)
 
 	putc('\n');
 
-#ifdef CONFIG_SILENT_CONSOLE
-	if (abort)
+	if (autoconf_silent_console() && abort)
 		gd->flags &= ~GD_FLG_SILENT;
-#endif
 
 	return abort;
 }
-- 
1.8.1.3

  parent reply	other threads:[~2013-02-26 16:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26 16:10 [U-Boot] [PATCH v3 0/16] Provide a mechanism to avoid using #ifdef everywhere Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 01/16] Implement autoconf header file Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 02/16] at91: Correct CONFIG_AUTOBOOT_PROMPT definition for pm9263 Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 03/16] net: Add prototype for update_tftp, and use autoconf Simon Glass
2013-03-20 19:40   ` Tom Rini
2013-03-20 19:57     ` Simon Glass
2013-03-20 20:30       ` Tom Rini
2013-03-21  1:47         ` Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 04/16] main: Separate out the two abortboot() functions Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 05/16] main: Move boot_delay code into its own function Simon Glass
2013-02-26 16:10 ` [U-Boot] [PATCH v3 06/16] main: Use autoconf for boot retry feature Simon Glass
2013-02-26 16:11 ` Simon Glass [this message]
2013-02-26 16:11 ` [U-Boot] [PATCH v3 08/16] main: Use get/setenv_ulong() Simon Glass
2013-02-26 16:11 ` [U-Boot] [PATCH v3 09/16] main: Use autoconf for boot_delay code Simon Glass
2013-02-27  9:14   ` Joe Hershberger
2013-02-26 16:11 ` [U-Boot] [PATCH v3 10/16] main: Use autoconf for parser selection Simon Glass
2013-02-26 16:11 ` [U-Boot] [PATCH v3 11/16] main: Fix typos and checkpatch warnings in command line reading Simon Glass
2013-02-27  9:25   ` Joe Hershberger
2013-02-26 16:11 ` [U-Boot] [PATCH v3 12/16] main: Use autoconf " Simon Glass
2013-02-27  9:17   ` Joe Hershberger
2013-02-26 16:11 ` [U-Boot] [PATCH v3 13/16] main: Use autoconf in main_loop() Simon Glass
2013-02-27  9:23   ` Joe Hershberger
2013-02-26 16:11 ` [U-Boot] [PATCH v3 14/16] main: Correct header order Simon Glass
2013-02-26 16:11 ` [U-Boot] [PATCH v3 15/16] main: Add debug_parser() to avoid #ifdefs Simon Glass
2013-02-26 16:11 ` [U-Boot] [PATCH v3 16/16] main: Add debug_bootkeys " Simon Glass
2013-03-21 14:38 ` [U-Boot] [PATCH v3 0/16] Provide a mechanism to avoid using #ifdef everywhere Tom Rini
2013-05-13 22:12   ` Simon Glass
2013-05-14 21:21     ` Tom Rini
2013-05-14 21:27       ` Simon Glass
2013-05-14 22:15         ` Tom Rini
2013-05-14 22:22           ` Vadim Bendebury
2013-05-14 22:28             ` Tom Rini
2013-05-15 14:13               ` Simon Glass
2013-05-16 16:26                 ` Tom Rini
2013-05-16 18:49                   ` Simon Glass
2013-05-30 13:57                     ` Simon Glass
2013-05-30 15:17                       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1361895069-7343-8-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.