[U-Boot] [PATCH] Fix incorrect use of getenv() before relocation

Detlev Zundel dzu at denx.de
Tue May 10 12:44:01 CEST 2011


Hi Wolfgang,

> A large number of boards incorrectly used getenv() in their board init
> code running before relocation.  In some cases this caused U-Boot to
> hang when certain environment variables grew too long.
> Fix the code to use getenv_r().
>
> Signed-off-by: Wolfgang Denk <wd at denx.de>
> Cc: Stefan Roese <sr at denx.de>
> Cc: The LEOX team <team at leox.org>
> Cc: Michael Schwingen <michael at schwingen.org>
> Cc: Georg Schardt <schardt at team-ctech.de>
> Cc: Werner Pfister <Pfister_Werner at intercontrol.de>
> Cc: Dirk Eibach <eibach at gdsys.de>
> Cc: Peter De Schrijver <p2 at mind.be>
> Cc: John Zhan <zhanz at sinovee.com>
> Cc: Rishi Bhattacharya <rishi at ti.com>
> Cc: Peter Tyser <ptyser at xes-inc.com>
> ---
>  board/LEOX/elpt860/elpt860.c          |    5 +++--
>  board/RRvision/RRvision.c             |   10 ++++++----
>  board/actux1/actux1.c                 |    9 +++++----
>  board/actux2/actux2.c                 |    9 +++++----
>  board/actux3/actux3.c                 |    7 ++++---
>  board/amcc/acadia/acadia.c            |    7 ++++---
>  board/amcc/bamboo/bamboo.c            |    7 ++++---
>  board/amcc/bluestone/bluestone.c      |    7 ++++---
>  board/amcc/bubinga/bubinga.c          |    7 ++++---
>  board/amcc/canyonlands/canyonlands.c  |    7 ++++---
>  board/amcc/ebony/ebony.c              |    7 ++++---
>  board/amcc/katmai/katmai.c            |    7 ++++---
>  board/amcc/kilauea/kilauea.c          |    7 ++++---
>  board/amcc/luan/luan.c                |    7 ++++---
>  board/amcc/makalu/makalu.c            |    7 ++++---
>  board/amcc/ocotea/ocotea.c            |    9 +++++----
>  board/amcc/redwood/redwood.c          |    7 ++++---
>  board/amcc/sequoia/sequoia.c          |    7 ++++---
>  board/amcc/taihu/taihu.c              |    7 ++++---
>  board/amcc/taishan/taishan.c          |    9 +++++----
>  board/amcc/walnut/walnut.c            |    7 ++++---
>  board/amcc/yosemite/yosemite.c        |    7 ++++---
>  board/amcc/yucca/yucca.c              |    7 ++++---
>  board/amirix/ap1000/ap1000.c          |   24 ++++++++++++++----------
>  board/avnet/fx12mm/fx12mm.c           |   17 ++++++++---------
>  board/c2mon/c2mon.c                   |   10 ++++++----
>  board/digsy_mtc/digsy_mtc.c           |    9 +++++----
>  board/etx094/etx094.c                 |   16 +++++++---------
>  board/gdsys/405ep/dlvision-10g.c      |    7 ++++---
>  board/gdsys/405ep/io.c                |    7 ++++---
>  board/gdsys/405ep/iocon.c             |    7 ++++---
>  board/gdsys/dlvision/dlvision.c       |    7 ++++---
>  board/gdsys/gdppc440etx/gdppc440etx.c |    7 ++++---
>  board/gdsys/intip/intip.c             |    7 ++++---
>  board/gdsys/neo/neo.c                 |    7 ++++---
>  board/gw8260/gw8260.c                 |    8 ++++----
>  board/hermes/hermes.c                 |   16 +++++++---------
>  board/ixdp425/ixdp425.c               |    7 ++++---
>  board/lwmon5/lwmon5.c                 |    7 ++++---
>  board/micronas/vct/vct.c              |    7 ++++---
>  board/ml2/ml2.c                       |   18 +++++++-----------
>  board/mosaixtech/icon/icon.c          |    7 ++++---
>  board/pcs440ep/pcs440ep.c             |    7 ++++---
>  board/prodrive/alpr/alpr.c            |    9 +++++----
>  board/prodrive/p3mx/p3mx.c            |    7 ++++---
>  board/prodrive/p3p440/p3p440.c        |    7 ++++---
>  board/prodrive/pdnb3/pdnb3.c          |    7 ++++---
>  board/quad100hd/quad100hd.c           |    7 ++++---
>  board/quantum/quantum.c               |   10 ++++++----
>  board/rbc823/rbc823.c                 |    9 +++++----
>  board/socrates/socrates.c             |   12 +++++++-----
>  board/svm_sc8xx/svm_sc8xx.c           |   32 +++++++++++++++++---------------
>  board/t3corp/t3corp.c                 |    7 ++++---
>  board/ti/omap5912osk/omap5912osk.c    |    7 ++++---
>  board/tqc/tqm8260/tqm8260.c           |    8 ++++----
>  board/tqc/tqm8272/tqm8272.c           |    8 ++++++--
>  board/tqc/tqm85xx/tqm85xx.c           |   19 +++++++++++--------
>  board/tqc/tqm8xx/tqm8xx.c             |   18 ++++++++++--------
>  board/xes/common/board.c              |   17 +++++++++++------
>  board/xes/xpedite1000/xpedite1000.c   |   21 +++++++++++----------
>  board/zeus/zeus.c                     |    7 ++++---
>  61 files changed, 324 insertions(+), 260 deletions(-)
>

[...]

> diff --git a/board/RRvision/RRvision.c b/board/RRvision/RRvision.c
> index 9d016c5..0182d8a 100644
> --- a/board/RRvision/RRvision.c
> +++ b/board/RRvision/RRvision.c
> @@ -93,14 +93,16 @@ const uint sdram_table[] =
>  
>  int checkboard (void)
>  {
> -	char *s = getenv ("serial#");
> +	char buf[64];
> +	int i;
> +	int l = getenv_f("serial#", buf, sizeof(buf));
>  
>  	puts ("Board: RRvision ");
>  
> -	for (; s && *s; ++s) {
> -		if (*s == ' ')
> +	for (i=0; i < l; ++i) {
> +		if (buf[i] == ' ')
>  			break;
> -		putc (*s);
> +		putc (buf[i]);
>  	}
>  
>  	putc ('\n');

Looks good.

[...]

> diff --git a/board/digsy_mtc/digsy_mtc.c b/board/digsy_mtc/digsy_mtc.c
> index 9f13a3d..a0c4b10 100644
> --- a/board/digsy_mtc/digsy_mtc.c
> +++ b/board/digsy_mtc/digsy_mtc.c
> @@ -191,15 +191,16 @@ phys_size_t initdram(int board_type)
>  
>  int checkboard(void)
>  {
> -	char *s = getenv("serial#");
> +	char buf[64];
> +	int i = getenv_f("serial#", buf, sizeof(buf));
>  
>  	puts ("Board: InterControl digsyMTC");
>  #if defined(CONFIG_DIGSY_REV5)
>  	puts (" rev5");
>  #endif
> -	if (s != NULL) {
> -		puts(", ");
> -		puts(s);
> +	if (i > 0) {
> +		puts(", serial# ");
> +		puts(buf);
>  	}
>  	putc('\n');

This changes the output.  On the other hand, this feature was never used
on this board, so I'm ok with removing this read altogether.

[...]

> diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
> index 72e7401..65fb70a 100644
> --- a/board/socrates/socrates.c
> +++ b/board/socrates/socrates.c
> @@ -52,15 +52,17 @@ ulong flash_get_size (ulong base, int banknum);
>  int checkboard (void)
>  {
>  	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
> -
> -	char *src;
> +	char buf[64];
>  	int f;
> -	char *s = getenv("serial#");
> +	int i = getenv_f("serial#", buf, sizeof(buf));
> +#ifdef CONFIG_PCI
> +	char *src;
> +#endif
>  
>  	puts("Board: Socrates");
> -	if (s != NULL) {
> +	if (i > 0) {
>  		puts(", serial# ");
> -		puts(s);
> +		puts(buf);
>  	}
>  	putc('\n');
>  

Looks good.

Cheers
  Detlev

-- 
Another helpful hint for successful MIME processing:

application/msword; rm -f %s; description="MS Word Text";
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de


More information about the U-Boot mailing list