summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ungar <david.ungar@timesys.com>2010-10-11 14:23:20 -0400
committerDavid Ungar <david.ungar@timesys.com>2010-10-11 14:23:20 -0400
commit4df97e84d1436d3cbaac610a8139e64f31de3883 (patch)
tree6ed1611a751dfc00ba39ebac0d4e377e6d0dc02b
parenta1b30934acaf13cab1147d7955c9487d179c5cf0 (diff)
Add redundant environment
-rw-r--r--common/env_nand.c51
-rw-r--r--include/configs/omap3_logic.h6
2 files changed, 43 insertions, 14 deletions
diff --git a/common/env_nand.c b/common/env_nand.c
index ca631af195..e7b70150cd 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -168,24 +168,53 @@ int writeenv(size_t offset, u_char *buf)
size_t blocksize, len;
u_char *char_ptr;
+ size_t ncopies = 0;
blocksize = nand_info[0].erasesize;
len = min(blocksize, CONFIG_ENV_SIZE);
- while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
- if (nand_block_isbad(&nand_info[0], offset)) {
+ /* If the environment fits into a single block, then write that block
+ * into each block of the range. This allows readenv to pick *any*
+ * good block to pull the environment out of which helps if a block
+ * goes bad between the write and next read. If envrironment is
+ * larger than one block, just write one copy of the environment.
+ */
+
+ if (CONFIG_ENV_SIZE <= blocksize) {
+ while (offset < end) {
+ if (!nand_block_isbad(&nand_info[0], offset)) {
+ char_ptr = &buf[amount_saved];
+ if (nand_write(&nand_info[0], offset, &len,
+ char_ptr)) {
+ /* write failed, skip it */
+ } else {
+ amount_saved += len;
+ if (amount_saved >= CONFIG_ENV_SIZE) {
+ ncopies++;
+ amount_saved = 0;
+ }
+ }
+ }
offset += blocksize;
- } else {
- char_ptr = &buf[amount_saved];
- if (nand_write(&nand_info[0], offset, &len,
- char_ptr))
- return 1;
- offset += blocksize;
- amount_saved += len;
}
+ if (!ncopies)
+ return 1;
+ } else {
+ while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
+ if (nand_block_isbad(&nand_info[0], offset)) {
+ offset += blocksize;
+ } else {
+ char_ptr = &buf[amount_saved];
+ if (nand_write(&nand_info[0], offset, &len,
+ char_ptr))
+ return 1;
+ offset += blocksize;
+ amount_saved += len;
+ }
+ }
+ if (amount_saved != CONFIG_ENV_SIZE)
+ return 1;
}
- if (amount_saved != CONFIG_ENV_SIZE)
- return 1;
return 0;
}
diff --git a/include/configs/omap3_logic.h b/include/configs/omap3_logic.h
index 6033526dcf..1599eeea28 100644
--- a/include/configs/omap3_logic.h
+++ b/include/configs/omap3_logic.h
@@ -64,8 +64,6 @@
/*
* Size of malloc() pool
*/
-#define CONFIG_ENV_SIZE SZ_128K /* Total Size Environment */
- /* Sector */
#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + SZ_128K)
#define CONFIG_SYS_GBL_DATA_SIZE 128 /* bytes reserved for */
/* initial data */
@@ -324,7 +322,9 @@
#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_FLASH_BASE
#define CONFIG_ENV_IS_IN_NAND 1
-#define SMNAND_ENV_OFFSET 0xffe0000 /* environment starts here */
+#define CONFIG_ENV_SIZE SZ_128K /* Total Size Environment */
+#define CONFIG_ENV_RANGE (CONFIG_ENV_SIZE * 2) /* Total Size Environment */
+#define SMNAND_ENV_OFFSET (SZ_256M - CONFIG_ENV_RANGE) /* environment starts here */
#define CONFIG_SYS_ENV_SECT_SIZE boot_flash_sec
#define CONFIG_ENV_OFFSET boot_flash_off