Patchwork [U-Boot,14/17] console: Call overwrite_console before searching for console devices

login
register
mail settings
Submitter Simon Glass
Date Nov. 3, 2012, 12:27 a.m.
Message ID <1351902453-27956-15-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/196795/
State Superseded, archived
Delegated to: Tom Rini
Headers show

Comments

Simon Glass - Nov. 3, 2012, 12:27 a.m.
From: Anton Staaf <robotboy@chromium.org>

Move the overwrite_console function call to before the search for
the console devices.  This lets the board specific function
replace the environment variables and have that picked up by the
console code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/console.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
Wolfgang Denk - Nov. 3, 2012, 3:32 p.m.
Dear Simon Glass,

In message <1351902453-27956-15-git-send-email-sjg@chromium.org> you wrote:
> From: Anton Staaf <robotboy@chromium.org>
> 
> Move the overwrite_console function call to before the search for
> the console devices.  This lets the board specific function
> replace the environment variables and have that picked up by the
> console code.

Can you please explain what "replace the environment variables" means,
and how this is related to the console code?

Or what exactly this patch is needed for?

Best regards,

Wolfgang Denk
Simon Glass - Nov. 7, 2012, 9:28 p.m.
Hi Wolfgang,

On Sat, Nov 3, 2012 at 8:32 AM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Simon Glass,
>
> In message <1351902453-27956-15-git-send-email-sjg@chromium.org> you wrote:
>> From: Anton Staaf <robotboy@chromium.org>
>>
>> Move the overwrite_console function call to before the search for
>> the console devices.  This lets the board specific function
>> replace the environment variables and have that picked up by the
>> console code.
>
> Can you please explain what "replace the environment variables" means,
> and how this is related to the console code?

It allows the environment variables (e.g. stdin) to be changed by the
overwrite_console function call.

I have had another look at this, and I believe that Allen Warren's
patch last week for Tegra does a similar thing:

http://patchwork.ozlabs.org/patch/196412/

So I think we can drop this patch.

Regards,
Simon

>
> Or what exactly this patch is needed for?
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
> Mike's Law: For a lumber company employing two men and a cut-off saw,
> the marginal product of labor for any number  of  additional  workers
> equals  zero  until the acquisition of another cut-off saw. Let's not
> even consider a chainsaw.
> - Mike Dennison [You could always  schedule the saw, though - ed.]
Wolfgang Denk - Nov. 8, 2012, 10:33 a.m.
Dear Simon,

In message <CAPnjgZ1mmjh7xD3ZAqznjfGE2UVG_KM1j0pwF4xsL3pRY23f6Q@mail.gmail.com> you wrote:
> 
> >> Move the overwrite_console function call to before the search for
> >> the console devices.  This lets the board specific function
> >> replace the environment variables and have that picked up by the
> >> console code.
> >
> > Can you please explain what "replace the environment variables" means,
> > and how this is related to the console code?
> 
> It allows the environment variables (e.g. stdin) to be changed by the
> overwrite_console function call.

Ah!  I feared that would be some other way to reset / change /
overwrite the _whole_ environment - "the environment variables" is not
really specific.

> So I think we can drop this patch.

Fine.

Best regards,

Wolfgang Denk

Patch

diff --git a/common/console.c b/common/console.c
index 1177f7d..831897b 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1,4 +1,6 @@ 
 /*
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
  * (C) Copyright 2000
  * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
  *
@@ -622,6 +624,7 @@  int console_init_r(void)
 {
 	char *stdinname, *stdoutname, *stderrname;
 	struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
+	int overwrite_console_retval;
 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
 	int i;
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
@@ -636,13 +639,19 @@  int console_init_r(void)
 	gd->jt[XF_puts] = serial_puts;
 	gd->jt[XF_printf] = serial_printf;
 
-	/* stdin stdout and stderr are in environment */
-	/* scan for it */
+	/*
+	 * stdin stdout and stderr are in environment.
+	 * Call OVERWRITE_CONSOLE function before scanning for stdio, stdout,
+	 * stderr to get latest pointer after update.
+	 * (getenv() returns NULL if var not present)
+	 */
+	overwrite_console_retval = OVERWRITE_CONSOLE;
 	stdinname  = getenv("stdin");
 	stdoutname = getenv("stdout");
 	stderrname = getenv("stderr");
 
-	if (OVERWRITE_CONSOLE == 0) {	/* if not overwritten by config switch */
+	/* if not overwritten by config switch */
+	if (overwrite_console_retval == 0) {
 		inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
 		outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
 		errdev    = search_device(DEV_FLAGS_OUTPUT, stderrname);