diff mbox

[U-Boot,v6,3/5] generic board patch of manual reloc and zero gd_t

Message ID 1378734616-37558-4-git-send-email-fenghua@phytium.com.cn
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Commit Message

fenghua@phytium.com.cn Sept. 9, 2013, 1:50 p.m. UTC
From: David Feng <fenghua@phytium.com.cn>

1. function board_init_f in board_f.c should firstly zero gd_t structure
   before it call initcall_run_list, otherwise the debug print will go run
   if DEBUG is defined. Because the printf function will use global data
   to determine whether serial port is initialized and could be written.
2. function board_init_r in board_r.c should firstly relocate init_sequence_r
   table before it call initcall_run_list. Command table also should be relocated.

Signed-off-by: David Feng <fenghua@phytium.com.cn>
---
Changes for v5:
  - no

 common/board_f.c |   19 +++++++++++++------
 common/board_r.c |   17 +++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

Comments

Wolfgang Denk Sept. 9, 2013, 2:21 p.m. UTC | #1
Dear fenghua@phytium.com.cn,

In message <1378734616-37558-4-git-send-email-fenghua@phytium.com.cn> you wrote:
> From: David Feng <fenghua@phytium.com.cn>
> 
> 1. function board_init_f in board_f.c should firstly zero gd_t structure
>    before it call initcall_run_list, otherwise the debug print will go run
>    if DEBUG is defined. Because the printf function will use global data
>    to determine whether serial port is initialized and could be written.
> 2. function board_init_r in board_r.c should firstly relocate init_sequence_r
>    table before it call initcall_run_list. Command table also should be relocated.

Please restrict the line length of your commit messages to some 70
characters or so.

> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -458,7 +458,11 @@ static int reserve_round_4k(void)
>  static int reserve_mmu(void)
>  {
>  	/* reserve TLB table */
> +#ifndef CONFIG_ARMV8
>  	gd->arch.tlb_size = 4096 * 4;
> +#else
> +	gd->arch.tlb_size = 0x10000;
> +#endif
>  	gd->relocaddr -= gd->arch.tlb_size;

Please avoid such #ifdef's in the code.  Replace the hard coded
default (here 0x10000) by a variable, and define these as needed.

> -#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
> -		!defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
> -		!defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
> -	zero_global_data,
> -#endif
>  #ifdef CONFIG_SANDBOX
>  	setup_ram_buf,
>  #endif
> @@ -1005,6 +1004,14 @@ void board_init_f(ulong boot_flags)
>  	gd = &data;
>  #endif
>  
> +	/*
> +	 * Zero gd_t first, otherwise the debug print in initcall_run_list
> +	 * function before zero_global_data is called will go wrong.
> +	 */
> +#ifndef CONFIG_X86
> +	zero_global_data();
> +#endif

This change does not look right to me.  The condition was much
different before.


Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/common/board_f.c b/common/board_f.c
index 0ada1af..98e24c3 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -458,7 +458,11 @@  static int reserve_round_4k(void)
 static int reserve_mmu(void)
 {
 	/* reserve TLB table */
+#ifndef CONFIG_ARMV8
 	gd->arch.tlb_size = 4096 * 4;
+#else
+	gd->arch.tlb_size = 0x10000;
+#endif
 	gd->relocaddr -= gd->arch.tlb_size;
 
 	/* round down to next 64 kB limit */
@@ -610,7 +614,7 @@  static int reserve_stacks(void)
 	 * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
 	 * to handle this and put in arch/xxx/lib/stack.c
 	 */
-# ifdef CONFIG_ARM
+# if defined(CONFIG_ARM) && !defined(CONFIG_ARMV8)
 #  ifdef CONFIG_USE_IRQ
 	gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
 	debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
@@ -807,11 +811,6 @@  static int mark_bootstage(void)
 }
 
 static init_fnc_t init_sequence_f[] = {
-#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
-		!defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
-		!defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
-	zero_global_data,
-#endif
 #ifdef CONFIG_SANDBOX
 	setup_ram_buf,
 #endif
@@ -1005,6 +1004,14 @@  void board_init_f(ulong boot_flags)
 	gd = &data;
 #endif
 
+	/*
+	 * Zero gd_t first, otherwise the debug print in initcall_run_list
+	 * function before zero_global_data is called will go wrong.
+	 */
+#ifndef CONFIG_X86
+	zero_global_data();
+#endif
+
 	gd->flags = boot_flags;
 
 	if (initcall_run_list(init_sequence_f))
diff --git a/common/board_r.c b/common/board_r.c
index 86ca1cb..1b4bdd2 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -157,6 +157,13 @@  static int initr_reloc_global_data(void)
 	 */
 	gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
 #endif
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+	/*
+	 * We have to relocate the command table manually
+	 */
+	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
+			ll_entry_count(cmd_tbl_t, cmd));
+#endif /* CONFIG_NEEDS_MANUAL_RELOC */
 	return 0;
 }
 
@@ -899,6 +906,7 @@  init_fnc_t init_sequence_r[] = {
 	initr_modem,
 #endif
 	run_main_loop,
+	NULL,
 };
 
 void board_init_r(gd_t *new_gd, ulong dest_addr)
@@ -906,6 +914,15 @@  void board_init_r(gd_t *new_gd, ulong dest_addr)
 #ifndef CONFIG_X86
 	gd = new_gd;
 #endif
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+	/*
+	 * We have to relocate the init_sequence_r table manually
+	 */
+	init_fnc_t	*init_fnc_ptr;
+	for (init_fnc_ptr = init_sequence_r; *init_fnc_ptr; ++init_fnc_ptr)
+		*init_fnc_ptr = (init_fnc_t *)((unsigned long)(*init_fnc_ptr) + gd->reloc_off);
+#endif /* CONFIG_NEEDS_MANUAL_RELOC */
+
 	if (initcall_run_list(init_sequence_r))
 		hang();