/* this is called before nand_init()
* so we can't read Nand to validate env data.
* 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;
#ifdef CMD_SAVEENV
/*
* The legacy NAND code saved the environment in the first NAND device i.e.,
* nand_dev_desc + 0. This is also the behaviour using the new NAND code.
*/
#ifdef CFG_ENV_OFFSET_REDUND
int saveenv(void)
{
ulong total;
int ret = 0;
env_ptr->flags++;
total = CFG_ENV_SIZE;
if(gd->env_valid == 1) {
puts ("Erasing redundant Nand...");
if (nand_erase(&nand_info[0],
CFG_ENV_OFFSET_REDUND, CFG_ENV_SIZE))
return 1;
puts ("Writing to redundant Nand... ");
ret = nand_write(&nand_info[0], CFG_ENV_OFFSET_REDUND, &total,
(u_char*) env_ptr);
} else {
puts ("Erasing Nand...");
if (nand_erase(&nand_info[0],
CFG_ENV_OFFSET, CFG_ENV_SIZE))
return 1;
puts ("Writing to Nand... ");
ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total,
(u_char*) env_ptr);
}
if (ret || total != CFG_ENV_SIZE)
return 1;
puts ("done\n");
gd->env_valid = (gd->env_valid == 2 ? 1 : 2);
return ret;
}
#else /* ! CFG_ENV_OFFSET_REDUND */
int saveenv(void)
{
ulong total;
int ret = 0;
#endif /* ! ENV_IS_EMBEDDED */
}
#else /* ! CFG_ENV_OFFSET_REDUND */
/*
* The legacy NAND code saved the environment in the first NAND device i.e.,
* nand_dev_desc + 0. This is also the behaviour using the new NAND code.
*/
void env_relocate_spec (void)
{
#if !defined(ENV_IS_EMBEDDED)
ulong total;
int ret;
total = CFG_ENV_SIZE;
//ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
nand_legacy_rw(nand_dev_desc+0,0x01|0x02,CFG_ENV_OFFSET,CFG_ENV_SIZE,&total,(u_char*)env_ptr);
if (ret || total != CFG_ENV_SIZE)
return use_default();
if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
return use_default();