blob: 48286c2f27f756d3dd86dbc88e2108e6d29abc7f [file] [log] [blame]
Louis Mayencourtbadcac82019-10-24 15:18:46 +01001/*
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
20const io_block_spec_t fip_block_spec = {
21 .offset = PLAT_ARM_FIP_BASE,
22 .length = PLAT_ARM_FIP_MAX_SIZE
23};
24
25const 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},
Louis Mayencourt244027d2020-06-11 21:15:15 +010028 [FW_CONFIG_ID] = {UUID_FW_CONFIG},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000029#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 */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010041#if TRUSTED_BOARD_BOOT
42 [TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000043#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},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010053#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +010054 [SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT},
Manish Pandeyaff80752020-07-31 16:15:16 +010055 [PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT},
Manish Pandey5f8e1a02020-05-27 22:40:10 +010056#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +000057#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010058#endif /* TRUSTED_BOARD_BOOT */
59};
60
61/* By default, ARM platforms load images from the FIP */
62struct 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 },
Louis Mayencourt244027d2020-06-11 21:15:15 +010078 [FW_CONFIG_ID] = {
79 &fip_dev_handle,
80 (uintptr_t)&arm_uuid_spec[FW_CONFIG_ID],
81 open_fip
82 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +000083#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 */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100135#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 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000141#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 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100187#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100188 [SIP_SP_CONTENT_CERT_ID] = {
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100189 &fip_dev_handle,
Manish Pandeyd07d0172020-07-23 16:54:30 +0100190 (uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID],
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100191 open_fip
192 },
Manish Pandeyaff80752020-07-31 16:15:16 +0100193 [PLAT_SP_CONTENT_CERT_ID] = {
194 &fip_dev_handle,
195 (uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID],
196 open_fip
197 },
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100198#endif
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000199#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100200#endif /* TRUSTED_BOARD_BOOT */
201};
202
203#ifdef IMAGE_BL2
204
205#if TRUSTED_BOARD_BOOT
Manish Pandeyaff80752020-07-31 16:15:16 +0100206#define FCONF_ARM_IO_UUID_NUMBER U(21)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100207#else
Louis Mayencourt2711cc82020-02-24 14:37:25 +0000208#define FCONF_ARM_IO_UUID_NUMBER U(10)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100209#endif
210
211static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
212static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);
213
214struct policies_load_info {
215 unsigned int image_id;
216 const char *name;
217};
218
219/* image id to property name table */
220static 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"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100241#if defined(SPD_spmd)
Manish Pandeyd07d0172020-07-23 16:54:30 +0100242 {SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"},
Manish Pandeyaff80752020-07-31 16:15:16 +0100243 {PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"},
Manish Pandey5f8e1a02020-05-27 22:40:10 +0100244#endif
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100245#endif /* TRUSTED_BOARD_BOOT */
246};
247
248int fconf_populate_arm_io_policies(uintptr_t config)
249{
250 int err, node;
251 unsigned int i;
Ruari Phipps57d48a02020-08-10 15:53:45 +0100252 unsigned int j;
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100253
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);
Andre Przywara6cf6a1b2020-03-30 23:21:13 +0100271 err = fdt_read_uint32_array(dtb, node, load_info[i].name,
272 4, uuid_helper.word);
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100273 if (err < 0) {
274 WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
275 return err;
276 }
277
Ruari Phipps57d48a02020-08-10 15:53:45 +0100278 /* 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
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100287 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
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000300#if ARM_IO_IN_DTB
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600301FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000302#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100303
304#endif /* IMAGE_BL2 */