• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016-2021, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <common/bl_common.h>
9 #include <common/desc_image_load.h>
10 #if defined(SPD_spmd)
11 #include <plat/arm/common/fconf_arm_sp_getter.h>
12 #endif
13 #include <plat/arm/common/plat_arm.h>
14 #include <plat/common/platform.h>
15 
16 #pragma weak plat_flush_next_bl_params
17 #pragma weak plat_get_bl_image_load_info
18 #pragma weak plat_get_next_bl_params
19 
20 static bl_params_t *next_bl_params_cpy_ptr;
21 
22 /*******************************************************************************
23  * This function flushes the data structures so that they are visible
24  * in memory for the next BL image.
25  ******************************************************************************/
plat_flush_next_bl_params(void)26 void plat_flush_next_bl_params(void)
27 {
28 	assert(next_bl_params_cpy_ptr != NULL);
29 
30 	flush_bl_params_desc_args(bl_mem_params_desc_ptr,
31 		bl_mem_params_desc_num,
32 		next_bl_params_cpy_ptr);
33 }
34 
35 #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD
36 /*******************************************************************************
37  * This function appends Secure Partitions to list of loadable images.
38  ******************************************************************************/
plat_add_sp_images_load_info(struct bl_load_info * load_info)39 static void plat_add_sp_images_load_info(struct bl_load_info *load_info)
40 {
41 	bl_load_info_node_t *curr_node = load_info->head;
42 	bl_load_info_node_t *prev_node;
43 
44 	/* Shortcut for empty SP list */
45 	if (sp_mem_params_descs[0].image_id == 0) {
46 		ERROR("No Secure Partition Image available\n");
47 		return;
48 	}
49 
50 	/* Traverse through the bl images list */
51 	do {
52 		curr_node = curr_node->next_load_info;
53 	} while (curr_node->next_load_info != NULL);
54 
55 	prev_node = curr_node;
56 
57 	for (unsigned int index = 0; index < MAX_SP_IDS; index++) {
58 		if (sp_mem_params_descs[index].image_id == 0) {
59 			return;
60 		}
61 		curr_node = &sp_mem_params_descs[index].load_node_mem;
62 		/* Populate the image information */
63 		curr_node->image_id = sp_mem_params_descs[index].image_id;
64 		curr_node->image_info = &sp_mem_params_descs[index].image_info;
65 
66 		prev_node->next_load_info = curr_node;
67 		prev_node = curr_node;
68 	}
69 
70 	INFO("Reached Max number of SPs\n");
71 }
72 #endif
73 
74 /*******************************************************************************
75  * This function returns the list of loadable images.
76  ******************************************************************************/
plat_get_bl_image_load_info(void)77 struct bl_load_info *plat_get_bl_image_load_info(void)
78 {
79 #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD
80 	bl_load_info_t *bl_load_info;
81 
82 	bl_load_info = get_bl_load_info_from_mem_params_desc();
83 	plat_add_sp_images_load_info(bl_load_info);
84 
85 	return bl_load_info;
86 #else
87 	return get_bl_load_info_from_mem_params_desc();
88 #endif
89 }
90 
91 /*******************************************************************************
92  * ARM helper function to return the list of executable images.Since the default
93  * descriptors are allocated within BL2 RW memory, this prevents BL31/BL32
94  * overlay of BL2 memory. Hence this function also copies the descriptors to a
95  * pre-allocated memory indicated by ARM_BL2_MEM_DESC_BASE.
96  ******************************************************************************/
arm_get_next_bl_params(void)97 struct bl_params *arm_get_next_bl_params(void)
98 {
99 	bl_mem_params_node_t *bl2_mem_params_descs_cpy
100 			= (bl_mem_params_node_t *)ARM_BL2_MEM_DESC_BASE;
101 	const bl_params_t *next_bl_params;
102 
103 	next_bl_params_cpy_ptr =
104 		(bl_params_t *)(ARM_BL2_MEM_DESC_BASE +
105 		(bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
106 
107 	/*
108 	 * Copy the memory descriptors to ARM_BL2_MEM_DESC_BASE area.
109 	 */
110 	(void) memcpy(bl2_mem_params_descs_cpy, bl_mem_params_desc_ptr,
111 		(bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
112 
113 	/*
114 	 * Modify the global 'bl_mem_params_desc_ptr' to point to the
115 	 * copied location.
116 	 */
117 	bl_mem_params_desc_ptr = bl2_mem_params_descs_cpy;
118 
119 	next_bl_params = get_next_bl_params_from_mem_params_desc();
120 	assert(next_bl_params != NULL);
121 
122 	/*
123 	 * Copy 'next_bl_params' to the reserved location after the copied
124 	 * memory descriptors.
125 	 */
126 	(void) memcpy(next_bl_params_cpy_ptr, next_bl_params,
127 						(sizeof(bl_params_t)));
128 
129 	populate_next_bl_params_config(next_bl_params_cpy_ptr);
130 
131 	return next_bl_params_cpy_ptr;
132 }
133 
134 /*******************************************************************************
135  * This function returns the list of executable images
136  ******************************************************************************/
plat_get_next_bl_params(void)137 struct bl_params *plat_get_next_bl_params(void)
138 {
139 	return arm_get_next_bl_params();
140 }
141 
142