[U-Boot] [PATCH] Fix board init code to use a valid C runtime environment

Albert ARIBAUD albert.u.boot at aribaud.net
Tue Nov 10 07:06:25 CET 2015


Hello Thomas,

On Tue, 10 Nov 2015 09:14:01 +0800, Thomas Chou <thomas at wytron.com.tw>
wrote:
> Hi Albert,
> 
> On 2015年11月10日 08:20, Albert ARIBAUD wrote:
> > board_init_f_mem() alters the C runtime environment's
> > stack it ls actually already using. This is not a valid
> > C runtime environment and may conflict with the C compiler's
> > expectations.
> >
> > Split board_init_f_mem into C functions which do not
> > alter their own stack and therefore function in a valid C
> > runtime environment.
> >
> > NOTE: this has not been tested with all architectures.
> >
> > Signed-off-by: Albert ARIBAUD <albert.u.boot at aribaud.net>
> > ---
> >   arch/arc/lib/start.S            | 20 +++++++++++++---
> >   arch/arm/lib/crt0.S             | 10 ++++++--
> >   arch/arm/lib/crt0_64.S          | 12 +++++++---
> >   arch/microblaze/cpu/start.S     |  4 ++--
> >   arch/nios2/cpu/start.S          | 17 ++++++++++++--
> >   arch/powerpc/cpu/ppc4xx/start.S | 18 ++++++++++----
> >   arch/x86/cpu/start.S            | 10 ++++++--
> >   arch/x86/lib/fsp/fsp_common.c   |  2 +-
> >   common/init/board_init.c        | 33 +++++++++++++++-----------
> >   include/common.h                | 52 +++++++++++++++++++++++++----------------
> >   10 files changed, 126 insertions(+), 52 deletions(-)
> >
> 
> Apply the patch.
> 
> $ git am "/work/tmp/[U-Boot] [PATCH] Fix board init code to use a valid 
> C runtime environment.eml"
> Applying: Fix board init code to use a valid C runtime environment
> /work/nios2-linux/u-boot/.git/rebase-apply/patch:91: trailing whitespace.
> 	
> /work/nios2-linux/u-boot/.git/rebase-apply/patch:292: trailing whitespace.
>   *
> /work/nios2-linux/u-boot/.git/rebase-apply/patch:309: trailing whitespace.
>   *
> /work/nios2-linux/u-boot/.git/rebase-apply/patch:325: trailing whitespace.
>   *
> /work/nios2-linux/u-boot/.git/rebase-apply/patch:337: trailing whitespace.
>   *
> warning: 5 lines add whitespace errors.
> 
> Make.
> 
>    LD      arch/nios2/lib/built-in.o
>    CC      common/init/board_init.o
> common/init/board_init.c:61:6: error: conflicting types for 
> 'board_init_f_malloc'
>   void board_init_f_malloc(ulong malloc_base)
>        ^
> In file included from common/init/board_init.c:10:0:
> include/common.h:265:7: note: previous declaration of 
> 'board_init_f_malloc' was here
>   ulong board_init_f_malloc(ulong malloc_base);
>         ^
> scripts/Makefile.build:277: recipe for target 'common/init/board_init.o' 
> failed
> make[2]: *** [common/init/board_init.o] Error 1
> scripts/Makefile.build:422: recipe for target 'common/init' failed
> make[1]: *** [common/init] Error 2
> Makefile:1205: recipe for target 'common' failed
> make: *** [common] Error 2
> 
> Fix common.h.
> 
> diff --git a/include/common.h b/include/common.h
> index dbc2808..7eb3ba8 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -262,7 +262,7 @@ ulong board_init_f_malloc_size(void);
>    *
>    * @malloc_base: the base of the malloc arena
>    */
> -ulong board_init_f_malloc(ulong malloc_base);
> +void board_init_f_malloc(ulong malloc_base);
> 
>   /**
>    * arch_setup_gd() - Set up the global_data pointer
> 
> Make again.
> 
>    LDS     u-boot.lds
>    LD      u-boot
> arch/nios2/cpu/start.o: In function `_reloc':
> /work/nios2-linux/u-boot/arch/nios2/cpu/start.S:111: undefined reference 
> to `board_init_gd_size'
> /work/nios2-linux/u-boot/arch/nios2/cpu/start.S:120: undefined reference 
> to `board_init_malloc_size'
> Makefile:1187: recipe for target 'u-boot' failed
> make: *** [u-boot] Error 1
> 
> Fix start.S.
> 
> diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
> index 4d5f0b0..c163ce1 100644
> --- a/arch/nios2/cpu/start.S
> +++ b/arch/nios2/cpu/start.S
> @@ -108,7 +108,7 @@ _reloc:
> 
>   	/* Allocate and zero GD, update SP */
>   	movhi	r2, %hi(board_init_f_gd_size at h)
> -	ori	r2, r2, %lo(board_init_gd_size at h)
> +	ori	r2, r2, %lo(board_init_f_gd_size at h)
>   	callr	r2
>   	sub	sp, sp, r4
>   	mov	r4, sp
> @@ -117,7 +117,7 @@ _reloc:
>   	callr	r2
>   	/* Allocate malloc arena, update SP */
>   	movhi	r2, %hi(board_init_f_malloc_size at h)
> -	ori	r2, r2, %lo(board_init_malloc_size at h)
> +	ori	r2, r2, %lo(board_init_f_malloc_size at h)
>   	callr	r2
>   	sub	sp, sp, r4
>   	mov	r4, sp
> 
> Make and run, but failed to boot. I will gdb and tell you the trace later.

I'll fix the general part ASAP -- I did a first run of the patch on ARM
then generalized it afterward but I had to rush to remain in the merge
window, which explains the header bunder, sorry.

Regarding the NIOS part, I did it by copying the ARM code and guessing
the NIOS asm language, but I am no expert (and have no  NIOS HW) - so
apologies for this, and thanks for your help!

> Best regards,
> Thomas

Amicalement,
-- 
Albert.


More information about the U-Boot mailing list