blob: 76569da0fef2169172e5977ebf4ac84bece3388c [file] [log] [blame]
wdenk13a56952004-06-09 14:58:14 +00001/*
Stuart Woodcc49cad2008-05-30 16:05:28 -04002 * (C) Copyright 2008
3 * Stuart Wood, Lab X Technologies <stuart.wood@labxtechnologies.com>
4 *
wdenk13a56952004-06-09 14:58:14 +00005 * (C) Copyright 2004
6 * Jian Zhang, Texas Instruments, jzhang@ti.com.
7
Stefan Roesed12ae802006-09-12 20:19:10 +02008 * (C) Copyright 2000-2006
wdenk13a56952004-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>
wdenk13a56952004-06-09 14:58:14 +000036#include <command.h>
37#include <environment.h>
38#include <linux/stddef.h>
Markus Klotzbuechere443c942006-03-20 18:02:44 +010039#include <malloc.h>
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +010040#include <nand.h>
wdenk13a56952004-06-09 14:58:14 +000041
Mike Frysingerbdab39d2009-01-28 19:08:14 -050042#if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND)
wdenk13a56952004-06-09 14:58:14 +000043#define CMD_SAVEENV
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020044#elif defined(CONFIG_ENV_OFFSET_REDUND)
Mike Frysingerbdab39d2009-01-28 19:08:14 -050045#error Cannot use CONFIG_ENV_OFFSET_REDUND without CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND
wdenk13a56952004-06-09 14:58:14 +000046#endif
47
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-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
wdenk13a56952004-06-09 14:58:14 +000050#endif
51
wdenk13a56952004-06-09 14:58:14 +000052#ifdef CONFIG_INFERNO
53#error CONFIG_INFERNO not supported yet
54#endif
55
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020056#ifndef CONFIG_ENV_RANGE
57#define CONFIG_ENV_RANGE CONFIG_ENV_SIZE
Stuart Woodcc49cad2008-05-30 16:05:28 -040058#endif
59
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +010060int nand_legacy_rw (struct nand_chip* nand, int cmd,
wdenk13a56952004-06-09 14:58:14 +000061 size_t start, size_t len,
62 size_t * retlen, u_char * buf);
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +010063
wdenk13a56952004-06-09 14:58:14 +000064/* references to names in env_common.c */
65extern uchar default_environment[];
66extern int default_environment_size;
67
68char * env_name_spec = "NAND";
69
70
71#ifdef ENV_IS_EMBEDDED
72extern uchar environment[];
73env_t *env_ptr = (env_t *)(&environment[0]);
74#else /* ! ENV_IS_EMBEDDED */
wdenk49822e22004-06-19 21:19:10 +000075env_t *env_ptr = 0;
wdenk13a56952004-06-09 14:58:14 +000076#endif /* ENV_IS_EMBEDDED */
77
78
79/* local functions */
Stefan Roesed12ae802006-09-12 20:19:10 +020080#if !defined(ENV_IS_EMBEDDED)
wdenk13a56952004-06-09 14:58:14 +000081static void use_default(void);
Stefan Roesed12ae802006-09-12 20:19:10 +020082#endif
wdenk13a56952004-06-09 14:58:14 +000083
Wolfgang Denkd87080b2006-03-31 18:32:53 +020084DECLARE_GLOBAL_DATA_PTR;
wdenk13a56952004-06-09 14:58:14 +000085
86uchar env_get_char_spec (int index)
87{
wdenk13a56952004-06-09 14:58:14 +000088 return ( *((uchar *)(gd->env_addr + index)) );
89}
90
91
92/* this is called before nand_init()
93 * so we can't read Nand to validate env data.
94 * Mark it OK for now. env_relocate() in env_common.c
Marcel Ziswiler99c2b432008-06-22 16:13:46 +020095 * will call our relocate function which does the real
96 * validation.
Stefan Roesed12ae802006-09-12 20:19:10 +020097 *
98 * When using a NAND boot image (like sequoia_nand), the environment
99 * can be embedded or attached to the U-Boot image in NAND flash. This way
100 * the SPL loads not only the U-Boot image from NAND but also the
101 * environment.
wdenk13a56952004-06-09 14:58:14 +0000102 */
103int env_init(void)
104{
Stefan Roesed12ae802006-09-12 20:19:10 +0200105#if defined(ENV_IS_EMBEDDED)
dirk.behme@googlemail.com378e7ec2008-04-30 18:02:59 +0200106 size_t total;
Stefan Roesed12ae802006-09-12 20:19:10 +0200107 int crc1_ok = 0, crc2_ok = 0;
108 env_t *tmp_env1, *tmp_env2;
109
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200110 total = CONFIG_ENV_SIZE;
Stefan Roesed12ae802006-09-12 20:19:10 +0200111
112 tmp_env1 = env_ptr;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200113 tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE);
Stefan Roesed12ae802006-09-12 20:19:10 +0200114
115 crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
116 crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
117
118 if (!crc1_ok && !crc2_ok)
119 gd->env_valid = 0;
120 else if(crc1_ok && !crc2_ok)
121 gd->env_valid = 1;
122 else if(!crc1_ok && crc2_ok)
123 gd->env_valid = 2;
124 else {
125 /* both ok - check serial */
126 if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
127 gd->env_valid = 2;
128 else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
129 gd->env_valid = 1;
130 else if(tmp_env1->flags > tmp_env2->flags)
131 gd->env_valid = 1;
132 else if(tmp_env2->flags > tmp_env1->flags)
133 gd->env_valid = 2;
134 else /* flags are equal - almost impossible */
135 gd->env_valid = 1;
136 }
137
138 if (gd->env_valid == 1)
139 env_ptr = tmp_env1;
140 else if (gd->env_valid == 2)
141 env_ptr = tmp_env2;
142#else /* ENV_IS_EMBEDDED */
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100143 gd->env_addr = (ulong)&default_environment[0];
wdenk13a56952004-06-09 14:58:14 +0000144 gd->env_valid = 1;
Stefan Roesed12ae802006-09-12 20:19:10 +0200145#endif /* ENV_IS_EMBEDDED */
wdenk13a56952004-06-09 14:58:14 +0000146
147 return (0);
148}
149
150#ifdef CMD_SAVEENV
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +0100151/*
152 * The legacy NAND code saved the environment in the first NAND device i.e.,
153 * nand_dev_desc + 0. This is also the behaviour using the new NAND code.
154 */
Stuart Woodcc49cad2008-05-30 16:05:28 -0400155int writeenv(size_t offset, u_char *buf)
156{
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200157 size_t end = offset + CONFIG_ENV_RANGE;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400158 size_t amount_saved = 0;
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200159 size_t blocksize, len;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400160
161 u_char *char_ptr;
162
163 blocksize = nand_info[0].erasesize;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200164 len = min(blocksize, CONFIG_ENV_SIZE);
Stuart Woodcc49cad2008-05-30 16:05:28 -0400165
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200166 while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
Stuart Woodcc49cad2008-05-30 16:05:28 -0400167 if (nand_block_isbad(&nand_info[0], offset)) {
168 offset += blocksize;
169 } else {
170 char_ptr = &buf[amount_saved];
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200171 if (nand_write(&nand_info[0], offset, &len,
Stuart Woodcc49cad2008-05-30 16:05:28 -0400172 char_ptr))
173 return 1;
174 offset += blocksize;
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200175 amount_saved += len;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400176 }
177 }
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200178 if (amount_saved != CONFIG_ENV_SIZE)
Stuart Woodcc49cad2008-05-30 16:05:28 -0400179 return 1;
180
181 return 0;
182}
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200183#ifdef CONFIG_ENV_OFFSET_REDUND
wdenk13a56952004-06-09 14:58:14 +0000184int saveenv(void)
185{
Wolfgang Denk4ca79f42008-04-28 12:08:18 +0200186 size_t total;
Markus Klotzbuecher2770bcb2006-03-24 15:43:16 +0100187 int ret = 0;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400188 nand_erase_options_t nand_erase_options;
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100189
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100190 env_ptr->flags++;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200191 total = CONFIG_ENV_SIZE;
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100192
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200193 nand_erase_options.length = CONFIG_ENV_RANGE;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400194 nand_erase_options.quiet = 0;
195 nand_erase_options.jffs2 = 0;
196 nand_erase_options.scrub = 0;
197
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200198 if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
Stuart Woodcc49cad2008-05-30 16:05:28 -0400199 return 1;
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100200 if(gd->env_valid == 1) {
Stuart Woodcc49cad2008-05-30 16:05:28 -0400201 puts ("Erasing redundant Nand...\n");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200202 nand_erase_options.offset = CONFIG_ENV_OFFSET_REDUND;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400203 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100204 return 1;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400205
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100206 puts ("Writing to redundant Nand... ");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200207 ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) env_ptr);
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100208 } else {
Stuart Woodcc49cad2008-05-30 16:05:28 -0400209 puts ("Erasing Nand...\n");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200210 nand_erase_options.offset = CONFIG_ENV_OFFSET;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400211 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100212 return 1;
213
214 puts ("Writing to Nand... ");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200215 ret = writeenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr);
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100216 }
Stuart Woodcc49cad2008-05-30 16:05:28 -0400217 if (ret) {
218 puts("FAILED!\n");
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100219 return 1;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400220 }
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100221
222 puts ("done\n");
223 gd->env_valid = (gd->env_valid == 2 ? 1 : 2);
224 return ret;
225}
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200226#else /* ! CONFIG_ENV_OFFSET_REDUND */
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100227int saveenv(void)
228{
dirk.behme@googlemail.com378e7ec2008-04-30 18:02:59 +0200229 size_t total;
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100230 int ret = 0;
Philip Balister9e4006bc2008-06-16 08:58:07 -0400231 nand_erase_options_t nand_erase_options;
Wolfgang Denke093a242008-06-28 23:34:37 +0200232
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200233 nand_erase_options.length = CONFIG_ENV_RANGE;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400234 nand_erase_options.quiet = 0;
235 nand_erase_options.jffs2 = 0;
236 nand_erase_options.scrub = 0;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200237 nand_erase_options.offset = CONFIG_ENV_OFFSET;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400238
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200239 if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
Stuart Woodcc49cad2008-05-30 16:05:28 -0400240 return 1;
241 puts ("Erasing Nand...\n");
242 if (nand_erase_opts(&nand_info[0], &nand_erase_options))
wdenk13a56952004-06-09 14:58:14 +0000243 return 1;
244
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +0100245 puts ("Writing to Nand... ");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200246 total = CONFIG_ENV_SIZE;
247 if (writeenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr)) {
Stuart Woodcc49cad2008-05-30 16:05:28 -0400248 puts("FAILED!\n");
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +0100249 return 1;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400250 }
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +0100251
252 puts ("done\n");
253 return ret;
wdenk13a56952004-06-09 14:58:14 +0000254}
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200255#endif /* CONFIG_ENV_OFFSET_REDUND */
wdenk13a56952004-06-09 14:58:14 +0000256#endif /* CMD_SAVEENV */
257
Stuart Woodcc49cad2008-05-30 16:05:28 -0400258int readenv (size_t offset, u_char * buf)
259{
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200260 size_t end = offset + CONFIG_ENV_RANGE;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400261 size_t amount_loaded = 0;
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200262 size_t blocksize, len;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400263
264 u_char *char_ptr;
265
266 blocksize = nand_info[0].erasesize;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200267 len = min(blocksize, CONFIG_ENV_SIZE);
Stuart Woodcc49cad2008-05-30 16:05:28 -0400268
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200269 while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
Stuart Woodcc49cad2008-05-30 16:05:28 -0400270 if (nand_block_isbad(&nand_info[0], offset)) {
271 offset += blocksize;
272 } else {
273 char_ptr = &buf[amount_loaded];
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200274 if (nand_read(&nand_info[0], offset, &len, char_ptr))
Stuart Woodcc49cad2008-05-30 16:05:28 -0400275 return 1;
276 offset += blocksize;
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200277 amount_loaded += len;
Stuart Woodcc49cad2008-05-30 16:05:28 -0400278 }
279 }
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200280 if (amount_loaded != CONFIG_ENV_SIZE)
Stuart Woodcc49cad2008-05-30 16:05:28 -0400281 return 1;
282
283 return 0;
284}
285
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200286#ifdef CONFIG_ENV_OFFSET_REDUND
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100287void env_relocate_spec (void)
288{
289#if !defined(ENV_IS_EMBEDDED)
Wolfgang Denkf7b16a02008-04-29 23:32:20 +0200290 size_t total;
Markus Klotzbuecher2770bcb2006-03-24 15:43:16 +0100291 int crc1_ok = 0, crc2_ok = 0;
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100292 env_t *tmp_env1, *tmp_env2;
wdenk13a56952004-06-09 14:58:14 +0000293
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200294 total = CONFIG_ENV_SIZE;
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100295
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200296 tmp_env1 = (env_t *) malloc(CONFIG_ENV_SIZE);
297 tmp_env2 = (env_t *) malloc(CONFIG_ENV_SIZE);
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100298
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200299 if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1))
Stuart Woodcc49cad2008-05-30 16:05:28 -0400300 puts("No Valid Environment Area Found\n");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200301 if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2))
Stuart Woodcc49cad2008-05-30 16:05:28 -0400302 puts("No Valid Reundant Environment Area Found\n");
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100303
304 crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
305 crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
306
derek@siconix.com5a9427d2009-01-26 14:08:17 -0700307 if(!crc1_ok && !crc2_ok) {
308 free(tmp_env1);
309 free(tmp_env2);
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100310 return use_default();
derek@siconix.com5a9427d2009-01-26 14:08:17 -0700311 } else if(crc1_ok && !crc2_ok)
Markus Klotzbuechere443c942006-03-20 18:02:44 +0100312 gd->env_valid = 1;
313 else if(!crc1_ok && crc2_ok)
314 gd->env_valid = 2;
315 else {
316 /* both ok - check serial */
317 if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
318 gd->env_valid = 2;
319 else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
320 gd->env_valid = 1;
321 else if(tmp_env1->flags > tmp_env2->flags)
322 gd->env_valid = 1;
323 else if(tmp_env2->flags > tmp_env1->flags)
324 gd->env_valid = 2;
325 else /* flags are equal - almost impossible */
326 gd->env_valid = 1;
327
328 }
329
330 free(env_ptr);
331 if(gd->env_valid == 1) {
332 env_ptr = tmp_env1;
333 free(tmp_env2);
334 } else {
335 env_ptr = tmp_env2;
336 free(tmp_env1);
337 }
338
339#endif /* ! ENV_IS_EMBEDDED */
340}
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200341#else /* ! CONFIG_ENV_OFFSET_REDUND */
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +0100342/*
343 * The legacy NAND code saved the environment in the first NAND device i.e.,
344 * nand_dev_desc + 0. This is also the behaviour using the new NAND code.
345 */
wdenk13a56952004-06-09 14:58:14 +0000346void env_relocate_spec (void)
347{
348#if !defined(ENV_IS_EMBEDDED)
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100349 int ret;
wdenk13a56952004-06-09 14:58:14 +0000350
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200351 ret = readenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr);
Guennadi Liakhovetskic3db8c62008-07-31 12:38:26 +0200352 if (ret)
wdenk13a56952004-06-09 14:58:14 +0000353 return use_default();
354
355 if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
356 return use_default();
357#endif /* ! ENV_IS_EMBEDDED */
wdenk13a56952004-06-09 14:58:14 +0000358}
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200359#endif /* CONFIG_ENV_OFFSET_REDUND */
wdenk13a56952004-06-09 14:58:14 +0000360
Stefan Roesed12ae802006-09-12 20:19:10 +0200361#if !defined(ENV_IS_EMBEDDED)
wdenk13a56952004-06-09 14:58:14 +0000362static void use_default()
363{
wdenk13a56952004-06-09 14:58:14 +0000364 puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
Harald Welte5bb12db2008-07-07 15:40:39 +0800365 set_default_env();
wdenk13a56952004-06-09 14:58:14 +0000366}
Stefan Roesed12ae802006-09-12 20:19:10 +0200367#endif