blob: d7c5cac2463e9cc3f7106fcf1b131a7aa60429a2 [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 */
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>
18#include <plat/common/platform.h>
19#include <tools_share/firmware_image_package.h>
20
21#include <plat_arm.h>
Dan Handley9df48042015-03-19 18:58:55 +000022
23/* IO devices */
24static const io_dev_connector_t *fip_dev_con;
25static uintptr_t fip_dev_handle;
26static const io_dev_connector_t *memmap_dev_con;
27static uintptr_t memmap_dev_handle;
28
29static const io_block_spec_t fip_block_spec = {
30 .offset = PLAT_ARM_FIP_BASE,
31 .length = PLAT_ARM_FIP_MAX_SIZE
32};
33
Juan Castillo3a66aca2015-04-13 17:36:19 +010034static const io_uuid_spec_t bl2_uuid_spec = {
35 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000036};
37
Juan Castilloa72b6472015-12-10 15:49:17 +000038static const io_uuid_spec_t scp_bl2_uuid_spec = {
39 .uuid = UUID_SCP_FIRMWARE_SCP_BL2,
Dan Handley9df48042015-03-19 18:58:55 +000040};
41
Juan Castillo3a66aca2015-04-13 17:36:19 +010042static const io_uuid_spec_t bl31_uuid_spec = {
43 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
Dan Handley9df48042015-03-19 18:58:55 +000044};
45
Juan Castillo3a66aca2015-04-13 17:36:19 +010046static const io_uuid_spec_t bl32_uuid_spec = {
47 .uuid = UUID_SECURE_PAYLOAD_BL32,
Dan Handley9df48042015-03-19 18:58:55 +000048};
49
Summer Qin80726782017-04-20 16:28:39 +010050static const io_uuid_spec_t bl32_extra1_uuid_spec = {
51 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
52};
53
54static const io_uuid_spec_t bl32_extra2_uuid_spec = {
55 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
56};
57
Juan Castillo3a66aca2015-04-13 17:36:19 +010058static const io_uuid_spec_t bl33_uuid_spec = {
59 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
Dan Handley9df48042015-03-19 18:58:55 +000060};
61
Soby Mathew7c6df5b2018-01-15 14:43:42 +000062static const io_uuid_spec_t tb_fw_config_uuid_spec = {
63 .uuid = UUID_TB_FW_CONFIG,
64};
65
Soby Mathew96a1c6b2018-01-15 14:45:33 +000066static const io_uuid_spec_t hw_config_uuid_spec = {
67 .uuid = UUID_HW_CONFIG,
68};
69
Soby Mathewb6814842018-04-04 09:40:32 +010070static const io_uuid_spec_t soc_fw_config_uuid_spec = {
71 .uuid = UUID_SOC_FW_CONFIG,
72};
73
74static const io_uuid_spec_t tos_fw_config_uuid_spec = {
75 .uuid = UUID_TOS_FW_CONFIG,
76};
77
78static const io_uuid_spec_t nt_fw_config_uuid_spec = {
79 .uuid = UUID_NT_FW_CONFIG,
80};
81
Dan Handley9df48042015-03-19 18:58:55 +000082#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000083static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
84 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Dan Handley9df48042015-03-19 18:58:55 +000085};
86
Juan Castillo3a66aca2015-04-13 17:36:19 +010087static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
88 .uuid = UUID_TRUSTED_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_key_cert_uuid_spec = {
92 .uuid = UUID_SCP_FW_KEY_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_key_cert_uuid_spec = {
96 .uuid = UUID_SOC_FW_KEY_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_key_cert_uuid_spec = {
100 .uuid = UUID_TRUSTED_OS_FW_KEY_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_key_cert_uuid_spec = {
104 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000105};
106
Juan Castillobe801202015-12-03 10:19:21 +0000107static const io_uuid_spec_t scp_fw_cert_uuid_spec = {
108 .uuid = UUID_SCP_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000109};
110
Juan Castillobe801202015-12-03 10:19:21 +0000111static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
112 .uuid = UUID_SOC_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000113};
114
Juan Castillobe801202015-12-03 10:19:21 +0000115static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
116 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000117};
118
Juan Castillobe801202015-12-03 10:19:21 +0000119static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
120 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Dan Handley9df48042015-03-19 18:58:55 +0000121};
122#endif /* TRUSTED_BOARD_BOOT */
123
Juan Castillo3a66aca2015-04-13 17:36:19 +0100124
Dan Handley9df48042015-03-19 18:58:55 +0000125static int open_fip(const uintptr_t spec);
126static int open_memmap(const uintptr_t spec);
127
128struct plat_io_policy {
Dan Handley9df48042015-03-19 18:58:55 +0000129 uintptr_t *dev_handle;
130 uintptr_t image_spec;
131 int (*check)(const uintptr_t spec);
132};
133
Juan Castillo3a66aca2015-04-13 17:36:19 +0100134/* By default, ARM platforms load images from the FIP */
Dan Handley9df48042015-03-19 18:58:55 +0000135static const struct plat_io_policy policies[] = {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100136 [FIP_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000137 &memmap_dev_handle,
138 (uintptr_t)&fip_block_spec,
139 open_memmap
Juan Castillo3a66aca2015-04-13 17:36:19 +0100140 },
141 [BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000142 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100143 (uintptr_t)&bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000144 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100145 },
Juan Castilloa72b6472015-12-10 15:49:17 +0000146 [SCP_BL2_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000147 &fip_dev_handle,
Juan Castilloa72b6472015-12-10 15:49:17 +0000148 (uintptr_t)&scp_bl2_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000149 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100150 },
151 [BL31_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000152 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100153 (uintptr_t)&bl31_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000154 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100155 },
156 [BL32_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000157 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100158 (uintptr_t)&bl32_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000159 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100160 },
Summer Qin80726782017-04-20 16:28:39 +0100161 [BL32_EXTRA1_IMAGE_ID] = {
162 &fip_dev_handle,
163 (uintptr_t)&bl32_extra1_uuid_spec,
164 open_fip
165 },
166 [BL32_EXTRA2_IMAGE_ID] = {
167 &fip_dev_handle,
168 (uintptr_t)&bl32_extra2_uuid_spec,
169 open_fip
170 },
Juan Castillo3a66aca2015-04-13 17:36:19 +0100171 [BL33_IMAGE_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000172 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100173 (uintptr_t)&bl33_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000174 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100175 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000176 [TB_FW_CONFIG_ID] = {
177 &fip_dev_handle,
178 (uintptr_t)&tb_fw_config_uuid_spec,
179 open_fip
180 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000181 [HW_CONFIG_ID] = {
182 &fip_dev_handle,
183 (uintptr_t)&hw_config_uuid_spec,
184 open_fip
185 },
Soby Mathewb6814842018-04-04 09:40:32 +0100186 [SOC_FW_CONFIG_ID] = {
187 &fip_dev_handle,
188 (uintptr_t)&soc_fw_config_uuid_spec,
189 open_fip
190 },
191 [TOS_FW_CONFIG_ID] = {
192 &fip_dev_handle,
193 (uintptr_t)&tos_fw_config_uuid_spec,
194 open_fip
195 },
196 [NT_FW_CONFIG_ID] = {
197 &fip_dev_handle,
198 (uintptr_t)&nt_fw_config_uuid_spec,
199 open_fip
200 },
Dan Handley9df48042015-03-19 18:58:55 +0000201#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +0000202 [TRUSTED_BOOT_FW_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000203 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000204 (uintptr_t)&tb_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000205 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100206 },
207 [TRUSTED_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000208 &fip_dev_handle,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100209 (uintptr_t)&trusted_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000210 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100211 },
Juan Castillobe801202015-12-03 10:19:21 +0000212 [SCP_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000213 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000214 (uintptr_t)&scp_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000215 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100216 },
Juan Castillobe801202015-12-03 10:19:21 +0000217 [SOC_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000218 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000219 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000220 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100221 },
Juan Castillobe801202015-12-03 10:19:21 +0000222 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000223 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000224 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000225 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100226 },
Juan Castillobe801202015-12-03 10:19:21 +0000227 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000228 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000229 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000230 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100231 },
Juan Castillobe801202015-12-03 10:19:21 +0000232 [SCP_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000233 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000234 (uintptr_t)&scp_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000235 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100236 },
Juan Castillobe801202015-12-03 10:19:21 +0000237 [SOC_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000238 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000239 (uintptr_t)&soc_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000240 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100241 },
Juan Castillobe801202015-12-03 10:19:21 +0000242 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000243 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000244 (uintptr_t)&tos_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000245 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100246 },
Juan Castillobe801202015-12-03 10:19:21 +0000247 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Dan Handley9df48042015-03-19 18:58:55 +0000248 &fip_dev_handle,
Juan Castillobe801202015-12-03 10:19:21 +0000249 (uintptr_t)&nt_fw_cert_uuid_spec,
Dan Handley9df48042015-03-19 18:58:55 +0000250 open_fip
Juan Castillo3a66aca2015-04-13 17:36:19 +0100251 },
Dan Handley9df48042015-03-19 18:58:55 +0000252#endif /* TRUSTED_BOARD_BOOT */
Dan Handley9df48042015-03-19 18:58:55 +0000253};
254
255
256/* Weak definitions may be overridden in specific ARM standard platform */
257#pragma weak plat_arm_io_setup
258#pragma weak plat_arm_get_alt_image_source
259
260
261static int open_fip(const uintptr_t spec)
262{
263 int result;
264 uintptr_t local_image_handle;
265
266 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100267 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +0000268 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000269 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000270 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000271 VERBOSE("Using FIP\n");
272 io_close(local_image_handle);
273 }
274 }
275 return result;
276}
277
278
279static int open_memmap(const uintptr_t spec)
280{
281 int result;
282 uintptr_t local_image_handle;
283
284 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000285 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000286 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000287 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +0000288 VERBOSE("Using Memmap\n");
289 io_close(local_image_handle);
290 }
291 }
292 return result;
293}
294
295
296void arm_io_setup(void)
297{
298 int io_result;
299
300 io_result = register_io_dev_fip(&fip_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000301 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000302
303 io_result = register_io_dev_memmap(&memmap_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000304 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000305
306 /* Open connections to devices and cache the handles */
307 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
308 &fip_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000309 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000310
311 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
312 &memmap_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000313 assert(io_result == 0);
Dan Handley9df48042015-03-19 18:58:55 +0000314
315 /* Ignore improbable errors in release builds */
316 (void)io_result;
317}
318
319void plat_arm_io_setup(void)
320{
321 arm_io_setup();
322}
323
324int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800325 unsigned int image_id __unused,
326 uintptr_t *dev_handle __unused,
327 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000328{
329 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000330 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000331}
332
333/* Return an IO device handle and specification which can be used to access
334 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100335int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000336 uintptr_t *image_spec)
337{
Juan Castillo6e762062015-11-02 10:47:01 +0000338 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000339 const struct plat_io_policy *policy;
340
Juan Castillo3a66aca2015-04-13 17:36:19 +0100341 assert(image_id < ARRAY_SIZE(policies));
342
343 policy = &policies[image_id];
344 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000345 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100346 *image_spec = policy->image_spec;
347 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000348 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100349 VERBOSE("Trying alternative IO\n");
350 result = plat_arm_get_alt_image_source(image_id, dev_handle,
351 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000352 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100353
Dan Handley9df48042015-03-19 18:58:55 +0000354 return result;
355}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100356
357/*
358 * See if a Firmware Image Package is available,
359 * by checking if TOC is valid or not.
360 */
361int arm_io_is_toc_valid(void)
362{
363 int result;
364
365 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
366
367 return (result == 0);
368}
369