
New patch at the end of this mail!
On Sun, Jul 06, 2008 at 08:57:34PM +0200, Wolfgang Denk wrote:
In message 20080706170626.GH20299@prithivi.gnumonks.org you wrote:
+void default_env(void) +{
- if (sizeof(default_environment) > ENV_SIZE)
- {
puts ("*** Error - default environment is too large\n\n");
return;
- }
Incorrect brace style.
just moving one piece of code around here. Didn't want to introduce more whitespace changes than needed in order to make clear there is no functional change, but just code reorganization. Changed it now.
- memset (env_ptr, 0, sizeof(env_t));
- memcpy (env_ptr->data,
default_environment,
sizeof(default_environment));
Put on one line ?
too long for one line, but works on two lines.
--- u-boot.orig/common/env_common.c +++ u-boot/common/env_common.c
...
if (sizeof(default_environment) > ENV_SIZE)
...
--- u-boot.orig/common/env_nand.c +++ u-boot/common/env_nand.c
...
- if (default_environment_size > CFG_ENV_SIZE){
Looks like a sleeping bug to me...
yes, indeed. should have been ENV_SIZE before... with the old code you can overflow env_ptr->data.
+void default_env(void);
Please name "set_default_env()".
done.
***********************
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 werner@openmoko.org Signed-off-by: Harald Welte laforge@openmoko.org
Index: u-boot/common/env_common.c =================================================================== --- u-boot.orig/common/env_common.c +++ u-boot/common/env_common.c @@ -192,6 +192,23 @@ } }
+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__, @@ -228,22 +245,7 @@ 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 (); Index: u-boot/common/env_nand.c =================================================================== --- u-boot.orig/common/env_nand.c +++ u-boot/common/env_nand.c @@ -363,19 +363,7 @@ 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
Index: u-boot/include/environment.h =================================================================== --- u-boot.orig/include/environment.h +++ u-boot/include/environment.h @@ -117,4 +117,7 @@ /* 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_ */