blob: f5d8a414d958988750dd658989faed5f79aab8af [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Louis Mayencourt70d7c092020-01-29 11:42:31 +00002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
Dan Handley9df48042015-03-19 18:58:55 +00007#include <assert.h>
Dan Handley9df48042015-03-19 18:58:55 +00008#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <platform_def.h>
11
12#include <common/debug.h>
13#include <drivers/io/io_driver.h>
14#include <drivers/io/io_fip.h>
15#include <drivers/io/io_memmap.h>
16#include <drivers/io/io_storage.h>
17#include <lib/utils.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000018#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019#include <plat/common/platform.h>
20#include <tools_share/firmware_image_package.h>
21
Dan Handley9df48042015-03-19 18:58:55 +000022/* IO devices */
23static const io_dev_connector_t *fip_dev_con;
24static uintptr_t fip_dev_handle;
25static const io_dev_connector_t *memmap_dev_con;
26static uintptr_t memmap_dev_handle;
27
28static const io_block_spec_t fip_block_spec = {
29 .offset = PLAT_ARM_FIP_BASE,
30 .length = PLAT_ARM_FIP_MAX_SIZE
31};
32
Juan Castillo3a66aca2015-04-13 17:36:19 +010033static const io_uuid_spec_t bl2_uuid_spec = {
34 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000035};
36
Juan Castilloa72b6472015-12-10 15:49:17 +000037static const io_uuid_spec_t scp_bl2_uuid_spec = {
38 .uuid = UUID_SCP_FIRMWARE_SCP_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000039};
40
Juan Castillo3a66aca2015-04-13 17:36:19 +010041static const io_uuid_spec_t bl31_uuid_spec = {
42 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
Dan Handley9df48042015-03-19 18:58:55 +000043};
44
Juan Castillo3a66aca2015-04-13 17:36:19 +010045static const io_uuid_spec_t bl32_uuid_spec = {
46 .uuid = UUID_SECURE_PAYLOAD_BL32,
Dan Handley9df48042015-03-19 18:58:55 +000047};
48
Summer Qin80726782017-04-20 16:28:39 +010049static const io_uuid_spec_t bl32_extra1_uuid_spec = {
50 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
51};
52
53static const io_uuid_spec_t bl32_extra2_uuid_spec = {
54 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
55};
56
Juan Castillo3a66aca2015-04-13 17:36:19 +010057static const io_uuid_spec_t bl33_uuid_spec = {
58 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
Dan Handley9df48042015-03-19 18:58:55 +000059};
60
Soby Mathew7c6df5b2018-01-15 14:43:42 +000061static const io_uuid_spec_t tb_fw_config_uuid_spec = {
62 .uuid = UUID_TB_FW_CONFIG,
63};
64
Soby Mathew96a1c6b2018-01-15 14:45:33 +000065static const io_uuid_spec_t hw_config_uuid_spec = {
66 .uuid = UUID_HW_CONFIG,
67};
68
Soby Mathewb6814842018-04-04 09:40:32 +010069static const io_uuid_spec_t soc_fw_config_uuid_spec = {
70 .uuid = UUID_SOC_FW_CONFIG,
71};
72
73static const io_uuid_spec_t tos_fw_config_uuid_spec = {
74 .uuid = UUID_TOS_FW_CONFIG,
75};
76
77static const io_uuid_spec_t nt_fw_config_uuid_spec = {
78 .uuid = UUID_NT_FW_CONFIG,
79};
80
Dan Handley9df48042015-03-19 18:58:55 +000081#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000082static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
83 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000084};
85
Juan Castillo3a66aca2015-04-13 17:36:19 +010086static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
87 .uuid = UUID_TRUSTED_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000088};
89
Juan Castillobe801202015-12-03 10:19:21 +000090static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = {
91 .uuid = UUID_SCP_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000092};
93
Juan Castillobe801202015-12-03 10:19:21 +000094static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
95 .uuid = UUID_SOC_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000096};
97
Juan Castillobe801202015-12-03 10:19:21 +000098static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
99 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000100};
101
Juan Castillobe801202015-12-03 10:19:21 +0000102static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
103 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000104};
105
Juan Castillobe801202015-12-03 10:19:21 +0000106static const io_uuid_spec_t scp_fw_cert_uuid_spec = {
107 .uuid = UUID_SCP_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000108};
109
Juan Castillobe801202015-12-03 10:19:21 +0000110static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
111 .uuid = UUID_SOC_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000112};
113
Juan Castillobe801202015-12-03 10:19:21 +0000114static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
115 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000116};
117
Juan Castillobe801202015-12-03 10:19:21 +0000118static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
119 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000120};
121#endif /* TRUSTED_BOARD_BOOT */
122
Juan Castillo3a66aca2015-04-13 17:36:19 +0100123
Dan Handley9df48042015-03-19 18:58:55 +0000124static int open_fip(const uintptr_t spec);
125static int open_memmap(const uintptr_t spec);
126
127struct plat_io_policy {
Dan Handley9df48042015-03-19 18:58:55 +0000128 uintptr_t *dev_handle;
129 uintptr_t image_spec;
130 int (*check)(const uintptr_t spec);
131};
132
Juan Castillo3a66aca2015-04-13 17:36:19 +0100133/* By default, ARM platforms load images from the FIP */
Dan Handley9df48042015-03-19 18:58:55 +0000134static const struct plat_io_policy policies[] = {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100135 [FIP_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000136 &memmap_dev_handle,
137 (uintptr_t)&fip_block_spec,
138 open_memmap
Juan Castillo3a66aca2015-04-13 17:36:19 +0100139 },
140 [BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000141 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100142 (uintptr_t)&bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000143 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100144 },
Juan Castilloa72b6472015-12-10 15:49:17 +0000145 [SCP_BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000146 &fip_dev_handle,
Juan Castilloa72b6472015-12-10 15:49:17 +0000147 (uintptr_t)&scp_bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000148 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100149 },
150 [BL31_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000151 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100152 (uintptr_t)&bl31_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000153 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100154 },
155 [BL32_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000156 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100157 (uintptr_t)&bl32_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000158 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100159 },
Summer Qin80726782017-04-20 16:28:39 +0100160 [BL32_EXTRA1_IMAGE_ID] = {
161 &fip_dev_handle,
162 (uintptr_t)&bl32_extra1_uuid_spec,
163 open_fip
164 },
165 [BL32_EXTRA2_IMAGE_ID] = {
166 &fip_dev_handle,
167 (uintptr_t)&bl32_extra2_uuid_spec,
168 open_fip
169 },
Juan Castillo3a66aca2015-04-13 17:36:19 +0100170 [BL33_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000171 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100172 (uintptr_t)&bl33_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000173 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100174 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000175 [TB_FW_CONFIG_ID] = {
176 &fip_dev_handle,
177 (uintptr_t)&tb_fw_config_uuid_spec,
178 open_fip
179 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000180 [HW_CONFIG_ID] = {
181 &fip_dev_handle,
182 (uintptr_t)&hw_config_uuid_spec,
183 open_fip
184 },
Soby Mathewb6814842018-04-04 09:40:32 +0100185 [SOC_FW_CONFIG_ID] = {
186 &fip_dev_handle,
187 (uintptr_t)&soc_fw_config_uuid_spec,
188 open_fip
189 },
190 [TOS_FW_CONFIG_ID] = {
191 &fip_dev_handle,
192 (uintptr_t)&tos_fw_config_uuid_spec,
193 open_fip
194 },
195 [NT_FW_CONFIG_ID] = {
196 &fip_dev_handle,
197 (uintptr_t)&nt_fw_config_uuid_spec,
198 open_fip
199 },
Dan Handley9df48042015-03-19 18:58:55 +0000200#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +0000201 [TRUSTED_BOOT_FW_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000202 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000203 (uintptr_t)&tb_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000204 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100205 },
206 [TRUSTED_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000207 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100208 (uintptr_t)&trusted_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000209 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100210 },
Juan Castillobe801202015-12-03 10:19:21 +0000211 [SCP_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000212 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000213 (uintptr_t)&scp_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000214 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100215 },
Juan Castillobe801202015-12-03 10:19:21 +0000216 [SOC_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000217 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000218 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000219 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100220 },
Juan Castillobe801202015-12-03 10:19:21 +0000221 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000222 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000223 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000224 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100225 },
Juan Castillobe801202015-12-03 10:19:21 +0000226 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000227 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000228 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000229 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100230 },
Juan Castillobe801202015-12-03 10:19:21 +0000231 [SCP_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000232 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000233 (uintptr_t)&scp_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000234 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100235 },
Juan Castillobe801202015-12-03 10:19:21 +0000236 [SOC_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000237 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000238 (uintptr_t)&soc_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000239 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100240 },
Juan Castillobe801202015-12-03 10:19:21 +0000241 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000242 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000243 (uintptr_t)&tos_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000244 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100245 },
Juan Castillobe801202015-12-03 10:19:21 +0000246 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000247 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000248 (uintptr_t)&nt_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000249 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100250 },
Dan Handley9df48042015-03-19 18:58:55 +0000251#endif /* TRUSTED_BOARD_BOOT */
Dan Handley9df48042015-03-19 18:58:55 +0000252};
253
254
255/* Weak definitions may be overridden in specific ARM standard platform */
256#pragma weak plat_arm_io_setup
257#pragma weak plat_arm_get_alt_image_source
258
259
260static int open_fip(const uintptr_t spec)
261{
262 int result;
263 uintptr_t local_image_handle;
264
265 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100266 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +0000267 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000268 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000269 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000270 VERBOSE("Using FIP\n");
271 io_close(local_image_handle);
272 }
273 }
274 return result;
275}
276
277
278static int open_memmap(const uintptr_t spec)
279{
280 int result;
281 uintptr_t local_image_handle;
282
283 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000284 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000285 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000286 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000287 VERBOSE("Using Memmap\n");
288 io_close(local_image_handle);
289 }
290 }
291 return result;
292}
293
294
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000295int arm_io_setup(void)
Dan Handley9df48042015-03-19 18:58:55 +0000296{
297 int io_result;
298
299 io_result = register_io_dev_fip(&fip_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000300 if (io_result < 0) {
301 return io_result;
302 }
Dan Handley9df48042015-03-19 18:58:55 +0000303
304 io_result = register_io_dev_memmap(&memmap_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000305 if (io_result < 0) {
306 return io_result;
307 }
Dan Handley9df48042015-03-19 18:58:55 +0000308
309 /* Open connections to devices and cache the handles */
310 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
311 &fip_dev_handle);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000312 if (io_result < 0) {
313 return io_result;
314 }
Dan Handley9df48042015-03-19 18:58:55 +0000315
316 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
317 &memmap_dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000318
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000319 return io_result;
Dan Handley9df48042015-03-19 18:58:55 +0000320}
321
322void plat_arm_io_setup(void)
323{
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000324 int err;
325
326 err = arm_io_setup();
327 if (err < 0) {
328 panic();
329 }
Dan Handley9df48042015-03-19 18:58:55 +0000330}
331
332int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800333 unsigned int image_id __unused,
334 uintptr_t *dev_handle __unused,
335 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000336{
337 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000338 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000339}
340
341/* Return an IO device handle and specification which can be used to access
342 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100343int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000344 uintptr_t *image_spec)
345{
Juan Castillo6e762062015-11-02 10:47:01 +0000346 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000347 const struct plat_io_policy *policy;
348
Juan Castillo3a66aca2015-04-13 17:36:19 +0100349 assert(image_id < ARRAY_SIZE(policies));
350
351 policy = &policies[image_id];
352 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000353 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100354 *image_spec = policy->image_spec;
355 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000356 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100357 VERBOSE("Trying alternative IO\n");
358 result = plat_arm_get_alt_image_source(image_id, dev_handle,
359 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000360 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100361
Dan Handley9df48042015-03-19 18:58:55 +0000362 return result;
363}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100364
365/*
366 * See if a Firmware Image Package is available,
367 * by checking if TOC is valid or not.
368 */
Louis Mayencourt70d7c092020-01-29 11:42:31 +0000369bool arm_io_is_toc_valid(void)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100370{
Louis Mayencourt70d7c092020-01-29 11:42:31 +0000371 return (io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID) == 0);
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100372}
373