xref: /aosp_15_r20/external/arm-trusted-firmware/plat/common/plat_bl1_common.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include <assert.h>
8*54fd6939SJiyong Park #include <errno.h>
9*54fd6939SJiyong Park 
10*54fd6939SJiyong Park #include <platform_def.h>
11*54fd6939SJiyong Park 
12*54fd6939SJiyong Park #include <arch_helpers.h>
13*54fd6939SJiyong Park #include <bl1/bl1.h>
14*54fd6939SJiyong Park #include <common/bl_common.h>
15*54fd6939SJiyong Park #include <common/debug.h>
16*54fd6939SJiyong Park #include <plat/common/platform.h>
17*54fd6939SJiyong Park 
18*54fd6939SJiyong Park /*
19*54fd6939SJiyong Park  * The following platform functions are weakly defined. They
20*54fd6939SJiyong Park  * are default implementations that allow BL1 to compile in
21*54fd6939SJiyong Park  * absence of real definitions. The Platforms may override
22*54fd6939SJiyong Park  * with more complex definitions.
23*54fd6939SJiyong Park  */
24*54fd6939SJiyong Park #pragma weak bl1_plat_get_next_image_id
25*54fd6939SJiyong Park #pragma weak bl1_plat_set_ep_info
26*54fd6939SJiyong Park #pragma weak bl1_plat_get_image_desc
27*54fd6939SJiyong Park #pragma weak bl1_plat_fwu_done
28*54fd6939SJiyong Park #pragma weak bl1_plat_handle_pre_image_load
29*54fd6939SJiyong Park #pragma weak bl1_plat_handle_post_image_load
30*54fd6939SJiyong Park 
bl1_plat_get_next_image_id(void)31*54fd6939SJiyong Park unsigned int bl1_plat_get_next_image_id(void)
32*54fd6939SJiyong Park {
33*54fd6939SJiyong Park 	/* BL2 load will be done by default. */
34*54fd6939SJiyong Park 	return BL2_IMAGE_ID;
35*54fd6939SJiyong Park }
36*54fd6939SJiyong Park 
bl1_plat_set_ep_info(unsigned int image_id,struct entry_point_info * ep_info)37*54fd6939SJiyong Park void bl1_plat_set_ep_info(unsigned int image_id,
38*54fd6939SJiyong Park 		struct entry_point_info *ep_info)
39*54fd6939SJiyong Park {
40*54fd6939SJiyong Park 
41*54fd6939SJiyong Park }
42*54fd6939SJiyong Park 
bl1_plat_handle_pre_image_load(unsigned int image_id)43*54fd6939SJiyong Park int bl1_plat_handle_pre_image_load(unsigned int image_id)
44*54fd6939SJiyong Park {
45*54fd6939SJiyong Park 	return 0;
46*54fd6939SJiyong Park }
47*54fd6939SJiyong Park 
48*54fd6939SJiyong Park /*
49*54fd6939SJiyong Park  * Following is the default definition that always
50*54fd6939SJiyong Park  * returns BL2 image details.
51*54fd6939SJiyong Park  */
bl1_plat_get_image_desc(unsigned int image_id)52*54fd6939SJiyong Park struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
53*54fd6939SJiyong Park {
54*54fd6939SJiyong Park 	static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
55*54fd6939SJiyong Park 	return &bl2_img_desc;
56*54fd6939SJiyong Park }
57*54fd6939SJiyong Park 
bl1_plat_fwu_done(void * client_cookie,void * reserved)58*54fd6939SJiyong Park __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
59*54fd6939SJiyong Park {
60*54fd6939SJiyong Park 	while (true)
61*54fd6939SJiyong Park 		wfi();
62*54fd6939SJiyong Park }
63*54fd6939SJiyong Park 
64*54fd6939SJiyong Park /*
65*54fd6939SJiyong Park  * The Platforms must override with real definition.
66*54fd6939SJiyong Park  */
67*54fd6939SJiyong Park #pragma weak bl1_plat_mem_check
68*54fd6939SJiyong Park 
bl1_plat_mem_check(uintptr_t mem_base,unsigned int mem_size,unsigned int flags)69*54fd6939SJiyong Park int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
70*54fd6939SJiyong Park 		unsigned int flags)
71*54fd6939SJiyong Park {
72*54fd6939SJiyong Park 	assert(0);
73*54fd6939SJiyong Park 	return -ENOMEM;
74*54fd6939SJiyong Park }
75*54fd6939SJiyong Park 
76*54fd6939SJiyong Park /*
77*54fd6939SJiyong Park  * Default implementation for bl1_plat_handle_post_image_load(). This function
78*54fd6939SJiyong Park  * populates the default arguments to BL2. The BL2 memory layout structure
79*54fd6939SJiyong Park  * is allocated and the calculated layout is populated in arg1 to BL2.
80*54fd6939SJiyong Park  */
bl1_plat_handle_post_image_load(unsigned int image_id)81*54fd6939SJiyong Park int bl1_plat_handle_post_image_load(unsigned int image_id)
82*54fd6939SJiyong Park {
83*54fd6939SJiyong Park 	meminfo_t *bl2_secram_layout;
84*54fd6939SJiyong Park 	meminfo_t *bl1_secram_layout;
85*54fd6939SJiyong Park 	image_desc_t *image_desc;
86*54fd6939SJiyong Park 	entry_point_info_t *ep_info;
87*54fd6939SJiyong Park 
88*54fd6939SJiyong Park 	if (image_id != BL2_IMAGE_ID)
89*54fd6939SJiyong Park 		return 0;
90*54fd6939SJiyong Park 
91*54fd6939SJiyong Park 	/* Get the image descriptor */
92*54fd6939SJiyong Park 	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
93*54fd6939SJiyong Park 	assert(image_desc != NULL);
94*54fd6939SJiyong Park 
95*54fd6939SJiyong Park 	/* Get the entry point info */
96*54fd6939SJiyong Park 	ep_info = &image_desc->ep_info;
97*54fd6939SJiyong Park 
98*54fd6939SJiyong Park 	/* Find out how much free trusted ram remains after BL1 load */
99*54fd6939SJiyong Park 	bl1_secram_layout = bl1_plat_sec_mem_layout();
100*54fd6939SJiyong Park 
101*54fd6939SJiyong Park 	/*
102*54fd6939SJiyong Park 	 * Create a new layout of memory for BL2 as seen by BL1 i.e.
103*54fd6939SJiyong Park 	 * tell it the amount of total and free memory available.
104*54fd6939SJiyong Park 	 * This layout is created at the first free address visible
105*54fd6939SJiyong Park 	 * to BL2. BL2 will read the memory layout before using its
106*54fd6939SJiyong Park 	 * memory for other purposes.
107*54fd6939SJiyong Park 	 */
108*54fd6939SJiyong Park 	bl2_secram_layout = (meminfo_t *) bl1_secram_layout->total_base;
109*54fd6939SJiyong Park 
110*54fd6939SJiyong Park 	bl1_calc_bl2_mem_layout(bl1_secram_layout, bl2_secram_layout);
111*54fd6939SJiyong Park 
112*54fd6939SJiyong Park 	ep_info->args.arg1 = (uintptr_t)bl2_secram_layout;
113*54fd6939SJiyong Park 
114*54fd6939SJiyong Park 	VERBOSE("BL1: BL2 memory layout address = %p\n",
115*54fd6939SJiyong Park 		(void *) bl2_secram_layout);
116*54fd6939SJiyong Park 	return 0;
117*54fd6939SJiyong Park }
118