• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <common/debug.h>
10 #include <common/fdt_wrappers.h>
11 #include <drivers/io/io_storage.h>
12 #include <lib/object_pool.h>
13 #include <libfdt.h>
14 #include <tools_share/firmware_image_package.h>
15 
16 #include <plat/arm/common/arm_fconf_getter.h>
17 #include <plat/arm/common/arm_fconf_io_storage.h>
18 #include <platform_def.h>
19 
20 const io_block_spec_t fip_block_spec = {
21 	.offset = PLAT_ARM_FIP_BASE,
22 	.length = PLAT_ARM_FIP_MAX_SIZE
23 };
24 
25 const io_uuid_spec_t arm_uuid_spec[MAX_NUMBER_IDS] = {
26 	[BL2_IMAGE_ID] = {UUID_TRUSTED_BOOT_FIRMWARE_BL2},
27 	[TB_FW_CONFIG_ID] = {UUID_TB_FW_CONFIG},
28 	[FW_CONFIG_ID] = {UUID_FW_CONFIG},
29 #if !ARM_IO_IN_DTB
30 	[SCP_BL2_IMAGE_ID] = {UUID_SCP_FIRMWARE_SCP_BL2},
31 	[BL31_IMAGE_ID] = {UUID_EL3_RUNTIME_FIRMWARE_BL31},
32 	[BL32_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32},
33 	[BL32_EXTRA1_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA1},
34 	[BL32_EXTRA2_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA2},
35 	[BL33_IMAGE_ID] = {UUID_NON_TRUSTED_FIRMWARE_BL33},
36 	[HW_CONFIG_ID] = {UUID_HW_CONFIG},
37 	[SOC_FW_CONFIG_ID] = {UUID_SOC_FW_CONFIG},
38 	[TOS_FW_CONFIG_ID] = {UUID_TOS_FW_CONFIG},
39 	[NT_FW_CONFIG_ID] = {UUID_NT_FW_CONFIG},
40 #endif /* ARM_IO_IN_DTB */
41 #if TRUSTED_BOARD_BOOT
42 	[TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT},
43 #if !ARM_IO_IN_DTB
44 	[TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT},
45 	[SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT},
46 	[SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT},
47 	[TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT},
48 	[NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT},
49 	[SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT},
50 	[SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT},
51 	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT},
52 	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT},
53 #if defined(SPD_spmd)
54 	[SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT},
55 	[PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT},
56 #endif
57 #endif /* ARM_IO_IN_DTB */
58 #endif /* TRUSTED_BOARD_BOOT */
59 };
60 
61 /* By default, ARM platforms load images from the FIP */
62 struct plat_io_policy policies[MAX_NUMBER_IDS] = {
63 	[FIP_IMAGE_ID] = {
64 		&memmap_dev_handle,
65 		(uintptr_t)&fip_block_spec,
66 		open_memmap
67 	},
68 	[BL2_IMAGE_ID] = {
69 		&fip_dev_handle,
70 		(uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID],
71 		open_fip
72 	},
73 	[TB_FW_CONFIG_ID] = {
74 		&fip_dev_handle,
75 		(uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID],
76 		open_fip
77 	},
78 	[FW_CONFIG_ID] = {
79 		&fip_dev_handle,
80 		(uintptr_t)&arm_uuid_spec[FW_CONFIG_ID],
81 		open_fip
82 	},
83 #if !ARM_IO_IN_DTB
84 	[SCP_BL2_IMAGE_ID] = {
85 		&fip_dev_handle,
86 		(uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID],
87 		open_fip
88 	},
89 	[BL31_IMAGE_ID] = {
90 		&fip_dev_handle,
91 		(uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID],
92 		open_fip
93 	},
94 	[BL32_IMAGE_ID] = {
95 		&fip_dev_handle,
96 		(uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID],
97 		open_fip
98 	},
99 	[BL32_EXTRA1_IMAGE_ID] = {
100 		&fip_dev_handle,
101 		(uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID],
102 		open_fip
103 	},
104 	[BL32_EXTRA2_IMAGE_ID] = {
105 		&fip_dev_handle,
106 		(uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID],
107 		open_fip
108 	},
109 	[BL33_IMAGE_ID] = {
110 		&fip_dev_handle,
111 		(uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID],
112 		open_fip
113 	},
114 	[HW_CONFIG_ID] = {
115 		&fip_dev_handle,
116 		(uintptr_t)&arm_uuid_spec[HW_CONFIG_ID],
117 		open_fip
118 	},
119 	[SOC_FW_CONFIG_ID] = {
120 		&fip_dev_handle,
121 		(uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID],
122 		open_fip
123 	},
124 	[TOS_FW_CONFIG_ID] = {
125 		&fip_dev_handle,
126 		(uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID],
127 		open_fip
128 	},
129 	[NT_FW_CONFIG_ID] = {
130 		&fip_dev_handle,
131 		(uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID],
132 		open_fip
133 	},
134 #endif /* ARM_IO_IN_DTB */
135 #if TRUSTED_BOARD_BOOT
136 	[TRUSTED_BOOT_FW_CERT_ID] = {
137 		&fip_dev_handle,
138 		(uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID],
139 		open_fip
140 	},
141 #if !ARM_IO_IN_DTB
142 	[TRUSTED_KEY_CERT_ID] = {
143 		&fip_dev_handle,
144 		(uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID],
145 		open_fip
146 	},
147 	[SCP_FW_KEY_CERT_ID] = {
148 		&fip_dev_handle,
149 		(uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID],
150 		open_fip
151 	},
152 	[SOC_FW_KEY_CERT_ID] = {
153 		&fip_dev_handle,
154 		(uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID],
155 		open_fip
156 	},
157 	[TRUSTED_OS_FW_KEY_CERT_ID] = {
158 		&fip_dev_handle,
159 		(uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID],
160 		open_fip
161 	},
162 	[NON_TRUSTED_FW_KEY_CERT_ID] = {
163 		&fip_dev_handle,
164 		(uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID],
165 		open_fip
166 	},
167 	[SCP_FW_CONTENT_CERT_ID] = {
168 		&fip_dev_handle,
169 		(uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID],
170 		open_fip
171 	},
172 	[SOC_FW_CONTENT_CERT_ID] = {
173 		&fip_dev_handle,
174 		(uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID],
175 		open_fip
176 	},
177 	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
178 		&fip_dev_handle,
179 		(uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID],
180 		open_fip
181 	},
182 	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
183 		&fip_dev_handle,
184 		(uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID],
185 		open_fip
186 	},
187 #if defined(SPD_spmd)
188 	[SIP_SP_CONTENT_CERT_ID] = {
189 		&fip_dev_handle,
190 		(uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID],
191 		open_fip
192 	},
193 	[PLAT_SP_CONTENT_CERT_ID] = {
194 		&fip_dev_handle,
195 		(uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID],
196 		open_fip
197 	},
198 #endif
199 #endif /* ARM_IO_IN_DTB */
200 #endif /* TRUSTED_BOARD_BOOT */
201 };
202 
203 #ifdef IMAGE_BL2
204 
205 #if TRUSTED_BOARD_BOOT
206 #define FCONF_ARM_IO_UUID_NUMBER	U(21)
207 #else
208 #define FCONF_ARM_IO_UUID_NUMBER	U(10)
209 #endif
210 
211 static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
212 static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);
213 
214 struct policies_load_info {
215 	unsigned int image_id;
216 	const char *name;
217 };
218 
219 /* image id to property name table */
220 static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = {
221 	{SCP_BL2_IMAGE_ID, "scp_bl2_uuid"},
222 	{BL31_IMAGE_ID, "bl31_uuid"},
223 	{BL32_IMAGE_ID, "bl32_uuid"},
224 	{BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
225 	{BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
226 	{BL33_IMAGE_ID, "bl33_uuid"},
227 	{HW_CONFIG_ID, "hw_cfg_uuid"},
228 	{SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
229 	{TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
230 	{NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"},
231 #if TRUSTED_BOARD_BOOT
232 	{TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
233 	{SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"},
234 	{SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"},
235 	{TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
236 	{NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
237 	{SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"},
238 	{SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"},
239 	{TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
240 	{NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
241 #if defined(SPD_spmd)
242 	{SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"},
243 	{PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"},
244 #endif
245 #endif /* TRUSTED_BOARD_BOOT */
246 };
247 
fconf_populate_arm_io_policies(uintptr_t config)248 int fconf_populate_arm_io_policies(uintptr_t config)
249 {
250 	int err, node;
251 	unsigned int i;
252 	unsigned int j;
253 
254 	union uuid_helper_t uuid_helper;
255 	io_uuid_spec_t *uuid_ptr;
256 
257 	/* As libfdt uses void *, we can't avoid this cast */
258 	const void *dtb = (void *)config;
259 
260 	/* Assert the node offset point to "arm,io-fip-handle" compatible property */
261 	const char *compatible_str = "arm,io-fip-handle";
262 	node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
263 	if (node < 0) {
264 		ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
265 		return node;
266 	}
267 
268 	/* Locate the uuid cells and read the value for all the load info uuid */
269 	for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
270 		uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
271 		err = fdt_read_uint32_array(dtb, node, load_info[i].name,
272 					    4, uuid_helper.word);
273 		if (err < 0) {
274 			WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
275 			return err;
276 		}
277 
278 		/* Convert uuid from big endian to little endian */
279 		for (j = 0U; j < 4U; j++) {
280 			uuid_helper.word[j] =
281 				((uuid_helper.word[j] >> 24U) & 0xff) |
282 				((uuid_helper.word[j] << 8U) & 0xff0000) |
283 				((uuid_helper.word[j] >> 8U) & 0xff00) |
284 				((uuid_helper.word[j] << 24U) & 0xff000000);
285 		}
286 
287 		VERBOSE("FCONF: arm-io_policies.%s cell found with value = 0x%x 0x%x 0x%x 0x%x\n",
288 			load_info[i].name,
289 			uuid_helper.word[0], uuid_helper.word[1],
290 			uuid_helper.word[2], uuid_helper.word[3]);
291 
292 		uuid_ptr->uuid = uuid_helper.uuid_struct;
293 		policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
294 		policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
295 		policies[load_info[i].image_id].check = open_fip;
296 	}
297 	return 0;
298 }
299 
300 #if ARM_IO_IN_DTB
301 FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
302 #endif /* ARM_IO_IN_DTB */
303 
304 #endif /* IMAGE_BL2 */
305