Commit 5bb12dbd authored by Harald Welte's avatar Harald Welte Committed by Wolfgang Denk

Remove code duplication for setting the default environment

common/env_common.c (default_env): new function that resets the environment to
		    the default value
common/env_common.c (env_relocate): use default_env instead of own copy
common/env_nand.c (env_relocate_spec): use default_env instead of own copy
include/environment.h: added default_env prototype
Signed-off-by: default avatarWerner Almesberger <werner@openmoko.org>
Signed-off-by: default avatarHarald Welte <laforge@openmoko.org>
parent c3bf1ad7
......@@ -204,6 +204,23 @@ uchar *env_get_addr (int index)
}
}
void set_default_env(void)
{
if (sizeof(default_environment) > ENV_SIZE) {
puts ("*** Error - default environment is too large\n\n");
return;
}
memset(env_ptr, 0, sizeof(env_t));
memcpy(env_ptr->data, default_environment,
sizeof(default_environment));
#ifdef CFG_REDUNDAND_ENVIRONMENT
env_ptr->flags = 0xFF;
#endif
env_crc_update ();
gd->env_valid = 1;
}
void env_relocate (void)
{
DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
......@@ -235,22 +252,7 @@ void env_relocate (void)
puts ("*** Warning - bad CRC, using default environment\n\n");
show_boot_progress (-60);
#endif
if (sizeof(default_environment) > ENV_SIZE)
{
puts ("*** Error - default environment is too large\n\n");
return;
}
memset (env_ptr, 0, sizeof(env_t));
memcpy (env_ptr->data,
default_environment,
sizeof(default_environment));
#ifdef CFG_REDUNDAND_ENVIRONMENT
env_ptr->flags = 0xFF;
#endif
env_crc_update ();
gd->env_valid = 1;
set_default_env();
}
else {
env_relocate_spec ();
......
......@@ -363,19 +363,7 @@ void env_relocate_spec (void)
static void use_default()
{
puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
if (default_environment_size > CFG_ENV_SIZE){
puts ("*** Error - default environment is too large\n\n");
return;
}
memset (env_ptr, 0, sizeof(env_t));
memcpy (env_ptr->data,
default_environment,
default_environment_size);
env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
gd->env_valid = 1;
set_default_env();
}
#endif
......
......@@ -117,4 +117,7 @@ unsigned char env_get_char_memory (int index);
/* Function that updates CRC of the enironment */
void env_crc_update (void);
/* [re]set to the default environment */
void set_default_env(void);
#endif /* _ENVIRONMENT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment