blob: 5cabc54657b4aed44c18bfe486152506c16f6a0c [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Soby Mathew7c6df5b2018-01-15 14:43:42 +00002 * Copyright (c) 2015-2018, 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 */
6#include <assert.h>
7#include <debug.h>
Juan Castillo3a66aca2015-04-13 17:36:19 +01008#include <firmware_image_package.h>
Dan Handley9df48042015-03-19 18:58:55 +00009#include <io_driver.h>
10#include <io_fip.h>
11#include <io_memmap.h>
12#include <io_storage.h>
13#include <platform_def.h>
Dan Handley9df48042015-03-19 18:58:55 +000014#include <string.h>
Sandrine Bailleux7659a262016-07-05 09:55:03 +010015#include <utils.h>
Dan Handley9df48042015-03-19 18:58:55 +000016
17/* IO devices */
18static const io_dev_connector_t *fip_dev_con;
19static uintptr_t fip_dev_handle;
20static const io_dev_connector_t *memmap_dev_con;
21static uintptr_t memmap_dev_handle;
22
23static const io_block_spec_t fip_block_spec = {
24 .offset = PLAT_ARM_FIP_BASE,
25 .length = PLAT_ARM_FIP_MAX_SIZE
26};
27
Juan Castillo3a66aca2015-04-13 17:36:19 +010028static const io_uuid_spec_t bl2_uuid_spec = {
29 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000030};
31
Juan Castilloa72b6472015-12-10 15:49:17 +000032static const io_uuid_spec_t scp_bl2_uuid_spec = {
33 .uuid = UUID_SCP_FIRMWARE_SCP_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000034};
35
Juan Castillo3a66aca2015-04-13 17:36:19 +010036static const io_uuid_spec_t bl31_uuid_spec = {
37 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
Dan Handley9df48042015-03-19 18:58:55 +000038};
39
Juan Castillo3a66aca2015-04-13 17:36:19 +010040static const io_uuid_spec_t bl32_uuid_spec = {
41 .uuid = UUID_SECURE_PAYLOAD_BL32,
Dan Handley9df48042015-03-19 18:58:55 +000042};
43
Summer Qin80726782017-04-20 16:28:39 +010044static const io_uuid_spec_t bl32_extra1_uuid_spec = {
45 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
46};
47
48static const io_uuid_spec_t bl32_extra2_uuid_spec = {
49 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
50};
51
Juan Castillo3a66aca2015-04-13 17:36:19 +010052static const io_uuid_spec_t bl33_uuid_spec = {
53 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
Dan Handley9df48042015-03-19 18:58:55 +000054};
55
Soby Mathew7c6df5b2018-01-15 14:43:42 +000056static const io_uuid_spec_t tb_fw_config_uuid_spec = {
57 .uuid = UUID_TB_FW_CONFIG,
58};
59
Soby Mathew96a1c6b2018-01-15 14:45:33 +000060static const io_uuid_spec_t hw_config_uuid_spec = {
61 .uuid = UUID_HW_CONFIG,
62};
63
Dan Handley9df48042015-03-19 18:58:55 +000064#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000065static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
66 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000067};
68
Juan Castillo3a66aca2015-04-13 17:36:19 +010069static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
70 .uuid = UUID_TRUSTED_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000071};
72
Juan Castillobe801202015-12-03 10:19:21 +000073static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = {
74 .uuid = UUID_SCP_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000075};
76
Juan Castillobe801202015-12-03 10:19:21 +000077static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
78 .uuid = UUID_SOC_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000079};
80
Juan Castillobe801202015-12-03 10:19:21 +000081static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
82 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000083};
84
Juan Castillobe801202015-12-03 10:19:21 +000085static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
86 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000087};
88
Juan Castillobe801202015-12-03 10:19:21 +000089static const io_uuid_spec_t scp_fw_cert_uuid_spec = {
90 .uuid = UUID_SCP_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000091};
92
Juan Castillobe801202015-12-03 10:19:21 +000093static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
94 .uuid = UUID_SOC_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000095};
96
Juan Castillobe801202015-12-03 10:19:21 +000097static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
98 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000099};
100
Juan Castillobe801202015-12-03 10:19:21 +0000101static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
102 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000103};
104#endif /* TRUSTED_BOARD_BOOT */
105
Juan Castillo3a66aca2015-04-13 17:36:19 +0100106
Dan Handley9df48042015-03-19 18:58:55 +0000107static int open_fip(const uintptr_t spec);
108static int open_memmap(const uintptr_t spec);
109
110struct plat_io_policy {
Dan Handley9df48042015-03-19 18:58:55 +0000111 uintptr_t *dev_handle;
112 uintptr_t image_spec;
113 int (*check)(const uintptr_t spec);
114};
115
Juan Castillo3a66aca2015-04-13 17:36:19 +0100116/* By default, ARM platforms load images from the FIP */
Dan Handley9df48042015-03-19 18:58:55 +0000117static const struct plat_io_policy policies[] = {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100118 [FIP_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000119 &memmap_dev_handle,
120 (uintptr_t)&fip_block_spec,
121 open_memmap
Juan Castillo3a66aca2015-04-13 17:36:19 +0100122 },
123 [BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000124 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100125 (uintptr_t)&bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000126 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100127 },
Juan Castilloa72b6472015-12-10 15:49:17 +0000128 [SCP_BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000129 &fip_dev_handle,
Juan Castilloa72b6472015-12-10 15:49:17 +0000130 (uintptr_t)&scp_bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000131 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100132 },
133 [BL31_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000134 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100135 (uintptr_t)&bl31_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000136 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100137 },
138 [BL32_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000139 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100140 (uintptr_t)&bl32_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000141 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100142 },
Summer Qin80726782017-04-20 16:28:39 +0100143 [BL32_EXTRA1_IMAGE_ID] = {
144 &fip_dev_handle,
145 (uintptr_t)&bl32_extra1_uuid_spec,
146 open_fip
147 },
148 [BL32_EXTRA2_IMAGE_ID] = {
149 &fip_dev_handle,
150 (uintptr_t)&bl32_extra2_uuid_spec,
151 open_fip
152 },
Juan Castillo3a66aca2015-04-13 17:36:19 +0100153 [BL33_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000154 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100155 (uintptr_t)&bl33_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000156 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100157 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000158 [TB_FW_CONFIG_ID] = {
159 &fip_dev_handle,
160 (uintptr_t)&tb_fw_config_uuid_spec,
161 open_fip
162 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000163 [HW_CONFIG_ID] = {
164 &fip_dev_handle,
165 (uintptr_t)&hw_config_uuid_spec,
166 open_fip
167 },
Dan Handley9df48042015-03-19 18:58:55 +0000168#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +0000169 [TRUSTED_BOOT_FW_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000170 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000171 (uintptr_t)&tb_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000172 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100173 },
174 [TRUSTED_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000175 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100176 (uintptr_t)&trusted_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000177 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100178 },
Juan Castillobe801202015-12-03 10:19:21 +0000179 [SCP_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000180 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000181 (uintptr_t)&scp_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000182 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100183 },
Juan Castillobe801202015-12-03 10:19:21 +0000184 [SOC_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000185 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000186 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000187 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100188 },
Juan Castillobe801202015-12-03 10:19:21 +0000189 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000190 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000191 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000192 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100193 },
Juan Castillobe801202015-12-03 10:19:21 +0000194 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000195 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000196 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000197 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100198 },
Juan Castillobe801202015-12-03 10:19:21 +0000199 [SCP_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000200 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000201 (uintptr_t)&scp_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000202 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100203 },
Juan Castillobe801202015-12-03 10:19:21 +0000204 [SOC_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000205 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000206 (uintptr_t)&soc_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000207 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100208 },
Juan Castillobe801202015-12-03 10:19:21 +0000209 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000210 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000211 (uintptr_t)&tos_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000212 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100213 },
Juan Castillobe801202015-12-03 10:19:21 +0000214 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000215 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000216 (uintptr_t)&nt_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000217 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100218 },
Dan Handley9df48042015-03-19 18:58:55 +0000219#endif /* TRUSTED_BOARD_BOOT */
Dan Handley9df48042015-03-19 18:58:55 +0000220};
221
222
223/* Weak definitions may be overridden in specific ARM standard platform */
224#pragma weak plat_arm_io_setup
225#pragma weak plat_arm_get_alt_image_source
226
227
228static int open_fip(const uintptr_t spec)
229{
230 int result;
231 uintptr_t local_image_handle;
232
233 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100234 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +0000235 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000236 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000237 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000238 VERBOSE("Using FIP\n");
239 io_close(local_image_handle);
240 }
241 }
242 return result;
243}
244
245
246static int open_memmap(const uintptr_t spec)
247{
248 int result;
249 uintptr_t local_image_handle;
250
251 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000252 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000253 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000254 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000255 VERBOSE("Using Memmap\n");
256 io_close(local_image_handle);
257 }
258 }
259 return result;
260}
261
262
263void arm_io_setup(void)
264{
265 int io_result;
266
267 io_result = register_io_dev_fip(&fip_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000268 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000269
270 io_result = register_io_dev_memmap(&memmap_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000271 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000272
273 /* Open connections to devices and cache the handles */
274 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
275 &fip_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000276 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000277
278 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
279 &memmap_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000280 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000281
282 /* Ignore improbable errors in release builds */
283 (void)io_result;
284}
285
286void plat_arm_io_setup(void)
287{
288 arm_io_setup();
289}
290
291int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800292 unsigned int image_id __unused,
293 uintptr_t *dev_handle __unused,
294 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000295{
296 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000297 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000298}
299
300/* Return an IO device handle and specification which can be used to access
301 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100302int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000303 uintptr_t *image_spec)
304{
Juan Castillo6e762062015-11-02 10:47:01 +0000305 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000306 const struct plat_io_policy *policy;
307
Juan Castillo3a66aca2015-04-13 17:36:19 +0100308 assert(image_id < ARRAY_SIZE(policies));
309
310 policy = &policies[image_id];
311 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000312 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100313 *image_spec = policy->image_spec;
314 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000315 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100316 VERBOSE("Trying alternative IO\n");
317 result = plat_arm_get_alt_image_source(image_id, dev_handle,
318 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000319 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100320
Dan Handley9df48042015-03-19 18:58:55 +0000321 return result;
322}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100323
324/*
325 * See if a Firmware Image Package is available,
326 * by checking if TOC is valid or not.
327 */
328int arm_io_is_toc_valid(void)
329{
330 int result;
331
332 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
333
334 return (result == 0);
335}
336