blob: dcf3cd2c62cfd7bd399c6c379c84b98a4908b925 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Wolfgang Denkea882ba2010-06-20 23:33:59 +02002 * (C) Copyright 2000-2010
wdenkc6097192002-11-03 00:24:07 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Andreas Heppel <aheppel@sysgo.de>
7
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00009 */
10
11/* #define DEBUG */
12
13#include <common.h>
wdenkc6097192002-11-03 00:24:07 +000014#include <command.h>
15#include <environment.h>
wdenkc6097192002-11-03 00:24:07 +000016#include <linux/stddef.h>
wdenk47cd00f2003-03-06 13:39:27 +000017#include <malloc.h>
Wolfgang Denkea882ba2010-06-20 23:33:59 +020018#include <search.h>
19#include <errno.h>
wdenkc6097192002-11-03 00:24:07 +000020
Wolfgang Denkd87080b2006-03-31 18:32:53 +020021DECLARE_GLOBAL_DATA_PTR;
22
Mike Frysingerbdab39d2009-01-28 19:08:14 -050023#if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_FLASH)
wdenkc6097192002-11-03 00:24:07 +000024#define CMD_SAVEENV
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020025#elif defined(CONFIG_ENV_ADDR_REDUND)
Igor Grinberg82b54b92011-11-07 01:14:09 +000026#error CONFIG_ENV_ADDR_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_FLASH
wdenkc6097192002-11-03 00:24:07 +000027#endif
28
Igor Grinberg82b54b92011-11-07 01:14:09 +000029#if defined(CONFIG_ENV_SIZE_REDUND) && \
30 (CONFIG_ENV_SIZE_REDUND < CONFIG_ENV_SIZE)
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020031#error CONFIG_ENV_SIZE_REDUND should not be less then CONFIG_ENV_SIZE
wdenkc6097192002-11-03 00:24:07 +000032#endif
33
Igor Grinberg82b54b92011-11-07 01:14:09 +000034char *env_name_spec = "Flash";
wdenkc6097192002-11-03 00:24:07 +000035
36#ifdef ENV_IS_EMBEDDED
Igor Grinberg994bc672011-11-17 06:07:23 +000037env_t *env_ptr = &environment;
wdenkc6097192002-11-03 00:24:07 +000038
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020039static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
wdenkc6097192002-11-03 00:24:07 +000040
41#else /* ! ENV_IS_EMBEDDED */
42
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020043env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020044static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR;
wdenkc6097192002-11-03 00:24:07 +000045#endif /* ENV_IS_EMBEDDED */
46
Wolfgang Denkea882ba2010-06-20 23:33:59 +020047#if defined(CMD_SAVEENV) || defined(CONFIG_ENV_ADDR_REDUND)
48/* CONFIG_ENV_ADDR is supposed to be on sector boundary */
49static ulong end_addr = CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1;
50#endif
51
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020052#ifdef CONFIG_ENV_ADDR_REDUND
53static env_t *flash_addr_new = (env_t *)CONFIG_ENV_ADDR_REDUND;
wdenkc6097192002-11-03 00:24:07 +000054
Wolfgang Denkea882ba2010-06-20 23:33:59 +020055/* CONFIG_ENV_ADDR_REDUND is supposed to be on sector boundary */
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020056static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020057#endif /* CONFIG_ENV_ADDR_REDUND */
wdenkc6097192002-11-03 00:24:07 +000058
wdenkc6097192002-11-03 00:24:07 +000059
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +020060#ifdef CONFIG_ENV_ADDR_REDUND
Igor Grinberg82b54b92011-11-07 01:14:09 +000061int env_init(void)
wdenkc6097192002-11-03 00:24:07 +000062{
wdenk8ed96042005-01-09 23:16:25 +000063 int crc1_ok = 0, crc2_ok = 0;
wdenkc6097192002-11-03 00:24:07 +000064
65 uchar flag1 = flash_addr->flags;
66 uchar flag2 = flash_addr_new->flags;
67
68 ulong addr_default = (ulong)&default_environment[0];
69 ulong addr1 = (ulong)&(flash_addr->data);
70 ulong addr2 = (ulong)&(flash_addr_new->data);
71
Igor Grinberg82b54b92011-11-07 01:14:09 +000072 crc1_ok = crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc;
73 crc2_ok =
74 crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc;
wdenk8ed96042005-01-09 23:16:25 +000075
Igor Grinberg82b54b92011-11-07 01:14:09 +000076 if (crc1_ok && !crc2_ok) {
77 gd->env_addr = addr1;
Simon Glass203e94f2017-08-03 12:21:56 -060078 gd->env_valid = ENV_VALID;
Igor Grinberg82b54b92011-11-07 01:14:09 +000079 } else if (!crc1_ok && crc2_ok) {
80 gd->env_addr = addr2;
Simon Glass203e94f2017-08-03 12:21:56 -060081 gd->env_valid = ENV_VALID;
Igor Grinberg82b54b92011-11-07 01:14:09 +000082 } else if (!crc1_ok && !crc2_ok) {
83 gd->env_addr = addr_default;
84 gd->env_valid = 0;
wdenkc3f9d492004-03-14 00:59:59 +000085 } else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG) {
Igor Grinberg82b54b92011-11-07 01:14:09 +000086 gd->env_addr = addr1;
Simon Glass203e94f2017-08-03 12:21:56 -060087 gd->env_valid = ENV_VALID;
wdenkc3f9d492004-03-14 00:59:59 +000088 } else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG) {
Igor Grinberg82b54b92011-11-07 01:14:09 +000089 gd->env_addr = addr2;
Simon Glass203e94f2017-08-03 12:21:56 -060090 gd->env_valid = ENV_VALID;
wdenkc3f9d492004-03-14 00:59:59 +000091 } else if (flag1 == flag2) {
Igor Grinberg82b54b92011-11-07 01:14:09 +000092 gd->env_addr = addr1;
Simon Glass203e94f2017-08-03 12:21:56 -060093 gd->env_valid = ENV_REDUND;
wdenkc3f9d492004-03-14 00:59:59 +000094 } else if (flag1 == 0xFF) {
Igor Grinberg82b54b92011-11-07 01:14:09 +000095 gd->env_addr = addr1;
Simon Glass203e94f2017-08-03 12:21:56 -060096 gd->env_valid = ENV_REDUND;
wdenkc3f9d492004-03-14 00:59:59 +000097 } else if (flag2 == 0xFF) {
Igor Grinberg82b54b92011-11-07 01:14:09 +000098 gd->env_addr = addr2;
Simon Glass203e94f2017-08-03 12:21:56 -060099 gd->env_valid = ENV_REDUND;
wdenkc6097192002-11-03 00:24:07 +0000100 }
101
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200102 return 0;
wdenkc6097192002-11-03 00:24:07 +0000103}
104
105#ifdef CMD_SAVEENV
106int saveenv(void)
107{
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200108 env_t env_new;
Marek Vasut7ce15262014-03-05 19:59:50 +0100109 char *saved_data = NULL;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200110 char flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG;
Igor Grinberg82b54b92011-11-07 01:14:09 +0000111 int rc = 1;
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200112#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200113 ulong up_data = 0;
wdenk500545c2003-03-06 14:23:06 +0000114#endif
wdenkc6097192002-11-03 00:24:07 +0000115
Igor Grinberg82b54b92011-11-07 01:14:09 +0000116 debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr);
wdenkc6097192002-11-03 00:24:07 +0000117
Igor Grinberg82b54b92011-11-07 01:14:09 +0000118 if (flash_sect_protect(0, (ulong)flash_addr, end_addr))
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200119 goto done;
wdenkc6097192002-11-03 00:24:07 +0000120
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200121 debug("Protect off %08lX ... %08lX\n",
wdenkc6097192002-11-03 00:24:07 +0000122 (ulong)flash_addr_new, end_addr_new);
123
Igor Grinberg82b54b92011-11-07 01:14:09 +0000124 if (flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new))
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200125 goto done;
wdenkc6097192002-11-03 00:24:07 +0000126
Marek Vasut7ce15262014-03-05 19:59:50 +0100127 rc = env_export(&env_new);
128 if (rc)
129 return rc;
Igor Grinberg82b54b92011-11-07 01:14:09 +0000130 env_new.flags = new_flag;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200131
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200132#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
Igor Grinberg82b54b92011-11-07 01:14:09 +0000133 up_data = end_addr_new + 1 - ((long)flash_addr_new + CONFIG_ENV_SIZE);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200134 debug("Data to save 0x%lX\n", up_data);
wdenk47cd00f2003-03-06 13:39:27 +0000135 if (up_data) {
Igor Grinberg82b54b92011-11-07 01:14:09 +0000136 saved_data = malloc(up_data);
137 if (saved_data == NULL) {
wdenk8bde7f72003-06-27 21:31:46 +0000138 printf("Unable to save the rest of sector (%ld)\n",
wdenk47cd00f2003-03-06 13:39:27 +0000139 up_data);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200140 goto done;
wdenk47cd00f2003-03-06 13:39:27 +0000141 }
wdenk8bde7f72003-06-27 21:31:46 +0000142 memcpy(saved_data,
Igor Grinberg82b54b92011-11-07 01:14:09 +0000143 (void *)((long)flash_addr_new + CONFIG_ENV_SIZE),
144 up_data);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200145 debug("Data (start 0x%lX, len 0x%lX) saved at 0x%p\n",
146 (long)flash_addr_new + CONFIG_ENV_SIZE,
147 up_data, saved_data);
wdenk47cd00f2003-03-06 13:39:27 +0000148 }
149#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200150 puts("Erasing Flash...");
Igor Grinberg82b54b92011-11-07 01:14:09 +0000151 debug(" %08lX ... %08lX ...", (ulong)flash_addr_new, end_addr_new);
wdenkc6097192002-11-03 00:24:07 +0000152
Igor Grinberg82b54b92011-11-07 01:14:09 +0000153 if (flash_sect_erase((ulong)flash_addr_new, end_addr_new))
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200154 goto done;
wdenkc6097192002-11-03 00:24:07 +0000155
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200156 puts("Writing to Flash... ");
157 debug(" %08lX ... %08lX ...",
wdenkc6097192002-11-03 00:24:07 +0000158 (ulong)&(flash_addr_new->data),
Igor Grinberg82b54b92011-11-07 01:14:09 +0000159 sizeof(env_ptr->data) + (ulong)&(flash_addr_new->data));
160 rc = flash_write((char *)&env_new, (ulong)flash_addr_new,
161 sizeof(env_new));
162 if (rc)
163 goto perror;
164
165 rc = flash_write(&flag, (ulong)&(flash_addr->flags),
166 sizeof(flash_addr->flags));
167 if (rc)
168 goto perror;
wdenkc6097192002-11-03 00:24:07 +0000169
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200170#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
wdenk47cd00f2003-03-06 13:39:27 +0000171 if (up_data) { /* restore the rest of sector */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200172 debug("Restoring the rest of data to 0x%lX len 0x%lX\n",
173 (long)flash_addr_new + CONFIG_ENV_SIZE, up_data);
wdenk8bde7f72003-06-27 21:31:46 +0000174 if (flash_write(saved_data,
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200175 (long)flash_addr_new + CONFIG_ENV_SIZE,
Igor Grinberg82b54b92011-11-07 01:14:09 +0000176 up_data))
177 goto perror;
wdenk47cd00f2003-03-06 13:39:27 +0000178 }
179#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200180 puts("done\n");
181
wdenkc6097192002-11-03 00:24:07 +0000182 {
Igor Grinberg82b54b92011-11-07 01:14:09 +0000183 env_t *etmp = flash_addr;
wdenkc6097192002-11-03 00:24:07 +0000184 ulong ltmp = end_addr;
185
186 flash_addr = flash_addr_new;
187 flash_addr_new = etmp;
188
189 end_addr = end_addr_new;
190 end_addr_new = ltmp;
191 }
192
193 rc = 0;
Igor Grinberg82b54b92011-11-07 01:14:09 +0000194 goto done;
195perror:
196 flash_perror(rc);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200197done:
wdenk47cd00f2003-03-06 13:39:27 +0000198 if (saved_data)
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200199 free(saved_data);
wdenkc6097192002-11-03 00:24:07 +0000200 /* try to re-protect */
Igor Grinberg82b54b92011-11-07 01:14:09 +0000201 flash_sect_protect(1, (ulong)flash_addr, end_addr);
202 flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
wdenkc6097192002-11-03 00:24:07 +0000203
204 return rc;
205}
206#endif /* CMD_SAVEENV */
207
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200208#else /* ! CONFIG_ENV_ADDR_REDUND */
wdenkc6097192002-11-03 00:24:07 +0000209
Igor Grinberg82b54b92011-11-07 01:14:09 +0000210int env_init(void)
wdenkc6097192002-11-03 00:24:07 +0000211{
wdenkc6097192002-11-03 00:24:07 +0000212 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
Igor Grinberg82b54b92011-11-07 01:14:09 +0000213 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -0600214 gd->env_valid = ENV_VALID;
Igor Grinberg82b54b92011-11-07 01:14:09 +0000215 return 0;
wdenkc6097192002-11-03 00:24:07 +0000216 }
Dirk Behme9bb8b202007-08-20 07:09:05 +0200217
Igor Grinberg82b54b92011-11-07 01:14:09 +0000218 gd->env_addr = (ulong)&default_environment[0];
219 gd->env_valid = 0;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200220 return 0;
wdenkc6097192002-11-03 00:24:07 +0000221}
222
223#ifdef CMD_SAVEENV
wdenkc6097192002-11-03 00:24:07 +0000224int saveenv(void)
225{
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200226 env_t env_new;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200227 int rc = 1;
Tom Rini3fa19812014-04-17 16:20:39 -0400228 char *saved_data = NULL;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200229#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
230 ulong up_data = 0;
wdenkc6097192002-11-03 00:24:07 +0000231
Igor Grinberg82b54b92011-11-07 01:14:09 +0000232 up_data = end_addr + 1 - ((long)flash_addr + CONFIG_ENV_SIZE);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200233 debug("Data to save 0x%lx\n", up_data);
234 if (up_data) {
Igor Grinberg82b54b92011-11-07 01:14:09 +0000235 saved_data = malloc(up_data);
236 if (saved_data == NULL) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200237 printf("Unable to save the rest of sector (%ld)\n",
238 up_data);
239 goto done;
240 }
241 memcpy(saved_data,
242 (void *)((long)flash_addr + CONFIG_ENV_SIZE), up_data);
243 debug("Data (start 0x%lx, len 0x%lx) saved at 0x%lx\n",
244 (ulong)flash_addr + CONFIG_ENV_SIZE,
245 up_data,
246 (ulong)saved_data);
wdenkc6097192002-11-03 00:24:07 +0000247 }
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200248#endif /* CONFIG_ENV_SECT_SIZE */
wdenkc6097192002-11-03 00:24:07 +0000249
Igor Grinberg82b54b92011-11-07 01:14:09 +0000250 debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200251
252 if (flash_sect_protect(0, (long)flash_addr, end_addr))
253 goto done;
254
Marek Vasut7ce15262014-03-05 19:59:50 +0100255 rc = env_export(&env_new);
256 if (rc)
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200257 goto done;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200258
259 puts("Erasing Flash...");
260 if (flash_sect_erase((long)flash_addr, end_addr))
261 goto done;
262
263 puts("Writing to Flash... ");
264 rc = flash_write((char *)&env_new, (long)flash_addr, CONFIG_ENV_SIZE);
Igor Grinberg82b54b92011-11-07 01:14:09 +0000265 if (rc != 0)
266 goto perror;
267
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200268#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
269 if (up_data) { /* restore the rest of sector */
270 debug("Restoring the rest of data to 0x%lx len 0x%lx\n",
271 (ulong)flash_addr + CONFIG_ENV_SIZE, up_data);
272 if (flash_write(saved_data,
273 (long)flash_addr + CONFIG_ENV_SIZE,
Igor Grinberg82b54b92011-11-07 01:14:09 +0000274 up_data))
275 goto perror;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200276 }
277#endif
278 puts("done\n");
279 rc = 0;
Igor Grinberg82b54b92011-11-07 01:14:09 +0000280 goto done;
281perror:
282 flash_perror(rc);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200283done:
284 if (saved_data)
285 free(saved_data);
wdenkc6097192002-11-03 00:24:07 +0000286 /* try to re-protect */
Igor Grinberg82b54b92011-11-07 01:14:09 +0000287 flash_sect_protect(1, (long)flash_addr, end_addr);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200288 return rc;
wdenkc6097192002-11-03 00:24:07 +0000289}
wdenkc6097192002-11-03 00:24:07 +0000290#endif /* CMD_SAVEENV */
291
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200292#endif /* CONFIG_ENV_ADDR_REDUND */
wdenkc6097192002-11-03 00:24:07 +0000293
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200294void env_relocate_spec(void)
wdenkc6097192002-11-03 00:24:07 +0000295{
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200296#ifdef CONFIG_ENV_ADDR_REDUND
wdenkc3f9d492004-03-14 00:59:59 +0000297 if (gd->env_addr != (ulong)&(flash_addr->data)) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200298 env_t *etmp = flash_addr;
wdenkc6097192002-11-03 00:24:07 +0000299 ulong ltmp = end_addr;
300
301 flash_addr = flash_addr_new;
302 flash_addr_new = etmp;
303
304 end_addr = end_addr_new;
305 end_addr_new = ltmp;
306 }
307
wdenkc3f9d492004-03-14 00:59:59 +0000308 if (flash_addr_new->flags != OBSOLETE_FLAG &&
Igor Grinberg82b54b92011-11-07 01:14:09 +0000309 crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc) {
wdenkc3f9d492004-03-14 00:59:59 +0000310 char flag = OBSOLETE_FLAG;
311
Simon Glass203e94f2017-08-03 12:21:56 -0600312 gd->env_valid = ENV_REDUND;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200313 flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new);
wdenkc3f9d492004-03-14 00:59:59 +0000314 flash_write(&flag,
wdenk8bde7f72003-06-27 21:31:46 +0000315 (ulong)&(flash_addr_new->flags),
316 sizeof(flash_addr_new->flags));
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200317 flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
wdenkc6097192002-11-03 00:24:07 +0000318 }
319
wdenkc3f9d492004-03-14 00:59:59 +0000320 if (flash_addr->flags != ACTIVE_FLAG &&
321 (flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
322 char flag = ACTIVE_FLAG;
323
Simon Glass203e94f2017-08-03 12:21:56 -0600324 gd->env_valid = ENV_REDUND;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200325 flash_sect_protect(0, (ulong)flash_addr, end_addr);
wdenkc3f9d492004-03-14 00:59:59 +0000326 flash_write(&flag,
wdenk8bde7f72003-06-27 21:31:46 +0000327 (ulong)&(flash_addr->flags),
328 sizeof(flash_addr->flags));
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200329 flash_sect_protect(1, (ulong)flash_addr, end_addr);
wdenkc6097192002-11-03 00:24:07 +0000330 }
331
Simon Glass203e94f2017-08-03 12:21:56 -0600332 if (gd->env_valid == ENV_REDUND)
Igor Grinberg82b54b92011-11-07 01:14:09 +0000333 puts("*** Warning - some problems detected "
334 "reading environment; recovered successfully\n\n");
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200335#endif /* CONFIG_ENV_ADDR_REDUND */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200336
337 env_import((char *)flash_addr, 1);
wdenkc6097192002-11-03 00:24:07 +0000338}