blob: 6c323312cdb0f9f6394e2d8acbc4758f9076b007 [file] [log] [blame]
Louis Mayencourtbadcac82019-10-24 15:18:46 +01001/*
laurenw-arm23075462022-04-21 17:03:30 -05002 * Copyright (c) 2019-2022, ARM Limited. All rights reserved.
Louis Mayencourtbadcac82019-10-24 15:18:46 +01003 *
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>
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000012#include <drivers/partition/partition.h>
Louis Mayencourtbadcac82019-10-24 15:18:46 +010013#include <lib/object_pool.h>
14#include <libfdt.h>
15#include <tools_share/firmware_image_package.h>
16
17#include <plat/arm/common/arm_fconf_getter.h>
18#include <plat/arm/common/arm_fconf_io_storage.h>
19#include <platform_def.h>
20
Manish V Badarkhed2f0a7a2021-06-25 23:43:33 +010021#if PSA_FWU_SUPPORT
22/* metadata entry details */
23static io_block_spec_t fwu_metadata_spec;
24#endif /* PSA_FWU_SUPPORT */
25
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000026io_block_spec_t fip_block_spec = {
27/*
28 * This is fixed FIP address used by BL1, BL2 loads partition table
29 * to get FIP address.
30 */
31#if ARM_GPT_SUPPORT
32 .offset = PLAT_ARM_FLASH_IMAGE_BASE + PLAT_ARM_FIP_OFFSET_IN_GPT,
33#else
Manish V Badarkhe443ccbc2021-04-22 11:13:21 +010034 .offset = PLAT_ARM_FLASH_IMAGE_BASE,
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000035#endif /* ARM_GPT_SUPPORT */
Manish V Badarkhe443ccbc2021-04-22 11:13:21 +010036 .length = PLAT_ARM_FLASH_IMAGE_MAX_SIZE
Louis Mayencourtbadcac82019-10-24 15:18:46 +010037};
38
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000039#if ARM_GPT_SUPPORT
40static const io_block_spec_t gpt_spec = {
41 .offset = PLAT_ARM_FLASH_IMAGE_BASE,
42 /*
43 * PLAT_PARTITION_BLOCK_SIZE = 512
44 * PLAT_PARTITION_MAX_ENTRIES = 128
45 * each sector has 4 partition entries, and there are
46 * 2 reserved sectors i.e. protective MBR and primary
47 * GPT header hence length gets calculated as,
48 * length = 512 * (128/4 + 2)
49 */
50 .length = PLAT_PARTITION_BLOCK_SIZE *
51 (PLAT_PARTITION_MAX_ENTRIES / 4 + 2),
52};
53#endif /* ARM_GPT_SUPPORT */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010054
55const io_uuid_spec_t arm_uuid_spec[MAX_NUMBER_IDS] = {
56 [BL2_IMAGE_ID] = {UUID_TRUSTED_BOOT_FIRMWARE_BL2},
57 [TB_FW_CONFIG_ID] = {UUID_TB_FW_CONFIG},
Louis Mayencourt244027d2020-06-11 21:15:15 +010058 [FW_CONFIG_ID] = {UUID_FW_CONFIG},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000059#if !ARM_IO_IN_DTB
60 [SCP_BL2_IMAGE_ID] = {UUID_SCP_FIRMWARE_SCP_BL2},
61 [BL31_IMAGE_ID] = {UUID_EL3_RUNTIME_FIRMWARE_BL31},
62 [BL32_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32},
63 [BL32_EXTRA1_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA1},
64 [BL32_EXTRA2_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA2},
65 [BL33_IMAGE_ID] = {UUID_NON_TRUSTED_FIRMWARE_BL33},
66 [HW_CONFIG_ID] = {UUID_HW_CONFIG},
67 [SOC_FW_CONFIG_ID] = {UUID_SOC_FW_CONFIG},
68 [TOS_FW_CONFIG_ID] = {UUID_TOS_FW_CONFIG},
69 [NT_FW_CONFIG_ID] = {UUID_NT_FW_CONFIG},
Zelalem Aweke96c0bab2021-07-11 18:39:39 -050070 [RMM_IMAGE_ID] = {UUID_REALM_MONITOR_MGMT_FIRMWARE},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000071#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010072#if TRUSTED_BOARD_BOOT
73 [TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000074#if !ARM_IO_IN_DTB
laurenw-arm23075462022-04-21 17:03:30 -050075 [CCA_CONTENT_CERT_ID] = {UUID_CCA_CONTENT_CERT},
76 [CORE_SWD_KEY_CERT_ID] = {UUID_CORE_SWD_KEY_CERT},
77 [PLAT_KEY_CERT_ID] = {UUID_PLAT_KEY_CERT},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000078 [TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT},
79 [SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT},
80 [SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT},
81 [TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT},
82 [NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT},
83 [SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT},
84 [SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT},
85 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT},
86 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010087#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +010088 [SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT},
Manish Pandeyaff80752020-07-31 16:15:16 +010089 [PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010090#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +000091#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010092#endif /* TRUSTED_BOARD_BOOT */
93};
94
95/* By default, ARM platforms load images from the FIP */
96struct plat_io_policy policies[MAX_NUMBER_IDS] = {
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000097#if ARM_GPT_SUPPORT
98 [GPT_IMAGE_ID] = {
99 &memmap_dev_handle,
100 (uintptr_t)&gpt_spec,
101 open_memmap
102 },
103#endif /* ARM_GPT_SUPPORT */
Manish V Badarkhed2f0a7a2021-06-25 23:43:33 +0100104#if PSA_FWU_SUPPORT
105 [FWU_METADATA_IMAGE_ID] = {
106 &memmap_dev_handle,
107 /* filled runtime from partition information */
108 (uintptr_t)&fwu_metadata_spec,
109 open_memmap
110 },
111 [BKUP_FWU_METADATA_IMAGE_ID] = {
112 &memmap_dev_handle,
113 /* filled runtime from partition information */
114 (uintptr_t)&fwu_metadata_spec,
115 open_memmap
116 },
117#endif /* PSA_FWU_SUPPORT */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100118 [FIP_IMAGE_ID] = {
119 &memmap_dev_handle,
120 (uintptr_t)&fip_block_spec,
121 open_memmap
122 },
123 [BL2_IMAGE_ID] = {
124 &fip_dev_handle,
125 (uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID],
126 open_fip
127 },
128 [TB_FW_CONFIG_ID] = {
129 &fip_dev_handle,
130 (uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID],
131 open_fip
132 },
Louis Mayencourt244027d2020-06-11 21:15:15 +0100133 [FW_CONFIG_ID] = {
134 &fip_dev_handle,
135 (uintptr_t)&arm_uuid_spec[FW_CONFIG_ID],
136 open_fip
137 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000138#if !ARM_IO_IN_DTB
139 [SCP_BL2_IMAGE_ID] = {
140 &fip_dev_handle,
141 (uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID],
142 open_fip
143 },
144 [BL31_IMAGE_ID] = {
145 &fip_dev_handle,
146 (uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID],
147 open_fip
148 },
149 [BL32_IMAGE_ID] = {
150 &fip_dev_handle,
151 (uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID],
152 open_fip
153 },
154 [BL32_EXTRA1_IMAGE_ID] = {
155 &fip_dev_handle,
156 (uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID],
157 open_fip
158 },
159 [BL32_EXTRA2_IMAGE_ID] = {
160 &fip_dev_handle,
161 (uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID],
162 open_fip
163 },
164 [BL33_IMAGE_ID] = {
165 &fip_dev_handle,
166 (uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID],
167 open_fip
168 },
Zelalem Aweke96c0bab2021-07-11 18:39:39 -0500169 [RMM_IMAGE_ID] = {
170 &fip_dev_handle,
171 (uintptr_t)&arm_uuid_spec[RMM_IMAGE_ID],
172 open_fip
173 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000174 [HW_CONFIG_ID] = {
175 &fip_dev_handle,
176 (uintptr_t)&arm_uuid_spec[HW_CONFIG_ID],
177 open_fip
178 },
179 [SOC_FW_CONFIG_ID] = {
180 &fip_dev_handle,
181 (uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID],
182 open_fip
183 },
184 [TOS_FW_CONFIG_ID] = {
185 &fip_dev_handle,
186 (uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID],
187 open_fip
188 },
189 [NT_FW_CONFIG_ID] = {
190 &fip_dev_handle,
191 (uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID],
192 open_fip
193 },
194#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100195#if TRUSTED_BOARD_BOOT
196 [TRUSTED_BOOT_FW_CERT_ID] = {
197 &fip_dev_handle,
198 (uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID],
199 open_fip
200 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000201#if !ARM_IO_IN_DTB
laurenw-arm23075462022-04-21 17:03:30 -0500202 [CCA_CONTENT_CERT_ID] = {
203 &fip_dev_handle,
204 (uintptr_t)&arm_uuid_spec[CCA_CONTENT_CERT_ID],
205 open_fip
206 },
207 [CORE_SWD_KEY_CERT_ID] = {
208 &fip_dev_handle,
209 (uintptr_t)&arm_uuid_spec[CORE_SWD_KEY_CERT_ID],
210 open_fip
211 },
212 [PLAT_KEY_CERT_ID] = {
213 &fip_dev_handle,
214 (uintptr_t)&arm_uuid_spec[PLAT_KEY_CERT_ID],
215 open_fip
216 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000217 [TRUSTED_KEY_CERT_ID] = {
218 &fip_dev_handle,
219 (uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID],
220 open_fip
221 },
222 [SCP_FW_KEY_CERT_ID] = {
223 &fip_dev_handle,
224 (uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID],
225 open_fip
226 },
227 [SOC_FW_KEY_CERT_ID] = {
228 &fip_dev_handle,
229 (uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID],
230 open_fip
231 },
232 [TRUSTED_OS_FW_KEY_CERT_ID] = {
233 &fip_dev_handle,
234 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID],
235 open_fip
236 },
237 [NON_TRUSTED_FW_KEY_CERT_ID] = {
238 &fip_dev_handle,
239 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID],
240 open_fip
241 },
242 [SCP_FW_CONTENT_CERT_ID] = {
243 &fip_dev_handle,
244 (uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID],
245 open_fip
246 },
247 [SOC_FW_CONTENT_CERT_ID] = {
248 &fip_dev_handle,
249 (uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID],
250 open_fip
251 },
252 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
253 &fip_dev_handle,
254 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID],
255 open_fip
256 },
257 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
258 &fip_dev_handle,
259 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID],
260 open_fip
261 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100262#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100263 [SIP_SP_CONTENT_CERT_ID] = {
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100264 &fip_dev_handle,
Manish Pandeyd07d0172020-07-23 16:54:30 +0100265 (uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID],
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100266 open_fip
267 },
Manish Pandeyaff80752020-07-31 16:15:16 +0100268 [PLAT_SP_CONTENT_CERT_ID] = {
269 &fip_dev_handle,
270 (uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID],
271 open_fip
272 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100273#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000274#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100275#endif /* TRUSTED_BOARD_BOOT */
276};
277
278#ifdef IMAGE_BL2
279
280#if TRUSTED_BOARD_BOOT
laurenw-arm23075462022-04-21 17:03:30 -0500281#define FCONF_ARM_IO_UUID_NUMBER U(24)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100282#else
Louis Mayencourt2711cc82020-02-24 14:37:25 +0000283#define FCONF_ARM_IO_UUID_NUMBER U(10)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100284#endif
285
286static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
287static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);
288
289struct policies_load_info {
290 unsigned int image_id;
291 const char *name;
292};
293
294/* image id to property name table */
295static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = {
296 {SCP_BL2_IMAGE_ID, "scp_bl2_uuid"},
297 {BL31_IMAGE_ID, "bl31_uuid"},
298 {BL32_IMAGE_ID, "bl32_uuid"},
299 {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
300 {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
301 {BL33_IMAGE_ID, "bl33_uuid"},
302 {HW_CONFIG_ID, "hw_cfg_uuid"},
303 {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
304 {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
305 {NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"},
306#if TRUSTED_BOARD_BOOT
laurenw-arm23075462022-04-21 17:03:30 -0500307 {CCA_CONTENT_CERT_ID, "cca_cert_uuid"},
308 {CORE_SWD_KEY_CERT_ID, "core_swd_cert_uuid"},
309 {PLAT_KEY_CERT_ID, "plat_cert_uuid"},
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100310 {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
311 {SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"},
312 {SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"},
313 {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
314 {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
315 {SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"},
316 {SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"},
317 {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
318 {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100319#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100320 {SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"},
Manish Pandeyaff80752020-07-31 16:15:16 +0100321 {PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100322#endif
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100323#endif /* TRUSTED_BOARD_BOOT */
324};
325
326int fconf_populate_arm_io_policies(uintptr_t config)
327{
328 int err, node;
329 unsigned int i;
330
331 union uuid_helper_t uuid_helper;
332 io_uuid_spec_t *uuid_ptr;
333
334 /* As libfdt uses void *, we can't avoid this cast */
335 const void *dtb = (void *)config;
336
337 /* Assert the node offset point to "arm,io-fip-handle" compatible property */
338 const char *compatible_str = "arm,io-fip-handle";
339 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
340 if (node < 0) {
341 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
342 return node;
343 }
344
345 /* Locate the uuid cells and read the value for all the load info uuid */
346 for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
347 uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
David Horstmannb2df4c12021-04-08 14:50:21 +0100348 err = fdtw_read_uuid(dtb, node, load_info[i].name, 16,
349 (uint8_t *)&uuid_helper);
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100350 if (err < 0) {
351 WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
352 return err;
353 }
354
David Horstmannb2df4c12021-04-08 14:50:21 +0100355 VERBOSE("FCONF: arm-io_policies.%s cell found with value = "
356 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100357 load_info[i].name,
David Horstmannb2df4c12021-04-08 14:50:21 +0100358 uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
359 uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
360 uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
361 uuid_helper.uuid_struct.time_hi_and_version[0],
362 uuid_helper.uuid_struct.time_hi_and_version[1],
363 uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
364 uuid_helper.uuid_struct.clock_seq_low,
365 uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
366 uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
367 uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]);
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100368
369 uuid_ptr->uuid = uuid_helper.uuid_struct;
370 policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
371 policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
372 policies[load_info[i].image_id].check = open_fip;
373 }
374 return 0;
375}
376
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000377#if ARM_IO_IN_DTB
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600378FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000379#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100380
381#endif /* IMAGE_BL2 */