summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWolfgang Denk <wd@pollux.denx.de>2006-09-13 10:25:40 +0200
committerWolfgang Denk <wd@pollux.denx.de>2006-09-13 10:25:40 +0200
commit5d5269f87fc00a3fe1960cacd92e3d04864dff7d (patch)
tree208a387f1e0f0399696132e556e58b36e6072efd /common
parenta87d46f7327eedead89284a0d0c5e5a769b984b9 (diff)
parentd12ae80889568365ecb9e6698322f9771ae76dde (diff)
Merge with /home/sr/git/u-boot/denx
Diffstat (limited to 'common')
-rw-r--r--common/env_nand.c50
-rw-r--r--common/environment.c3
2 files changed, 51 insertions, 2 deletions
diff --git a/common/env_nand.c b/common/env_nand.c
index 0a05b09a7a8..67c4a4e0117 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -2,7 +2,7 @@
* (C) Copyright 2004
* Jian Zhang, Texas Instruments, jzhang@ti.com.
- * (C) Copyright 2000-2004
+ * (C) Copyright 2000-2006
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
@@ -76,7 +76,9 @@ env_t *env_ptr = 0;
/* local functions */
+#if !defined(ENV_IS_EMBEDDED)
static void use_default(void);
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -91,11 +93,55 @@ uchar env_get_char_spec (int index)
* Mark it OK for now. env_relocate() in env_common.c
* will call our relocate function which will does
* the real validation.
+ *
+ * When using a NAND boot image (like sequoia_nand), the environment
+ * can be embedded or attached to the U-Boot image in NAND flash. This way
+ * the SPL loads not only the U-Boot image from NAND but also the
+ * environment.
*/
int env_init(void)
{
+#if defined(ENV_IS_EMBEDDED)
+ ulong total;
+ int crc1_ok = 0, crc2_ok = 0;
+ env_t *tmp_env1, *tmp_env2;
+
+ total = CFG_ENV_SIZE;
+
+ tmp_env1 = env_ptr;
+ tmp_env2 = (env_t *)((ulong)env_ptr + CFG_ENV_SIZE);
+
+ crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
+ crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
+
+ if (!crc1_ok && !crc2_ok)
+ gd->env_valid = 0;
+ else if(crc1_ok && !crc2_ok)
+ gd->env_valid = 1;
+ else if(!crc1_ok && crc2_ok)
+ gd->env_valid = 2;
+ else {
+ /* both ok - check serial */
+ if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
+ gd->env_valid = 2;
+ else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
+ gd->env_valid = 1;
+ else if(tmp_env1->flags > tmp_env2->flags)
+ gd->env_valid = 1;
+ else if(tmp_env2->flags > tmp_env1->flags)
+ gd->env_valid = 2;
+ else /* flags are equal - almost impossible */
+ gd->env_valid = 1;
+ }
+
+ if (gd->env_valid == 1)
+ env_ptr = tmp_env1;
+ else if (gd->env_valid == 2)
+ env_ptr = tmp_env2;
+#else /* ENV_IS_EMBEDDED */
gd->env_addr = (ulong)&default_environment[0];
gd->env_valid = 1;
+#endif /* ENV_IS_EMBEDDED */
return (0);
}
@@ -236,6 +282,7 @@ void env_relocate_spec (void)
}
#endif /* CFG_ENV_OFFSET_REDUND */
+#if !defined(ENV_IS_EMBEDDED)
static void use_default()
{
puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
@@ -253,5 +300,6 @@ static void use_default()
gd->env_valid = 1;
}
+#endif
#endif /* CFG_ENV_IS_IN_NAND */
diff --git a/common/environment.c b/common/environment.c
index 81471ce71cd..19bdeb0f62a 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -60,7 +60,8 @@
defined(CONFIG_RRVISION) || \
defined(CONFIG_TRAB) || \
defined(CONFIG_PPCHAMELEONEVB) || \
- defined(CONFIG_M5271EVB)) && \
+ defined(CONFIG_M5271EVB) || \
+ defined(CONFIG_NAND_U_BOOT)) && \
defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
/* XXX - This only works with GNU C */
# define __PPCENV__ __attribute__ ((section(".ppcenv")))