blob: 3df0bfae2c020ea927aebd8d071d12070172116b [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Yann Gautierae770fe2024-01-16 19:39:31 +01002 * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Alexei Fedoroved108b52019-09-13 14:11:59 +01007#include <assert.h>
8
Achin Gupta4f6ad662013-10-25 09:08:21 +01009#include <arch_helpers.h>
Alexei Fedoroved108b52019-09-13 14:11:59 +010010#include <arch_features.h>
Antonio Nino Diaz09d40e02018-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 Badarkhe0aa0b3a2021-12-16 10:41:47 +000016#include <drivers/auth/crypto_mod.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000017#include <drivers/console.h>
Manish V Badarkhe396b3392021-06-25 23:28:59 +010018#include <drivers/fwu/fwu.h>
thagon01-armed8f06d2023-07-12 10:43:58 -050019#include <lib/bootmarker_capture.h>
Alexei Fedoroved108b52019-09-13 14:11:59 +010020#include <lib/extensions/pauth.h>
thagon01-armed8f06d2023-07-12 10:43:58 -050021#include <lib/pmf/pmf.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000022#include <plat/common/platform.h>
23
Dan Handley5b827a82014-04-17 18:53:42 +010024#include "bl2_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010025
Julius Werner402b3cf2019-07-09 14:02:43 -070026#ifdef __aarch64__
Roberto Vargasb1d27b42017-10-30 14:43:43 +000027#define NEXT_IMAGE "BL31"
Julius Werner402b3cf2019-07-09 14:02:43 -070028#else
29#define NEXT_IMAGE "BL32"
Roberto Vargasb1d27b42017-10-30 14:43:43 +000030#endif
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010031
thagon01-armed8f06d2023-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 Prakash42d4d3b2022-11-22 14:41:00 -060037#if RESET_TO_BL2
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010038/*******************************************************************************
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060039 * Setup function for BL2 when RESET_TO_BL2=1
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000040 ******************************************************************************/
41void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
42 u_register_t arg3)
43{
Yann Gautierae770fe2024-01-16 19:39:31 +010044 /* Enable early console if EARLY_CONSOLE flag is enabled */
45 plat_setup_early_console();
46
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000047 /* Perform early platform-specific setup */
48 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
49
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000050 /* Perform late platform-specific setup */
51 bl2_el3_plat_arch_setup();
Alexei Fedoroved108b52019-09-13 14:11:59 +010052
53#if CTX_INCLUDE_PAUTH_REGS
54 /*
55 * Assert that the ARMv8.3-PAuth registers are present or an access
56 * fault will be triggered when they are being saved or restored.
57 */
58 assert(is_armv8_3_pauth_present());
59#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000060}
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060061#else /* RESET_TO_BL2 */
62
Zelalem Aweke6c09af92021-07-09 11:37:10 -050063/*******************************************************************************
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060064 * Setup function for BL2 when RESET_TO_BL2=0
Zelalem Aweke6c09af92021-07-09 11:37:10 -050065 ******************************************************************************/
66void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
67 u_register_t arg3)
68{
Yann Gautierae770fe2024-01-16 19:39:31 +010069 /* Enable early console if EARLY_CONSOLE flag is enabled */
70 plat_setup_early_console();
71
Zelalem Aweke6c09af92021-07-09 11:37:10 -050072 /* Perform early platform-specific setup */
73 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
74
75 /* Perform late platform-specific setup */
76 bl2_plat_arch_setup();
77
78#if CTX_INCLUDE_PAUTH_REGS
79 /*
80 * Assert that the ARMv8.3-PAuth registers are present or an access
81 * fault will be triggered when they are being saved or restored.
82 */
83 assert(is_armv8_3_pauth_present());
84#endif /* CTX_INCLUDE_PAUTH_REGS */
85}
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060086#endif /* RESET_TO_BL2 */
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000087
Antonio Nino Diaz9d93fc22019-01-31 10:48:47 +000088/*******************************************************************************
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010089 * The only thing to do in BL2 is to load further images and pass control to
Yatharth Kochar42019bf2016-09-12 16:10:33 +010090 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
91 * runs entirely in S-EL1.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010092 ******************************************************************************/
93void bl2_main(void)
94{
Yatharth Kochar42019bf2016-09-12 16:10:33 +010095 entry_point_info_t *next_bl_ep_info;
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010096
thagon01-armed8f06d2023-07-12 10:43:58 -050097#if ENABLE_RUNTIME_INSTRUMENTATION
98 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
99#endif
100
Dan Handley6ad2e462014-07-29 17:14:00 +0100101 NOTICE("BL2: %s\n", version_string);
102 NOTICE("BL2: %s\n", build_message);
103
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100104 /* Perform remaining generic architectural setup in S-EL1 */
105 bl2_arch_setup();
106
Manish V Badarkhe396b3392021-06-25 23:28:59 +0100107#if PSA_FWU_SUPPORT
108 fwu_init();
109#endif /* PSA_FWU_SUPPORT */
110
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +0000111 crypto_mod_init();
112
Juan Castillodec840a2015-01-28 16:46:57 +0000113 /* Initialize authentication module */
Juan Castillo1779ba62015-05-19 11:54:12 +0100114 auth_mod_init();
Juan Castillodec840a2015-01-28 16:46:57 +0000115
Manish V Badarkhe47bf3ac2021-08-06 09:26:20 +0100116 /* Initialize the Measured Boot backend */
117 bl2_plat_mboot_init();
118
Alexei Fedorov3f498b02020-07-13 14:06:47 +0100119 /* Initialize boot source */
Roberto Vargas01f62b62017-09-26 12:53:01 +0100120 bl2_plat_preload_setup();
121
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100122 /* Load the subsequent bootloader images. */
123 next_bl_ep_info = bl2_load_images();
Juan Castilloef538c62014-09-04 14:43:09 +0100124
Manish V Badarkhe47bf3ac2021-08-06 09:26:20 +0100125 /* Teardown the Measured Boot backend */
126 bl2_plat_mboot_finish();
Alexei Fedorov3f498b02020-07-13 14:06:47 +0100127
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600128#if !BL2_RUNS_AT_EL3
Julius Werner402b3cf2019-07-09 14:02:43 -0700129#ifndef __aarch64__
Yatharth Kochard48c12e2016-06-30 14:52:12 +0100130 /*
131 * For AArch32 state BL1 and BL2 share the MMU setup.
132 * Given that BL2 does not map BL1 regions, MMU needs
133 * to be disabled in order to go back to BL1.
134 */
135 disable_mmu_icache_secure();
Julius Werner402b3cf2019-07-09 14:02:43 -0700136#endif /* !__aarch64__ */
Yatharth Kochard48c12e2016-06-30 14:52:12 +0100137
Alexei Fedoroved108b52019-09-13 14:11:59 +0100138#if ENABLE_PAUTH
139 /*
140 * Disable pointer authentication before running next boot image
141 */
142 pauth_disable_el1();
143#endif /* ENABLE_PAUTH */
144
thagon01-armed8f06d2023-07-12 10:43:58 -0500145#if ENABLE_RUNTIME_INSTRUMENTATION
146 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
147#endif
148
149 console_flush();
150
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100151 /*
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100152 * Run next BL image via an SMC to BL1. Information on how to pass
153 * control to the BL32 (if present) and BL33 software images will
154 * be passed to next BL image as an argument.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100155 */
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100156 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600157#else /* if BL2_RUNS_AT_EL3 */
158
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000159 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
160 print_entry_point_info(next_bl_ep_info);
thagon01-armed8f06d2023-07-12 10:43:58 -0500161#if ENABLE_RUNTIME_INSTRUMENTATION
162 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
163#endif
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000164 console_flush();
165
Alexei Fedoroved108b52019-09-13 14:11:59 +0100166#if ENABLE_PAUTH
167 /*
168 * Disable pointer authentication before running next boot image
169 */
170 pauth_disable_el3();
171#endif /* ENABLE_PAUTH */
172
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000173 bl2_run_next_image(next_bl_ep_info);
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600174#endif /* BL2_RUNS_AT_EL3 */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100175}