From b502611b51f02718c2d1117d4981dabceb5af6de Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Sun, 6 Jul 2008 12:30:09 +0200 Subject: Change env_get_char from a global function ptr to a function This avoids an early global data reference. Signed-off-by: Joakim Tjernlund --- common/env_common.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'common/env_common.c') diff --git a/common/env_common.c b/common/env_common.c index e6df9a5..5ac14e8 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -50,7 +50,6 @@ extern void env_relocate_spec (void); extern uchar env_get_char_spec(int); static uchar env_get_char_init (int index); -uchar (*env_get_char)(int) = env_get_char_init; /************************************************************************ * Default settings to be used when no valid environment is found @@ -183,6 +182,19 @@ uchar env_get_char_memory (int index) } #endif +uchar env_get_char (int index) +{ + uchar c; + + /* if relocated to RAM */ + if (gd->flags & GD_FLG_RELOC) + c = env_get_char_memory(index); + else + c = env_get_char_init(index); + + return (c); +} + uchar *env_get_addr (int index) { if (gd->env_valid) { @@ -216,11 +228,6 @@ void env_relocate (void) DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr); #endif - /* - * After relocation to RAM, we can always use the "memory" functions - */ - env_get_char = env_get_char_memory; - if (gd->env_valid == 0) { #if defined(CONFIG_GTH) || defined(CFG_ENV_IS_NOWHERE) /* Environment not changable */ puts ("Using default environment\n\n"); -- cgit v1.1 From 5bb12dbd7ae03189b6c13d8737b5a1b37c3df698 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 7 Jul 2008 15:40:39 +0800 Subject: 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: Werner Almesberger Signed-off-by: Harald Welte --- common/env_common.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'common/env_common.c') diff --git a/common/env_common.c b/common/env_common.c index 5ac14e8..d51c211 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -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 (); -- cgit v1.1