Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 2 | * Copyright (c) 2013-2023, 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> |
| 14 | #include <common/debug.h> |
| 15 | #include <drivers/auth/auth_mod.h> |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 16 | #include <drivers/auth/crypto_mod.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <drivers/console.h> |
Manish V Badarkhe | 99575e4 | 2021-06-25 23:28:59 +0100 | [diff] [blame] | 18 | #include <drivers/fwu/fwu.h> |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 19 | #include <lib/extensions/pauth.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | #include <plat/common/platform.h> |
| 21 | |
Dan Handley | bcd60ba | 2014-04-17 18:53:42 +0100 | [diff] [blame] | 22 | #include "bl2_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 23 | |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 24 | #ifdef __aarch64__ |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 25 | #define NEXT_IMAGE "BL31" |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 26 | #else |
| 27 | #define NEXT_IMAGE "BL32" |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 28 | #endif |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 29 | |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 30 | #if RESET_TO_BL2 |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 31 | /******************************************************************************* |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 32 | * Setup function for BL2 when RESET_TO_BL2=1 |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 33 | ******************************************************************************/ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 34 | void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, |
| 35 | u_register_t arg3) |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 36 | { |
| 37 | /* Perform early platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 38 | bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3); |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 39 | |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 40 | /* Perform late platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 41 | bl2_el3_plat_arch_setup(); |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 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 */ |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 50 | } |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 51 | #else /* RESET_TO_BL2 */ |
| 52 | |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 53 | /******************************************************************************* |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 54 | * Setup function for BL2 when RESET_TO_BL2=0 |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 55 | ******************************************************************************/ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 56 | void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, |
| 57 | u_register_t arg3) |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 58 | { |
| 59 | /* Perform early platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 60 | bl2_early_platform_setup2(arg0, arg1, arg2, arg3); |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 61 | |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 62 | /* Perform late platform-specific setup */ |
Zelalem Aweke | 688fbf7 | 2021-07-09 11:37:10 -0500 | [diff] [blame] | 63 | bl2_plat_arch_setup(); |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 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 */ |
Antonio Nino Diaz | 4f29fb7 | 2019-01-31 17:40:44 +0000 | [diff] [blame] | 72 | } |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 73 | #endif /* RESET_TO_BL2 */ |
Antonio Nino Diaz | 6e4b083 | 2019-01-31 10:48:47 +0000 | [diff] [blame] | 74 | |
| 75 | /******************************************************************************* |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 76 | * 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] | 77 | * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2 |
| 78 | * runs entirely in S-EL1. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 79 | ******************************************************************************/ |
| 80 | void bl2_main(void) |
| 81 | { |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 82 | entry_point_info_t *next_bl_ep_info; |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 83 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 84 | NOTICE("BL2: %s\n", version_string); |
| 85 | NOTICE("BL2: %s\n", build_message); |
| 86 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 87 | /* Perform remaining generic architectural setup in S-EL1 */ |
| 88 | bl2_arch_setup(); |
| 89 | |
Manish V Badarkhe | 99575e4 | 2021-06-25 23:28:59 +0100 | [diff] [blame] | 90 | #if PSA_FWU_SUPPORT |
| 91 | fwu_init(); |
| 92 | #endif /* PSA_FWU_SUPPORT */ |
| 93 | |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 94 | crypto_mod_init(); |
| 95 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 96 | /* Initialize authentication module */ |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 97 | auth_mod_init(); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 98 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 99 | /* Initialize the Measured Boot backend */ |
| 100 | bl2_plat_mboot_init(); |
| 101 | |
Alexei Fedorov | 71707b1 | 2020-07-13 14:06:47 +0100 | [diff] [blame] | 102 | /* Initialize boot source */ |
Roberto Vargas | bc1ae1f | 2017-09-26 12:53:01 +0100 | [diff] [blame] | 103 | bl2_plat_preload_setup(); |
| 104 | |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 105 | /* Load the subsequent bootloader images. */ |
| 106 | next_bl_ep_info = bl2_load_images(); |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 107 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 108 | /* Teardown the Measured Boot backend */ |
| 109 | bl2_plat_mboot_finish(); |
Alexei Fedorov | 71707b1 | 2020-07-13 14:06:47 +0100 | [diff] [blame] | 110 | |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 111 | #if !BL2_RUNS_AT_EL3 |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 112 | #ifndef __aarch64__ |
Yatharth Kochar | dafb247 | 2016-06-30 14:52:12 +0100 | [diff] [blame] | 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(); |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 119 | #endif /* !__aarch64__ */ |
Yatharth Kochar | dafb247 | 2016-06-30 14:52:12 +0100 | [diff] [blame] | 120 | |
Antonio Nino Diaz | e3962d0 | 2017-02-16 16:17:19 +0000 | [diff] [blame] | 121 | console_flush(); |
| 122 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 123 | #if ENABLE_PAUTH |
| 124 | /* |
| 125 | * Disable pointer authentication before running next boot image |
| 126 | */ |
| 127 | pauth_disable_el1(); |
| 128 | #endif /* ENABLE_PAUTH */ |
| 129 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 130 | /* |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 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. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | */ |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 135 | 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] | 136 | #else /* if BL2_RUNS_AT_EL3 */ |
| 137 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 138 | NOTICE("BL2: Booting " NEXT_IMAGE "\n"); |
| 139 | print_entry_point_info(next_bl_ep_info); |
| 140 | console_flush(); |
| 141 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 142 | #if ENABLE_PAUTH |
| 143 | /* |
| 144 | * Disable pointer authentication before running next boot image |
| 145 | */ |
| 146 | pauth_disable_el3(); |
| 147 | #endif /* ENABLE_PAUTH */ |
| 148 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 149 | bl2_run_next_image(next_bl_ep_info); |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 150 | #endif /* BL2_RUNS_AT_EL3 */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 151 | } |