1 /* 2 * Copyright (c) 2013-2025, 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/build_message.h> 15 #include <common/debug.h> 16 #include <drivers/auth/auth_mod.h> 17 #include <drivers/auth/crypto_mod.h> 18 #include <drivers/console.h> 19 #include <drivers/fwu/fwu.h> 20 #include <lib/bootmarker_capture.h> 21 #include <lib/extensions/pauth.h> 22 #include <lib/pmf/pmf.h> 23 #include <plat/common/platform.h> 24 25 #include "bl2_private.h" 26 27 #ifdef __aarch64__ 28 #define NEXT_IMAGE "BL31" 29 #else 30 #define NEXT_IMAGE "BL32" 31 #endif 32 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 38 /******************************************************************************* 39 * The only thing to do in BL2 is to load further images and pass control to 40 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. 41 ******************************************************************************/ 42 void __no_pauth bl2_main(u_register_t arg0, u_register_t arg1, u_register_t arg2, 43 u_register_t arg3) 44 { 45 entry_point_info_t *next_bl_ep_info; 46 47 /* Enable early console if EARLY_CONSOLE flag is enabled */ 48 plat_setup_early_console(); 49 #if RESET_TO_BL2 50 51 /* Perform early platform-specific setup */ 52 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3); 53 54 /* Perform late platform-specific setup */ 55 bl2_el3_plat_arch_setup(); 56 #else /* RESET_TO_BL2 */ 57 /* Perform early platform-specific setup */ 58 bl2_early_platform_setup2(arg0, arg1, arg2, arg3); 59 60 /* Perform late platform-specific setup */ 61 bl2_plat_arch_setup(); 62 #endif /* RESET_TO_BL2 */ 63 64 if (is_feat_pauth_supported()) { 65 #if BL2_RUNS_AT_EL3 66 pauth_init_enable_el3(); 67 #else 68 pauth_init_enable_el1(); 69 #endif 70 } 71 72 #if ENABLE_RUNTIME_INSTRUMENTATION 73 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT); 74 #endif 75 76 NOTICE("BL2: %s\n", build_version_string); 77 NOTICE("BL2: %s\n", build_message); 78 79 /* Perform remaining generic architectural setup in S-EL1 */ 80 bl2_arch_setup(); 81 82 #if PSA_FWU_SUPPORT 83 fwu_init(); 84 #endif /* PSA_FWU_SUPPORT */ 85 86 crypto_mod_init(); 87 88 /* Initialize authentication module */ 89 auth_mod_init(); 90 91 /* Initialize the Measured Boot backend */ 92 bl2_plat_mboot_init(); 93 94 /* Initialize boot source */ 95 bl2_plat_preload_setup(); 96 97 /* Load the subsequent bootloader images. */ 98 next_bl_ep_info = bl2_load_images(); 99 100 /* Teardown the Measured Boot backend */ 101 bl2_plat_mboot_finish(); 102 103 crypto_mod_finish(); 104 105 #if !BL2_RUNS_AT_EL3 106 #ifndef __aarch64__ 107 /* 108 * For AArch32 state BL1 and BL2 share the MMU setup. 109 * Given that BL2 does not map BL1 regions, MMU needs 110 * to be disabled in order to go back to BL1. 111 */ 112 disable_mmu_icache_secure(); 113 #endif /* !__aarch64__ */ 114 115 /* 116 * Disable pointer authentication before running next boot image 117 */ 118 if (is_feat_pauth_supported()) { 119 pauth_disable_el1(); 120 } 121 122 #if ENABLE_RUNTIME_INSTRUMENTATION 123 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT); 124 #endif 125 126 console_flush(); 127 128 /* 129 * Run next BL image via an SMC to BL1. Information on how to pass 130 * control to the BL32 (if present) and BL33 software images will 131 * be passed to next BL image as an argument. 132 */ 133 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0); 134 #else /* if BL2_RUNS_AT_EL3 */ 135 136 NOTICE("BL2: Booting " NEXT_IMAGE "\n"); 137 print_entry_point_info(next_bl_ep_info); 138 #if ENABLE_RUNTIME_INSTRUMENTATION 139 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT); 140 #endif 141 console_flush(); 142 143 /* 144 * Disable pointer authentication before running next boot image 145 */ 146 if (is_feat_pauth_supported()) { 147 pauth_disable_el3(); 148 } 149 150 bl2_run_next_image(next_bl_ep_info); 151 #endif /* BL2_RUNS_AT_EL3 */ 152 } 153