14f6ad66aSAchin Gupta /* 2*3f498b0dSAlexei Fedorov * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54f6ad66aSAchin Gupta */ 64f6ad66aSAchin Gupta 7ed108b56SAlexei Fedorov #include <assert.h> 8ed108b56SAlexei Fedorov 94f6ad66aSAchin Gupta #include <arch_helpers.h> 10ed108b56SAlexei Fedorov #include <arch_features.h> 1109d40e0eSAntonio Nino Diaz #include <bl1/bl1.h> 1209d40e0eSAntonio Nino Diaz #include <bl2/bl2.h> 1309d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1409d40e0eSAntonio Nino Diaz #include <common/debug.h> 1509d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_mod.h> 1609d40e0eSAntonio Nino Diaz #include <drivers/console.h> 17*3f498b0dSAlexei Fedorov #if MEASURED_BOOT 18*3f498b0dSAlexei Fedorov #include <drivers/measured_boot/measured_boot.h> 19*3f498b0dSAlexei Fedorov #endif 20ed108b56SAlexei Fedorov #include <lib/extensions/pauth.h> 2109d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 2209d40e0eSAntonio Nino Diaz 235b827a8fSDan Handley #include "bl2_private.h" 244f6ad66aSAchin Gupta 25402b3cf8SJulius Werner #ifdef __aarch64__ 26b1d27b48SRoberto Vargas #define NEXT_IMAGE "BL31" 27402b3cf8SJulius Werner #else 28402b3cf8SJulius Werner #define NEXT_IMAGE "BL32" 29b1d27b48SRoberto Vargas #endif 3093d81d64SSandrine Bailleux 31dcbfa11bSAntonio Nino Diaz #if !BL2_AT_EL3 3293d81d64SSandrine Bailleux /******************************************************************************* 339d93fc2fSAntonio Nino Diaz * Setup function for BL2. 349d93fc2fSAntonio Nino Diaz ******************************************************************************/ 359d93fc2fSAntonio Nino Diaz void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, 369d93fc2fSAntonio Nino Diaz u_register_t arg3) 379d93fc2fSAntonio Nino Diaz { 389d93fc2fSAntonio Nino Diaz /* Perform early platform-specific setup */ 399d93fc2fSAntonio Nino Diaz bl2_early_platform_setup2(arg0, arg1, arg2, arg3); 409d93fc2fSAntonio Nino Diaz 419d93fc2fSAntonio Nino Diaz /* Perform late platform-specific setup */ 429d93fc2fSAntonio Nino Diaz bl2_plat_arch_setup(); 43ed108b56SAlexei Fedorov 44ed108b56SAlexei Fedorov #if CTX_INCLUDE_PAUTH_REGS 45ed108b56SAlexei Fedorov /* 46ed108b56SAlexei Fedorov * Assert that the ARMv8.3-PAuth registers are present or an access 47ed108b56SAlexei Fedorov * fault will be triggered when they are being saved or restored. 48ed108b56SAlexei Fedorov */ 49ed108b56SAlexei Fedorov assert(is_armv8_3_pauth_present()); 50ed108b56SAlexei Fedorov #endif /* CTX_INCLUDE_PAUTH_REGS */ 519d93fc2fSAntonio Nino Diaz } 529d93fc2fSAntonio Nino Diaz 53dcbfa11bSAntonio Nino Diaz #else /* if BL2_AT_EL3 */ 54dcbfa11bSAntonio Nino Diaz /******************************************************************************* 55dcbfa11bSAntonio Nino Diaz * Setup function for BL2 when BL2_AT_EL3=1. 56dcbfa11bSAntonio Nino Diaz ******************************************************************************/ 57dcbfa11bSAntonio Nino Diaz void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, 58dcbfa11bSAntonio Nino Diaz u_register_t arg3) 59dcbfa11bSAntonio Nino Diaz { 60dcbfa11bSAntonio Nino Diaz /* Perform early platform-specific setup */ 61dcbfa11bSAntonio Nino Diaz bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3); 62dcbfa11bSAntonio Nino Diaz 63dcbfa11bSAntonio Nino Diaz /* Perform late platform-specific setup */ 64dcbfa11bSAntonio Nino Diaz bl2_el3_plat_arch_setup(); 65ed108b56SAlexei Fedorov 66ed108b56SAlexei Fedorov #if CTX_INCLUDE_PAUTH_REGS 67ed108b56SAlexei Fedorov /* 68ed108b56SAlexei Fedorov * Assert that the ARMv8.3-PAuth registers are present or an access 69ed108b56SAlexei Fedorov * fault will be triggered when they are being saved or restored. 70ed108b56SAlexei Fedorov */ 71ed108b56SAlexei Fedorov assert(is_armv8_3_pauth_present()); 72ed108b56SAlexei Fedorov #endif /* CTX_INCLUDE_PAUTH_REGS */ 73dcbfa11bSAntonio Nino Diaz } 74dcbfa11bSAntonio Nino Diaz #endif /* BL2_AT_EL3 */ 75dcbfa11bSAntonio Nino Diaz 769d93fc2fSAntonio Nino Diaz /******************************************************************************* 7793d81d64SSandrine Bailleux * The only thing to do in BL2 is to load further images and pass control to 7842019bf4SYatharth Kochar * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2 7942019bf4SYatharth Kochar * runs entirely in S-EL1. 8093d81d64SSandrine Bailleux ******************************************************************************/ 8193d81d64SSandrine Bailleux void bl2_main(void) 8293d81d64SSandrine Bailleux { 8342019bf4SYatharth Kochar entry_point_info_t *next_bl_ep_info; 8493d81d64SSandrine Bailleux 856ad2e461SDan Handley NOTICE("BL2: %s\n", version_string); 866ad2e461SDan Handley NOTICE("BL2: %s\n", build_message); 876ad2e461SDan Handley 8893d81d64SSandrine Bailleux /* Perform remaining generic architectural setup in S-EL1 */ 8993d81d64SSandrine Bailleux bl2_arch_setup(); 9093d81d64SSandrine Bailleux 91dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 92dec840afSJuan Castillo /* Initialize authentication module */ 931779ba6bSJuan Castillo auth_mod_init(); 94*3f498b0dSAlexei Fedorov 95*3f498b0dSAlexei Fedorov #if MEASURED_BOOT 96*3f498b0dSAlexei Fedorov /* Initialize measured boot module */ 97*3f498b0dSAlexei Fedorov measured_boot_init(); 98*3f498b0dSAlexei Fedorov 99*3f498b0dSAlexei Fedorov #endif /* MEASURED_BOOT */ 100dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 101dec840afSJuan Castillo 102*3f498b0dSAlexei Fedorov /* Initialize boot source */ 10301f62b6dSRoberto Vargas bl2_plat_preload_setup(); 10401f62b6dSRoberto Vargas 10542019bf4SYatharth Kochar /* Load the subsequent bootloader images. */ 10642019bf4SYatharth Kochar next_bl_ep_info = bl2_load_images(); 107ef538c6fSJuan Castillo 108*3f498b0dSAlexei Fedorov #if MEASURED_BOOT 109*3f498b0dSAlexei Fedorov /* Finalize measured boot */ 110*3f498b0dSAlexei Fedorov measured_boot_finish(); 111*3f498b0dSAlexei Fedorov #endif /* MEASURED_BOOT */ 112*3f498b0dSAlexei Fedorov 11301a1f7c2SYann Gautier #if !BL2_AT_EL3 114402b3cf8SJulius Werner #ifndef __aarch64__ 115d48c12e9SYatharth Kochar /* 116d48c12e9SYatharth Kochar * For AArch32 state BL1 and BL2 share the MMU setup. 117d48c12e9SYatharth Kochar * Given that BL2 does not map BL1 regions, MMU needs 118d48c12e9SYatharth Kochar * to be disabled in order to go back to BL1. 119d48c12e9SYatharth Kochar */ 120d48c12e9SYatharth Kochar disable_mmu_icache_secure(); 121402b3cf8SJulius Werner #endif /* !__aarch64__ */ 122d48c12e9SYatharth Kochar 1230b32628eSAntonio Nino Diaz console_flush(); 1240b32628eSAntonio Nino Diaz 125ed108b56SAlexei Fedorov #if ENABLE_PAUTH 126ed108b56SAlexei Fedorov /* 127ed108b56SAlexei Fedorov * Disable pointer authentication before running next boot image 128ed108b56SAlexei Fedorov */ 129ed108b56SAlexei Fedorov pauth_disable_el1(); 130ed108b56SAlexei Fedorov #endif /* ENABLE_PAUTH */ 131ed108b56SAlexei Fedorov 13293d81d64SSandrine Bailleux /* 13342019bf4SYatharth Kochar * Run next BL image via an SMC to BL1. Information on how to pass 13442019bf4SYatharth Kochar * control to the BL32 (if present) and BL33 software images will 13542019bf4SYatharth Kochar * be passed to next BL image as an argument. 13693d81d64SSandrine Bailleux */ 13742019bf4SYatharth Kochar smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0); 138dcbfa11bSAntonio Nino Diaz #else /* if BL2_AT_EL3 */ 139b1d27b48SRoberto Vargas NOTICE("BL2: Booting " NEXT_IMAGE "\n"); 140b1d27b48SRoberto Vargas print_entry_point_info(next_bl_ep_info); 141b1d27b48SRoberto Vargas console_flush(); 142b1d27b48SRoberto Vargas 143ed108b56SAlexei Fedorov #if ENABLE_PAUTH 144ed108b56SAlexei Fedorov /* 145ed108b56SAlexei Fedorov * Disable pointer authentication before running next boot image 146ed108b56SAlexei Fedorov */ 147ed108b56SAlexei Fedorov pauth_disable_el3(); 148ed108b56SAlexei Fedorov #endif /* ENABLE_PAUTH */ 149ed108b56SAlexei Fedorov 150b1d27b48SRoberto Vargas bl2_run_next_image(next_bl_ep_info); 151dcbfa11bSAntonio Nino Diaz #endif /* BL2_AT_EL3 */ 1524f6ad66aSAchin Gupta } 153