Commit b74ab737369bbbe66c15cbe6c0d0b6a351b00c96

Authored by Guennadi Liakhovetski
Committed by Scott Wood
1 parent 378adfcdf4

nand_spl: read environment early, when booting from NAND using nand_spl

Currently, when booting from NAND using nand_spl, in the beginning the default
environment is used until later in boot process the dynamic environment is read
out. This way environment variables that must be interpreted early, like the
baudrate or "silent", cannot be modified dynamically and remain at their
default values. Fix this problem by reading out main and redundand (if used)
copies of the environment in the nand_spl code.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Scott Wood <scottwood@freescale.com>

Showing 4 changed files with 49 additions and 13 deletions Side-by-side Diff

... ... @@ -2428,6 +2428,12 @@
2428 2428 to a block boundary, and CONFIG_ENV_SIZE must be a multiple of
2429 2429 the NAND devices block size.
2430 2430  
  2431 +- CONFIG_NAND_ENV_DST
  2432 +
  2433 + Defines address in RAM to which the nand_spl code should copy the
  2434 + environment. If redundant environment is used, it will be copied to
  2435 + CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE.
  2436 +
2431 2437 - CONFIG_SYS_SPI_INIT_OFFSET
2432 2438  
2433 2439 Defines offset to the initial SPI buffer area in DPRAM. The
... ... @@ -68,9 +68,11 @@
68 68 char * env_name_spec = "NAND";
69 69  
70 70  
71   -#ifdef ENV_IS_EMBEDDED
  71 +#if defined(ENV_IS_EMBEDDED)
72 72 extern uchar environment[];
73 73 env_t *env_ptr = (env_t *)(&environment[0]);
  74 +#elif defined(CONFIG_NAND_ENV_DST)
  75 +env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST;
74 76 #else /* ! ENV_IS_EMBEDDED */
75 77 env_t *env_ptr = 0;
76 78 #endif /* ENV_IS_EMBEDDED */
77 79  
78 80  
79 81  
80 82  
81 83  
82 84  
83 85  
84 86  
85 87  
... ... @@ -102,23 +104,33 @@
102 104 */
103 105 int env_init(void)
104 106 {
105   -#if defined(ENV_IS_EMBEDDED)
  107 +#if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST)
106 108 int crc1_ok = 0, crc2_ok = 0;
107   - env_t *tmp_env1, *tmp_env2;
  109 + env_t *tmp_env1;
108 110  
109   - tmp_env1 = env_ptr;
  111 +#ifdef CONFIG_ENV_OFFSET_REDUND
  112 + env_t *tmp_env2;
  113 +
110 114 tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE);
  115 + crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
  116 +#endif
111 117  
  118 + tmp_env1 = env_ptr;
  119 +
112 120 crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
113   - crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
114 121  
115   - if (!crc1_ok && !crc2_ok)
  122 + if (!crc1_ok && !crc2_ok) {
  123 + gd->env_addr = 0;
116 124 gd->env_valid = 0;
117   - else if(crc1_ok && !crc2_ok)
  125 +
  126 + return 0;
  127 + } else if (crc1_ok && !crc2_ok) {
118 128 gd->env_valid = 1;
119   - else if(!crc1_ok && crc2_ok)
  129 + }
  130 +#ifdef CONFIG_ENV_OFFSET_REDUND
  131 + else if (!crc1_ok && crc2_ok) {
120 132 gd->env_valid = 2;
121   - else {
  133 + } else {
122 134 /* both ok - check serial */
123 135 if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
124 136 gd->env_valid = 2;
125 137  
126 138  
... ... @@ -132,14 +144,19 @@
132 144 gd->env_valid = 1;
133 145 }
134 146  
  147 + if (gd->env_valid == 2)
  148 + env_ptr = tmp_env2;
  149 + else
  150 +#endif
135 151 if (gd->env_valid == 1)
136 152 env_ptr = tmp_env1;
137   - else if (gd->env_valid == 2)
138   - env_ptr = tmp_env2;
139   -#else /* ENV_IS_EMBEDDED */
  153 +
  154 + gd->env_addr = (ulong)env_ptr->data;
  155 +
  156 +#else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
140 157 gd->env_addr = (ulong)&default_environment[0];
141 158 gd->env_valid = 1;
142   -#endif /* ENV_IS_EMBEDDED */
  159 +#endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
143 160  
144 161 return (0);
145 162 }
include/configs/smdk6400.h
... ... @@ -209,6 +209,9 @@
209 209 /* total memory available to uboot */
210 210 #define CONFIG_SYS_UBOOT_SIZE (1024 * 1024)
211 211  
  212 +/* Put environment copies after the end of U-Boot owned RAM */
  213 +#define CONFIG_NAND_ENV_DST (CONFIG_SYS_UBOOT_BASE + CONFIG_SYS_UBOOT_SIZE)
  214 +
212 215 #ifdef CONFIG_ENABLE_MMU
213 216 #define CONFIG_SYS_MAPPED_RAM_BASE 0xc0000000
214 217 #define CONFIG_BOOTCOMMAND "nand read 0xc0018000 0x60000 0x1c0000;" \
nand_spl/nand_boot.c
... ... @@ -246,6 +246,16 @@
246 246 ret = nand_load(&nand_info, CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
247 247 (uchar *)CONFIG_SYS_NAND_U_BOOT_DST);
248 248  
  249 +#ifdef CONFIG_NAND_ENV_DST
  250 + nand_load(&nand_info, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  251 + (uchar *)CONFIG_NAND_ENV_DST);
  252 +
  253 +#ifdef CONFIG_ENV_OFFSET_REDUND
  254 + nand_load(&nand_info, CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE,
  255 + (uchar *)CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE);
  256 +#endif
  257 +#endif
  258 +
249 259 if (nand_chip.select_chip)
250 260 nand_chip.select_chip(&nand_info, -1);
251 261