[U-Boot-Users] [PATCH] Move init_sequence table into code.

Global variables are not ideal before relocation to RAM. ---
I hope this still applies.
lib_ppc/board.c | 144 +++++++++++++++++++++++++----------------------------- 1 files changed, 67 insertions(+), 77 deletions(-)
diff --git a/lib_ppc/board.c b/lib_ppc/board.c index 8a18350..c64bbd5 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -288,124 +288,114 @@ static int init_func_watchdog_reset (void) ************************************************************************ */
-init_fnc_t *init_sequence[] = { +/************************************************************************ + * + * This is the first part of the initialization sequence that is + * implemented in C, but still running from ROM. + * + * The main purpose is to provide a (serial) console interface as + * soon as possible (so we can see any error messages), and to + * initialize the RAM so that we can relocate the monitor code to + * RAM. + * + * Be aware of the restrictions: global data is read-only, BSS is not + * initialized, and stack space is limited to a few kB. + * + ************************************************************************ + */ + +void board_init_f (ulong bootflag) +{ + bd_t *bd; + ulong len, addr, addr_sp; + ulong *s; + gd_t *id; + init_fnc_t **init_fnc_ptr; +#ifdef CONFIG_PRAM + int i; + ulong reg; + uchar tmp[64]; /* long enough for environment variables */ +#endif + + /* Pointer is writable since we allocated a register for it */ + gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET); + /* compiler optimization barrier needed for GCC >= 3.4 */ + __asm__ __volatile__("": : :"memory"); + +#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC83XX) + /* Clear initial global data */ + memset ((void *) gd, 0, sizeof (gd_t)); +#endif
#if defined(CONFIG_BOARD_EARLY_INIT_F) - board_early_init_f, + board_early_init_f(); #endif
#if !defined(CONFIG_8xx_CPUCLK_DEFAULT) - get_clocks, /* get CPU and bus clocks (etc.) */ + get_clocks(); /* get CPU and bus clocks (etc.) */ #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \ && !defined(CONFIG_TQM885D) - adjust_sdram_tbs_8xx, + adjust_sdram_tbs_8xx(); #endif - init_timebase, + init_timebase(); #endif #ifdef CFG_ALLOC_DPRAM #if !defined(CONFIG_CPM2) - dpram_init, + dpram_init(); #endif #endif #if defined(CONFIG_BOARD_POSTCLK_INIT) - board_postclk_init, + board_postclk_init(); #endif - env_init, + env_init(); #if defined(CONFIG_8xx_CPUCLK_DEFAULT) - get_clocks_866, /* get CPU and bus clocks according to the environment variable */ - sdram_adjust_866, /* adjust sdram refresh rate according to the new clock */ - init_timebase, -#endif - init_baudrate, - serial_init, - console_init_f, - display_options, + get_clocks_866(); /* get CPU and bus clocks according to the environment variable */ + sdram_adjust_866(); /* adjust sdram refresh rate according to the new clock */ + init_timebase(); +#endif + init_baudrate(); + serial_init(); + console_init_f(); + display_options(); #if defined(CONFIG_8260) - prt_8260_rsr, - prt_8260_clks, + prt_8260_rsr(); + prt_8260_clks(); #endif /* CONFIG_8260 */ #if defined(CONFIG_MPC83XX) - prt_83xx_rsr, + prt_83xx_rsr(); #endif - checkcpu, + checkcpu(); #if defined(CONFIG_MPC5xxx) - prt_mpc5xxx_clks, + prt_mpc5xxx_clks(); #endif /* CONFIG_MPC5xxx */ #if defined(CONFIG_MPC8220) - prt_mpc8220_clks, + prt_mpc8220_clks(); #endif - checkboard, + checkboard(); INIT_FUNC_WATCHDOG_INIT #if defined(CONFIG_MISC_INIT_F) - misc_init_f, + misc_init_f(); #endif INIT_FUNC_WATCHDOG_RESET #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) - init_func_i2c, + init_func_i2c(); #endif #if defined(CONFIG_HARD_SPI) - init_func_spi, + init_func_spi(); #endif #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */ - dtt_init, + dtt_init(); #endif #ifdef CONFIG_POST - post_init_f, + post_init_f(); #endif INIT_FUNC_WATCHDOG_RESET - init_func_ram, + init_func_ram(); #if defined(CFG_DRAM_TEST) - testdram, + testdram(); #endif /* CFG_DRAM_TEST */ INIT_FUNC_WATCHDOG_RESET
- NULL, /* Terminate this list */ -}; - -/************************************************************************ - * - * This is the first part of the initialization sequence that is - * implemented in C, but still running from ROM. - * - * The main purpose is to provide a (serial) console interface as - * soon as possible (so we can see any error messages), and to - * initialize the RAM so that we can relocate the monitor code to - * RAM. - * - * Be aware of the restrictions: global data is read-only, BSS is not - * initialized, and stack space is limited to a few kB. - * - ************************************************************************ - */ - -void board_init_f (ulong bootflag) -{ - bd_t *bd; - ulong len, addr, addr_sp; - ulong *s; - gd_t *id; - init_fnc_t **init_fnc_ptr; -#ifdef CONFIG_PRAM - int i; - ulong reg; - uchar tmp[64]; /* long enough for environment variables */ -#endif - - /* Pointer is writable since we allocated a register for it */ - gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET); - /* compiler optimization barrier needed for GCC >= 3.4 */ - __asm__ __volatile__("": : :"memory"); - -#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC83XX) - /* Clear initial global data */ - memset ((void *) gd, 0, sizeof (gd_t)); -#endif - - for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - if ((*init_fnc_ptr) () != 0) { - hang (); - } - }
/* * Now that we have DRAM mapped and working, we can

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);

On 16:45 Fri 28 Mar , Joakim Tjernlund wrote:
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);
- }
Please remove occolade Best Regards, J.

In message 1206719159-11200-2-git-send-email-Joakim.Tjernlund@transmode.se you wrote:
This avoids an early global data reference.
What exactly is the problem you're trying to fix? It seems the resulting code is not exactly smaller than the old one?
Best regards,
Wolfgang Denk

On Sun, 2008-03-30 at 22:59 +0200, Wolfgang Denk wrote:
In message 1206719159-11200-2-git-send-email-Joakim.Tjernlund@transmode.se you wrote:
This avoids an early global data reference.
What exactly is the problem you're trying to fix? It seems the resulting code is not exactly smaller than the old one?
Just one step closer to full relocation of u-boot. Global variables before relocation to RAM is hard to deal with. Not sure if the code got smaller or not.
Jocke

In message 1206911129.7589.411.camel@gentoo-jocke.transmode.se you wrote:
Just one step closer to full relocation of u-boot. Global variables before relocation to RAM is hard to deal with. Not sure if the code got smaller or not.
Hm...there are some such variables.
Did you compare sizes?
Best regards,
Wolfgang Denk

On Mon, 2008-03-31 at 00:33 +0200, Wolfgang Denk wrote:
In message 1206911129.7589.411.camel@gentoo-jocke.transmode.se you wrote:
Just one step closer to full relocation of u-boot. Global variables before relocation to RAM is hard to deal with. Not sure if the code got smaller or not.
Hm...there are some such variables.
Did you compare sizes?
I got the hint, thanks :)
size before: text data bss dec hex filename 204117 13520 28716 246353 3c251 u-boot
size after: text data bss dec hex filename 203893 13500 28716 246109 3c15d u-boot
So it also got smaller by 244 bytes. Updated patch, with signoff and Jean-Christophe comment addressed.
Jocke
From 9e7cc775fa1fbf09b65f4a5edb5b16fe861c85dd Mon Sep 17 00:00:00 2001
From: Joakim Tjernlund Joakim.Tjernlund@transmode.se Date: Thu, 7 Feb 2008 14:50:42 +0100 Subject: [PATCH] Change env_get_char from a global function ptr to a function. This avoids an early global data reference.
Signed-off-by: Joakim Tjernlund Joakim.Tjernlund@transmode.se --- api/api.c | 1 - common/cmd_bootm.c | 3 --- common/cmd_nvedit.c | 3 --- common/env_common.c | 19 +++++++++++++------ 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, 14 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..f366fdb 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,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) { @@ -215,11 +227,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);

Did you try this one or did du skip it this release?
Jocke
On Mon, 2008-03-31 at 00:33 +0200, Wolfgang Denk wrote:
In message 1206911129.7589.411.camel@gentoo-jocke.transmode.se you wrote:
Just one step closer to full relocation of u-boot. Global variables before relocation to RAM is hard to deal with. Not sure if the code got smaller or not.
Hm...there are some such variables.
Did you compare sizes?
I got the hint, thanks :)
size before: text data bss dec hex filename 204117 13520 28716 246353 3c251 u-boot
size after: text data bss dec hex filename 203893 13500 28716 246109 3c15d u-boot
So it also got smaller by 244 bytes. Updated patch, with signoff and Jean-Christophe comment addressed.
Jocke
From 9e7cc775fa1fbf09b65f4a5edb5b16fe861c85dd Mon Sep 17 00:00:00 2001
From: Joakim Tjernlund Joakim.Tjernlund@transmode.se Date: Thu, 7 Feb 2008 14:50:42 +0100 Subject: [PATCH] Change env_get_char from a global function ptr to a function. This avoids an early global data reference.
Signed-off-by: Joakim Tjernlund Joakim.Tjernlund@transmode.se --- api/api.c | 1 - common/cmd_bootm.c | 3 --- common/cmd_nvedit.c | 3 --- common/env_common.c | 19 +++++++++++++------ 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, 14 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..f366fdb 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,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) { @@ -215,11 +227,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);

In message 1206719159-11200-1-git-send-email-Joakim.Tjernlund@transmode.se you wrote:
Global variables are not ideal before relocation to RAM.
Byt they don't cause any real problem either, or am I missing something?
I tend to reject the patch.
-init_fnc_t *init_sequence[] = {
The original idea of having such a list of funtion pointers which just get executed one after another was to be able to wrap this into some "#ifndef CONFIG_INIT_SEQUENCE" and use this to allow for board- specific init sequences by just adding a #define with the needed list of functions to the board config files.
Even though this feature never was used so far, I still hesitate to throw it away - at least as long as I don't see benefits for the new solution.
Best regards,
Wolfgang Denk

On Mon, 2008-04-14 at 03:09 +0200, Wolfgang Denk wrote:
In message 1206719159-11200-1-git-send-email-Joakim.Tjernlund@transmode.se you wrote:
Global variables are not ideal before relocation to RAM.
Byt they don't cause any real problem either, or am I missing something?
Makes u-boot smaller too. It is a step closer towards full relocation of u-boot, I want to get rid of using global data while in FLASH.
I tend to reject the patch.
-init_fnc_t *init_sequence[] = {
The original idea of having such a list of funtion pointers which just get executed one after another was to be able to wrap this into some "#ifndef CONFIG_INIT_SEQUENCE" and use this to allow for board- specific init sequences by just adding a #define with the needed list of functions to the board config files.
You can do that with weak functions too. Just make all the functions weak, then a board can overide with its own function.
Even though this feature never was used so far, I still hesitate to throw it away - at least as long as I don't see benefits for the new solution.
Best regards,
Wolfgang Denk

In message 1208207184.5911.26.camel@gentoo-jocke.transmode.se you wrote:
It is a step closer towards full relocation of u-boot, I want to get rid of using global data while in FLASH.
I doubt that this will work, but I'd love to be surprised :-)
The original idea of having such a list of funtion pointers which just get executed one after another was to be able to wrap this into some "#ifndef CONFIG_INIT_SEQUENCE" and use this to allow for board- specific init sequences by just adding a #define with the needed list of functions to the board config files.
You can do that with weak functions too. Just make all the functions weak, then a board can overide with its own function.
That would not, for example, to allow to change the sequence - say one board needs to initialize PCI very early, but another one very late.
Best regards,
Wolfgang Denk

On Tue, 2008-04-15 at 06:35 +0200, Wolfgang Denk wrote:
In message 1208207184.5911.26.camel@gentoo-jocke.transmode.se you wrote:
It is a step closer towards full relocation of u-boot, I want to get rid of using global data while in FLASH.
I doubt that this will work, but I'd love to be surprised :-)
It is not going to be a walk in the park :) The big remaining part is string literals while still in flash, not sure how to solve these yet.
The original idea of having such a list of funtion pointers which just get executed one after another was to be able to wrap this into some "#ifndef CONFIG_INIT_SEQUENCE" and use this to allow for board- specific init sequences by just adding a #define with the needed list of functions to the board config files.
You can do that with weak functions too. Just make all the functions weak, then a board can overide with its own function.
That would not, for example, to allow to change the sequence - say one board needs to initialize PCI very early, but another one very late.
True, but as no one even uses this code ATM, it can't be a big deal.
Jocke

In message 1208241621.5911.32.camel@gentoo-jocke.transmode.se you wrote:
It is not going to be a walk in the park :) The big remaining part is string literals while still in flash, not sure how to solve these yet.
The original idea of having such a list of funtion pointers which just get executed one after another was to be able to wrap this into some "#ifndef CONFIG_INIT_SEQUENCE" and use this to allow for board- specific init sequences by just adding a #define with the needed list of functions to the board config files.
You can do that with weak functions too. Just make all the functions weak, then a board can overide with its own function.
That would not, for example, to allow to change the sequence - say one board needs to initialize PCI very early, but another one very late.
True, but as no one even uses this code ATM, it can't be a big deal.
OK. Well, this is not a bug fix, but a (more or less invasive) change to basic infrastructure. I will not add this so shortly before a release. Please rebase and resubmit when the next merge window is open.
Thanks.
Best regards,
Wolfgang Denk
participants (4)
-
Jean-Christophe PLAGNIOL-VILLARD
-
Joakim Tjernlund
-
Joakim Tjernlund
-
Wolfgang Denk