[U-Boot] [ARM] Environment variables not available during console initialisation?
Guennadi Liakhovetski
lg at denx.de
Mon Feb 2 17:35:58 CET 2009
Hi,
below is a patch / rfc that allows me to read the envorinment from NAND
early enough to be used in the console initialisation. It turns out this
is not only an ARM problem, rather it is common to all platforms storing
environment in NAND. Similarly, probably, env in SPI flash would have this
problem on all platforms too. The patch is not meant for mainline in its
present form because it only solves the problem for platforms, that not
only have their env in NAND, but also boot from NAND (using nand_spl).
OTOH, who would want to store environment in NAND if they didn't have to
boot from it? Anyway, it lacks generality. Also, it contains a couple of
clean ups, that actually would have to be submitted separately (removal
of unused "total" variable, and a typo fix in a comment).
So, this is mostly as an inspiration for someone to develop a proper
patch, or, if we do decide, that this approach is good enough, I'll split
it up and submit properly.
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
diff --git a/common/env_nand.c b/common/env_nand.c
index a8f0de7..1261dd2 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -71,9 +71,11 @@ extern int default_environment_size;
char * env_name_spec = "NAND";
-#ifdef ENV_IS_EMBEDDED
+#if defined(ENV_IS_EMBEDDED)
extern uchar environment[];
env_t *env_ptr = (env_t *)(&environment[0]);
+#elif defined(CFG_ENV_IS_APPENDED)
+env_t *env_ptr = (env_t *)CFG_NAND_ENV_DST;
#else /* ! ENV_IS_EMBEDDED */
env_t *env_ptr = 0;
#endif /* ENV_IS_EMBEDDED */
@@ -105,23 +107,28 @@ uchar env_get_char_spec (int index)
*/
int env_init(void)
{
-#if defined(ENV_IS_EMBEDDED)
- size_t total;
+#if defined(ENV_IS_EMBEDDED) || defined(CFG_ENV_IS_APPENDED)
int crc1_ok = 0, crc2_ok = 0;
- env_t *tmp_env1, *tmp_env2;
+ env_t *tmp_env1;
- total = CFG_ENV_SIZE;
+#ifdef CFG_REDUNDAND_ENVIRONMENT
+ env_t *tmp_env2;
- tmp_env1 = env_ptr;
tmp_env2 = (env_t *)((ulong)env_ptr + CFG_ENV_SIZE);
+ crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
+#endif
+ tmp_env1 = env_ptr;
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_addr = (ulong)env_ptr->data;
+
+ if (!crc1_ok && !crc2_ok) {
+ gd->env_addr = 0;
gd->env_valid = 0;
- else if(crc1_ok && !crc2_ok)
+ } else if(crc1_ok && !crc2_ok)
gd->env_valid = 1;
+#ifdef CFG_REDUNDAND_ENVIRONMENT
else if(!crc1_ok && crc2_ok)
gd->env_valid = 2;
else {
@@ -138,10 +145,13 @@ int env_init(void)
gd->env_valid = 1;
}
+ if (gd->env_valid == 2)
+ env_ptr = tmp_env2;
+ else
+#endif
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;
@@ -186,12 +196,10 @@ int writeenv(size_t offset, u_char *buf)
#ifdef CFG_ENV_OFFSET_REDUND
int saveenv(void)
{
- size_t total;
int ret = 0;
nand_erase_options_t nand_erase_options;
env_ptr->flags++;
- total = CFG_ENV_SIZE;
nand_erase_options.length = CFG_ENV_RANGE;
nand_erase_options.quiet = 0;
@@ -229,7 +237,6 @@ int saveenv(void)
#else /* ! CFG_ENV_OFFSET_REDUND */
int saveenv(void)
{
- size_t total;
int ret = 0;
nand_erase_options_t nand_erase_options;
@@ -246,7 +253,6 @@ int saveenv(void)
return 1;
puts ("Writing to Nand... ");
- total = CFG_ENV_SIZE;
if (writeenv(CFG_ENV_OFFSET, (u_char *) env_ptr)) {
puts("FAILED!\n");
return 1;
@@ -290,12 +296,9 @@ int readenv (size_t offset, u_char * buf)
void env_relocate_spec (void)
{
#if !defined(ENV_IS_EMBEDDED)
- size_t total;
int crc1_ok = 0, crc2_ok = 0;
env_t *tmp_env1, *tmp_env2;
- total = CFG_ENV_SIZE;
-
tmp_env1 = (env_t *) malloc(CFG_ENV_SIZE);
tmp_env2 = (env_t *) malloc(CFG_ENV_SIZE);
diff --git a/include/configs/smdk6400.h b/include/configs/smdk6400.h
index 1ee4191..3acf7cd 100644
--- a/include/configs/smdk6400.h
+++ b/include/configs/smdk6400.h
@@ -223,6 +224,8 @@
#define CFG_UBOOT_BASE (CFG_MAPPED_RAM_BASE + 0x07e00000)
#define CFG_ENV_OFFSET 0x0040000
+/* Leave enough space for bss, currently __bss_end == 0x57e74800 */
+#define CFG_NAND_ENV_DST (CFG_UBOOT_BASE + 0x80000)
/* NAND configuration */
#define CFG_MAX_NAND_DEVICE 1
@@ -284,7 +287,8 @@
*/
/* Settings as above boot configuration */
-#define CFG_ENV_IS_IN_NAND
+#define CFG_ENV_IS_IN_NAND 1
+#define CFG_ENV_IS_APPENDED 1
#define CONFIG_BOOTARGS "console=ttySAC,115200"
#if !defined(CONFIG_ENABLE_MMU)
diff --git a/lib_arm/board.c b/lib_arm/board.c
index a093860..2dadfce 100644
--- a/lib_arm/board.c
+++ b/lib_arm/board.c
@@ -282,7 +282,7 @@ init_fnc_t *init_sequence[] = {
board_init, /* basic board dependent setup */
interrupt_init, /* set up exceptions */
env_init, /* initialize environment */
- init_baudrate, /* initialze baudrate settings */
+ init_baudrate, /* initialize baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
display_banner, /* say that we are here */
diff --git a/nand_spl/nand_boot.c b/nand_spl/nand_boot.c
index 16d128f..1fe10d2 100644
--- a/nand_spl/nand_boot.c
+++ b/nand_spl/nand_boot.c
@@ -248,6 +248,11 @@ void nand_boot(void)
ret = nand_load(&nand_info, CFG_NAND_U_BOOT_OFFS, CFG_NAND_U_BOOT_SIZE,
(uchar *)CFG_NAND_U_BOOT_DST);
+#ifdef CFG_ENV_IS_APPENDED
+ nand_load(&nand_info, CFG_ENV_OFFSET, CFG_ENV_SIZE,
+ (uchar *)CFG_NAND_ENV_DST);
+#endif
+
if (nand_chip.select_chip)
nand_chip.select_chip(&nand_info, -1);
More information about the U-Boot
mailing list