blob: aea2f38d4f77203abf2daf3e6515e68a253fb1c9 [file] [log] [blame]
Louis Mayencourtbadcac82019-10-24 15:18:46 +01001/*
David Horstmannb2df4c12021-04-08 14:50:21 +01002 * Copyright (c) 2019-2021, 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
75 [TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT},
76 [SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT},
77 [SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT},
78 [TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT},
79 [NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT},
80 [SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT},
81 [SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT},
82 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT},
83 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010084#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +010085 [SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT},
Manish Pandeyaff80752020-07-31 16:15:16 +010086 [PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010087#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +000088#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010089#endif /* TRUSTED_BOARD_BOOT */
90};
91
92/* By default, ARM platforms load images from the FIP */
93struct plat_io_policy policies[MAX_NUMBER_IDS] = {
Manish V Badarkhedd6f2522021-02-22 17:30:17 +000094#if ARM_GPT_SUPPORT
95 [GPT_IMAGE_ID] = {
96 &memmap_dev_handle,
97 (uintptr_t)&gpt_spec,
98 open_memmap
99 },
100#endif /* ARM_GPT_SUPPORT */
Manish V Badarkhed2f0a7a2021-06-25 23:43:33 +0100101#if PSA_FWU_SUPPORT
102 [FWU_METADATA_IMAGE_ID] = {
103 &memmap_dev_handle,
104 /* filled runtime from partition information */
105 (uintptr_t)&fwu_metadata_spec,
106 open_memmap
107 },
108 [BKUP_FWU_METADATA_IMAGE_ID] = {
109 &memmap_dev_handle,
110 /* filled runtime from partition information */
111 (uintptr_t)&fwu_metadata_spec,
112 open_memmap
113 },
114#endif /* PSA_FWU_SUPPORT */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100115 [FIP_IMAGE_ID] = {
116 &memmap_dev_handle,
117 (uintptr_t)&fip_block_spec,
118 open_memmap
119 },
120 [BL2_IMAGE_ID] = {
121 &fip_dev_handle,
122 (uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID],
123 open_fip
124 },
125 [TB_FW_CONFIG_ID] = {
126 &fip_dev_handle,
127 (uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID],
128 open_fip
129 },
Louis Mayencourt244027d2020-06-11 21:15:15 +0100130 [FW_CONFIG_ID] = {
131 &fip_dev_handle,
132 (uintptr_t)&arm_uuid_spec[FW_CONFIG_ID],
133 open_fip
134 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000135#if !ARM_IO_IN_DTB
136 [SCP_BL2_IMAGE_ID] = {
137 &fip_dev_handle,
138 (uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID],
139 open_fip
140 },
141 [BL31_IMAGE_ID] = {
142 &fip_dev_handle,
143 (uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID],
144 open_fip
145 },
146 [BL32_IMAGE_ID] = {
147 &fip_dev_handle,
148 (uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID],
149 open_fip
150 },
151 [BL32_EXTRA1_IMAGE_ID] = {
152 &fip_dev_handle,
153 (uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID],
154 open_fip
155 },
156 [BL32_EXTRA2_IMAGE_ID] = {
157 &fip_dev_handle,
158 (uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID],
159 open_fip
160 },
161 [BL33_IMAGE_ID] = {
162 &fip_dev_handle,
163 (uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID],
164 open_fip
165 },
Zelalem Aweke96c0bab2021-07-11 18:39:39 -0500166 [RMM_IMAGE_ID] = {
167 &fip_dev_handle,
168 (uintptr_t)&arm_uuid_spec[RMM_IMAGE_ID],
169 open_fip
170 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000171 [HW_CONFIG_ID] = {
172 &fip_dev_handle,
173 (uintptr_t)&arm_uuid_spec[HW_CONFIG_ID],
174 open_fip
175 },
176 [SOC_FW_CONFIG_ID] = {
177 &fip_dev_handle,
178 (uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID],
179 open_fip
180 },
181 [TOS_FW_CONFIG_ID] = {
182 &fip_dev_handle,
183 (uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID],
184 open_fip
185 },
186 [NT_FW_CONFIG_ID] = {
187 &fip_dev_handle,
188 (uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID],
189 open_fip
190 },
191#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100192#if TRUSTED_BOARD_BOOT
193 [TRUSTED_BOOT_FW_CERT_ID] = {
194 &fip_dev_handle,
195 (uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID],
196 open_fip
197 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000198#if !ARM_IO_IN_DTB
199 [TRUSTED_KEY_CERT_ID] = {
200 &fip_dev_handle,
201 (uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID],
202 open_fip
203 },
204 [SCP_FW_KEY_CERT_ID] = {
205 &fip_dev_handle,
206 (uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID],
207 open_fip
208 },
209 [SOC_FW_KEY_CERT_ID] = {
210 &fip_dev_handle,
211 (uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID],
212 open_fip
213 },
214 [TRUSTED_OS_FW_KEY_CERT_ID] = {
215 &fip_dev_handle,
216 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID],
217 open_fip
218 },
219 [NON_TRUSTED_FW_KEY_CERT_ID] = {
220 &fip_dev_handle,
221 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID],
222 open_fip
223 },
224 [SCP_FW_CONTENT_CERT_ID] = {
225 &fip_dev_handle,
226 (uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID],
227 open_fip
228 },
229 [SOC_FW_CONTENT_CERT_ID] = {
230 &fip_dev_handle,
231 (uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID],
232 open_fip
233 },
234 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
235 &fip_dev_handle,
236 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID],
237 open_fip
238 },
239 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
240 &fip_dev_handle,
241 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID],
242 open_fip
243 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100244#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100245 [SIP_SP_CONTENT_CERT_ID] = {
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100246 &fip_dev_handle,
Manish Pandeyd07d0172020-07-23 16:54:30 +0100247 (uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID],
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100248 open_fip
249 },
Manish Pandeyaff80752020-07-31 16:15:16 +0100250 [PLAT_SP_CONTENT_CERT_ID] = {
251 &fip_dev_handle,
252 (uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID],
253 open_fip
254 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100255#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000256#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100257#endif /* TRUSTED_BOARD_BOOT */
258};
259
260#ifdef IMAGE_BL2
261
262#if TRUSTED_BOARD_BOOT
Manish Pandeyaff80752020-07-31 16:15:16 +0100263#define FCONF_ARM_IO_UUID_NUMBER U(21)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100264#else
Louis Mayencourt2711cc82020-02-24 14:37:25 +0000265#define FCONF_ARM_IO_UUID_NUMBER U(10)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100266#endif
267
268static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
269static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);
270
271struct policies_load_info {
272 unsigned int image_id;
273 const char *name;
274};
275
276/* image id to property name table */
277static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = {
278 {SCP_BL2_IMAGE_ID, "scp_bl2_uuid"},
279 {BL31_IMAGE_ID, "bl31_uuid"},
280 {BL32_IMAGE_ID, "bl32_uuid"},
281 {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
282 {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
283 {BL33_IMAGE_ID, "bl33_uuid"},
284 {HW_CONFIG_ID, "hw_cfg_uuid"},
285 {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
286 {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
287 {NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"},
288#if TRUSTED_BOARD_BOOT
289 {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
290 {SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"},
291 {SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"},
292 {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
293 {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
294 {SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"},
295 {SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"},
296 {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
297 {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100298#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100299 {SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"},
Manish Pandeyaff80752020-07-31 16:15:16 +0100300 {PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100301#endif
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100302#endif /* TRUSTED_BOARD_BOOT */
303};
304
305int fconf_populate_arm_io_policies(uintptr_t config)
306{
307 int err, node;
308 unsigned int i;
309
310 union uuid_helper_t uuid_helper;
311 io_uuid_spec_t *uuid_ptr;
312
313 /* As libfdt uses void *, we can't avoid this cast */
314 const void *dtb = (void *)config;
315
316 /* Assert the node offset point to "arm,io-fip-handle" compatible property */
317 const char *compatible_str = "arm,io-fip-handle";
318 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
319 if (node < 0) {
320 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
321 return node;
322 }
323
324 /* Locate the uuid cells and read the value for all the load info uuid */
325 for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
326 uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
David Horstmannb2df4c12021-04-08 14:50:21 +0100327 err = fdtw_read_uuid(dtb, node, load_info[i].name, 16,
328 (uint8_t *)&uuid_helper);
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100329 if (err < 0) {
330 WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
331 return err;
332 }
333
David Horstmannb2df4c12021-04-08 14:50:21 +0100334 VERBOSE("FCONF: arm-io_policies.%s cell found with value = "
335 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100336 load_info[i].name,
David Horstmannb2df4c12021-04-08 14:50:21 +0100337 uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
338 uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
339 uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
340 uuid_helper.uuid_struct.time_hi_and_version[0],
341 uuid_helper.uuid_struct.time_hi_and_version[1],
342 uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
343 uuid_helper.uuid_struct.clock_seq_low,
344 uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
345 uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
346 uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]);
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100347
348 uuid_ptr->uuid = uuid_helper.uuid_struct;
349 policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
350 policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
351 policies[load_info[i].image_id].check = open_fip;
352 }
353 return 0;
354}
355
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000356#if ARM_IO_IN_DTB
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600357FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000358#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100359
360#endif /* IMAGE_BL2 */