blob: 5da80379549425f91a922ef6c6db3974a26e1694 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Manish V Badarkhe92de80a2021-12-16 10:41:47 +00002 * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Alexei Fedorovf41355c2019-09-13 14:11:59 +01007#include <assert.h>
8
Achin Gupta4f6ad662013-10-25 09:08:21 +01009#include <arch_helpers.h>
Alexei Fedorovf41355c2019-09-13 14:11:59 +010010#include <arch_features.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#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 Badarkhe92de80a2021-12-16 10:41:47 +000016#include <drivers/auth/crypto_mod.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <drivers/console.h>
Manish V Badarkhe99575e42021-06-25 23:28:59 +010018#include <drivers/fwu/fwu.h>
Alexei Fedorovf41355c2019-09-13 14:11:59 +010019#include <lib/extensions/pauth.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000020#include <plat/common/platform.h>
21
Dan Handleybcd60ba2014-04-17 18:53:42 +010022#include "bl2_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010023
Julius Werner8e0ef0f2019-07-09 14:02:43 -070024#ifdef __aarch64__
Roberto Vargase0e99462017-10-30 14:43:43 +000025#define NEXT_IMAGE "BL31"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070026#else
27#define NEXT_IMAGE "BL32"
Roberto Vargase0e99462017-10-30 14:43:43 +000028#endif
Vikram Kanigirida567432014-04-15 18:08:08 +010029
Zelalem Aweke688fbf72021-07-09 11:37:10 -050030#if BL2_AT_EL3
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010031/*******************************************************************************
Zelalem Aweke688fbf72021-07-09 11:37:10 -050032 * Setup function for BL2 when BL2_AT_EL3=1
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000033 ******************************************************************************/
Zelalem Aweke688fbf72021-07-09 11:37:10 -050034void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
35 u_register_t arg3)
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000036{
37 /* Perform early platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050038 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000039
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000040 /* Perform late platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050041 bl2_el3_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010042
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 Diaz6e4b0832019-01-31 10:48:47 +000050}
Zelalem Aweke688fbf72021-07-09 11:37:10 -050051#else /* BL2_AT_EL3 */
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000052/*******************************************************************************
Zelalem Aweke688fbf72021-07-09 11:37:10 -050053 * Setup function for BL2 when BL2_AT_EL3=0
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000054 ******************************************************************************/
Zelalem Aweke688fbf72021-07-09 11:37:10 -050055void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
56 u_register_t arg3)
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000057{
58 /* Perform early platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050059 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000060
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000061 /* Perform late platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050062 bl2_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010063
64#if CTX_INCLUDE_PAUTH_REGS
65 /*
66 * Assert that the ARMv8.3-PAuth registers are present or an access
67 * fault will be triggered when they are being saved or restored.
68 */
69 assert(is_armv8_3_pauth_present());
70#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000071}
72#endif /* BL2_AT_EL3 */
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000073
74/*******************************************************************************
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010075 * The only thing to do in BL2 is to load further images and pass control to
Yatharth Kochar51f76f62016-09-12 16:10:33 +010076 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
77 * runs entirely in S-EL1.
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010078 ******************************************************************************/
79void bl2_main(void)
80{
Yatharth Kochar51f76f62016-09-12 16:10:33 +010081 entry_point_info_t *next_bl_ep_info;
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010082
Dan Handley91b624e2014-07-29 17:14:00 +010083 NOTICE("BL2: %s\n", version_string);
84 NOTICE("BL2: %s\n", build_message);
85
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010086 /* Perform remaining generic architectural setup in S-EL1 */
87 bl2_arch_setup();
88
Manish V Badarkhe99575e42021-06-25 23:28:59 +010089#if PSA_FWU_SUPPORT
90 fwu_init();
91#endif /* PSA_FWU_SUPPORT */
92
Manish V Badarkhe92de80a2021-12-16 10:41:47 +000093 crypto_mod_init();
94
Juan Castillo9246ab82015-01-28 16:46:57 +000095 /* Initialize authentication module */
Juan Castilloa08a5e72015-05-19 11:54:12 +010096 auth_mod_init();
Juan Castillo9246ab82015-01-28 16:46:57 +000097
Manish V Badarkhe5797b802021-08-06 09:26:20 +010098 /* Initialize the Measured Boot backend */
99 bl2_plat_mboot_init();
100
Alexei Fedorov71707b12020-07-13 14:06:47 +0100101 /* Initialize boot source */
Roberto Vargasbc1ae1f2017-09-26 12:53:01 +0100102 bl2_plat_preload_setup();
103
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100104 /* Load the subsequent bootloader images. */
105 next_bl_ep_info = bl2_load_images();
Andrew Thoelkea55566d2014-05-28 22:22:55 +0100106
Manish V Badarkhe5797b802021-08-06 09:26:20 +0100107 /* Teardown the Measured Boot backend */
108 bl2_plat_mboot_finish();
Alexei Fedorov71707b12020-07-13 14:06:47 +0100109
Zelalem Aweke688fbf72021-07-09 11:37:10 -0500110#if !BL2_AT_EL3 && !ENABLE_RME
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700111#ifndef __aarch64__
Yatharth Kochardafb2472016-06-30 14:52:12 +0100112 /*
113 * For AArch32 state BL1 and BL2 share the MMU setup.
114 * Given that BL2 does not map BL1 regions, MMU needs
115 * to be disabled in order to go back to BL1.
116 */
117 disable_mmu_icache_secure();
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700118#endif /* !__aarch64__ */
Yatharth Kochardafb2472016-06-30 14:52:12 +0100119
Antonio Nino Diaze3962d02017-02-16 16:17:19 +0000120 console_flush();
121
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100122#if ENABLE_PAUTH
123 /*
124 * Disable pointer authentication before running next boot image
125 */
126 pauth_disable_el1();
127#endif /* ENABLE_PAUTH */
128
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129 /*
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100130 * Run next BL image via an SMC to BL1. Information on how to pass
131 * control to the BL32 (if present) and BL33 software images will
132 * be passed to next BL image as an argument.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100133 */
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100134 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
Zelalem Aweke688fbf72021-07-09 11:37:10 -0500135#else /* if BL2_AT_EL3 || ENABLE_RME */
Roberto Vargase0e99462017-10-30 14:43:43 +0000136 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
137 print_entry_point_info(next_bl_ep_info);
138 console_flush();
139
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100140#if ENABLE_PAUTH
141 /*
142 * Disable pointer authentication before running next boot image
143 */
144 pauth_disable_el3();
145#endif /* ENABLE_PAUTH */
146
Roberto Vargase0e99462017-10-30 14:43:43 +0000147 bl2_run_next_image(next_bl_ep_info);
Zelalem Aweke688fbf72021-07-09 11:37:10 -0500148#endif /* BL2_AT_EL3 && ENABLE_RME */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100149}