blob: 923a554fb42af4982dd6fcae8fd56ab6d55badd3 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -06002 * Copyright (c) 2013-2023, 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>
thagon01-arm6805e8d2023-07-12 10:43:58 -050019#include <lib/bootmarker_capture.h>
Alexei Fedorovf41355c2019-09-13 14:11:59 +010020#include <lib/extensions/pauth.h>
thagon01-arm6805e8d2023-07-12 10:43:58 -050021#include <lib/pmf/pmf.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000022#include <plat/common/platform.h>
23
Dan Handleybcd60ba2014-04-17 18:53:42 +010024#include "bl2_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010025
Julius Werner8e0ef0f2019-07-09 14:02:43 -070026#ifdef __aarch64__
Roberto Vargase0e99462017-10-30 14:43:43 +000027#define NEXT_IMAGE "BL31"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070028#else
29#define NEXT_IMAGE "BL32"
Roberto Vargase0e99462017-10-30 14:43:43 +000030#endif
Vikram Kanigirida567432014-04-15 18:08:08 +010031
thagon01-arm6805e8d2023-07-12 10:43:58 -050032#if ENABLE_RUNTIME_INSTRUMENTATION
33 PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
34 BL_TOTAL_IDS, PMF_DUMP_ENABLE);
35#endif
36
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060037#if RESET_TO_BL2
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010038/*******************************************************************************
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060039 * Setup function for BL2 when RESET_TO_BL2=1
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000040 ******************************************************************************/
Zelalem Aweke688fbf72021-07-09 11:37:10 -050041void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
42 u_register_t arg3)
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000043{
44 /* Perform early platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050045 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000046
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000047 /* Perform late platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050048 bl2_el3_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010049
50#if CTX_INCLUDE_PAUTH_REGS
51 /*
52 * Assert that the ARMv8.3-PAuth registers are present or an access
53 * fault will be triggered when they are being saved or restored.
54 */
55 assert(is_armv8_3_pauth_present());
56#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000057}
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060058#else /* RESET_TO_BL2 */
59
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000060/*******************************************************************************
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060061 * Setup function for BL2 when RESET_TO_BL2=0
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000062 ******************************************************************************/
Zelalem Aweke688fbf72021-07-09 11:37:10 -050063void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
64 u_register_t arg3)
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000065{
66 /* Perform early platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050067 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000068
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000069 /* Perform late platform-specific setup */
Zelalem Aweke688fbf72021-07-09 11:37:10 -050070 bl2_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010071
72#if CTX_INCLUDE_PAUTH_REGS
73 /*
74 * Assert that the ARMv8.3-PAuth registers are present or an access
75 * fault will be triggered when they are being saved or restored.
76 */
77 assert(is_armv8_3_pauth_present());
78#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000079}
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060080#endif /* RESET_TO_BL2 */
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000081
82/*******************************************************************************
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010083 * The only thing to do in BL2 is to load further images and pass control to
Yatharth Kochar51f76f62016-09-12 16:10:33 +010084 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
85 * runs entirely in S-EL1.
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010086 ******************************************************************************/
87void bl2_main(void)
88{
Yatharth Kochar51f76f62016-09-12 16:10:33 +010089 entry_point_info_t *next_bl_ep_info;
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010090
thagon01-arm6805e8d2023-07-12 10:43:58 -050091#if ENABLE_RUNTIME_INSTRUMENTATION
92 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
93#endif
94
Dan Handley91b624e2014-07-29 17:14:00 +010095 NOTICE("BL2: %s\n", version_string);
96 NOTICE("BL2: %s\n", build_message);
97
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010098 /* Perform remaining generic architectural setup in S-EL1 */
99 bl2_arch_setup();
100
Manish V Badarkhe99575e42021-06-25 23:28:59 +0100101#if PSA_FWU_SUPPORT
102 fwu_init();
103#endif /* PSA_FWU_SUPPORT */
104
Manish V Badarkhe92de80a2021-12-16 10:41:47 +0000105 crypto_mod_init();
106
Juan Castillo9246ab82015-01-28 16:46:57 +0000107 /* Initialize authentication module */
Juan Castilloa08a5e72015-05-19 11:54:12 +0100108 auth_mod_init();
Juan Castillo9246ab82015-01-28 16:46:57 +0000109
Manish V Badarkhe5797b802021-08-06 09:26:20 +0100110 /* Initialize the Measured Boot backend */
111 bl2_plat_mboot_init();
112
Alexei Fedorov71707b12020-07-13 14:06:47 +0100113 /* Initialize boot source */
Roberto Vargasbc1ae1f2017-09-26 12:53:01 +0100114 bl2_plat_preload_setup();
115
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100116 /* Load the subsequent bootloader images. */
117 next_bl_ep_info = bl2_load_images();
Andrew Thoelkea55566d2014-05-28 22:22:55 +0100118
Manish V Badarkhe5797b802021-08-06 09:26:20 +0100119 /* Teardown the Measured Boot backend */
120 bl2_plat_mboot_finish();
Alexei Fedorov71707b12020-07-13 14:06:47 +0100121
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -0600122#if !BL2_RUNS_AT_EL3
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700123#ifndef __aarch64__
Yatharth Kochardafb2472016-06-30 14:52:12 +0100124 /*
125 * For AArch32 state BL1 and BL2 share the MMU setup.
126 * Given that BL2 does not map BL1 regions, MMU needs
127 * to be disabled in order to go back to BL1.
128 */
129 disable_mmu_icache_secure();
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700130#endif /* !__aarch64__ */
Yatharth Kochardafb2472016-06-30 14:52:12 +0100131
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100132#if ENABLE_PAUTH
133 /*
134 * Disable pointer authentication before running next boot image
135 */
136 pauth_disable_el1();
137#endif /* ENABLE_PAUTH */
138
thagon01-arm6805e8d2023-07-12 10:43:58 -0500139#if ENABLE_RUNTIME_INSTRUMENTATION
140 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
141#endif
142
143 console_flush();
144
Achin Gupta4f6ad662013-10-25 09:08:21 +0100145 /*
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100146 * Run next BL image via an SMC to BL1. Information on how to pass
147 * control to the BL32 (if present) and BL33 software images will
148 * be passed to next BL image as an argument.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100149 */
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100150 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -0600151#else /* if BL2_RUNS_AT_EL3 */
152
Roberto Vargase0e99462017-10-30 14:43:43 +0000153 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
154 print_entry_point_info(next_bl_ep_info);
thagon01-arm6805e8d2023-07-12 10:43:58 -0500155#if ENABLE_RUNTIME_INSTRUMENTATION
156 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
157#endif
Roberto Vargase0e99462017-10-30 14:43:43 +0000158 console_flush();
159
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100160#if ENABLE_PAUTH
161 /*
162 * Disable pointer authentication before running next boot image
163 */
164 pauth_disable_el3();
165#endif /* ENABLE_PAUTH */
166
Roberto Vargase0e99462017-10-30 14:43:43 +0000167 bl2_run_next_image(next_bl_ep_info);
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -0600168#endif /* BL2_RUNS_AT_EL3 */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100169}