blob: 652f5e95eeb2696eca26901d2bf9b01d6919d997 [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>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000013#include <plat_arm.h>
14#include <platform.h>
Dan Handley9df48042015-03-19 18:58:55 +000015#include <platform_def.h>
Dan Handley9df48042015-03-19 18:58:55 +000016#include <string.h>
Sandrine Bailleux7659a262016-07-05 09:55:03 +010017#include <utils.h>
Dan Handley9df48042015-03-19 18:58:55 +000018
19/* IO devices */
20static const io_dev_connector_t *fip_dev_con;
21static uintptr_t fip_dev_handle;
22static const io_dev_connector_t *memmap_dev_con;
23static uintptr_t memmap_dev_handle;
24
25static const io_block_spec_t fip_block_spec = {
26 .offset = PLAT_ARM_FIP_BASE,
27 .length = PLAT_ARM_FIP_MAX_SIZE
28};
29
Juan Castillo3a66aca2015-04-13 17:36:19 +010030static const io_uuid_spec_t bl2_uuid_spec = {
31 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000032};
33
Juan Castilloa72b6472015-12-10 15:49:17 +000034static const io_uuid_spec_t scp_bl2_uuid_spec = {
35 .uuid = UUID_SCP_FIRMWARE_SCP_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000036};
37
Juan Castillo3a66aca2015-04-13 17:36:19 +010038static const io_uuid_spec_t bl31_uuid_spec = {
39 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
Dan Handley9df48042015-03-19 18:58:55 +000040};
41
Juan Castillo3a66aca2015-04-13 17:36:19 +010042static const io_uuid_spec_t bl32_uuid_spec = {
43 .uuid = UUID_SECURE_PAYLOAD_BL32,
Dan Handley9df48042015-03-19 18:58:55 +000044};
45
Summer Qin80726782017-04-20 16:28:39 +010046static const io_uuid_spec_t bl32_extra1_uuid_spec = {
47 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
48};
49
50static const io_uuid_spec_t bl32_extra2_uuid_spec = {
51 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
52};
53
Juan Castillo3a66aca2015-04-13 17:36:19 +010054static const io_uuid_spec_t bl33_uuid_spec = {
55 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
Dan Handley9df48042015-03-19 18:58:55 +000056};
57
Soby Mathew7c6df5b2018-01-15 14:43:42 +000058static const io_uuid_spec_t tb_fw_config_uuid_spec = {
59 .uuid = UUID_TB_FW_CONFIG,
60};
61
Soby Mathew96a1c6b2018-01-15 14:45:33 +000062static const io_uuid_spec_t hw_config_uuid_spec = {
63 .uuid = UUID_HW_CONFIG,
64};
65
Dan Handley9df48042015-03-19 18:58:55 +000066#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000067static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
68 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000069};
70
Juan Castillo3a66aca2015-04-13 17:36:19 +010071static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
72 .uuid = UUID_TRUSTED_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000073};
74
Juan Castillobe801202015-12-03 10:19:21 +000075static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = {
76 .uuid = UUID_SCP_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000077};
78
Juan Castillobe801202015-12-03 10:19:21 +000079static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
80 .uuid = UUID_SOC_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000081};
82
Juan Castillobe801202015-12-03 10:19:21 +000083static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
84 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000085};
86
Juan Castillobe801202015-12-03 10:19:21 +000087static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
88 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000089};
90
Juan Castillobe801202015-12-03 10:19:21 +000091static const io_uuid_spec_t scp_fw_cert_uuid_spec = {
92 .uuid = UUID_SCP_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000093};
94
Juan Castillobe801202015-12-03 10:19:21 +000095static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
96 .uuid = UUID_SOC_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000097};
98
Juan Castillobe801202015-12-03 10:19:21 +000099static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
100 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000101};
102
Juan Castillobe801202015-12-03 10:19:21 +0000103static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
104 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000105};
106#endif /* TRUSTED_BOARD_BOOT */
107
Juan Castillo3a66aca2015-04-13 17:36:19 +0100108
Dan Handley9df48042015-03-19 18:58:55 +0000109static int open_fip(const uintptr_t spec);
110static int open_memmap(const uintptr_t spec);
111
112struct plat_io_policy {
Dan Handley9df48042015-03-19 18:58:55 +0000113 uintptr_t *dev_handle;
114 uintptr_t image_spec;
115 int (*check)(const uintptr_t spec);
116};
117
Juan Castillo3a66aca2015-04-13 17:36:19 +0100118/* By default, ARM platforms load images from the FIP */
Dan Handley9df48042015-03-19 18:58:55 +0000119static const struct plat_io_policy policies[] = {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100120 [FIP_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000121 &memmap_dev_handle,
122 (uintptr_t)&fip_block_spec,
123 open_memmap
Juan Castillo3a66aca2015-04-13 17:36:19 +0100124 },
125 [BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000126 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100127 (uintptr_t)&bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000128 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100129 },
Juan Castilloa72b6472015-12-10 15:49:17 +0000130 [SCP_BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000131 &fip_dev_handle,
Juan Castilloa72b6472015-12-10 15:49:17 +0000132 (uintptr_t)&scp_bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000133 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100134 },
135 [BL31_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000136 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100137 (uintptr_t)&bl31_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000138 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100139 },
140 [BL32_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000141 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100142 (uintptr_t)&bl32_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000143 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100144 },
Summer Qin80726782017-04-20 16:28:39 +0100145 [BL32_EXTRA1_IMAGE_ID] = {
146 &fip_dev_handle,
147 (uintptr_t)&bl32_extra1_uuid_spec,
148 open_fip
149 },
150 [BL32_EXTRA2_IMAGE_ID] = {
151 &fip_dev_handle,
152 (uintptr_t)&bl32_extra2_uuid_spec,
153 open_fip
154 },
Juan Castillo3a66aca2015-04-13 17:36:19 +0100155 [BL33_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000156 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100157 (uintptr_t)&bl33_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000158 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100159 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000160 [TB_FW_CONFIG_ID] = {
161 &fip_dev_handle,
162 (uintptr_t)&tb_fw_config_uuid_spec,
163 open_fip
164 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000165 [HW_CONFIG_ID] = {
166 &fip_dev_handle,
167 (uintptr_t)&hw_config_uuid_spec,
168 open_fip
169 },
Dan Handley9df48042015-03-19 18:58:55 +0000170#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +0000171 [TRUSTED_BOOT_FW_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000172 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000173 (uintptr_t)&tb_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000174 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100175 },
176 [TRUSTED_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000177 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100178 (uintptr_t)&trusted_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000179 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100180 },
Juan Castillobe801202015-12-03 10:19:21 +0000181 [SCP_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000182 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000183 (uintptr_t)&scp_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000184 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100185 },
Juan Castillobe801202015-12-03 10:19:21 +0000186 [SOC_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000187 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000188 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000189 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100190 },
Juan Castillobe801202015-12-03 10:19:21 +0000191 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000192 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000193 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000194 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100195 },
Juan Castillobe801202015-12-03 10:19:21 +0000196 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000197 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000198 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000199 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100200 },
Juan Castillobe801202015-12-03 10:19:21 +0000201 [SCP_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000202 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000203 (uintptr_t)&scp_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000204 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100205 },
Juan Castillobe801202015-12-03 10:19:21 +0000206 [SOC_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000207 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000208 (uintptr_t)&soc_fw_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 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000212 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000213 (uintptr_t)&tos_fw_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 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000217 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000218 (uintptr_t)&nt_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000219 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100220 },
Dan Handley9df48042015-03-19 18:58:55 +0000221#endif /* TRUSTED_BOARD_BOOT */
Dan Handley9df48042015-03-19 18:58:55 +0000222};
223
224
225/* Weak definitions may be overridden in specific ARM standard platform */
226#pragma weak plat_arm_io_setup
227#pragma weak plat_arm_get_alt_image_source
228
229
230static int open_fip(const uintptr_t spec)
231{
232 int result;
233 uintptr_t local_image_handle;
234
235 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100236 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +0000237 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000238 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000239 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000240 VERBOSE("Using FIP\n");
241 io_close(local_image_handle);
242 }
243 }
244 return result;
245}
246
247
248static int open_memmap(const uintptr_t spec)
249{
250 int result;
251 uintptr_t local_image_handle;
252
253 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000254 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000255 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000256 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000257 VERBOSE("Using Memmap\n");
258 io_close(local_image_handle);
259 }
260 }
261 return result;
262}
263
264
265void arm_io_setup(void)
266{
267 int io_result;
268
269 io_result = register_io_dev_fip(&fip_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000270 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000271
272 io_result = register_io_dev_memmap(&memmap_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000273 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000274
275 /* Open connections to devices and cache the handles */
276 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
277 &fip_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000278 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000279
280 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
281 &memmap_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000282 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000283
284 /* Ignore improbable errors in release builds */
285 (void)io_result;
286}
287
288void plat_arm_io_setup(void)
289{
290 arm_io_setup();
291}
292
293int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800294 unsigned int image_id __unused,
295 uintptr_t *dev_handle __unused,
296 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000297{
298 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000299 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000300}
301
302/* Return an IO device handle and specification which can be used to access
303 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100304int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000305 uintptr_t *image_spec)
306{
Juan Castillo6e762062015-11-02 10:47:01 +0000307 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000308 const struct plat_io_policy *policy;
309
Juan Castillo3a66aca2015-04-13 17:36:19 +0100310 assert(image_id < ARRAY_SIZE(policies));
311
312 policy = &policies[image_id];
313 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000314 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100315 *image_spec = policy->image_spec;
316 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000317 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100318 VERBOSE("Trying alternative IO\n");
319 result = plat_arm_get_alt_image_source(image_id, dev_handle,
320 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000321 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100322
Dan Handley9df48042015-03-19 18:58:55 +0000323 return result;
324}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100325
326/*
327 * See if a Firmware Image Package is available,
328 * by checking if TOC is valid or not.
329 */
330int arm_io_is_toc_valid(void)
331{
332 int result;
333
334 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
335
336 return (result == 0);
337}
338