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