1 /*
2 * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <assert.h>
8
9 #include <arch_helpers.h>
10 #include <arch_features.h>
11 #include <bl1/bl1.h>
12 #include <bl2/bl2.h>
13 #include <common/bl_common.h>
14 #include <common/debug.h>
15 #include <drivers/auth/auth_mod.h>
16 #include <drivers/auth/crypto_mod.h>
17 #include <drivers/console.h>
18 #include <drivers/fwu/fwu.h>
19 #include <lib/extensions/pauth.h>
20 #include <plat/common/platform.h>
21
22 #include "bl2_private.h"
23
24 #ifdef __aarch64__
25 #define NEXT_IMAGE "BL31"
26 #else
27 #define NEXT_IMAGE "BL32"
28 #endif
29
30 #if RESET_TO_BL2
31 /*******************************************************************************
32 * Setup function for BL2 when RESET_TO_BL2=1
33 ******************************************************************************/
bl2_el3_setup(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)34 void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
35 u_register_t arg3)
36 {
37 /* Perform early platform-specific setup */
38 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
39
40 /* Perform late platform-specific setup */
41 bl2_el3_plat_arch_setup();
42
43 #if CTX_INCLUDE_PAUTH_REGS
44 /*
45 * Assert that the ARMv8.3-PAuth registers are present or an access
46 * fault will be triggered when they are being saved or restored.
47 */
48 assert(is_armv8_3_pauth_present());
49 #endif /* CTX_INCLUDE_PAUTH_REGS */
50 }
51 #else /* RESET_TO_BL2 */
52
53 /*******************************************************************************
54 * Setup function for BL2 when RESET_TO_BL2=0
55 ******************************************************************************/
bl2_setup(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)56 void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
57 u_register_t arg3)
58 {
59 /* Perform early platform-specific setup */
60 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
61
62 /* Perform late platform-specific setup */
63 bl2_plat_arch_setup();
64
65 #if CTX_INCLUDE_PAUTH_REGS
66 /*
67 * Assert that the ARMv8.3-PAuth registers are present or an access
68 * fault will be triggered when they are being saved or restored.
69 */
70 assert(is_armv8_3_pauth_present());
71 #endif /* CTX_INCLUDE_PAUTH_REGS */
72 }
73 #endif /* RESET_TO_BL2 */
74
75 /*******************************************************************************
76 * The only thing to do in BL2 is to load further images and pass control to
77 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
78 * runs entirely in S-EL1.
79 ******************************************************************************/
bl2_main(void)80 void bl2_main(void)
81 {
82 entry_point_info_t *next_bl_ep_info;
83
84 NOTICE("BL2: %s\n", version_string);
85 NOTICE("BL2: %s\n", build_message);
86
87 /* Perform remaining generic architectural setup in S-EL1 */
88 bl2_arch_setup();
89
90 #if PSA_FWU_SUPPORT
91 fwu_init();
92 #endif /* PSA_FWU_SUPPORT */
93
94 crypto_mod_init();
95
96 /* Initialize authentication module */
97 auth_mod_init();
98
99 /* Initialize the Measured Boot backend */
100 bl2_plat_mboot_init();
101
102 /* Initialize boot source */
103 bl2_plat_preload_setup();
104
105 /* Load the subsequent bootloader images. */
106 next_bl_ep_info = bl2_load_images();
107
108 /* Teardown the Measured Boot backend */
109 bl2_plat_mboot_finish();
110
111 #if !BL2_RUNS_AT_EL3
112 #ifndef __aarch64__
113 /*
114 * For AArch32 state BL1 and BL2 share the MMU setup.
115 * Given that BL2 does not map BL1 regions, MMU needs
116 * to be disabled in order to go back to BL1.
117 */
118 disable_mmu_icache_secure();
119 #endif /* !__aarch64__ */
120
121 console_flush();
122
123 #if ENABLE_PAUTH
124 /*
125 * Disable pointer authentication before running next boot image
126 */
127 pauth_disable_el1();
128 #endif /* ENABLE_PAUTH */
129
130 /*
131 * Run next BL image via an SMC to BL1. Information on how to pass
132 * control to the BL32 (if present) and BL33 software images will
133 * be passed to next BL image as an argument.
134 */
135 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
136 #else /* if BL2_RUNS_AT_EL3 */
137
138 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
139 print_entry_point_info(next_bl_ep_info);
140 console_flush();
141
142 #if ENABLE_PAUTH
143 /*
144 * Disable pointer authentication before running next boot image
145 */
146 pauth_disable_el3();
147 #endif /* ENABLE_PAUTH */
148
149 bl2_run_next_image(next_bl_ep_info);
150 #endif /* BL2_RUNS_AT_EL3 */
151 }
152