blob: 4c68f076ad92612d1ea6d5c50ed61347a8f1ac7b [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Chris Kay758ccb82024-03-08 16:08:31 +00002 * 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>
Chris Kay758ccb82024-03-08 16:08:31 +000014#include <common/build_message.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000015#include <common/debug.h>
16#include <drivers/auth/auth_mod.h>
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +000017#include <drivers/auth/crypto_mod.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000018#include <drivers/console.h>
Manish V Badarkhe396b3392021-06-25 23:28:59 +010019#include <drivers/fwu/fwu.h>
thagon01-armed8f06d2023-07-12 10:43:58 -050020#include <lib/bootmarker_capture.h>
Alexei Fedoroved108b52019-09-13 14:11:59 +010021#include <lib/extensions/pauth.h>
thagon01-armed8f06d2023-07-12 10:43:58 -050022#include <lib/pmf/pmf.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000023#include <plat/common/platform.h>
24
Dan Handley5b827a82014-04-17 18:53:42 +010025#include "bl2_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010026
Julius Werner402b3cf2019-07-09 14:02:43 -070027#ifdef __aarch64__
Roberto Vargasb1d27b42017-10-30 14:43:43 +000028#define NEXT_IMAGE "BL31"
Julius Werner402b3cf2019-07-09 14:02:43 -070029#else
30#define NEXT_IMAGE "BL32"
Roberto Vargasb1d27b42017-10-30 14:43:43 +000031#endif
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010032
thagon01-armed8f06d2023-07-12 10:43:58 -050033#if ENABLE_RUNTIME_INSTRUMENTATION
34 PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
35 BL_TOTAL_IDS, PMF_DUMP_ENABLE);
36#endif
37
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060038#if RESET_TO_BL2
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010039/*******************************************************************************
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060040 * Setup function for BL2 when RESET_TO_BL2=1
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000041 ******************************************************************************/
42void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
43 u_register_t arg3)
44{
45 /* Perform early platform-specific setup */
46 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
47
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000048 /* Perform late platform-specific setup */
49 bl2_el3_plat_arch_setup();
Alexei Fedoroved108b52019-09-13 14:11:59 +010050
51#if CTX_INCLUDE_PAUTH_REGS
52 /*
53 * Assert that the ARMv8.3-PAuth registers are present or an access
54 * fault will be triggered when they are being saved or restored.
55 */
56 assert(is_armv8_3_pauth_present());
57#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000058}
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060059#else /* RESET_TO_BL2 */
60
Zelalem Aweke6c09af92021-07-09 11:37:10 -050061/*******************************************************************************
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060062 * Setup function for BL2 when RESET_TO_BL2=0
Zelalem Aweke6c09af92021-07-09 11:37:10 -050063 ******************************************************************************/
64void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
65 u_register_t arg3)
66{
67 /* Perform early platform-specific setup */
68 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
69
70 /* Perform late platform-specific setup */
71 bl2_plat_arch_setup();
72
73#if CTX_INCLUDE_PAUTH_REGS
74 /*
75 * Assert that the ARMv8.3-PAuth registers are present or an access
76 * fault will be triggered when they are being saved or restored.
77 */
78 assert(is_armv8_3_pauth_present());
79#endif /* CTX_INCLUDE_PAUTH_REGS */
80}
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -060081#endif /* RESET_TO_BL2 */
Antonio Nino Diazdcbfa112019-01-31 17:40:44 +000082
Antonio Nino Diaz9d93fc22019-01-31 10:48:47 +000083/*******************************************************************************
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010084 * The only thing to do in BL2 is to load further images and pass control to
Yatharth Kochar42019bf2016-09-12 16:10:33 +010085 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
86 * runs entirely in S-EL1.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010087 ******************************************************************************/
88void bl2_main(void)
89{
Yatharth Kochar42019bf2016-09-12 16:10:33 +010090 entry_point_info_t *next_bl_ep_info;
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010091
thagon01-armed8f06d2023-07-12 10:43:58 -050092#if ENABLE_RUNTIME_INSTRUMENTATION
93 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
94#endif
95
Chris Kay758ccb82024-03-08 16:08:31 +000096 NOTICE("BL2: %s\n", build_version_string);
Dan Handley6ad2e462014-07-29 17:14:00 +010097 NOTICE("BL2: %s\n", build_message);
98
Sandrine Bailleux93d81d62014-06-24 14:19:36 +010099 /* Perform remaining generic architectural setup in S-EL1 */
100 bl2_arch_setup();
101
Manish V Badarkhe396b3392021-06-25 23:28:59 +0100102#if PSA_FWU_SUPPORT
103 fwu_init();
104#endif /* PSA_FWU_SUPPORT */
105
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +0000106 crypto_mod_init();
107
Juan Castillodec840a2015-01-28 16:46:57 +0000108 /* Initialize authentication module */
Juan Castillo1779ba62015-05-19 11:54:12 +0100109 auth_mod_init();
Juan Castillodec840a2015-01-28 16:46:57 +0000110
Manish V Badarkhe47bf3ac2021-08-06 09:26:20 +0100111 /* Initialize the Measured Boot backend */
112 bl2_plat_mboot_init();
113
Alexei Fedorov3f498b02020-07-13 14:06:47 +0100114 /* Initialize boot source */
Roberto Vargas01f62b62017-09-26 12:53:01 +0100115 bl2_plat_preload_setup();
116
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100117 /* Load the subsequent bootloader images. */
118 next_bl_ep_info = bl2_load_images();
Juan Castilloef538c62014-09-04 14:43:09 +0100119
Manish V Badarkhe47bf3ac2021-08-06 09:26:20 +0100120 /* Teardown the Measured Boot backend */
121 bl2_plat_mboot_finish();
Alexei Fedorov3f498b02020-07-13 14:06:47 +0100122
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600123#if !BL2_RUNS_AT_EL3
Julius Werner402b3cf2019-07-09 14:02:43 -0700124#ifndef __aarch64__
Yatharth Kochard48c12e2016-06-30 14:52:12 +0100125 /*
126 * For AArch32 state BL1 and BL2 share the MMU setup.
127 * Given that BL2 does not map BL1 regions, MMU needs
128 * to be disabled in order to go back to BL1.
129 */
130 disable_mmu_icache_secure();
Julius Werner402b3cf2019-07-09 14:02:43 -0700131#endif /* !__aarch64__ */
Yatharth Kochard48c12e2016-06-30 14:52:12 +0100132
Alexei Fedoroved108b52019-09-13 14:11:59 +0100133#if ENABLE_PAUTH
134 /*
135 * Disable pointer authentication before running next boot image
136 */
137 pauth_disable_el1();
138#endif /* ENABLE_PAUTH */
139
thagon01-armed8f06d2023-07-12 10:43:58 -0500140#if ENABLE_RUNTIME_INSTRUMENTATION
141 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
142#endif
143
144 console_flush();
145
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100146 /*
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100147 * Run next BL image via an SMC to BL1. Information on how to pass
148 * control to the BL32 (if present) and BL33 software images will
149 * be passed to next BL image as an argument.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100150 */
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100151 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 -0600152#else /* if BL2_RUNS_AT_EL3 */
153
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000154 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
155 print_entry_point_info(next_bl_ep_info);
thagon01-armed8f06d2023-07-12 10:43:58 -0500156#if ENABLE_RUNTIME_INSTRUMENTATION
157 PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
158#endif
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000159 console_flush();
160
Alexei Fedoroved108b52019-09-13 14:11:59 +0100161#if ENABLE_PAUTH
162 /*
163 * Disable pointer authentication before running next boot image
164 */
165 pauth_disable_el3();
166#endif /* ENABLE_PAUTH */
167
Roberto Vargasb1d27b42017-10-30 14:43:43 +0000168 bl2_run_next_image(next_bl_ep_info);
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600169#endif /* BL2_RUNS_AT_EL3 */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100170}