[U-Boot-Users] [PATCH] simplify silent console

Ladislav Michl ladis at linux-mips.org
Tue Apr 24 14:02:07 CEST 2007


On Mon, Oct 30, 2006 at 09:25:14AM +0100, Stefan Roese wrote:
> Hi Ladis,
> 
> On Tuesday 25 July 2006 17:30, Ladislav Michl wrote:
> > silent console output is currently implemented by assigning nulldev
> > as output device. This is a bit overcomplicated, since there is
> > also GD_FLG_SILENT flag.
> >
> > Patch bellow tries to simplify silencing console by honouring
> > GD_FLG_SILENT in console output functions, so there is no need to
> > mess with output device. Comments?
> 
> Good idea. One thing though: After applying your patch the system _does_ print 
> the bootcount messages "Hit any key to stop autoboot: ..." even if 
> the "silent" variable is set. This was not done with the previous 
> implementation and is not intended. Could you please rework your patch, that 
> no message is printed here?

It is intended. See a bit older thread here:
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/17845/

On Thu, Jun 30, 2005 at 05:43:08PM -0400, Dave Ellis wrote:
| I think I see the problem. CONFIG_AUTOBOOT_PROMPT should be
| displayed, but it isn't because printf() is checking GD_FLG_SILENT.
| The cleanest solution I see is to check GD_FLG_SILENT only when
| sending directly to the handler, not when sending to the device.

Proposed change doesn't use nulldev at all and also doesn't set stdout
to nulldev and "back" [*] to serial.

[*] What is user wants to use usbtty? Safe way is not to deal with
output device at all. This way output that implies stdout is silenced - 
i.e. printf("Hello"); and output that specifies it would still work -
i.e. fprintf(stdout, "Hello"); This is used to get 'stop autoboot' prompt.

> And please update the README.silent documentation too to match the updated 
> implementation.

Signed-off-by: Ladislav Michl <ladis at linux-mips.org>

diff --git a/common/main.c b/common/main.c
index cc4b50f..e637bbf 100644
--- a/common/main.c
+++ b/common/main.c
@@ -112,16 +112,8 @@ static __inline__ int abortboot(int bootdelay)
 	u_int presskey_max = 0;
 	u_int i;
 
-#ifdef CONFIG_SILENT_CONSOLE
-	if (gd->flags & GD_FLG_SILENT) {
-		/* Restore serial console */
-		console_assign (stdout, "serial");
-		console_assign (stderr, "serial");
-	}
-#endif
-
 #  ifdef CONFIG_AUTOBOOT_PROMPT
-	printf (CONFIG_AUTOBOOT_PROMPT, bootdelay);
+	fprintf(stdout, CONFIG_AUTOBOOT_PROMPT, bootdelay);
 #  endif
 
 #  ifdef CONFIG_AUTOBOOT_DELAY_STR
@@ -151,7 +143,7 @@ static __inline__ int abortboot(int bootdelay)
 				    presskey_max : delaykey[i].len;
 
 #  if DEBUG_BOOTKEYS
-		printf("%s key:<%s>\n",
+		fprintf(stdout, "%s key:<%s>\n",
 		       delaykey[i].retry ? "delay" : "stop",
 		       delaykey[i].str ? delaykey[i].str : "NULL");
 #  endif
@@ -168,7 +160,7 @@ static __inline__ int abortboot(int bootdelay)
 				    delaykey[i].str,
 				    delaykey[i].len) == 0) {
 #  if DEBUG_BOOTKEYS
-				printf("got %skey\n",
+				fprintf(stdout, "got %skey\n",
 				       delaykey[i].retry ? "delay" : "stop");
 #  endif
 
@@ -195,18 +187,12 @@ static __inline__ int abortboot(int bootdelay)
 	}
 #  if DEBUG_BOOTKEYS
 	if (!abort)
-		puts ("key timeout\n");
+		fputs(stdout, "key timeout\n");
 #  endif
 
 #ifdef CONFIG_SILENT_CONSOLE
-	if (abort) {
-		/* permanently enable normal console output */
-		gd->flags &= ~(GD_FLG_SILENT);
-	} else if (gd->flags & GD_FLG_SILENT) {
-		/* Restore silent console */
-		console_assign (stdout, "nulldev");
-		console_assign (stderr, "nulldev");
-	}
+	if (abort)
+		gd->flags &= ~GD_FLG_SILENT;
 #endif
 
 	return abort;
@@ -222,18 +208,10 @@ static __inline__ int abortboot(int bootdelay)
 {
 	int abort = 0;
 
-#ifdef CONFIG_SILENT_CONSOLE
-	if (gd->flags & GD_FLG_SILENT) {
-		/* Restore serial console */
-		console_assign (stdout, "serial");
-		console_assign (stderr, "serial");
-	}
-#endif
-
 #ifdef CONFIG_MENUPROMPT
-	printf(CONFIG_MENUPROMPT, bootdelay);
+	fprintf(stdout, CONFIG_MENUPROMPT, bootdelay);
 #else
-	printf("Hit any key to stop autoboot: %2d ", bootdelay);
+	fprintf(stdout, "Hit any key to stop autoboot: %2d ", bootdelay);
 #endif
 
 #if defined CONFIG_ZERO_BOOTDELAY_CHECK
@@ -244,8 +222,8 @@ static __inline__ int abortboot(int bootdelay)
 	if (bootdelay >= 0) {
 		if (tstc()) {	/* we got a key press	*/
 			(void) getc();  /* consume input	*/
-			puts ("\b\b\b 0");
-			abort = 1; 	/* don't auto boot	*/
+			fputs(stdout, "\b\b\b 0");
+			abort = 1;	/* don't auto boot	*/
 		}
 	}
 #endif
@@ -269,20 +247,14 @@ static __inline__ int abortboot(int bootdelay)
 			udelay (10000);
 		}
 
-		printf ("\b\b\b%2d ", bootdelay);
+		fprintf(stdout, "\b\b\b%2d ", bootdelay);
 	}
 
-	putc ('\n');
+	fputc(stdout, '\n');
 
 #ifdef CONFIG_SILENT_CONSOLE
-	if (abort) {
-		/* permanently enable normal console output */
-		gd->flags &= ~(GD_FLG_SILENT);
-	} else if (gd->flags & GD_FLG_SILENT) {
-		/* Restore silent console */
-		console_assign (stdout, "nulldev");
-		console_assign (stderr, "nulldev");
-	}
+	if (abort)
+		gd->flags &= ~GD_FLG_SILENT;
 #endif
 
 	return abort;





More information about the U-Boot mailing list