blob: 203e1d4b1da1d0510cf28cd7475686b8eea2431b [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Alexei Fedorov71707b12020-07-13 14:06:47 +01002 * Copyright (c) 2013-2020, 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>
16#include <drivers/console.h>
Alexei Fedorov71707b12020-07-13 14:06:47 +010017#if MEASURED_BOOT
18#include <drivers/measured_boot/measured_boot.h>
19#endif
Alexei Fedorovf41355c2019-09-13 14:11:59 +010020#include <lib/extensions/pauth.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <plat/common/platform.h>
22
Dan Handleybcd60ba2014-04-17 18:53:42 +010023#include "bl2_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010024
Julius Werner8e0ef0f2019-07-09 14:02:43 -070025#ifdef __aarch64__
Roberto Vargase0e99462017-10-30 14:43:43 +000026#define NEXT_IMAGE "BL31"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070027#else
28#define NEXT_IMAGE "BL32"
Roberto Vargase0e99462017-10-30 14:43:43 +000029#endif
Vikram Kanigirida567432014-04-15 18:08:08 +010030
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000031#if !BL2_AT_EL3
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010032/*******************************************************************************
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000033 * Setup function for BL2.
34 ******************************************************************************/
35void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
36 u_register_t arg3)
37{
38 /* Perform early platform-specific setup */
39 bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
40
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000041 /* Perform late platform-specific setup */
42 bl2_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010043
44#if CTX_INCLUDE_PAUTH_REGS
45 /*
46 * Assert that the ARMv8.3-PAuth registers are present or an access
47 * fault will be triggered when they are being saved or restored.
48 */
49 assert(is_armv8_3_pauth_present());
50#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000051}
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000052
53#else /* if BL2_AT_EL3 */
54/*******************************************************************************
55 * Setup function for BL2 when BL2_AT_EL3=1.
56 ******************************************************************************/
57void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
58 u_register_t arg3)
59{
60 /* Perform early platform-specific setup */
61 bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
62
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000063 /* Perform late platform-specific setup */
64 bl2_el3_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010065
66#if CTX_INCLUDE_PAUTH_REGS
67 /*
68 * Assert that the ARMv8.3-PAuth registers are present or an access
69 * fault will be triggered when they are being saved or restored.
70 */
71 assert(is_armv8_3_pauth_present());
72#endif /* CTX_INCLUDE_PAUTH_REGS */
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +000073}
74#endif /* BL2_AT_EL3 */
Antonio Nino Diaz6e4b0832019-01-31 10:48:47 +000075
76/*******************************************************************************
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010077 * The only thing to do in BL2 is to load further images and pass control to
Yatharth Kochar51f76f62016-09-12 16:10:33 +010078 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
79 * runs entirely in S-EL1.
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010080 ******************************************************************************/
81void bl2_main(void)
82{
Yatharth Kochar51f76f62016-09-12 16:10:33 +010083 entry_point_info_t *next_bl_ep_info;
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010084
Dan Handley91b624e2014-07-29 17:14:00 +010085 NOTICE("BL2: %s\n", version_string);
86 NOTICE("BL2: %s\n", build_message);
87
Sandrine Bailleuxf841ef02014-06-24 14:19:36 +010088 /* Perform remaining generic architectural setup in S-EL1 */
89 bl2_arch_setup();
90
Juan Castillo9246ab82015-01-28 16:46:57 +000091#if TRUSTED_BOARD_BOOT
92 /* Initialize authentication module */
Juan Castilloa08a5e72015-05-19 11:54:12 +010093 auth_mod_init();
Alexei Fedorov71707b12020-07-13 14:06:47 +010094
95#if MEASURED_BOOT
96 /* Initialize measured boot module */
97 measured_boot_init();
98
99#endif /* MEASURED_BOOT */
Juan Castillo9246ab82015-01-28 16:46:57 +0000100#endif /* TRUSTED_BOARD_BOOT */
101
Alexei Fedorov71707b12020-07-13 14:06:47 +0100102 /* Initialize boot source */
Roberto Vargasbc1ae1f2017-09-26 12:53:01 +0100103 bl2_plat_preload_setup();
104
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100105 /* Load the subsequent bootloader images. */
106 next_bl_ep_info = bl2_load_images();
Andrew Thoelkea55566d2014-05-28 22:22:55 +0100107
Alexei Fedorov71707b12020-07-13 14:06:47 +0100108#if MEASURED_BOOT
109 /* Finalize measured boot */
110 measured_boot_finish();
111#endif /* MEASURED_BOOT */
112
Yann Gautier60e5c2f2018-04-26 19:07:17 +0200113#if !BL2_AT_EL3
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700114#ifndef __aarch64__
Yatharth Kochardafb2472016-06-30 14:52:12 +0100115 /*
116 * For AArch32 state BL1 and BL2 share the MMU setup.
117 * Given that BL2 does not map BL1 regions, MMU needs
118 * to be disabled in order to go back to BL1.
119 */
120 disable_mmu_icache_secure();
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700121#endif /* !__aarch64__ */
Yatharth Kochardafb2472016-06-30 14:52:12 +0100122
Antonio Nino Diaze3962d02017-02-16 16:17:19 +0000123 console_flush();
124
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100125#if ENABLE_PAUTH
126 /*
127 * Disable pointer authentication before running next boot image
128 */
129 pauth_disable_el1();
130#endif /* ENABLE_PAUTH */
131
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132 /*
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100133 * Run next BL image via an SMC to BL1. Information on how to pass
134 * control to the BL32 (if present) and BL33 software images will
135 * be passed to next BL image as an argument.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100136 */
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100137 smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +0000138#else /* if BL2_AT_EL3 */
Roberto Vargase0e99462017-10-30 14:43:43 +0000139 NOTICE("BL2: Booting " NEXT_IMAGE "\n");
140 print_entry_point_info(next_bl_ep_info);
141 console_flush();
142
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100143#if ENABLE_PAUTH
144 /*
145 * Disable pointer authentication before running next boot image
146 */
147 pauth_disable_el3();
148#endif /* ENABLE_PAUTH */
149
Roberto Vargase0e99462017-10-30 14:43:43 +0000150 bl2_run_next_image(next_bl_ep_info);
Antonio Nino Diaz4f29fb72019-01-31 17:40:44 +0000151#endif /* BL2_AT_EL3 */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152}