public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] [PATCH] Remove code duplication for setting the default environment
@ 2008-07-06 17:06 Harald Welte
  2008-07-06 18:57 ` Wolfgang Denk
  0 siblings, 1 reply; 9+ messages in thread
From: Harald Welte @ 2008-07-06 17:06 UTC (permalink / raw)
  To: u-boot

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,25 @@
 	}
 }
 
+void 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 +247,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;
+		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;
-
+	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);
 
+
+void default_env(void);
+
 #endif	/* _ENVIRONMENT_H_ */
-- 
- Harald Welte <laforge@gnumonks.org>           http://laforge.gnumonks.org/
============================================================================
"Privacy in residential applications is a desirable marketing option."
                                                  (ETSI EN 300 175-7 Ch. A6)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.denx.de/pipermail/u-boot/attachments/20080707/4de94f90/attachment.pgp 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-07-10  9:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-06 17:06 [U-Boot-Users] [PATCH] Remove code duplication for setting the default environment Harald Welte
2008-07-06 18:57 ` Wolfgang Denk
2008-07-07  7:40   ` Harald Welte
2008-07-09 22:30     ` Wolfgang Denk
2008-07-10  0:21       ` [U-Boot-Users] usage of git to send patches to u-boot mailinglist Harald Welte
2008-07-10  4:36         ` Paul Gortmaker
2008-07-10  8:34         ` Markus Klotzbücher
2008-07-10  8:49           ` Stefan Roese
2008-07-10  9:00         ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox