Debian Codegraph @

plat/arm/board/fvp_r/fvp_r_bl1_main.c

raw
1 /*
2 * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <assert.h>
8
9 #include "../../../../bl1/bl1_private.h"
10 #include <arch.h>
11 #include <arch_features.h>
12 #include <arch_helpers.h>
13 #include <bl1/bl1.h>
14 #include <common/bl_common.h>
15 #include <common/build_message.h>
16 #include <common/debug.h>
17 #include <drivers/auth/auth_mod.h>
18 #include <drivers/console.h>
19 #include <lib/cpus/errata.h>
20 #include <lib/utils.h>
21 #include <smccc_helpers.h>
22 #include <tools_share/uuid.h>
23 #include <plat/arm/common/plat_arm.h>
24 #include <plat/common/platform.h>
25
26 #include <platform_def.h>
27
28
29 void cm_prepare_el2_exit(void);
30
31 void bl1_run_next_image(const struct entry_point_info *bl_ep_info);
32
33 /*******************************************************************************
34 * Function to perform late architectural and platform specific initialization.
35 * It also queries the platform to load and run next BL image. Only called
36 * by the primary cpu after a cold boot.
37 ******************************************************************************/
38 void bl1_transfer_bl33(void)
39 {
40 unsigned int image_id;
41
42 /* Get the image id of next image to load and run. */
43 image_id = bl1_plat_get_next_image_id();
44
45 #if !ARM_DISABLE_TRUSTED_WDOG
46 /* Disable watchdog before leaving BL1 */
47 plat_arm_secure_wdt_stop();
48 #endif
49
50 bl1_run_next_image(&bl1_plat_get_image_desc(image_id)->ep_info);
51 }
52
53 /*******************************************************************************
54 * This function locates and loads the BL33 raw binary image in the trusted SRAM.
55 * Called by the primary cpu after a cold boot.
56 * TODO: Add support for alternative image load mechanism e.g using virtio/elf
57 * loader etc.
58 ******************************************************************************/
59 void bl1_load_bl33(void)
60 {
61 image_desc_t *desc;
62 image_info_t *info;
63 int err;
64
65 /* Get the image descriptor */
66 desc = bl1_plat_get_image_desc(BL33_IMAGE_ID);
67 assert(desc != NULL);
68
69 /* Get the image info */
70 info = &desc->image_info;
71 INFO("BL1: Loading BL33\n");
72
73 err = bl1_plat_handle_pre_image_load(BL33_IMAGE_ID);
74 if (err != 0) {
75 ERROR("Failure in pre image load handling of BL33 (%d)\n", err);
76 plat_error_handler(err);
77 }
78
79 err = load_auth_image(BL33_IMAGE_ID, info);
80 if (err != 0) {
81 ERROR("Failed to load BL33 firmware.\n");
82 plat_error_handler(err);
83 }
84
85 /* Allow platform to handle image information. */
86 err = bl1_plat_handle_post_image_load(BL33_IMAGE_ID);
87 if (err != 0) {
88 ERROR("Failure in post image load handling of BL33 (%d)\n", err);
89 plat_error_handler(err);
90 }
91
92 NOTICE("BL1: Booting BL33\n");
93 }
94
95 /*******************************************************************************
96 * This function prepares for entry to BL33
97 ******************************************************************************/
98 void bl1_prepare_next_image(unsigned int image_id)
99 {
100 unsigned int mode = MODE_EL1;
101 image_desc_t *desc;
102 entry_point_info_t *next_bl_ep;
103
104 #if CTX_INCLUDE_AARCH32_REGS
105 /*
106 * Ensure that the build flag to save AArch32 system registers in CPU
107 * context is not set for AArch64-only platforms.
108 */
109 if (el_implemented(1) == EL_IMPL_A64ONLY) {
110 ERROR("EL1 supports AArch64-only. Please set build flag %s",
111 "CTX_INCLUDE_AARCH32_REGS = 0\n");
112 panic();
113 }
114 #endif
115
116 /* Get the image descriptor. */
117 desc = bl1_plat_get_image_desc(image_id);
118 assert(desc != NULL);
119
120 /* Get the entry point info. */
121 next_bl_ep = &desc->ep_info;
122
123 /* FVP-R is only secure */
124 assert(GET_SECURITY_STATE(next_bl_ep->h.attr) == SECURE);
125
126 /* Prepare the SPSR for the next BL image. */
127 next_bl_ep->spsr = (uint32_t)SPSR_64((uint64_t) mode,
128 (uint64_t)MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
129
130 /* Allow platform to make change */
131 bl1_plat_set_ep_info(image_id, next_bl_ep);
132
133 /* Prepare context for the next EL */
134 cm_prepare_el2_exit();
135
136 /* Indicate that image is in execution state. */
137 desc->state = IMAGE_STATE_EXECUTED;
138
139 print_entry_point_info(next_bl_ep);
140 }
141
142 /*******************************************************************************
143 * Setup function for BL1.
144 ******************************************************************************/
145 void bl1_setup(void)
146 {
147 /* Perform early platform-specific setup */
148 bl1_early_platform_setup();
149
150 /* Perform late platform-specific setup */
151 bl1_plat_arch_setup();
152 }
153
154 /*******************************************************************************
155 * Function to perform late architectural and platform specific initialization.
156 * It also queries the platform to load and run next BL image. Only called
157 * by the primary cpu after a cold boot.
158 ******************************************************************************/
159 void bl1_main(void)
160 {
161 unsigned int image_id;
162
163 /* Announce our arrival */
164 NOTICE(FIRMWARE_WELCOME_STR);
165 NOTICE("BL1: %s\n", build_version_string);
166 NOTICE("BL1: %s\n", build_message);
167
168 INFO("BL1: RAM %p - %p\n", (void *)BL1_RAM_BASE, (void *)BL1_RAM_LIMIT);
169
170 print_errata_status();
171
172 #if ENABLE_ASSERTIONS
173 u_register_t val;
174 /*
175 * Ensure that MMU/Caches and coherency are turned on
176 */
177 val = read_sctlr_el2();
178
179 assert((val & SCTLR_M_BIT) != 0U);
180 assert((val & SCTLR_C_BIT) != 0U);
181 assert((val & SCTLR_I_BIT) != 0U);
182 /*
183 * Check that Cache Writeback Granule (CWG) in CTR_EL0 matches the
184 * provided platform value
185 */
186 val = (read_ctr_el0() >> CTR_CWG_SHIFT) & CTR_CWG_MASK;
187 /*
188 * If CWG is zero, then no CWG information is available but we can
189 * at least check the platform value is less than the architectural
190 * maximum.
191 */
192 if (val != 0) {
193 assert(SIZE_FROM_LOG2_WORDS(val) == CACHE_WRITEBACK_GRANULE);
194 } else {
195 assert(MAX_CACHE_LINE_SIZE >= CACHE_WRITEBACK_GRANULE);
196 }
197 #endif /* ENABLE_ASSERTIONS */
198
199 /* Perform remaining generic architectural setup from ELmax */
200 bl1_arch_setup();
201
202 #if TRUSTED_BOARD_BOOT
203 /* Initialize authentication module */
204 auth_mod_init();
205 #endif /* TRUSTED_BOARD_BOOT */
206
207 /* Perform platform setup in BL1. */
208 bl1_platform_setup();
209
210 /* Get the image id of next image to load and run. */
211 image_id = bl1_plat_get_next_image_id();
212
213 /*
214 * We currently interpret any image id other than
215 * BL2_IMAGE_ID as the start of firmware update.
216 */
217 if (image_id == BL33_IMAGE_ID) {
218 bl1_load_bl33();
219 } else {
220 NOTICE("BL1-FWU: *******FWU Process Started*******\n");
221 }
222
223 bl1_prepare_next_image(image_id);
224
225 console_flush();
226
227 bl1_transfer_bl33();
228 }
229
230 /*******************************************************************************
231 * Function called just before handing over to the next BL to inform the user
232 * about the boot progress. In debug mode, also print details about the BL
233 * image's execution context.
234 ******************************************************************************/
235 void bl1_print_next_bl_ep_info(const entry_point_info_t *bl_ep_info)
236 {
237 NOTICE("BL1: Booting BL31\n");
238 print_entry_point_info(bl_ep_info);
239 }
240
241 #if SPIN_ON_BL1_EXIT
242 void print_debug_loop_message(void)
243 {
244 NOTICE("BL1: Debug loop, spinning forever\n");
245 NOTICE("BL1: Please connect the debugger to continue\n");
246 }
247 #endif