[U-Boot] [PATCH v2 05/17] x86: Simplify Flash-to-RAM code execution transition

Simon Glass sjg at chromium.org
Thu Jan 12 05:48:07 CET 2012


Hi Graeme,

On Wed, Jan 4, 2012 at 11:59 AM, Graeme Russ <graeme.russ at gmail.com> wrote:
> Move the relocation offset calculation out of assembler and into C. This
> also paves the way for the upcoming init sequence simplification by adding
> the board_init_f_r flash to RAM transitional function
>
> Signed-off-by: Graeme Russ <graeme.russ at gmail.com>

Still not thrilled with the name but it's not important.

Acked-by: Simon Glass <sjg at chromium.org>

Regards,
Simon

> ---
> Changes for v2:
>  - Added commit message
>  - Minor adjustment to new stack address comment
>
>  arch/x86/cpu/start.S              |   22 ++++++----------------
>  arch/x86/include/asm/u-boot-x86.h |    2 ++
>  arch/x86/lib/board.c              |   25 ++++++++++++++++++++++---
>  3 files changed, 30 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/cpu/start.S b/arch/x86/cpu/start.S
> index 6027f54..69a9b2c 100644
> --- a/arch/x86/cpu/start.S
> +++ b/arch/x86/cpu/start.S
> @@ -96,32 +96,22 @@ car_init_ret:
>        movw    $0x85, %ax
>        jmp     die
>
> -.globl relocate_code
> -.type relocate_code, @function
> -relocate_code:
> +.globl board_init_f_r_trampoline
> +.type board_init_f_r_trampoline, @function
> +board_init_f_r_trampoline:
>        /*
>         * SDRAM has been initialised, U-Boot code has been copied into
>         * RAM, BSS has been cleared and relocation adjustments have been
>         * made. It is now time to jump into the in-RAM copy of U-Boot
>         *
> -        * %eax = Address of top of stack
> -        * %edx = Address of Global Data
> -        * %ecx = Base address of in-RAM copy of U-Boot
> +        * %eax = Address of top of new stack
>         */
>
>        /* Setup stack in RAM */
>        movl    %eax, %esp
>
> -       /* Setup call address of in-RAM copy of board_init_r() */
> -       movl    $board_init_r, %ebp
> -       addl    (GENERATED_GD_RELOC_OFF)(%edx), %ebp
> -
> -       /* Setup parameters to board_init_r() */
> -       movl    %edx, %eax
> -       movl    %ecx, %edx
> -
> -       /* Jump to in-RAM copy of board_init_r() */
> -       call    *%ebp
> +       /* Re-enter U-Boot by calling board_init_f_r */
> +       call    board_init_f_r
>
>  die:
>        hlt
> diff --git a/arch/x86/include/asm/u-boot-x86.h b/arch/x86/include/asm/u-boot-x86.h
> index 755f88a..c3d2277 100644
> --- a/arch/x86/include/asm/u-boot-x86.h
> +++ b/arch/x86/include/asm/u-boot-x86.h
> @@ -61,5 +61,7 @@ u32 isa_map_rom(u32 bus_addr, int size);
>  int video_bios_init(void);
>  int video_init(void);
>
> +void   board_init_f_r_trampoline(ulong) __attribute__ ((noreturn));
> +void   board_init_f_r(void) __attribute__ ((noreturn));
>
>  #endif /* _U_BOOT_I386_H_ */
> diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c
> index f9eb15b..382ada7 100644
> --- a/arch/x86/lib/board.c
> +++ b/arch/x86/lib/board.c
> @@ -253,10 +253,29 @@ void board_init_f(ulong boot_flags)
>
>        gd->flags |= GD_FLG_RELOC;
>
> -       /* Enter the relocated U-Boot! */
> -       relocate_code(gd->start_addr_sp, gd, gd->relocaddr);
> +       /*
> +        * SDRAM is now initialised, U-Boot has been copied into SDRAM,
> +        * the BSS has been cleared etc. The final stack can now be setup
> +        * in SDRAM. Code execution will continue (momentarily) in Flash,
> +        * but with the stack in SDRAM and Global Data in temporary memory
> +        * (CPU cache)
> +        */
> +       board_init_f_r_trampoline(gd->start_addr_sp);
> +
> +       /* NOTREACHED - board_init_f_r_trampoline() does not return */
> +       while (1)
> +               ;
> +}
> +
> +void board_init_f_r(void)
> +{
> +       /*
> +        * Transfer execution from Flash to RAM by calculating the address
> +        * of the in-RAM copy of board_init_r() and calling it
> +        */
> +       (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
>
> -       /* NOTREACHED - relocate_code() does not return */
> +       /* NOTREACHED - board_init_r() does not return */
>        while (1)
>                ;
>  }
> --
> 1.7.5.2.317.g391b14
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


More information about the U-Boot mailing list