xref: /rk3399_ARM-atf/bl2/bl2_main.c (revision 6c09af9f8b36cdfa1dc4d5052f7e4792f63fa88a)
14f6ad66aSAchin Gupta /*
2396b339dSManish V Badarkhe  * Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta  */
64f6ad66aSAchin Gupta 
7ed108b56SAlexei Fedorov #include <assert.h>
8ed108b56SAlexei Fedorov 
94f6ad66aSAchin Gupta #include <arch_helpers.h>
10ed108b56SAlexei Fedorov #include <arch_features.h>
1109d40e0eSAntonio Nino Diaz #include <bl1/bl1.h>
1209d40e0eSAntonio Nino Diaz #include <bl2/bl2.h>
1309d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1409d40e0eSAntonio Nino Diaz #include <common/debug.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_mod.h>
1609d40e0eSAntonio Nino Diaz #include <drivers/console.h>
17396b339dSManish V Badarkhe #include <drivers/fwu/fwu.h>
183f498b0dSAlexei Fedorov #if MEASURED_BOOT
193f498b0dSAlexei Fedorov #include <drivers/measured_boot/measured_boot.h>
203f498b0dSAlexei Fedorov #endif
21ed108b56SAlexei Fedorov #include <lib/extensions/pauth.h>
2209d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
2309d40e0eSAntonio Nino Diaz 
245b827a8fSDan Handley #include "bl2_private.h"
254f6ad66aSAchin Gupta 
26402b3cf8SJulius Werner #ifdef __aarch64__
27b1d27b48SRoberto Vargas #define NEXT_IMAGE	"BL31"
28402b3cf8SJulius Werner #else
29402b3cf8SJulius Werner #define NEXT_IMAGE	"BL32"
30b1d27b48SRoberto Vargas #endif
3193d81d64SSandrine Bailleux 
32*6c09af9fSZelalem Aweke #if BL2_AT_EL3
3393d81d64SSandrine Bailleux /*******************************************************************************
34*6c09af9fSZelalem Aweke  * Setup function for BL2 when BL2_AT_EL3=1
35dcbfa11bSAntonio Nino Diaz  ******************************************************************************/
36dcbfa11bSAntonio Nino Diaz void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
37dcbfa11bSAntonio Nino Diaz 		   u_register_t arg3)
38dcbfa11bSAntonio Nino Diaz {
39dcbfa11bSAntonio Nino Diaz 	/* Perform early platform-specific setup */
40dcbfa11bSAntonio Nino Diaz 	bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
41dcbfa11bSAntonio Nino Diaz 
42dcbfa11bSAntonio Nino Diaz 	/* Perform late platform-specific setup */
43dcbfa11bSAntonio Nino Diaz 	bl2_el3_plat_arch_setup();
44ed108b56SAlexei Fedorov 
45ed108b56SAlexei Fedorov #if CTX_INCLUDE_PAUTH_REGS
46ed108b56SAlexei Fedorov 	/*
47ed108b56SAlexei Fedorov 	 * Assert that the ARMv8.3-PAuth registers are present or an access
48ed108b56SAlexei Fedorov 	 * fault will be triggered when they are being saved or restored.
49ed108b56SAlexei Fedorov 	 */
50ed108b56SAlexei Fedorov 	assert(is_armv8_3_pauth_present());
51ed108b56SAlexei Fedorov #endif /* CTX_INCLUDE_PAUTH_REGS */
52dcbfa11bSAntonio Nino Diaz }
53*6c09af9fSZelalem Aweke #else /* BL2_AT_EL3 */
54*6c09af9fSZelalem Aweke /*******************************************************************************
55*6c09af9fSZelalem Aweke  * Setup function for BL2 when BL2_AT_EL3=0
56*6c09af9fSZelalem Aweke  ******************************************************************************/
57*6c09af9fSZelalem Aweke void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
58*6c09af9fSZelalem Aweke 	       u_register_t arg3)
59*6c09af9fSZelalem Aweke {
60*6c09af9fSZelalem Aweke 	/* Perform early platform-specific setup */
61*6c09af9fSZelalem Aweke 	bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
62*6c09af9fSZelalem Aweke 
63*6c09af9fSZelalem Aweke 	/* Perform late platform-specific setup */
64*6c09af9fSZelalem Aweke 	bl2_plat_arch_setup();
65*6c09af9fSZelalem Aweke 
66*6c09af9fSZelalem Aweke #if CTX_INCLUDE_PAUTH_REGS
67*6c09af9fSZelalem Aweke 	/*
68*6c09af9fSZelalem Aweke 	 * Assert that the ARMv8.3-PAuth registers are present or an access
69*6c09af9fSZelalem Aweke 	 * fault will be triggered when they are being saved or restored.
70*6c09af9fSZelalem Aweke 	 */
71*6c09af9fSZelalem Aweke 	assert(is_armv8_3_pauth_present());
72*6c09af9fSZelalem Aweke #endif /* CTX_INCLUDE_PAUTH_REGS */
73*6c09af9fSZelalem Aweke }
74dcbfa11bSAntonio Nino Diaz #endif /* BL2_AT_EL3 */
75dcbfa11bSAntonio Nino Diaz 
769d93fc2fSAntonio Nino Diaz /*******************************************************************************
7793d81d64SSandrine Bailleux  * The only thing to do in BL2 is to load further images and pass control to
7842019bf4SYatharth Kochar  * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
7942019bf4SYatharth Kochar  * runs entirely in S-EL1.
8093d81d64SSandrine Bailleux  ******************************************************************************/
8193d81d64SSandrine Bailleux void bl2_main(void)
8293d81d64SSandrine Bailleux {
8342019bf4SYatharth Kochar 	entry_point_info_t *next_bl_ep_info;
8493d81d64SSandrine Bailleux 
856ad2e461SDan Handley 	NOTICE("BL2: %s\n", version_string);
866ad2e461SDan Handley 	NOTICE("BL2: %s\n", build_message);
876ad2e461SDan Handley 
8893d81d64SSandrine Bailleux 	/* Perform remaining generic architectural setup in S-EL1 */
8993d81d64SSandrine Bailleux 	bl2_arch_setup();
9093d81d64SSandrine Bailleux 
91396b339dSManish V Badarkhe #if PSA_FWU_SUPPORT
92396b339dSManish V Badarkhe 	fwu_init();
93396b339dSManish V Badarkhe #endif /* PSA_FWU_SUPPORT */
94396b339dSManish V Badarkhe 
95dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT
96dec840afSJuan Castillo 	/* Initialize authentication module */
971779ba6bSJuan Castillo 	auth_mod_init();
983f498b0dSAlexei Fedorov 
993f498b0dSAlexei Fedorov #if MEASURED_BOOT
1003f498b0dSAlexei Fedorov 	/* Initialize measured boot module */
1013f498b0dSAlexei Fedorov 	measured_boot_init();
1023f498b0dSAlexei Fedorov 
1033f498b0dSAlexei Fedorov #endif /* MEASURED_BOOT */
104dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */
105dec840afSJuan Castillo 
1063f498b0dSAlexei Fedorov 	/* Initialize boot source */
10701f62b6dSRoberto Vargas 	bl2_plat_preload_setup();
10801f62b6dSRoberto Vargas 
10942019bf4SYatharth Kochar 	/* Load the subsequent bootloader images. */
11042019bf4SYatharth Kochar 	next_bl_ep_info = bl2_load_images();
111ef538c6fSJuan Castillo 
1123f498b0dSAlexei Fedorov #if MEASURED_BOOT
1133f498b0dSAlexei Fedorov 	/* Finalize measured boot */
1143f498b0dSAlexei Fedorov 	measured_boot_finish();
1153f498b0dSAlexei Fedorov #endif /* MEASURED_BOOT */
1163f498b0dSAlexei Fedorov 
117*6c09af9fSZelalem Aweke #if !BL2_AT_EL3 && !ENABLE_RME
118402b3cf8SJulius Werner #ifndef __aarch64__
119d48c12e9SYatharth Kochar 	/*
120d48c12e9SYatharth Kochar 	 * For AArch32 state BL1 and BL2 share the MMU setup.
121d48c12e9SYatharth Kochar 	 * Given that BL2 does not map BL1 regions, MMU needs
122d48c12e9SYatharth Kochar 	 * to be disabled in order to go back to BL1.
123d48c12e9SYatharth Kochar 	 */
124d48c12e9SYatharth Kochar 	disable_mmu_icache_secure();
125402b3cf8SJulius Werner #endif /* !__aarch64__ */
126d48c12e9SYatharth Kochar 
1270b32628eSAntonio Nino Diaz 	console_flush();
1280b32628eSAntonio Nino Diaz 
129ed108b56SAlexei Fedorov #if ENABLE_PAUTH
130ed108b56SAlexei Fedorov 	/*
131ed108b56SAlexei Fedorov 	 * Disable pointer authentication before running next boot image
132ed108b56SAlexei Fedorov 	 */
133ed108b56SAlexei Fedorov 	pauth_disable_el1();
134ed108b56SAlexei Fedorov #endif /* ENABLE_PAUTH */
135ed108b56SAlexei Fedorov 
13693d81d64SSandrine Bailleux 	/*
13742019bf4SYatharth Kochar 	 * Run next BL image via an SMC to BL1. Information on how to pass
13842019bf4SYatharth Kochar 	 * control to the BL32 (if present) and BL33 software images will
13942019bf4SYatharth Kochar 	 * be passed to next BL image as an argument.
14093d81d64SSandrine Bailleux 	 */
14142019bf4SYatharth Kochar 	smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
142*6c09af9fSZelalem Aweke #else /* if BL2_AT_EL3 || ENABLE_RME */
143b1d27b48SRoberto Vargas 	NOTICE("BL2: Booting " NEXT_IMAGE "\n");
144b1d27b48SRoberto Vargas 	print_entry_point_info(next_bl_ep_info);
145b1d27b48SRoberto Vargas 	console_flush();
146b1d27b48SRoberto Vargas 
147ed108b56SAlexei Fedorov #if ENABLE_PAUTH
148ed108b56SAlexei Fedorov 	/*
149ed108b56SAlexei Fedorov 	 * Disable pointer authentication before running next boot image
150ed108b56SAlexei Fedorov 	 */
151ed108b56SAlexei Fedorov 	pauth_disable_el3();
152ed108b56SAlexei Fedorov #endif /* ENABLE_PAUTH */
153ed108b56SAlexei Fedorov 
154b1d27b48SRoberto Vargas 	bl2_run_next_image(next_bl_ep_info);
155*6c09af9fSZelalem Aweke #endif /* BL2_AT_EL3 && ENABLE_RME */
1564f6ad66aSAchin Gupta }
157