ARM: dts: stm32: Repair SDMMC1 operation on AV96
[oweals/u-boot.git] / arch / arm / lib / crt0.S
index a5bffb8da6df6e62645ea7aa9d403ac7853e1c64..fb6c37cf519494aa55a562354e066dcf434ddce6 100644 (file)
@@ -1,30 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  *  crt0 - C-runtime startup Code for ARM U-Boot
  *
  *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include <config.h>
 #include <asm-offsets.h>
 #include <linux/linkage.h>
+#include <asm/assembler.h>
 
 /*
  * This file handles the target-independent stages of the U-Boot
@@ -38,7 +22,8 @@
  *    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
- *    CONSTANT initialized data are available.
+ *    CONSTANT initialized data are available. GD should be zeroed
+ *    before board_init_f() is called.
  *
  * 2. Call board_init_f(). This function prepares the hardware for
  *    execution from system RAM (DRAM, DDR...) As system RAM may not
  *    data include the relocation destination, the future stack, and
  *    the future GD location.
  *
- * (the following applies only to non-SPL builds)
- *
  * 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.
  *
- * 4. Call relocate_code(). This function relocates U-Boot from its
- *    current location into the relocation destination computed by
- *    board_init_f().
+ * 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.
  *
  * 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
- *    RAM. GD has retained values set by board_init_f(). Some CPUs
- *    have some work left to do at this point regarding memory, so
- *    call c_runtime_cpu_setup.
+ *    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. Branch to board_init_r().
+ * 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().
+ *
+ * For more information see 'Board Initialisation Flow in README.
+ */
+
+/*
+ * Macro for clearing BSS during SPL execution. Usually called during the
+ * relocation process for most boards before entering board_init_r(), but
+ * can also be done early before entering board_init_f() on plaforms that
+ * can afford it due to sufficient memory being available early.
  */
 
+.macro SPL_CLEAR_BSS
+       ldr     r0, =__bss_start        /* this is auto-relocated! */
+
+#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! */
+       mov     r2, #0x00000000         /* prepare zero to clear BSS */
+
+clbss_l:cmp    r0, r1                  /* while not at end of BSS */
+       strlo   r2, [r0]                /* clear 32-bit BSS word */
+       addlo   r0, r0, #4              /* move to next */
+       blo     clbss_l
+#endif
+.endm
+
 /*
  * entry point of crt0 sequence
  */
@@ -77,15 +94,25 @@ ENTRY(_main)
  * Set up initial C runtime environment and call board_init_f(0).
  */
 
-#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
-       ldr     sp, =(CONFIG_SPL_STACK)
+#if defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_NEEDS_SEPARATE_STACK)
+       ldr     r0, =(CONFIG_TPL_STACK)
+#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
+       ldr     r0, =(CONFIG_SPL_STACK)
 #else
-       ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
+       ldr     r0, =(CONFIG_SYS_INIT_SP_ADDR)
 #endif
-       bic     sp, sp, #7      /* 8-byte alignment for ABI compliance */
-       sub     sp, #GD_SIZE    /* allocate one GD above SP */
-       bic     sp, sp, #7      /* 8-byte alignment for ABI compliance */
-       mov     r8, sp          /* GD is above SP */
+       bic     r0, r0, #7      /* 8-byte alignment for ABI compliance */
+       mov     sp, r0
+       bl      board_init_f_alloc_reserve
+       mov     sp, r0
+       /* set up gd here, outside any C code */
+       mov     r9, r0
+       bl      board_init_f_init_reserve
+
+#if defined(CONFIG_SPL_EARLY_BSS)
+       SPL_CLEAR_BSS
+#endif
+
        mov     r0, #0
        bl      board_init_f
 
@@ -97,43 +124,60 @@ ENTRY(_main)
  * 'here' but relocated.
  */
 
-       ldr     sp, [r8, #GD_START_ADDR_SP]     /* sp = gd->start_addr_sp */
-       bic     sp, sp, #7      /* 8-byte alignment for ABI compliance */
-       ldr     r8, [r8, #GD_BD]                /* r8 = gd->bd */
-       sub     r8, r8, #GD_SIZE                /* new GD is below bd */
+       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
+       ldr     r9, [r9, #GD_BD]                /* r9 = gd->bd */
+       sub     r9, r9, #GD_SIZE                /* new GD is below bd */
 
        adr     lr, here
-       ldr     r0, [r8, #GD_RELOC_OFF]         /* r0 = gd->reloc_off */
+       ldr     r0, [r9, #GD_RELOC_OFF]         /* r0 = gd->reloc_off */
        add     lr, lr, r0
-       ldr     r0, [r8, #GD_RELOCADDR]         /* r0 = gd->relocaddr */
+#if defined(CONFIG_CPU_V7M)
+       orr     lr, #1                          /* As required by Thumb-only */
+#endif
+       ldr     r0, [r9, #GD_RELOCADDR]         /* r0 = gd->relocaddr */
        b       relocate_code
 here:
+/*
+ * now relocate vectors
+ */
+
+       bl      relocate_vectors
 
 /* Set up final (full) environment */
 
        bl      c_runtime_cpu_setup     /* we still call old routine here */
+#endif
+#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(FRAMEWORK)
 
-       ldr     r0, =__bss_start        /* this is auto-relocated! */
-       ldr     r1, =__bss_end          /* this is auto-relocated! */
+#if !defined(CONFIG_SPL_EARLY_BSS)
+       SPL_CLEAR_BSS
+#endif
 
-       mov     r2, #0x00000000         /* prepare zero to clear BSS */
-
-clbss_l:cmp    r0, r1                  /* while not at end of BSS */
-       strlo   r2, [r0]                /* clear 32-bit BSS word */
-       addlo   r0, r0, #4              /* move to next */
-       blo     clbss_l
+# 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
+       movne   r9, r0
+# endif
 
+#if ! defined(CONFIG_SPL_BUILD)
        bl coloured_LED_init
        bl red_led_on
-
+#endif
        /* call board_init_r(gd_t *id, ulong dest_addr) */
-       mov     r0, r8                  /* gd_t */
-       ldr     r1, [r8, #GD_RELOCADDR] /* dest_addr */
+       mov     r0, r9                  /* gd_t */
+       ldr     r1, [r9, #GD_RELOCADDR] /* dest_addr */
        /* call board_init_r */
+#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
+       ldr     lr, =board_init_r       /* this is auto-relocated! */
+       bx      lr
+#else
        ldr     pc, =board_init_r       /* this is auto-relocated! */
-
+#endif
        /* we should not return here. */
-
 #endif
 
 ENDPROC(_main)