2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2013-01-08 10:18:02 +00:00
|
|
|
/*
|
|
|
|
* crt0 - C-runtime startup Code for ARM U-Boot
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Albert ARIBAUD <albert.u.boot@aribaud.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <asm-offsets.h>
|
2013-04-11 09:35:47 +00:00
|
|
|
#include <linux/linkage.h>
|
2015-03-01 11:44:39 +00:00
|
|
|
#ifdef CONFIG_CPU_V7M
|
|
|
|
#include <asm/armv7m.h>
|
|
|
|
#endif
|
2013-01-08 10:18:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file handles the target-independent stages of the U-Boot
|
|
|
|
* start-up where a C runtime environment is needed. Its entry point
|
|
|
|
* is _main and is branched into from the target's start.S file.
|
|
|
|
*
|
|
|
|
* _main execution sequence is:
|
|
|
|
*
|
|
|
|
* 1. Set up initial environment for calling board_init_f().
|
|
|
|
* This environment only provides a stack and a place to store
|
|
|
|
* the GD ('global data') structure, both located in some readily
|
|
|
|
* available RAM (SRAM, locked cache...). In this context, VARIABLE
|
|
|
|
* global data, initialized or not (BSS), are UNAVAILABLE; only
|
2015-08-01 14:55:46 +00:00
|
|
|
* CONSTANT initialized data are available. GD should be zeroed
|
|
|
|
* before board_init_f() is called.
|
2013-01-08 10:18:02 +00:00
|
|
|
*
|
|
|
|
* 2. Call board_init_f(). This function prepares the hardware for
|
|
|
|
* execution from system RAM (DRAM, DDR...) As system RAM may not
|
|
|
|
* be available yet, , board_init_f() must use the current GD to
|
|
|
|
* store any data which must be passed on to later stages. These
|
|
|
|
* data include the relocation destination, the future stack, and
|
|
|
|
* the future GD location.
|
|
|
|
*
|
|
|
|
* 3. Set up intermediate environment where the stack and GD are the
|
|
|
|
* ones allocated by board_init_f() in system RAM, but BSS and
|
|
|
|
* initialized non-const data are still not available.
|
|
|
|
*
|
2015-08-01 14:55:46 +00:00
|
|
|
* 4a.For U-Boot proper (not SPL), call relocate_code(). This function
|
|
|
|
* relocates U-Boot from its current location into the relocation
|
|
|
|
* destination computed by board_init_f().
|
|
|
|
*
|
|
|
|
* 4b.For SPL, board_init_f() just returns (to crt0). There is no
|
|
|
|
* code relocation in SPL.
|
2013-01-08 10:18:02 +00:00
|
|
|
*
|
|
|
|
* 5. Set up final environment for calling board_init_r(). This
|
|
|
|
* environment has BSS (initialized to 0), initialized non-const
|
|
|
|
* data (initialized to their intended value), and stack in system
|
2015-08-01 14:55:46 +00:00
|
|
|
* RAM (for SPL moving the stack and GD into RAM is optional - see
|
|
|
|
* CONFIG_SPL_STACK_R). GD has retained values set by board_init_f().
|
|
|
|
*
|
|
|
|
* 6. For U-Boot proper (not SPL), some CPUs have some work left to do
|
|
|
|
* at this point regarding memory, so call c_runtime_cpu_setup.
|
|
|
|
*
|
|
|
|
* 7. Branch to board_init_r().
|
2013-01-08 10:18:02 +00:00
|
|
|
*
|
2015-08-01 14:55:46 +00:00
|
|
|
* For more information see 'Board Initialisation Flow in README.
|
2013-01-08 10:18:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* entry point of crt0 sequence
|
|
|
|
*/
|
|
|
|
|
2013-04-11 09:35:47 +00:00
|
|
|
ENTRY(_main)
|
2013-01-08 10:18:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up initial C runtime environment and call board_init_f(0).
|
|
|
|
*/
|
|
|
|
|
2013-04-11 09:36:01 +00:00
|
|
|
#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
|
2016-02-05 18:43:01 +00:00
|
|
|
ldr r0, =(CONFIG_SPL_STACK)
|
2013-01-08 10:18:02 +00:00
|
|
|
#else
|
2016-02-05 18:43:01 +00:00
|
|
|
ldr r0, =(CONFIG_SYS_INIT_SP_ADDR)
|
2013-01-08 10:18:02 +00:00
|
|
|
#endif
|
2016-02-05 18:43:01 +00:00
|
|
|
bic r0, r0, #7 /* 8-byte alignment for ABI compliance */
|
|
|
|
mov sp, r0
|
2015-11-25 16:56:32 +00:00
|
|
|
bl board_init_f_alloc_reserve
|
2015-10-19 12:50:00 +00:00
|
|
|
mov sp, r0
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
/* set up gd here, outside any C code */
|
|
|
|
mov r9, r0
|
2015-11-25 16:56:32 +00:00
|
|
|
bl board_init_f_init_reserve
|
2015-10-19 12:50:00 +00:00
|
|
|
|
2013-01-08 10:18:02 +00:00
|
|
|
mov r0, #0
|
|
|
|
bl board_init_f
|
|
|
|
|
|
|
|
#if ! defined(CONFIG_SPL_BUILD)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up intermediate environment (new sp and gd) and call
|
2013-04-11 09:35:53 +00:00
|
|
|
* relocate_code(addr_moni). Trick here is that we'll return
|
|
|
|
* 'here' but relocated.
|
2013-01-08 10:18:02 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-05 18:43:01 +00:00
|
|
|
ldr r0, [r9, #GD_START_ADDR_SP] /* sp = gd->start_addr_sp */
|
|
|
|
bic r0, r0, #7 /* 8-byte alignment for ABI compliance */
|
|
|
|
mov sp, r0
|
2013-09-21 12:04:41 +00:00
|
|
|
ldr r9, [r9, #GD_BD] /* r9 = gd->bd */
|
|
|
|
sub r9, r9, #GD_SIZE /* new GD is below bd */
|
2013-01-08 10:18:02 +00:00
|
|
|
|
|
|
|
adr lr, here
|
2013-09-21 12:04:41 +00:00
|
|
|
ldr r0, [r9, #GD_RELOC_OFF] /* r0 = gd->reloc_off */
|
2013-01-08 10:18:02 +00:00
|
|
|
add lr, lr, r0
|
2015-03-01 11:44:39 +00:00
|
|
|
#if defined(CONFIG_CPU_V7M)
|
|
|
|
orr lr, #1 /* As required by Thumb-only */
|
|
|
|
#endif
|
2013-09-21 12:04:41 +00:00
|
|
|
ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
|
2013-01-08 10:18:02 +00:00
|
|
|
b relocate_code
|
|
|
|
here:
|
2014-11-13 16:59:15 +00:00
|
|
|
/*
|
|
|
|
* now relocate vectors
|
|
|
|
*/
|
|
|
|
|
|
|
|
bl relocate_vectors
|
2013-01-08 10:18:02 +00:00
|
|
|
|
|
|
|
/* Set up final (full) environment */
|
|
|
|
|
|
|
|
bl c_runtime_cpu_setup /* we still call old routine here */
|
2015-03-03 15:03:00 +00:00
|
|
|
#endif
|
|
|
|
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_FRAMEWORK)
|
|
|
|
# ifdef CONFIG_SPL_BUILD
|
|
|
|
/* Use a DRAM stack for the rest of SPL, if requested */
|
|
|
|
bl spl_relocate_stack_gd
|
|
|
|
cmp r0, #0
|
|
|
|
movne sp, r0
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
movne r9, r0
|
2015-03-03 15:03:00 +00:00
|
|
|
# endif
|
2013-01-08 10:18:02 +00:00
|
|
|
ldr r0, =__bss_start /* this is auto-relocated! */
|
|
|
|
|
2015-03-04 13:01:22 +00:00
|
|
|
#ifdef CONFIG_USE_ARCH_MEMSET
|
|
|
|
ldr r3, =__bss_end /* this is auto-relocated! */
|
|
|
|
mov r1, #0x00000000 /* prepare zero to clear BSS */
|
|
|
|
|
|
|
|
subs r2, r3, r0 /* r2 = memset len */
|
|
|
|
bl memset
|
|
|
|
#else
|
|
|
|
ldr r1, =__bss_end /* this is auto-relocated! */
|
2013-01-08 10:18:02 +00:00
|
|
|
mov r2, #0x00000000 /* prepare zero to clear BSS */
|
|
|
|
|
|
|
|
clbss_l:cmp r0, r1 /* while not at end of BSS */
|
2015-03-01 11:44:39 +00:00
|
|
|
#if defined(CONFIG_CPU_V7M)
|
|
|
|
itt lo
|
|
|
|
#endif
|
2013-01-08 10:18:02 +00:00
|
|
|
strlo r2, [r0] /* clear 32-bit BSS word */
|
|
|
|
addlo r0, r0, #4 /* move to next */
|
|
|
|
blo clbss_l
|
2015-03-04 13:01:22 +00:00
|
|
|
#endif
|
2013-01-08 10:18:02 +00:00
|
|
|
|
2015-03-03 15:03:00 +00:00
|
|
|
#if ! defined(CONFIG_SPL_BUILD)
|
2013-01-08 10:18:02 +00:00
|
|
|
bl coloured_LED_init
|
|
|
|
bl red_led_on
|
2015-03-03 15:03:00 +00:00
|
|
|
#endif
|
2013-01-08 10:18:02 +00:00
|
|
|
/* call board_init_r(gd_t *id, ulong dest_addr) */
|
2013-09-21 12:04:41 +00:00
|
|
|
mov r0, r9 /* gd_t */
|
|
|
|
ldr r1, [r9, #GD_RELOCADDR] /* dest_addr */
|
2013-01-08 10:18:02 +00:00
|
|
|
/* call board_init_r */
|
2017-03-18 13:01:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
|
2016-02-09 15:48:28 +00:00
|
|
|
ldr lr, =board_init_r /* this is auto-relocated! */
|
|
|
|
bx lr
|
|
|
|
#else
|
2013-01-08 10:18:02 +00:00
|
|
|
ldr pc, =board_init_r /* this is auto-relocated! */
|
2016-02-09 15:48:28 +00:00
|
|
|
#endif
|
2013-01-08 10:18:02 +00:00
|
|
|
/* we should not return here. */
|
|
|
|
#endif
|
2013-04-11 09:35:47 +00:00
|
|
|
|
|
|
|
ENDPROC(_main)
|