Commit 91a76751a090bf43c166fda0815c9b5b2bfccbe9
1 parent
6d014adfa2
Exists in
master
and in
54 other branches
Make getenv() work before relocation.
So far, getenv() would work before relocation is most cases, even though it was not intended to be used that way. When switching to a hash table based implementation, this would break a number of boards. For convenience, we make getenv() check if it's running before relocation and, if so, use getenv_f() internally. Note that this is limited to simple cases, as we use a small static buffer (32 bytes) in the global data for this purpose. For this reason, it is also not a good idea to convert all current uses of getenv_f() into getenv() - some of the existing use cases need to be able to deal with longer variable values, so getenv_f() is still needed and recommended for use before relocation. Signed-off-by: Wolfgang Denk <wd@denx.de>
Showing 12 changed files with 51 additions and 39 deletions Side-by-side Diff
- arch/arm/include/asm/global_data.h
- arch/avr32/include/asm/global_data.h
- arch/blackfin/include/asm/global_data.h
- arch/i386/include/asm/global_data.h
- arch/m68k/include/asm/global_data.h
- arch/microblaze/include/asm/global_data.h
- arch/mips/include/asm/global_data.h
- arch/nios2/include/asm/global_data.h
- arch/powerpc/include/asm/global_data.h
- arch/sh/include/asm/global_data.h
- arch/sparc/include/asm/global_data.h
- common/cmd_nvedit.c
arch/arm/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * See file CREDITS for list of people who contributed to this |
6 | 6 | |
... | ... | @@ -47,13 +47,8 @@ |
47 | 47 | #ifdef CONFIG_FSL_ESDHC |
48 | 48 | unsigned long sdhc_clk; |
49 | 49 | #endif |
50 | -#if 0 | |
51 | - unsigned long cpu_clk; /* CPU clock in Hz! */ | |
52 | - unsigned long bus_clk; | |
53 | - phys_size_t ram_size; /* RAM size */ | |
54 | - unsigned long reset_status; /* reset status register at boot */ | |
55 | -#endif | |
56 | 50 | void **jt; /* jump table */ |
51 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
57 | 52 | } gd_t; |
58 | 53 | |
59 | 54 | /* |
... | ... | @@ -65,7 +60,7 @@ |
65 | 60 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
66 | 61 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
67 | 62 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
68 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
63 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
69 | 64 | |
70 | 65 | #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r8") |
71 | 66 |
arch/avr32/include/asm/global_data.h
... | ... | @@ -46,6 +46,7 @@ |
46 | 46 | void *fb_base; /* framebuffer address */ |
47 | 47 | #endif |
48 | 48 | void **jt; /* jump table */ |
49 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
49 | 50 | } gd_t; |
50 | 51 | |
51 | 52 | /* |
... | ... | @@ -57,7 +58,7 @@ |
57 | 58 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
58 | 59 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
59 | 60 | #define GD_FLG_LOGINIT 0x00020 /* Log Buf has been initialized */ |
60 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | 62 | |
62 | 63 | #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm("r5") |
63 | 64 |
arch/blackfin/include/asm/global_data.h
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | * |
4 | 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
5 | 5 | * |
6 | - * (C) Copyright 2000-2004 | |
6 | + * (C) Copyright 2000-2010 | |
7 | 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
8 | 8 | * |
9 | 9 | * See file CREDITS for list of people who contributed to this |
... | ... | @@ -53,7 +53,8 @@ |
53 | 53 | unsigned long post_init_f_time; /* When post_init_f started */ |
54 | 54 | #endif |
55 | 55 | |
56 | - void **jt; /* jump table */ | |
56 | + void **jt; /* jump table */ | |
57 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
57 | 58 | } gd_t; |
58 | 59 | |
59 | 60 | /* |
... | ... | @@ -65,7 +66,7 @@ |
65 | 66 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
66 | 67 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
67 | 68 | #define GD_FLG_LOGINIT 0x00020 /* Log Buf has been initialized */ |
68 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
69 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
69 | 70 | |
70 | 71 | #define DECLARE_GLOBAL_DATA_PTR register gd_t * volatile gd asm ("P3") |
71 | 72 |
arch/i386/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * See file CREDITS for list of people who contributed to this |
... | ... | @@ -46,6 +46,7 @@ |
46 | 46 | phys_size_t ram_size; /* RAM size */ |
47 | 47 | unsigned long reset_status; /* reset status register at boot */ |
48 | 48 | void **jt; /* jump table */ |
49 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
49 | 50 | } gd_t; |
50 | 51 | |
51 | 52 | /* |
... | ... | @@ -57,7 +58,7 @@ |
57 | 58 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
58 | 59 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
59 | 60 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
60 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | 62 | |
62 | 63 | extern gd_t *gd; |
63 | 64 |
arch/m68k/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 - 2003 | |
2 | + * (C) Copyright 2002 - 2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * See file CREDITS for list of people who contributed to this |
... | ... | @@ -64,6 +64,7 @@ |
64 | 64 | unsigned long board_type; |
65 | 65 | #endif |
66 | 66 | void **jt; /* Standalone app jump table */ |
67 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
67 | 68 | } gd_t; |
68 | 69 | |
69 | 70 | /* |
... | ... | @@ -75,7 +76,7 @@ |
75 | 76 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
76 | 77 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
77 | 78 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
78 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
79 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
79 | 80 | |
80 | 81 | #if 0 |
81 | 82 | extern gd_t *global_data; |
arch/microblaze/include/asm/global_data.h
... | ... | @@ -43,6 +43,7 @@ |
43 | 43 | unsigned long env_valid; /* Checksum of Environment valid? */ |
44 | 44 | unsigned long fb_base; /* base address of frame buffer */ |
45 | 45 | void **jt; /* jump table */ |
46 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
46 | 47 | } gd_t; |
47 | 48 | |
48 | 49 | /* |
... | ... | @@ -54,7 +55,7 @@ |
54 | 55 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
55 | 56 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
56 | 57 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
57 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
58 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
58 | 59 | |
59 | 60 | #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r31") |
60 | 61 |
arch/mips/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002-2003 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * See file CREDITS for list of people who contributed to this |
... | ... | @@ -46,6 +46,7 @@ |
46 | 46 | unsigned long env_addr; /* Address of Environment struct */ |
47 | 47 | unsigned long env_valid; /* Checksum of Environment valid? */ |
48 | 48 | void **jt; /* jump table */ |
49 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
49 | 50 | } gd_t; |
50 | 51 | |
51 | 52 | /* |
... | ... | @@ -57,7 +58,7 @@ |
57 | 58 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
58 | 59 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
59 | 60 | #define GD_FLG_LOGINIT 0x00020 /* Log Buf has been initialized */ |
60 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
61 | 62 | |
62 | 63 | #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("k0") |
63 | 64 |
arch/nios2/include/asm/global_data.h
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | unsigned long post_init_f_time; /* When post_init_f started */ |
38 | 38 | #endif |
39 | 39 | void **jt; /* Standalone app jump table */ |
40 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
40 | 41 | } gd_t; |
41 | 42 | |
42 | 43 | /* flags */ |
... | ... | @@ -46,7 +47,7 @@ |
46 | 47 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
47 | 48 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
48 | 49 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
49 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
50 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
50 | 51 | |
51 | 52 | #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp") |
52 | 53 |
arch/powerpc/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * See file CREDITS for list of people who contributed to this |
... | ... | @@ -176,6 +176,7 @@ |
176 | 176 | unsigned long long wdt_last; /* trace watch-dog triggering rate */ |
177 | 177 | #endif |
178 | 178 | void **jt; /* jump table */ |
179 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
179 | 180 | } gd_t; |
180 | 181 | |
181 | 182 | /* |
... | ... | @@ -187,7 +188,7 @@ |
187 | 188 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
188 | 189 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
189 | 190 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
190 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
191 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
191 | 192 | |
192 | 193 | #if 1 |
193 | 194 | #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r2") |
arch/sh/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * (C) Copyright 2007 |
... | ... | @@ -38,7 +38,8 @@ |
38 | 38 | unsigned long env_addr; /* Address of Environment struct */ |
39 | 39 | unsigned long env_valid; /* Checksum of Environment valid */ |
40 | 40 | void **jt; /* Standalone app jump table */ |
41 | -}gd_t; | |
41 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
42 | +} gd_t; | |
42 | 43 | |
43 | 44 | #define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */ |
44 | 45 | #define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */ |
... | ... | @@ -46,7 +47,7 @@ |
46 | 47 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
47 | 48 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
48 | 49 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
49 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
50 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
50 | 51 | |
51 | 52 | #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("r13") |
52 | 53 |
arch/sparc/include/asm/global_data.h
1 | 1 | /* |
2 | - * (C) Copyright 2002 | |
2 | + * (C) Copyright 2002-2010 | |
3 | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | 4 | * |
5 | 5 | * (C) Copyright 2007 |
... | ... | @@ -70,7 +70,8 @@ |
70 | 70 | #ifdef CONFIG_LWMON |
71 | 71 | unsigned long kbd_status; |
72 | 72 | #endif |
73 | - void **jt; /* jump table */ | |
73 | + void **jt; /* jump table */ | |
74 | + char env_buf[32]; /* buffer for getenv() before reloc. */ | |
74 | 75 | } gd_t; |
75 | 76 | |
76 | 77 | /* |
... | ... | @@ -82,7 +83,7 @@ |
82 | 83 | #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ |
83 | 84 | #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ |
84 | 85 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
85 | -#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
86 | +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ | |
86 | 87 | |
87 | 88 | #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("%g7") |
88 | 89 |
common/cmd_nvedit.c
... | ... | @@ -511,24 +511,31 @@ |
511 | 511 | |
512 | 512 | char *getenv (char *name) |
513 | 513 | { |
514 | - int i, nxt; | |
514 | + if (gd->flags & GD_FLG_RELOC) { /* full C runtime after reloc */ | |
515 | + int i, nxt; | |
515 | 516 | |
516 | - WATCHDOG_RESET(); | |
517 | + WATCHDOG_RESET(); | |
517 | 518 | |
518 | - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { | |
519 | - int val; | |
519 | + for (i=0; env_get_char(i) != '\0'; i=nxt+1) { | |
520 | + int val; | |
520 | 521 | |
521 | - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) { | |
522 | - if (nxt >= CONFIG_ENV_SIZE) { | |
523 | - return (NULL); | |
522 | + for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) { | |
523 | + if (nxt >= CONFIG_ENV_SIZE) { | |
524 | + return (NULL); | |
525 | + } | |
524 | 526 | } |
527 | + if ((val=envmatch((uchar *)name, i)) < 0) | |
528 | + continue; | |
529 | + return ((char *)env_get_addr(val)); | |
525 | 530 | } |
526 | - if ((val=envmatch((uchar *)name, i)) < 0) | |
527 | - continue; | |
528 | - return ((char *)env_get_addr(val)); | |
531 | + | |
532 | + return (NULL); | |
529 | 533 | } |
530 | 534 | |
531 | - return (NULL); | |
535 | + /* restricted C runtime before reloc */ | |
536 | + | |
537 | + return ((getenv_f(name,gd->env_buf,sizeof(gd->env_buf)) > 0) ? | |
538 | + gd->env_buf : NULL); | |
532 | 539 | } |
533 | 540 | |
534 | 541 | int getenv_f(char *name, char *buf, unsigned len) |