Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Chris Kay | 99b5b2e | 2024-03-08 16:08:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 9 | #include <arch_helpers.h> |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 10 | #include <arch_features.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <bl1/bl1.h> |
| 12 | #include <bl2/bl2.h> |
| 13 | #include <common/bl_common.h> |
Chris Kay | 99b5b2e | 2024-03-08 16:08:31 +0000 | [diff] [blame] | 14 | #include <common/build_message.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <common/debug.h> |
| 16 | #include <drivers/auth/auth_mod.h> |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 17 | #include <drivers/auth/crypto_mod.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 18 | #include <drivers/console.h> |
Manish V Badarkhe | 99575e4 | 2021-06-25 23:28:59 +0100 | [diff] [blame] | 19 | #include <drivers/fwu/fwu.h> |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 20 | #include <lib/bootmarker_capture.h> |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 21 | #include <lib/extensions/pauth.h> |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 22 | #include <lib/pmf/pmf.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <plat/common/platform.h> |
| 24 | |
Dan Handley | bcd60ba | 2014-04-17 18:53:42 +0100 | [diff] [blame] | 25 | #include "bl2_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 26 | |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 27 | #ifdef __aarch64__ |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 28 | #define NEXT_IMAGE "BL31" |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 29 | #else |
| 30 | #define NEXT_IMAGE "BL32" |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 31 | #endif |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 32 | |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 33 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 34 | PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID, |
| 35 | BL_TOTAL_IDS, PMF_DUMP_ENABLE); |
| 36 | #endif |
| 37 | |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 38 | #if RESET_TO_BL2 |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 39 | /******************************************************************************* |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 40 | * Setup function for BL2 when RESET_TO_BL2=1 |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 41 | ******************************************************************************/ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 42 | void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, |
| 43 | u_register_t arg3) |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 44 | { |
Yann Gautier | 5ae29c0 | 2024-01-16 19:39:31 +0100 | [diff] [blame] | 45 | /* Enable early console if EARLY_CONSOLE flag is enabled */ |
| 46 | plat_setup_early_console(); |
| 47 | |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 48 | /* Perform early platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 49 | bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3); |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 50 | |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 51 | /* Perform late platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 52 | bl2_el3_plat_arch_setup(); |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 53 | |
| 54 | #if CTX_INCLUDE_PAUTH_REGS |
| 55 | /* |
| 56 | * Assert that the ARMv8.3-PAuth registers are present or an access |
| 57 | * fault will be triggered when they are being saved or restored. |
| 58 | */ |
| 59 | assert(is_armv8_3_pauth_present()); |
| 60 | #endif /* CTX_INCLUDE_PAUTH_REGS */ |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 61 | } |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 62 | #else /* RESET_TO_BL2 */ |
| 63 | |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 64 | /******************************************************************************* |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 65 | * Setup function for BL2 when RESET_TO_BL2=0 |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 66 | ******************************************************************************/ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 67 | void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, |
| 68 | u_register_t arg3) |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 69 | { |
Yann Gautier | 5ae29c0 | 2024-01-16 19:39:31 +0100 | [diff] [blame] | 70 | /* Enable early console if EARLY_CONSOLE flag is enabled */ |
| 71 | plat_setup_early_console(); |
| 72 | |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 73 | /* Perform early platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 74 | bl2_early_platform_setup2(arg0, arg1, arg2, arg3); |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 75 | |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 76 | /* Perform late platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 77 | bl2_plat_arch_setup(); |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 78 | |
| 79 | #if CTX_INCLUDE_PAUTH_REGS |
| 80 | /* |
| 81 | * Assert that the ARMv8.3-PAuth registers are present or an access |
| 82 | * fault will be triggered when they are being saved or restored. |
| 83 | */ |
| 84 | assert(is_armv8_3_pauth_present()); |
| 85 | #endif /* CTX_INCLUDE_PAUTH_REGS */ |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 86 | } |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 87 | #endif /* RESET_TO_BL2 */ |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 88 | |
| 89 | /******************************************************************************* |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 90 | * The only thing to do in BL2 is to load further images and pass control to |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 91 | * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2 |
| 92 | * runs entirely in S-EL1. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 93 | ******************************************************************************/ |
| 94 | void bl2_main(void) |
| 95 | { |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 96 | entry_point_info_t *next_bl_ep_info; |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 97 | |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 98 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 99 | PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT); |
| 100 | #endif |
| 101 | |
Chris Kay | 99b5b2e | 2024-03-08 16:08:31 +0000 | [diff] [blame] | 102 | NOTICE("BL2: %s\n", build_version_string); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 103 | NOTICE("BL2: %s\n", build_message); |
| 104 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 105 | /* Perform remaining generic architectural setup in S-EL1 */ |
| 106 | bl2_arch_setup(); |
| 107 | |
Manish V Badarkhe | 99575e4 | 2021-06-25 23:28:59 +0100 | [diff] [blame] | 108 | #if PSA_FWU_SUPPORT |
| 109 | fwu_init(); |
| 110 | #endif /* PSA_FWU_SUPPORT */ |
| 111 | |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 112 | crypto_mod_init(); |
| 113 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 114 | /* Initialize authentication module */ |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 115 | auth_mod_init(); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 116 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 117 | /* Initialize the Measured Boot backend */ |
| 118 | bl2_plat_mboot_init(); |
| 119 | |
Alexei Fedorov | 71707b1 | 2020-07-13 14:06:47 +0100 | [diff] [blame] | 120 | /* Initialize boot source */ |
Roberto Vargas | bc1ae1f | 2017-09-26 12:53:01 +0100 | [diff] [blame] | 121 | bl2_plat_preload_setup(); |
| 122 | |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 123 | /* Load the subsequent bootloader images. */ |
| 124 | next_bl_ep_info = bl2_load_images(); |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 125 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 126 | /* Teardown the Measured Boot backend */ |
| 127 | bl2_plat_mboot_finish(); |
Alexei Fedorov | 71707b1 | 2020-07-13 14:06:47 +0100 | [diff] [blame] | 128 | |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 129 | #if !BL2_RUNS_AT_EL3 |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 130 | #ifndef __aarch64__ |
Yatharth Kochar | dafb247 | 2016-06-30 14:52:12 +0100 | [diff] [blame] | 131 | /* |
| 132 | * For AArch32 state BL1 and BL2 share the MMU setup. |
| 133 | * Given that BL2 does not map BL1 regions, MMU needs |
| 134 | * to be disabled in order to go back to BL1. |
| 135 | */ |
| 136 | disable_mmu_icache_secure(); |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 137 | #endif /* !__aarch64__ */ |
Yatharth Kochar | dafb247 | 2016-06-30 14:52:12 +0100 | [diff] [blame] | 138 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 139 | #if ENABLE_PAUTH |
| 140 | /* |
| 141 | * Disable pointer authentication before running next boot image |
| 142 | */ |
| 143 | pauth_disable_el1(); |
| 144 | #endif /* ENABLE_PAUTH */ |
| 145 | |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 146 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 147 | PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT); |
| 148 | #endif |
| 149 | |
| 150 | console_flush(); |
| 151 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 152 | /* |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 153 | * Run next BL image via an SMC to BL1. Information on how to pass |
| 154 | * control to the BL32 (if present) and BL33 software images will |
| 155 | * be passed to next BL image as an argument. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 156 | */ |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 157 | smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0); |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 158 | #else /* if BL2_RUNS_AT_EL3 */ |
| 159 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 160 | NOTICE("BL2: Booting " NEXT_IMAGE "\n"); |
| 161 | print_entry_point_info(next_bl_ep_info); |
thagon01-arm | 6805e8d | 2023-07-12 10:43:58 -0500 | [diff] [blame] | 162 | #if ENABLE_RUNTIME_INSTRUMENTATION |
| 163 | PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT); |
| 164 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 165 | console_flush(); |
| 166 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 167 | #if ENABLE_PAUTH |
| 168 | /* |
| 169 | * Disable pointer authentication before running next boot image |
| 170 | */ |
| 171 | pauth_disable_el3(); |
| 172 | #endif /* ENABLE_PAUTH */ |
| 173 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 174 | bl2_run_next_image(next_bl_ep_info); |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 175 | #endif /* BL2_RUNS_AT_EL3 */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 176 | } |