xref: /rk3399_ARM-atf/bl2/bl2_main.c (revision 96f227b72a4d0af5670a586d0d8cd8bd93df9f88)
1 /*
2  * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <arch_helpers.h>
10 #include <arch_features.h>
11 #include <bl1/bl1.h>
12 #include <bl2/bl2.h>
13 #include <common/bl_common.h>
14 #include <common/build_message.h>
15 #include <common/debug.h>
16 #include <drivers/auth/auth_mod.h>
17 #include <drivers/auth/crypto_mod.h>
18 #include <drivers/console.h>
19 #include <drivers/fwu/fwu.h>
20 #include <lib/bootmarker_capture.h>
21 #include <lib/extensions/pauth.h>
22 #include <lib/pmf/pmf.h>
23 #include <plat/common/platform.h>
24 
25 #include "bl2_private.h"
26 
27 #ifdef __aarch64__
28 #define NEXT_IMAGE	"BL31"
29 #else
30 #define NEXT_IMAGE	"BL32"
31 #endif
32 
33 #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 
38 /*******************************************************************************
39  * The only thing to do in BL2 is to load further images and pass control to
40  * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages.
41  ******************************************************************************/
42 void __no_pauth bl2_main(u_register_t arg0, u_register_t arg1, u_register_t arg2,
43 	       u_register_t arg3)
44 {
45 	entry_point_info_t *next_bl_ep_info;
46 
47 	/* Enable early console if EARLY_CONSOLE flag is enabled */
48 	plat_setup_early_console();
49 
50 	/* Perform early platform-specific setup */
51 	bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
52 
53 	/* Perform remaining generic architectural setup */
54 	bl2_arch_setup();
55 
56 	/* Perform late platform-specific setup */
57 	bl2_plat_arch_setup();
58 
59 	if (is_feat_pauth_supported()) {
60 #if BL2_RUNS_AT_EL3
61 		pauth_init_enable_el3();
62 #else
63 		pauth_init_enable_el1();
64 #endif
65 	}
66 
67 #if ENABLE_RUNTIME_INSTRUMENTATION
68 	PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
69 #endif
70 
71 	NOTICE("BL2: %s\n", build_version_string);
72 	NOTICE("BL2: %s\n", build_message);
73 
74 #if PSA_FWU_SUPPORT
75 	fwu_init();
76 #endif /* PSA_FWU_SUPPORT */
77 
78 	crypto_mod_init();
79 
80 	/* Initialize authentication module */
81 	auth_mod_init();
82 
83 	/* Initialize the Measured Boot backend */
84 	bl2_plat_mboot_init();
85 
86 	/* Initialize boot source */
87 	bl2_plat_preload_setup();
88 
89 	/* Load the subsequent bootloader images. */
90 	next_bl_ep_info = bl2_load_images();
91 
92 	/* Teardown the Measured Boot backend */
93 	bl2_plat_mboot_finish();
94 
95 	crypto_mod_finish();
96 
97 #if !BL2_RUNS_AT_EL3
98 #ifndef __aarch64__
99 	/*
100 	 * For AArch32 state BL1 and BL2 share the MMU setup.
101 	 * Given that BL2 does not map BL1 regions, MMU needs
102 	 * to be disabled in order to go back to BL1.
103 	 */
104 	disable_mmu_icache_secure();
105 #endif /* !__aarch64__ */
106 
107 	/*
108 	 * Disable pointer authentication before running next boot image
109 	 */
110 	if (is_feat_pauth_supported()) {
111 		pauth_disable_el1();
112 	}
113 
114 #if ENABLE_RUNTIME_INSTRUMENTATION
115 	PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
116 #endif
117 
118 	console_flush();
119 
120 	/*
121 	 * Run next BL image via an SMC to BL1. Information on how to pass
122 	 * control to the BL32 (if present) and BL33 software images will
123 	 * be passed to next BL image as an argument.
124 	 */
125 	smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
126 #else /* if BL2_RUNS_AT_EL3 */
127 
128 	NOTICE("BL2: Booting " NEXT_IMAGE "\n");
129 	print_entry_point_info(next_bl_ep_info);
130 #if ENABLE_RUNTIME_INSTRUMENTATION
131 	PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
132 #endif
133 	console_flush();
134 
135 	/*
136 	 * Disable pointer authentication before running next boot image
137 	 */
138 	if (is_feat_pauth_supported()) {
139 		pauth_disable_el3();
140 	}
141 
142 	bl2_run_next_image(next_bl_ep_info);
143 #endif /* BL2_RUNS_AT_EL3 */
144 }
145