blob: 8052fb79e58cd8bc313664ae813331067eb55dd2 [file] [log] [blame]
wdenk79b59372004-06-09 14:58:14 +00001/*
Stuart Wood37e11442008-05-30 16:05:28 -04002 * (C) Copyright 2008
3 * Stuart Wood, Lab X Technologies <stuart.wood@labxtechnologies.com>
4 *
wdenk79b59372004-06-09 14:58:14 +00005 * (C) Copyright 2004
6 * Jian Zhang, Texas Instruments, jzhang@ti.com.
7
Stefan Roesebbfcbb72006-09-12 20:19:10 +02008 * (C) Copyright 2000-2006
wdenk79b59372004-06-09 14:58:14 +00009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 *
11 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12 * Andreas Heppel <aheppel@sysgo.de>
13
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32
33/* #define DEBUG */
34
35#include <common.h>
wdenk79b59372004-06-09 14:58:14 +000036#include <command.h>
37#include <environment.h>
38#include <linux/stddef.h>
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +010039#include <malloc.h>
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +010040#include <nand.h>
wdenk79b59372004-06-09 14:58:14 +000041
Mike Frysinger78dcaf42009-01-28 19:08:14 -050042#if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND)
wdenk79b59372004-06-09 14:58:14 +000043#define CMD_SAVEENV
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020044#elif defined(CONFIG_ENV_OFFSET_REDUND)
Mike Frysinger78dcaf42009-01-28 19:08:14 -050045#error Cannot use CONFIG_ENV_OFFSET_REDUND without CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND
wdenk79b59372004-06-09 14:58:14 +000046#endif
47
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020048#if defined(CONFIG_ENV_SIZE_REDUND) && (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE)
49#error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE
wdenk79b59372004-06-09 14:58:14 +000050#endif
51
wdenk79b59372004-06-09 14:58:14 +000052#ifdef CONFIG_INFERNO
53#error CONFIG_INFERNO not supported yet
54#endif
55
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020056#ifndef CONFIG_ENV_RANGE
57#define CONFIG_ENV_RANGE CONFIG_ENV_SIZE
Stuart Wood37e11442008-05-30 16:05:28 -040058#endif
59
wdenk79b59372004-06-09 14:58:14 +000060/* references to names in env_common.c */
61extern uchar default_environment[];
62extern int default_environment_size;
63
64char * env_name_spec = "NAND";
65
66
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +020067#if defined(ENV_IS_EMBEDDED)
wdenk79b59372004-06-09 14:58:14 +000068extern uchar environment[];
69env_t *env_ptr = (env_t *)(&environment[0]);
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +020070#elif defined(CONFIG_NAND_ENV_DST)
71env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST;
wdenk79b59372004-06-09 14:58:14 +000072#else /* ! ENV_IS_EMBEDDED */
wdenk9e930b62004-06-19 21:19:10 +000073env_t *env_ptr = 0;
wdenk79b59372004-06-09 14:58:14 +000074#endif /* ENV_IS_EMBEDDED */
75
76
77/* local functions */
Stefan Roesebbfcbb72006-09-12 20:19:10 +020078#if !defined(ENV_IS_EMBEDDED)
wdenk79b59372004-06-09 14:58:14 +000079static void use_default(void);
Stefan Roesebbfcbb72006-09-12 20:19:10 +020080#endif
wdenk79b59372004-06-09 14:58:14 +000081
Wolfgang Denk6405a152006-03-31 18:32:53 +020082DECLARE_GLOBAL_DATA_PTR;
wdenk79b59372004-06-09 14:58:14 +000083
84uchar env_get_char_spec (int index)
85{
wdenk79b59372004-06-09 14:58:14 +000086 return ( *((uchar *)(gd->env_addr + index)) );
87}
88
89
90/* this is called before nand_init()
91 * so we can't read Nand to validate env data.
92 * Mark it OK for now. env_relocate() in env_common.c
Marcel Ziswilerf5e21f62008-06-22 16:13:46 +020093 * will call our relocate function which does the real
94 * validation.
Stefan Roesebbfcbb72006-09-12 20:19:10 +020095 *
96 * When using a NAND boot image (like sequoia_nand), the environment
97 * can be embedded or attached to the U-Boot image in NAND flash. This way
98 * the SPL loads not only the U-Boot image from NAND but also the
99 * environment.
wdenk79b59372004-06-09 14:58:14 +0000100 */
101int env_init(void)
102{
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200103#if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST)
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200104 int crc1_ok = 0, crc2_ok = 0;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200105 env_t *tmp_env1;
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200106
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200107#ifdef CONFIG_ENV_OFFSET_REDUND
108 env_t *tmp_env2;
109
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200110 tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE);
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200111 crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
112#endif
113
114 tmp_env1 = env_ptr;
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200115
116 crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200117
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200118 if (!crc1_ok && !crc2_ok) {
119 gd->env_addr = 0;
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200120 gd->env_valid = 0;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200121
122 return 0;
123 } else if (crc1_ok && !crc2_ok) {
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200124 gd->env_valid = 1;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200125 }
126#ifdef CONFIG_ENV_OFFSET_REDUND
127 else if (!crc1_ok && crc2_ok) {
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200128 gd->env_valid = 2;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200129 } else {
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200130 /* both ok - check serial */
131 if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
132 gd->env_valid = 2;
133 else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
134 gd->env_valid = 1;
135 else if(tmp_env1->flags > tmp_env2->flags)
136 gd->env_valid = 1;
137 else if(tmp_env2->flags > tmp_env1->flags)
138 gd->env_valid = 2;
139 else /* flags are equal - almost impossible */
140 gd->env_valid = 1;
141 }
142
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200143 if (gd->env_valid == 2)
144 env_ptr = tmp_env2;
145 else
146#endif
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200147 if (gd->env_valid == 1)
148 env_ptr = tmp_env1;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200149
150 gd->env_addr = (ulong)env_ptr->data;
151
152#else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100153 gd->env_addr = (ulong)&default_environment[0];
wdenk79b59372004-06-09 14:58:14 +0000154 gd->env_valid = 1;
Guennadi Liakhovetskifad24442009-05-18 16:07:22 +0200155#endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
wdenk79b59372004-06-09 14:58:14 +0000156
157 return (0);
158}
159
160#ifdef CMD_SAVEENV
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +0100161/*
162 * The legacy NAND code saved the environment in the first NAND device i.e.,
163 * nand_dev_desc + 0. This is also the behaviour using the new NAND code.
164 */
Stuart Wood37e11442008-05-30 16:05:28 -0400165int writeenv(size_t offset, u_char *buf)
166{
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200167 size_t end = offset + CONFIG_ENV_RANGE;
Stuart Wood37e11442008-05-30 16:05:28 -0400168 size_t amount_saved = 0;
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200169 size_t blocksize, len;
Stuart Wood37e11442008-05-30 16:05:28 -0400170
171 u_char *char_ptr;
172
173 blocksize = nand_info[0].erasesize;
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200174 len = min(blocksize, CONFIG_ENV_SIZE);
Stuart Wood37e11442008-05-30 16:05:28 -0400175
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200176 while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
Stuart Wood37e11442008-05-30 16:05:28 -0400177 if (nand_block_isbad(&nand_info[0], offset)) {
178 offset += blocksize;
179 } else {
180 char_ptr = &buf[amount_saved];
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200181 if (nand_write(&nand_info[0], offset, &len,
Stuart Wood37e11442008-05-30 16:05:28 -0400182 char_ptr))
183 return 1;
184 offset += blocksize;
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200185 amount_saved += len;
Stuart Wood37e11442008-05-30 16:05:28 -0400186 }
187 }
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200188 if (amount_saved != CONFIG_ENV_SIZE)
Stuart Wood37e11442008-05-30 16:05:28 -0400189 return 1;
190
191 return 0;
192}
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200193#ifdef CONFIG_ENV_OFFSET_REDUND
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100194int saveenv(void)
195{
Wolfgang Denk7fa6e902006-03-11 22:53:33 +0100196 int ret = 0;
Stuart Wood37e11442008-05-30 16:05:28 -0400197 nand_erase_options_t nand_erase_options;
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100198
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100199 env_ptr->flags++;
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100200
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200201 nand_erase_options.length = CONFIG_ENV_RANGE;
Stuart Wood37e11442008-05-30 16:05:28 -0400202 nand_erase_options.quiet = 0;
203 nand_erase_options.jffs2 = 0;
204 nand_erase_options.scrub = 0;
205
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200206 if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
Stuart Wood37e11442008-05-30 16:05:28 -0400207 return 1;
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100208 if(gd->env_valid == 1) {
Stuart Wood37e11442008-05-30 16:05:28 -0400209 puts ("Erasing redundant Nand...\n");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200210 nand_erase_options.offset = CONFIG_ENV_OFFSET_REDUND;
Stuart Wood37e11442008-05-30 16:05:28 -0400211 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100212 return 1;
Stuart Wood37e11442008-05-30 16:05:28 -0400213
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100214 puts ("Writing to redundant Nand... ");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200215 ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) env_ptr);
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100216 } else {
Stuart Wood37e11442008-05-30 16:05:28 -0400217 puts ("Erasing Nand...\n");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200218 nand_erase_options.offset = CONFIG_ENV_OFFSET;
Stuart Wood37e11442008-05-30 16:05:28 -0400219 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100220 return 1;
221
222 puts ("Writing to Nand... ");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200223 ret = writeenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr);
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100224 }
Stuart Wood37e11442008-05-30 16:05:28 -0400225 if (ret) {
226 puts("FAILED!\n");
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100227 return 1;
Stuart Wood37e11442008-05-30 16:05:28 -0400228 }
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100229
230 puts ("done\n");
231 gd->env_valid = (gd->env_valid == 2 ? 1 : 2);
232 return ret;
233}
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200234#else /* ! CONFIG_ENV_OFFSET_REDUND */
wdenk79b59372004-06-09 14:58:14 +0000235int saveenv(void)
236{
Markus Klotzbuecherffe7ef52006-03-24 15:43:16 +0100237 int ret = 0;
Philip Balister8c57e9a2008-06-16 08:58:07 -0400238 nand_erase_options_t nand_erase_options;
Wolfgang Denk41df50a2008-06-28 23:34:37 +0200239
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200240 nand_erase_options.length = CONFIG_ENV_RANGE;
Stuart Wood37e11442008-05-30 16:05:28 -0400241 nand_erase_options.quiet = 0;
242 nand_erase_options.jffs2 = 0;
243 nand_erase_options.scrub = 0;
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200244 nand_erase_options.offset = CONFIG_ENV_OFFSET;
Stuart Wood37e11442008-05-30 16:05:28 -0400245
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200246 if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
Stuart Wood37e11442008-05-30 16:05:28 -0400247 return 1;
248 puts ("Erasing Nand...\n");
249 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +0100250 return 1;
wdenk79b59372004-06-09 14:58:14 +0000251
252 puts ("Writing to Nand... ");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200253 if (writeenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr)) {
Stuart Wood37e11442008-05-30 16:05:28 -0400254 puts("FAILED!\n");
wdenk79b59372004-06-09 14:58:14 +0000255 return 1;
Stuart Wood37e11442008-05-30 16:05:28 -0400256 }
wdenk79b59372004-06-09 14:58:14 +0000257
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +0100258 puts ("done\n");
259 return ret;
wdenk79b59372004-06-09 14:58:14 +0000260}
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200261#endif /* CONFIG_ENV_OFFSET_REDUND */
wdenk79b59372004-06-09 14:58:14 +0000262#endif /* CMD_SAVEENV */
263
Stuart Wood37e11442008-05-30 16:05:28 -0400264int readenv (size_t offset, u_char * buf)
265{
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200266 size_t end = offset + CONFIG_ENV_RANGE;
Stuart Wood37e11442008-05-30 16:05:28 -0400267 size_t amount_loaded = 0;
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200268 size_t blocksize, len;
Stuart Wood37e11442008-05-30 16:05:28 -0400269
270 u_char *char_ptr;
271
272 blocksize = nand_info[0].erasesize;
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200273 len = min(blocksize, CONFIG_ENV_SIZE);
Stuart Wood37e11442008-05-30 16:05:28 -0400274
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200275 while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
Stuart Wood37e11442008-05-30 16:05:28 -0400276 if (nand_block_isbad(&nand_info[0], offset)) {
277 offset += blocksize;
278 } else {
279 char_ptr = &buf[amount_loaded];
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200280 if (nand_read(&nand_info[0], offset, &len, char_ptr))
Stuart Wood37e11442008-05-30 16:05:28 -0400281 return 1;
282 offset += blocksize;
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200283 amount_loaded += len;
Stuart Wood37e11442008-05-30 16:05:28 -0400284 }
285 }
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200286 if (amount_loaded != CONFIG_ENV_SIZE)
Stuart Wood37e11442008-05-30 16:05:28 -0400287 return 1;
288
289 return 0;
290}
291
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200292#ifdef CONFIG_ENV_OFFSET_REDUND
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100293void env_relocate_spec (void)
294{
295#if !defined(ENV_IS_EMBEDDED)
Markus Klotzbuecherffe7ef52006-03-24 15:43:16 +0100296 int crc1_ok = 0, crc2_ok = 0;
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100297 env_t *tmp_env1, *tmp_env2;
298
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200299 tmp_env1 = (env_t *) malloc(CONFIG_ENV_SIZE);
300 tmp_env2 = (env_t *) malloc(CONFIG_ENV_SIZE);
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100301
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200302 if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1))
Stuart Wood37e11442008-05-30 16:05:28 -0400303 puts("No Valid Environment Area Found\n");
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200304 if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2))
Stuart Wood37e11442008-05-30 16:05:28 -0400305 puts("No Valid Reundant Environment Area Found\n");
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100306
307 crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
308 crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
309
derek@siconix.com49043852009-01-26 14:08:17 -0700310 if(!crc1_ok && !crc2_ok) {
311 free(tmp_env1);
312 free(tmp_env2);
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100313 return use_default();
derek@siconix.com49043852009-01-26 14:08:17 -0700314 } else if(crc1_ok && !crc2_ok)
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100315 gd->env_valid = 1;
316 else if(!crc1_ok && crc2_ok)
317 gd->env_valid = 2;
318 else {
319 /* both ok - check serial */
320 if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
321 gd->env_valid = 2;
322 else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
323 gd->env_valid = 1;
324 else if(tmp_env1->flags > tmp_env2->flags)
325 gd->env_valid = 1;
326 else if(tmp_env2->flags > tmp_env1->flags)
327 gd->env_valid = 2;
328 else /* flags are equal - almost impossible */
329 gd->env_valid = 1;
wdenk79b59372004-06-09 14:58:14 +0000330
Markus Klotzbuecher5d113e02006-03-20 18:02:44 +0100331 }
332
333 free(env_ptr);
334 if(gd->env_valid == 1) {
335 env_ptr = tmp_env1;
336 free(tmp_env2);
337 } else {
338 env_ptr = tmp_env2;
339 free(tmp_env1);
340 }
341
342#endif /* ! ENV_IS_EMBEDDED */
343}
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200344#else /* ! CONFIG_ENV_OFFSET_REDUND */
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +0100345/*
346 * The legacy NAND code saved the environment in the first NAND device i.e.,
347 * nand_dev_desc + 0. This is also the behaviour using the new NAND code.
348 */
wdenk79b59372004-06-09 14:58:14 +0000349void env_relocate_spec (void)
350{
351#if !defined(ENV_IS_EMBEDDED)
Wolfgang Denk7fa6e902006-03-11 22:53:33 +0100352 int ret;
wdenk79b59372004-06-09 14:58:14 +0000353
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200354 ret = readenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr);
Guennadi Liakhovetski0c40ae942008-07-31 12:38:26 +0200355 if (ret)
wdenk79b59372004-06-09 14:58:14 +0000356 return use_default();
357
358 if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
359 return use_default();
360#endif /* ! ENV_IS_EMBEDDED */
wdenk79b59372004-06-09 14:58:14 +0000361}
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200362#endif /* CONFIG_ENV_OFFSET_REDUND */
wdenk79b59372004-06-09 14:58:14 +0000363
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200364#if !defined(ENV_IS_EMBEDDED)
wdenk79b59372004-06-09 14:58:14 +0000365static void use_default()
366{
wdenk79b59372004-06-09 14:58:14 +0000367 puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
Harald Welte72eb50a2008-07-07 15:40:39 +0800368 set_default_env();
wdenk79b59372004-06-09 14:58:14 +0000369}
Stefan Roesebbfcbb72006-09-12 20:19:10 +0200370#endif