[U-Boot-Users] [PATCH] Change env_get_char from a global function ptr to a function.

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Fri Mar 28 16:45:59 CET 2008


This avoids an early global data reference.

---
I hope this still applies.

 api/api.c            |    1 -
 common/cmd_bootm.c   |    3 ---
 common/cmd_nvedit.c  |    3 ---
 common/env_common.c  |   21 +++++++++++++++------
 common/env_eeprom.c  |    1 -
 common/env_nvram.c   |    1 -
 common/fdt_support.c |    4 ----
 common/ft_build.c    |    3 ---
 include/common.h     |    1 +
 9 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/api/api.c b/api/api.c
index 0598d90..c1b2b60 100644
--- a/api/api.c
+++ b/api/api.c
@@ -40,7 +40,6 @@
 
 /* U-Boot routines needed */
 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-extern uchar (*env_get_char)(int);
 extern uchar *env_get_addr(int);
 
 /*****************************************************************************
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 9546729..5062817 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -1150,9 +1150,6 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
 
 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
 
-/* Function that returns a character from the environment */
-extern uchar (*env_get_char)(int);
-
 static void
 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
 		int	argc, char *argv[],
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index dd263b6..15dca5b 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -68,9 +68,6 @@ DECLARE_GLOBAL_DATA_PTR;
 /************************************************************************
 ************************************************************************/
 
-/* Function that returns a character from the environment */
-extern uchar (*env_get_char)(int);
-
 /* Function that returns a pointer to a value from the environment */
 /* (Only memory version supported / needed). */
 extern uchar *env_get_addr(int);
diff --git a/common/env_common.c b/common/env_common.c
index a494812..e87818b 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
@@ -182,6 +181,21 @@ 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) {
@@ -215,11 +229,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");
diff --git a/common/env_eeprom.c b/common/env_eeprom.c
index 2adc129..fae87ca 100644
--- a/common/env_eeprom.c
+++ b/common/env_eeprom.c
@@ -38,7 +38,6 @@ env_t *env_ptr = NULL;
 
 char * env_name_spec = "EEPROM";
 
-extern uchar (*env_get_char)(int);
 extern uchar env_get_char_memory (int index);
 
 
diff --git a/common/env_nvram.c b/common/env_nvram.c
index 7c18896..bfc8d02 100644
--- a/common/env_nvram.c
+++ b/common/env_nvram.c
@@ -63,7 +63,6 @@ char * env_name_spec = "NVRAM";
 extern uchar default_environment[];
 extern int default_environment_size;
 
-extern uchar (*env_get_char)(int);
 extern uchar env_get_char_memory (int index);
 
 #ifdef CONFIG_AMIGAONEG3SE
diff --git a/common/fdt_support.c b/common/fdt_support.c
index a13c140..fc43b43 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -225,10 +225,6 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 
-/* Function that returns a character from the environment */
-extern uchar(*env_get_char) (int);
-
-
 int fdt_env(void *fdt)
 {
 	int   nodeoffset;
diff --git a/common/ft_build.c b/common/ft_build.c
index 5a0575e..bd0c915 100644
--- a/common/ft_build.c
+++ b/common/ft_build.c
@@ -396,9 +396,6 @@ void *ft_get_prop(void *bphp, const char *propname, int *szp)
 
 /********************************************************************/
 
-/* Function that returns a character from the environment */
-extern uchar(*env_get_char) (int);
-
 #define BDM(x)	{	.name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
 
 #ifdef CONFIG_OF_HAS_BD_T
diff --git a/include/common.h b/include/common.h
index 54083f1..4fed250 100644
--- a/include/common.h
+++ b/include/common.h
@@ -229,6 +229,7 @@ extern ulong load_addr;		/* Default Load Address */
 /* common/cmd_nvedit.c */
 int	env_init     (void);
 void	env_relocate (void);
+uchar	env_get_char (int);
 int	envmatch     (uchar *, int);
 char	*getenv	     (char *);
 int	getenv_r     (char *name, char *buf, unsigned len);
-- 
1.5.4.3





More information about the U-Boot mailing list