blob: da7509da3be1fad30dc9264a31959e72008c801b [file] [log] [blame]
David Hendricks8583ac32012-12-27 15:23:57 -08001/*
2 * Early initialization code for ARMv7 architecture.
3 *
4 * This file is based off of the OMAP3530/ARM Cortex start.S file from Das
5 * U-Boot, which itself got the file from armboot.
6 *
7 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
10 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
11 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
13 * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
14 * Copyright (c) 2013 The Chromium OS Authors
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
Ronald G. Minnich6a015632013-01-11 15:07:50 -080018 * published by the Free Software Foundation; version 2 of
19 * the License.
David Hendricks8583ac32012-12-27 15:23:57 -080020 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Paul Menzela8ae1c62013-02-20 13:21:20 +010023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
David Hendricks8583ac32012-12-27 15:23:57 -080024 * GNU General Public License for more details.
David Hendricks8583ac32012-12-27 15:23:57 -080025 */
26
Julius Werner64b9ca92013-12-12 20:24:48 -080027#include <arch/asm.h>
28
Julius Werner25a282d2014-01-13 13:24:30 -080029.arm
Vadim Bendeburybe7124e2015-03-02 11:33:13 -080030 /*
31 * Just in case the maskrom or the vendor basic firmware passes on a
32 * parameter when calling the bootblock, store it here for handling by C
33 * code.
34 */
35 .section .bss, "aw" @nobits
36 .global maskrom_param
37maskrom_param:
38 .word 0
39
Julius Werner64b9ca92013-12-12 20:24:48 -080040ENTRY(_start)
David Hendricks8583ac32012-12-27 15:23:57 -080041 /*
Elyes HAOUAS777ea892016-07-29 07:40:41 +020042 * Set the CPU to System mode with IRQ and FIQ disabled. Prefetch/Data
Julius Werner985ff362013-09-18 14:39:50 -070043 * aborts may happen early and crash before the abort handlers are
44 * installed, but at least the problem will show up near the code that
45 * causes it.
David Hendricks8583ac32012-12-27 15:23:57 -080046 */
Julius Werner985ff362013-09-18 14:39:50 -070047 msr cpsr_cxf, #0xdf
Julius Werner25a282d2014-01-13 13:24:30 -080048 bl _thumb_start
49ENDPROC(_start)
David Hendricks8583ac32012-12-27 15:23:57 -080050
Julius Werner25a282d2014-01-13 13:24:30 -080051.thumb
52ENTRY(_thumb_start)
Vadim Bendeburybe7124e2015-03-02 11:33:13 -080053
54 /* Preserve the maskrom passed value, if any */
55 mov r10, r0
56
Julius Wernerfd9defc2014-01-21 20:11:22 -080057 bl arm_init_caches
58
David Hendricks8583ac32012-12-27 15:23:57 -080059 /*
60 * From Cortex-A Series Programmer's Guide:
61 * Only CPU 0 performs initialization. Other CPUs go into WFI
62 * to do this, first work out which CPU this is
63 * this code typically is run before any other initialization step
64 */
65 mrc p15, 0, r1, c0, c0, 5 @ Read Multiprocessor Affinity Register
66 and r1, r1, #0x3 @ Extract CPU ID bits
67 cmp r1, #0
68 bne wait_for_interrupt @ If this is not core0, wait
69
David Hendricksb313e902013-02-15 17:50:20 -080070 /*
71 * Initialize the stack to a known value. This is used to check for
72 * stack overflow later in the boot process.
73 */
Julius Wernerec5e5e02014-08-20 15:29:56 -070074 ldr r0, =_stack
75 ldr r1, =_estack
David Hendricksb313e902013-02-15 17:50:20 -080076 ldr r2, =0xdeadbeef
77init_stack_loop:
78 str r2, [r0]
79 add r0, #4
80 cmp r0, r1
81 bne init_stack_loop
82
Ronald G. Minnich6a015632013-01-11 15:07:50 -080083call_bootblock:
Vadim Bendeburybe7124e2015-03-02 11:33:13 -080084
85 /* Restore parameter passed in by maskrom/vendor firmware. */
86 ldr r0, =maskrom_param
87 str r10, [r0]
88
89 /* Set stackpointer in internal RAM to call bootblock main() */
90 ldr sp, =_estack
David Hendricks8583ac32012-12-27 15:23:57 -080091 ldr r0,=0x00000000
Ronald G. Minnichd6b16f52013-08-16 15:57:56 -070092 /*
Julius Werner25a282d2014-01-13 13:24:30 -080093 * The current design of cpu_info places the struct at the top of the
Martin Roth2ed0aa22016-01-05 20:58:58 -070094 * stack. Free enough space to accommodate for that, but make sure it's
Julius Werner25a282d2014-01-13 13:24:30 -080095 * 8-byte aligned for ABI compliance.
Ronald G. Minnichd6b16f52013-08-16 15:57:56 -070096 */
Julius Werner25a282d2014-01-13 13:24:30 -080097 sub sp, sp, #16
Ronald G. Minnich6a015632013-01-11 15:07:50 -080098 bl main
David Hendricks8583ac32012-12-27 15:23:57 -080099
100wait_for_interrupt:
101 wfi
102 mov pc, lr @ back to my caller
Julius Werner25a282d2014-01-13 13:24:30 -0800103ENDPROC(_thumb_start)