blob: 5dfb56445a5599c41a4b5a020e5a2fa7d9ff58ec [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleyab2d31e2013-12-02 19:25:12 +00002 * Copyright (c) 2013, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <stdio.h>
32#include <string.h>
33#include <assert.h>
34#include <arch_helpers.h>
35#include <platform.h>
36#include <semihosting.h>
37#include <bl1.h>
38
39void bl1_arch_next_el_setup(void);
40
41/*******************************************************************************
42 * Function to perform late architectural and platform specific initialization.
43 * It also locates and loads the BL2 raw binary image in the trusted DRAM. Only
44 * called by the primary cpu after a cold boot.
45 * TODO: Add support for alternative image load mechanism e.g using virtio/elf
46 * loader etc.
47 ******************************************************************************/
48void bl1_main(void)
49{
50 unsigned long sctlr_el3 = read_sctlr();
51 unsigned long bl2_base;
52 unsigned int load_type = TOP_LOAD, spsr;
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000053 meminfo *bl1_tzram_layout;
54 meminfo *bl2_tzram_layout = 0x0;
Achin Gupta4f6ad662013-10-25 09:08:21 +010055
56 /*
57 * Ensure that MMU/Caches and coherency are turned on
58 */
59 assert(sctlr_el3 | SCTLR_M_BIT);
60 assert(sctlr_el3 | SCTLR_C_BIT);
61 assert(sctlr_el3 | SCTLR_I_BIT);
62
63 /* Perform remaining generic architectural setup from EL3 */
64 bl1_arch_setup();
65
66 /* Perform platform setup in BL1. */
67 bl1_platform_setup();
68
69 /* Announce our arrival */
70 printf(FIRMWARE_WELCOME_STR);
71 printf("Built : %s, %s\n\r", __TIME__, __DATE__);
72
73 /*
74 * Find out how much free trusted ram remains after BL1 load
75 * & load the BL2 image at its top
76 */
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000077 bl1_tzram_layout = bl1_plat_sec_mem_layout();
78 bl2_base = load_image(bl1_tzram_layout,
Achin Gupta4f6ad662013-10-25 09:08:21 +010079 (const char *) BL2_IMAGE_NAME,
80 load_type, BL2_BASE);
81
82 /*
83 * Create a new layout of memory for BL2 as seen by BL1 i.e.
84 * tell it the amount of total and free memory available.
85 * This layout is created at the first free address visible
86 * to BL2. BL2 will read the memory layout before using its
87 * memory for other purposes.
88 */
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000089 bl2_tzram_layout = (meminfo *) bl1_tzram_layout->free_base;
90 init_bl2_mem_layout(bl1_tzram_layout,
Achin Gupta4f6ad662013-10-25 09:08:21 +010091 bl2_tzram_layout,
92 load_type,
93 bl2_base);
94
95 if (bl2_base) {
96 bl1_arch_next_el_setup();
97 spsr = make_spsr(MODE_EL1, MODE_SP_ELX, MODE_RW_64);
98 printf("Booting trusted firmware boot loader stage 2\n\r");
99#if DEBUG
100 printf("BL2 address = 0x%llx \n\r", (unsigned long long) bl2_base);
101 printf("BL2 cpsr = 0x%x \n\r", spsr);
102 printf("BL2 memory layout address = 0x%llx \n\r",
103 (unsigned long long) bl2_tzram_layout);
104#endif
105 run_image(bl2_base, spsr, SECURE, bl2_tzram_layout, 0);
106 }
107
108 /*
109 * TODO: print failure to load BL2 but also add a tzwdog timer
110 * which will reset the system eventually.
111 */
112 printf("Failed to load boot loader stage 2 (BL2) firmware.\n\r");
113 return;
114}
115
116/*******************************************************************************
117 * Temporary function to print the fact that BL2 has done its job and BL31 is
118 * about to be loaded. This is needed as long as printfs cannot be used
119 ******************************************************************************/
120void display_boot_progress(unsigned long entrypoint,
121 unsigned long spsr,
122 unsigned long mem_layout,
123 unsigned long ns_image_info)
124{
125 printf("Booting trusted firmware boot loader stage 3\n\r");
126#if DEBUG
127 printf("BL31 address = 0x%llx \n\r", (unsigned long long) entrypoint);
128 printf("BL31 cpsr = 0x%llx \n\r", (unsigned long long)spsr);
129 printf("BL31 memory layout address = 0x%llx \n\r", (unsigned long long)mem_layout);
130 printf("BL31 non-trusted image info address = 0x%llx\n\r", (unsigned long long)ns_image_info);
131#endif
132 return;
133}