14f6ad66aSAchin Gupta /* 2*9d93fc2fSAntonio Nino Diaz * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54f6ad66aSAchin Gupta */ 64f6ad66aSAchin Gupta 74f6ad66aSAchin Gupta #include <arch_helpers.h> 809d40e0eSAntonio Nino Diaz #include <bl1/bl1.h> 909d40e0eSAntonio Nino Diaz #include <bl2/bl2.h> 1009d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1109d40e0eSAntonio Nino Diaz #include <common/debug.h> 1209d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_mod.h> 1309d40e0eSAntonio Nino Diaz #include <drivers/console.h> 1409d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 1509d40e0eSAntonio Nino Diaz 165b827a8fSDan Handley #include "bl2_private.h" 174f6ad66aSAchin Gupta 18b1d27b48SRoberto Vargas #ifdef AARCH32 19b1d27b48SRoberto Vargas #define NEXT_IMAGE "BL32" 20b1d27b48SRoberto Vargas #else 21b1d27b48SRoberto Vargas #define NEXT_IMAGE "BL31" 22b1d27b48SRoberto Vargas #endif 2393d81d64SSandrine Bailleux 2493d81d64SSandrine Bailleux /******************************************************************************* 25*9d93fc2fSAntonio Nino Diaz * Setup function for BL2. 26*9d93fc2fSAntonio Nino Diaz ******************************************************************************/ 27*9d93fc2fSAntonio Nino Diaz void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, 28*9d93fc2fSAntonio Nino Diaz u_register_t arg3) 29*9d93fc2fSAntonio Nino Diaz { 30*9d93fc2fSAntonio Nino Diaz /* Perform early platform-specific setup */ 31*9d93fc2fSAntonio Nino Diaz bl2_early_platform_setup2(arg0, arg1, arg2, arg3); 32*9d93fc2fSAntonio Nino Diaz 33*9d93fc2fSAntonio Nino Diaz #ifdef AARCH64 34*9d93fc2fSAntonio Nino Diaz /* 35*9d93fc2fSAntonio Nino Diaz * Update pointer authentication key before the MMU is enabled. It is 36*9d93fc2fSAntonio Nino Diaz * saved in the rodata section, that can be writen before enabling the 37*9d93fc2fSAntonio Nino Diaz * MMU. This function must be called after the console is initialized 38*9d93fc2fSAntonio Nino Diaz * in the early platform setup. 39*9d93fc2fSAntonio Nino Diaz */ 40*9d93fc2fSAntonio Nino Diaz bl_handle_pauth(); 41*9d93fc2fSAntonio Nino Diaz #endif /* AARCH64 */ 42*9d93fc2fSAntonio Nino Diaz 43*9d93fc2fSAntonio Nino Diaz /* Perform late platform-specific setup */ 44*9d93fc2fSAntonio Nino Diaz bl2_plat_arch_setup(); 45*9d93fc2fSAntonio Nino Diaz } 46*9d93fc2fSAntonio Nino Diaz 47*9d93fc2fSAntonio Nino Diaz /******************************************************************************* 4893d81d64SSandrine Bailleux * The only thing to do in BL2 is to load further images and pass control to 4942019bf4SYatharth Kochar * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2 5042019bf4SYatharth Kochar * runs entirely in S-EL1. 5193d81d64SSandrine Bailleux ******************************************************************************/ 5293d81d64SSandrine Bailleux void bl2_main(void) 5393d81d64SSandrine Bailleux { 5442019bf4SYatharth Kochar entry_point_info_t *next_bl_ep_info; 5593d81d64SSandrine Bailleux 566ad2e461SDan Handley NOTICE("BL2: %s\n", version_string); 576ad2e461SDan Handley NOTICE("BL2: %s\n", build_message); 586ad2e461SDan Handley 5993d81d64SSandrine Bailleux /* Perform remaining generic architectural setup in S-EL1 */ 6093d81d64SSandrine Bailleux bl2_arch_setup(); 6193d81d64SSandrine Bailleux 62dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 63dec840afSJuan Castillo /* Initialize authentication module */ 641779ba6bSJuan Castillo auth_mod_init(); 65dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 66dec840afSJuan Castillo 6701f62b6dSRoberto Vargas /* initialize boot source */ 6801f62b6dSRoberto Vargas bl2_plat_preload_setup(); 6901f62b6dSRoberto Vargas 7042019bf4SYatharth Kochar /* Load the subsequent bootloader images. */ 7142019bf4SYatharth Kochar next_bl_ep_info = bl2_load_images(); 72ef538c6fSJuan Castillo 7301a1f7c2SYann Gautier #if !BL2_AT_EL3 74d48c12e9SYatharth Kochar #ifdef AARCH32 75d48c12e9SYatharth Kochar /* 76d48c12e9SYatharth Kochar * For AArch32 state BL1 and BL2 share the MMU setup. 77d48c12e9SYatharth Kochar * Given that BL2 does not map BL1 regions, MMU needs 78d48c12e9SYatharth Kochar * to be disabled in order to go back to BL1. 79d48c12e9SYatharth Kochar */ 80d48c12e9SYatharth Kochar disable_mmu_icache_secure(); 81d48c12e9SYatharth Kochar #endif /* AARCH32 */ 82d48c12e9SYatharth Kochar 830b32628eSAntonio Nino Diaz console_flush(); 840b32628eSAntonio Nino Diaz 8593d81d64SSandrine Bailleux /* 8642019bf4SYatharth Kochar * Run next BL image via an SMC to BL1. Information on how to pass 8742019bf4SYatharth Kochar * control to the BL32 (if present) and BL33 software images will 8842019bf4SYatharth Kochar * be passed to next BL image as an argument. 8993d81d64SSandrine Bailleux */ 9042019bf4SYatharth Kochar smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0); 91b1d27b48SRoberto Vargas #else 92b1d27b48SRoberto Vargas NOTICE("BL2: Booting " NEXT_IMAGE "\n"); 93b1d27b48SRoberto Vargas print_entry_point_info(next_bl_ep_info); 94b1d27b48SRoberto Vargas console_flush(); 95b1d27b48SRoberto Vargas 96b1d27b48SRoberto Vargas bl2_run_next_image(next_bl_ep_info); 97b1d27b48SRoberto Vargas #endif 984f6ad66aSAchin Gupta } 99