blob: 6d8f20953b178aeb1c45a2a7e053a35b63b5fded [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
Dan Handley9df48042015-03-19 18:58:55 +000060#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000061static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
62 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000063};
64
Juan Castillo3a66aca2015-04-13 17:36:19 +010065static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
66 .uuid = UUID_TRUSTED_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000067};
68
Juan Castillobe801202015-12-03 10:19:21 +000069static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = {
70 .uuid = UUID_SCP_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000071};
72
Juan Castillobe801202015-12-03 10:19:21 +000073static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
74 .uuid = UUID_SOC_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 tos_fw_key_cert_uuid_spec = {
78 .uuid = UUID_TRUSTED_OS_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 nt_fw_key_cert_uuid_spec = {
82 .uuid = UUID_NON_TRUSTED_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 scp_fw_cert_uuid_spec = {
86 .uuid = UUID_SCP_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000087};
88
Juan Castillobe801202015-12-03 10:19:21 +000089static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
90 .uuid = UUID_SOC_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 tos_fw_cert_uuid_spec = {
94 .uuid = UUID_TRUSTED_OS_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 nt_fw_cert_uuid_spec = {
98 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000099};
100#endif /* TRUSTED_BOARD_BOOT */
101
Juan Castillo3a66aca2015-04-13 17:36:19 +0100102
Dan Handley9df48042015-03-19 18:58:55 +0000103static int open_fip(const uintptr_t spec);
104static int open_memmap(const uintptr_t spec);
105
106struct plat_io_policy {
Dan Handley9df48042015-03-19 18:58:55 +0000107 uintptr_t *dev_handle;
108 uintptr_t image_spec;
109 int (*check)(const uintptr_t spec);
110};
111
Juan Castillo3a66aca2015-04-13 17:36:19 +0100112/* By default, ARM platforms load images from the FIP */
Dan Handley9df48042015-03-19 18:58:55 +0000113static const struct plat_io_policy policies[] = {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100114 [FIP_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000115 &memmap_dev_handle,
116 (uintptr_t)&fip_block_spec,
117 open_memmap
Juan Castillo3a66aca2015-04-13 17:36:19 +0100118 },
119 [BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000120 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100121 (uintptr_t)&bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000122 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100123 },
Juan Castilloa72b6472015-12-10 15:49:17 +0000124 [SCP_BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000125 &fip_dev_handle,
Juan Castilloa72b6472015-12-10 15:49:17 +0000126 (uintptr_t)&scp_bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000127 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100128 },
129 [BL31_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000130 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100131 (uintptr_t)&bl31_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000132 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100133 },
134 [BL32_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000135 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100136 (uintptr_t)&bl32_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000137 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100138 },
Summer Qin80726782017-04-20 16:28:39 +0100139 [BL32_EXTRA1_IMAGE_ID] = {
140 &fip_dev_handle,
141 (uintptr_t)&bl32_extra1_uuid_spec,
142 open_fip
143 },
144 [BL32_EXTRA2_IMAGE_ID] = {
145 &fip_dev_handle,
146 (uintptr_t)&bl32_extra2_uuid_spec,
147 open_fip
148 },
Juan Castillo3a66aca2015-04-13 17:36:19 +0100149 [BL33_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000150 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100151 (uintptr_t)&bl33_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000152 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100153 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000154 [TB_FW_CONFIG_ID] = {
155 &fip_dev_handle,
156 (uintptr_t)&tb_fw_config_uuid_spec,
157 open_fip
158 },
Dan Handley9df48042015-03-19 18:58:55 +0000159#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +0000160 [TRUSTED_BOOT_FW_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000161 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000162 (uintptr_t)&tb_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000163 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100164 },
165 [TRUSTED_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000166 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100167 (uintptr_t)&trusted_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000168 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100169 },
Juan Castillobe801202015-12-03 10:19:21 +0000170 [SCP_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000171 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000172 (uintptr_t)&scp_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000173 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100174 },
Juan Castillobe801202015-12-03 10:19:21 +0000175 [SOC_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000176 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000177 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000178 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100179 },
Juan Castillobe801202015-12-03 10:19:21 +0000180 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000181 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000182 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000183 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100184 },
Juan Castillobe801202015-12-03 10:19:21 +0000185 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000186 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000187 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000188 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100189 },
Juan Castillobe801202015-12-03 10:19:21 +0000190 [SCP_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000191 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000192 (uintptr_t)&scp_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000193 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100194 },
Juan Castillobe801202015-12-03 10:19:21 +0000195 [SOC_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000196 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000197 (uintptr_t)&soc_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000198 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100199 },
Juan Castillobe801202015-12-03 10:19:21 +0000200 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000201 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000202 (uintptr_t)&tos_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000203 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100204 },
Juan Castillobe801202015-12-03 10:19:21 +0000205 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000206 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000207 (uintptr_t)&nt_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000208 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100209 },
Dan Handley9df48042015-03-19 18:58:55 +0000210#endif /* TRUSTED_BOARD_BOOT */
Dan Handley9df48042015-03-19 18:58:55 +0000211};
212
213
214/* Weak definitions may be overridden in specific ARM standard platform */
215#pragma weak plat_arm_io_setup
216#pragma weak plat_arm_get_alt_image_source
217
218
219static int open_fip(const uintptr_t spec)
220{
221 int result;
222 uintptr_t local_image_handle;
223
224 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100225 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +0000226 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000227 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000228 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000229 VERBOSE("Using FIP\n");
230 io_close(local_image_handle);
231 }
232 }
233 return result;
234}
235
236
237static int open_memmap(const uintptr_t spec)
238{
239 int result;
240 uintptr_t local_image_handle;
241
242 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000243 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000244 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000245 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000246 VERBOSE("Using Memmap\n");
247 io_close(local_image_handle);
248 }
249 }
250 return result;
251}
252
253
254void arm_io_setup(void)
255{
256 int io_result;
257
258 io_result = register_io_dev_fip(&fip_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000259 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000260
261 io_result = register_io_dev_memmap(&memmap_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000262 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000263
264 /* Open connections to devices and cache the handles */
265 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
266 &fip_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000267 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000268
269 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
270 &memmap_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000271 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000272
273 /* Ignore improbable errors in release builds */
274 (void)io_result;
275}
276
277void plat_arm_io_setup(void)
278{
279 arm_io_setup();
280}
281
282int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800283 unsigned int image_id __unused,
284 uintptr_t *dev_handle __unused,
285 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000286{
287 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000288 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000289}
290
291/* Return an IO device handle and specification which can be used to access
292 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100293int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000294 uintptr_t *image_spec)
295{
Juan Castillo6e762062015-11-02 10:47:01 +0000296 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000297 const struct plat_io_policy *policy;
298
Juan Castillo3a66aca2015-04-13 17:36:19 +0100299 assert(image_id < ARRAY_SIZE(policies));
300
301 policy = &policies[image_id];
302 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000303 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100304 *image_spec = policy->image_spec;
305 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000306 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100307 VERBOSE("Trying alternative IO\n");
308 result = plat_arm_get_alt_image_source(image_id, dev_handle,
309 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000310 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100311
Dan Handley9df48042015-03-19 18:58:55 +0000312 return result;
313}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100314
315/*
316 * See if a Firmware Image Package is available,
317 * by checking if TOC is valid or not.
318 */
319int arm_io_is_toc_valid(void)
320{
321 int result;
322
323 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
324
325 return (result == 0);
326}
327