From f0c0b3a9e6f28a34d6da5edabba1e874fdf8e675 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Wed, 4 May 2011 10:32:28 +0000 Subject: Fix incorrect use of getenv() before relocation 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 Cc: Stefan Roese Cc: The LEOX team Cc: Michael Schwingen Cc: Georg Schardt Cc: Werner Pfister Cc: Dirk Eibach Cc: Peter De Schrijver Cc: John Zhan Cc: Rishi Bhattacharya Cc: Peter Tyser --- board/tqc/tqm8260/tqm8260.c | 8 ++++---- board/tqc/tqm8272/tqm8272.c | 8 ++++++-- board/tqc/tqm85xx/tqm85xx.c | 19 +++++++++++-------- board/tqc/tqm8xx/tqm8xx.c | 18 ++++++++++-------- 4 files changed, 31 insertions(+), 22 deletions(-) (limited to 'board/tqc') diff --git a/board/tqc/tqm8260/tqm8260.c b/board/tqc/tqm8260/tqm8260.c index 95073b8446..65a3174ec6 100644 --- a/board/tqc/tqm8260/tqm8260.c +++ b/board/tqc/tqm8260/tqm8260.c @@ -195,17 +195,17 @@ const iop_conf_t iop_conf_tab[4][32] = { */ int checkboard (void) { - char str[64]; - int i = getenv_f("serial#", str, sizeof (str)); + char buf[64]; + int i = getenv_f("serial#", buf, sizeof(buf)); puts ("Board: "); - if (!i || strncmp (str, "TQM82", 5)) { + if (i < 0 || strncmp(buf, "TQM82", 5)) { puts ("### No HW ID - assuming TQM8260\n"); return (0); } - puts (str); + puts (buf); putc ('\n'); return 0; diff --git a/board/tqc/tqm8272/tqm8272.c b/board/tqc/tqm8272/tqm8272.c index 96ec078fd9..9efb54125e 100644 --- a/board/tqc/tqm8272/tqm8272.c +++ b/board/tqc/tqm8272/tqm8272.c @@ -514,12 +514,16 @@ static inline int scanChar (char *p, int len, unsigned long *number) static int dump_hwib(void) { HWIB_INFO *hw = &hwinf; + char buf[64]; + int i = getenv_f("serial#", buf, sizeof(buf)); volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; - char *s = getenv("serial#"); + + if (i < 0) + buf[0] = '\0'; if (hw->OK) { printf ("HWIB on %x\n", HWIB_INFO_START_ADDR); - printf ("serial : %s\n", s); + printf ("serial : %s\n", buf); printf ("ethaddr: %s\n", hw->ethaddr); printf ("FLASH : %x nr:%d\n", hw->flash, hw->flash_nr); printf ("RAM : %x cs:%d\n", hw->ram, hw->ram_cs); diff --git a/board/tqc/tqm85xx/tqm85xx.c b/board/tqc/tqm85xx/tqm85xx.c index 99b13311ce..8fb73abde7 100644 --- a/board/tqc/tqm85xx/tqm85xx.c +++ b/board/tqc/tqm85xx/tqm85xx.c @@ -227,17 +227,19 @@ static const int casl_table[] = { 20, 25, 30 }; int cas_latency (void) { - char *s = getenv ("serial#"); + char buf[128]; int casl; int val; int i; casl = CONFIG_DDR_DEFAULT_CL; - if (s != NULL) { - if (strncmp(s + strlen (s) - strlen (CASL_STRING1), + i = getenv_f("serial#", buf, sizeof(buf)); + + if (i >0) { + if (strncmp(buf + strlen (buf) - strlen (CASL_STRING1), CASL_STRING2, strlen (CASL_STRING2)) == 0) { - val = simple_strtoul (s + strlen (s) - 2, NULL, 10); + val = simple_strtoul (buf + strlen (buf) - 2, NULL, 10); for (i = 0; i < N_CASL; ++i) { if (val == casl_table[i]) { @@ -252,12 +254,13 @@ int cas_latency (void) int checkboard (void) { - char *s = getenv ("serial#"); + char buf[64]; + int i = getenv_f("serial#", buf, sizeof(buf)); printf ("Board: %s", CONFIG_BOARDNAME); - if (s != NULL) { - puts (", serial# "); - puts (s); + if (i > 0) { + puts(", serial# "); + puts(buf); } putc ('\n'); diff --git a/board/tqc/tqm8xx/tqm8xx.c b/board/tqc/tqm8xx/tqm8xx.c index 6576e0288a..1fda53b9ae 100644 --- a/board/tqc/tqm8xx/tqm8xx.c +++ b/board/tqc/tqm8xx/tqm8xx.c @@ -106,31 +106,33 @@ 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: "); - if (!s || strncmp (s, "TQM8", 4)) { + if (l < 0 || strncmp(buf, "TQM8", 4)) { puts ("### No HW ID - assuming TQM8xxL\n"); return (0); } - if ((*(s + 6) == 'L')) { /* a TQM8xxL type */ + if ((buf[6] == 'L')) { /* a TQM8xxL type */ gd->board_type = 'L'; } - if ((*(s + 6) == 'M')) { /* a TQM8xxM type */ + if ((buf[6] == 'M')) { /* a TQM8xxM type */ gd->board_type = 'M'; } - if ((*(s + 6) == 'D')) { /* a TQM885D type */ + if ((buf[6] == 'D')) { /* a TQM885D type */ gd->board_type = 'D'; } - for (; *s; ++s) { - if (*s == ' ') + for (i = 0; i < l; ++i) { + if (buf[i] == ' ') break; - putc (*s); + putc (buf[i]); } #ifdef CONFIG_VIRTLAB2 puts (" (Virtlab2)"); -- cgit v1.2.3