Commit f0c0b3a9 authored by Wolfgang Denk's avatar Wolfgang Denk
Browse files

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: default avatarWolfgang Denk <wd@denx.de>
Cc: Stefan Roese <sr@denx.de>
Cc: The LEOX team <team@leox.org>
Cc: Michael Schwingen <michael@schwingen.org>
Cc: Georg Schardt <schardt@team-ctech.de>
Cc: Werner Pfister <Pfister_Werner@intercontrol.de>
Cc: Dirk Eibach <eibach@gdsys.de>
Cc: Peter De Schrijver <p2@mind.be>
Cc: John Zhan <zhanz@sinovee.com>
Cc: Rishi Bhattacharya <rishi@ti.com>
Cc: Peter Tyser <ptyser@xes-inc.com>
parent a02a884b
......@@ -169,9 +169,10 @@ int board_early_init_f (void)
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
if (!s || strncmp (s, "ELPT860", 7))
if ((i < 0) || strncmp(buf, "ELPT860", 7))
printf ("### No HW ID - assuming ELPT860\n");
return (0); /* success */
......
......@@ -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');
......
......@@ -89,14 +89,15 @@ int board_init (void)
*/
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: AcTux-1 rev.");
putc (ACTUX1_BOARDREL + 'A' - 1);
if (s != NULL) {
puts (", serial# ");
puts (s);
if (i > 0) {
puts(", serial# ");
puts(buf);
}
putc ('\n');
......
......@@ -96,14 +96,15 @@ int board_init (void)
*/
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: AcTux-2 rev.");
putc (ACTUX2_BOARDREL + 'A' - 1);
if (s != NULL) {
puts (", serial# ");
puts (s);
if (i > 0) {
puts(", serial# ");
puts(buf);
}
putc ('\n');
......
......@@ -111,14 +111,15 @@ int board_init (void)
*/
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: AcTux-3 rev.");
putc (ACTUX3_BOARDREL + 'A' - 1);
if (s != NULL) {
if (i > 0) {
puts (", serial# ");
puts (s);
puts (buf);
}
putc ('\n');
......
......@@ -102,15 +102,16 @@ int misc_init_f(void)
*/
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
u8 rev;
rev = in8(CONFIG_SYS_CPLD_BASE + 0);
printf("Board: Acadia - AMCC PPC405EZ Evaluation Board, Rev. %X", rev);
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -440,12 +440,13 @@ int board_early_init_f(void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Bamboo - AMCC PPC440EP Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -78,13 +78,14 @@ int board_early_init_f(void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts("Board: Bluestone Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -53,13 +53,14 @@ int board_early_init_f(void)
*/
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts("Board: Bubinga - AMCC PPC405EP Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -293,7 +293,8 @@ int checkboard(void)
{
struct board_bcsr *bcsr_data =
(struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
if (pvr_460ex()) {
printf("Board: Canyonlands - AMCC PPC460EX Evaluation Board");
......@@ -319,9 +320,9 @@ int checkboard(void)
printf(", Rev. %X", in_8(&bcsr_data->cpld_rev));
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -92,12 +92,13 @@ int board_early_init_f(void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Ebony - AMCC PPC440GP Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -236,12 +236,13 @@ int board_early_init_f (void)
int checkboard (void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Katmai - AMCC 440SPe Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -307,16 +307,17 @@ int board_pcie_last(void)
int checkboard (void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
if (is_405exr())
printf("Board: Haleakala - AMCC PPC405EXr Evaluation Board");
else
printf("Board: Kilauea - AMCC PPC405EX Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
printf(" (CPLD rev. %ld)\n", gd->board_type);
......
......@@ -105,13 +105,14 @@ int misc_init_r(void)
************************************************************************/
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Luan - AMCC PPC440SP Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -224,13 +224,14 @@ int misc_init_r(void)
int checkboard (void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Makalu - AMCC PPC405EX Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -200,12 +200,13 @@ int board_early_init_f (void)
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf ("Board: Ocotea - AMCC PPC440GX Evaluation Board");
if (s != NULL) {
puts (", serial# ");
puts (s);
if (i > 0) {
puts(", serial# ");
puts(buf);
}
putc ('\n');
......
......@@ -200,12 +200,13 @@ int board_early_init_f(void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Redwood - AMCC 460SX Reference Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -331,7 +331,8 @@ int misc_init_r(void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
u8 rev;
u32 clock = get_async_pci_freq();
......@@ -344,9 +345,9 @@ int checkboard(void)
rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -65,13 +65,14 @@ int board_early_init_f(void)
*/
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
puts("Board: Taihu - AMCC PPC405EP Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -193,12 +193,13 @@ int misc_init_r(void)
int checkboard (void)
{
char *s = getenv ("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf ("Board: Taishan - AMCC PPC440GX Evaluation Board");
if (s != NULL) {
puts (", serial# ");
puts (s);
if (i > 0) {
puts(", serial# ");
puts(buf);
}
putc ('\n');
......
......@@ -67,7 +67,8 @@ int board_early_init_f(void)
*/
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
uint pvr = get_pvr();
if (pvr == PVR_405GPR_RB) {
......@@ -76,9 +77,9 @@ int checkboard(void)
puts("Board: Walnut - AMCC PPC405GP Evaluation Board");
}
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -188,7 +188,8 @@ int misc_init_r (void)
int checkboard(void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
u8 rev;
u32 clock = get_async_pci_freq();
......@@ -201,9 +202,9 @@ int checkboard(void)
rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -542,12 +542,13 @@ int board_early_init_f (void)
int checkboard (void)
{
char *s = getenv("serial#");
char buf[64];
int i = getenv_f("serial#", buf, sizeof(buf));
printf("Board: Yucca - AMCC 440SPe Evaluation Board");
if (s != NULL) {
if (i > 0) {
puts(", serial# ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -37,8 +37,8 @@ int board_pre_init (void)
/** serial number and platform display at startup */
int checkboard (void)
{
char *s = getenv ("serial#");
char *e;
char buf[64];
int l = getenv_f("serial#", buf, sizeof(buf));
/* After a loadace command, the SystemAce control register is left in a wonky state. */
/* this code did not work in board_pre_init */
......@@ -115,17 +115,19 @@ int checkboard (void)
puts ("Serial#: ");
if (!s) {
if (l < 0) {
printf ("### No HW ID - assuming AMIRIX");
} else {
for (e = s; *e; ++e) {
if (*e == ' ')
int i;
for (i = 0; i < l; ++i) {
if (buf[i] == ' ') {
buf[i] = '\0';
break;
}
}
for (; s < e; ++s) {
putc (*s);
}
puts(buf);
}
putc ('\n');
......@@ -136,9 +138,11 @@ int checkboard (void)
phys_size_t initdram (int board_type)
{
char *s = getenv ("dramsize");
char buf[64];
int i = getenv_f("dramsize", buf, sizeof(buf));
if (s != NULL) {
if (i > 0) {
char *s = buf;
if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
s += 2;
}
......
......@@ -32,20 +32,19 @@
int checkboard(void)
{
char tmp[64];
char *s, *e;
int i = getenv_f("serial", tmp, sizeof(tmp));
char buf[64];
int i;
int l = getenv_f("serial#", buf, sizeof(buf));
if (i < 0) {
if (l < 0) {
printf("Avnet Virtex4 FX12 with no serial #");
} else {
for (e = tmp; *e; ++e) {
if (*e == ' ')
printf("Avnet Virtex4 FX12 Minimodul # ");
for (i = 0; i < l; ++i) {
if (buf[i] == ' ')
break;
putc(buf[i]);
}
printf("Avnet Virtex4 FX12 Minimodul # ");
for (s = tmp; s < e; ++s)
putc(*s);
}
putc('\n');
return 0;
......
......@@ -91,14 +91,16 @@ const uint sdram_table[] =
int checkboard (void)
{
unsigned char *s = (unsigned char *)getenv ("serial#");
char buf[64];
int i;
int l = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: TTTech C2MON ");
for (; s && *s; ++s) {
if (*s == ' ')
for (i = 0; i < l; ++i) {
if (buf[i] == ' ')
break;
putc (*s);
putc (buf[i]);
}
putc ('\n');
......
......@@ -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) {
if (i > 0) {
puts(", ");
puts(s);
puts(buf);
}
putc('\n');
......
......@@ -92,8 +92,9 @@ const uint sdram_table[] = {
int checkboard (void)
{
char *s = getenv ("serial#");
char *e;
char buf[64];
int i;
int l = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: ");
......@@ -103,19 +104,16 @@ int checkboard (void)
gd->board_type = 1; /* 1 = 1SDRAM-Device */
#endif
if (!s || strncmp (s, "ETX_", 4)) {