blob: 49c6a760ca4fd3458c0fe11d206a253f2c2bfac5 [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +08002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00008#include <string.h>
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <platform_def.h>
11
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <drivers/io/io_driver.h>
15#include <drivers/io/io_fip.h>
16#include <drivers/io/io_memmap.h>
17#include <tools_share/firmware_image_package.h>
18
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000019/* Semihosting filenames */
20#define BL2_IMAGE_NAME "bl2.bin"
21#define BL31_IMAGE_NAME "bl31.bin"
22#define BL32_IMAGE_NAME "bl32.bin"
23#define BL33_IMAGE_NAME "bl33.bin"
24
25#if TRUSTED_BOARD_BOOT
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080026#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000027#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080028#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
29#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
30#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
31#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
32#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
33#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000034#endif /* TRUSTED_BOARD_BOOT */
35
36/* IO devices */
37static const io_dev_connector_t *fip_dev_con;
38static uintptr_t fip_dev_handle;
39static const io_dev_connector_t *memmap_dev_con;
40static uintptr_t memmap_dev_handle;
41
42static const io_block_spec_t fip_block_spec = {
43 .offset = PLAT_RPI3_FIP_BASE,
44 .length = PLAT_RPI3_FIP_MAX_SIZE
45};
46
47static const io_uuid_spec_t bl2_uuid_spec = {
48 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
49};
50
51static const io_uuid_spec_t bl31_uuid_spec = {
52 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
53};
54
55static const io_uuid_spec_t bl32_uuid_spec = {
56 .uuid = UUID_SECURE_PAYLOAD_BL32,
57};
58
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080059static const io_uuid_spec_t bl32_extra1_uuid_spec = {
60 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
61};
62
63static const io_uuid_spec_t bl32_extra2_uuid_spec = {
64 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
65};
66
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000067static const io_uuid_spec_t bl33_uuid_spec = {
68 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
69};
70
71#if TRUSTED_BOARD_BOOT
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080072static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
73 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000074};
75
76static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
77 .uuid = UUID_TRUSTED_KEY_CERT,
78};
79
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080080static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
81 .uuid = UUID_SOC_FW_KEY_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000082};
83
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080084static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
85 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000086};
87
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080088static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
89 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000090};
91
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080092static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
93 .uuid = UUID_SOC_FW_CONTENT_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000094};
95
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +080096static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
97 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000098};
99
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800100static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
101 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000102};
103#endif /* TRUSTED_BOARD_BOOT */
104
105static int open_fip(const uintptr_t spec);
106static int open_memmap(const uintptr_t spec);
107
108struct plat_io_policy {
109 uintptr_t *dev_handle;
110 uintptr_t image_spec;
111 int (*check)(const uintptr_t spec);
112};
113
114/* By default, load images from the FIP */
115static const struct plat_io_policy policies[] = {
116 [FIP_IMAGE_ID] = {
117 &memmap_dev_handle,
118 (uintptr_t)&fip_block_spec,
119 open_memmap
120 },
121 [BL2_IMAGE_ID] = {
122 &fip_dev_handle,
123 (uintptr_t)&bl2_uuid_spec,
124 open_fip
125 },
126 [BL31_IMAGE_ID] = {
127 &fip_dev_handle,
128 (uintptr_t)&bl31_uuid_spec,
129 open_fip
130 },
131 [BL32_IMAGE_ID] = {
132 &fip_dev_handle,
133 (uintptr_t)&bl32_uuid_spec,
134 open_fip
135 },
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800136 [BL32_EXTRA1_IMAGE_ID] = {
137 &fip_dev_handle,
138 (uintptr_t)&bl32_extra1_uuid_spec,
139 open_fip
140 },
141 [BL32_EXTRA2_IMAGE_ID] = {
142 &fip_dev_handle,
143 (uintptr_t)&bl32_extra2_uuid_spec,
144 open_fip
145 },
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000146 [BL33_IMAGE_ID] = {
147 &fip_dev_handle,
148 (uintptr_t)&bl33_uuid_spec,
149 open_fip
150 },
151#if TRUSTED_BOARD_BOOT
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800152 [TRUSTED_BOOT_FW_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000153 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800154 (uintptr_t)&tb_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000155 open_fip
156 },
157 [TRUSTED_KEY_CERT_ID] = {
158 &fip_dev_handle,
159 (uintptr_t)&trusted_key_cert_uuid_spec,
160 open_fip
161 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800162 [SOC_FW_KEY_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000163 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800164 (uintptr_t)&soc_fw_key_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000165 open_fip
166 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800167 [TRUSTED_OS_FW_KEY_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000168 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800169 (uintptr_t)&tos_fw_key_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000170 open_fip
171 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800172 [NON_TRUSTED_FW_KEY_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000173 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800174 (uintptr_t)&nt_fw_key_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000175 open_fip
176 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800177 [SOC_FW_CONTENT_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000178 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800179 (uintptr_t)&soc_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000180 open_fip
181 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800182 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000183 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800184 (uintptr_t)&tos_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000185 open_fip
186 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800187 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000188 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800189 (uintptr_t)&nt_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000190 open_fip
191 },
192#endif /* TRUSTED_BOARD_BOOT */
193};
194
195static int open_fip(const uintptr_t spec)
196{
197 int result;
198 uintptr_t local_image_handle;
199
200 /* See if a Firmware Image Package is available */
201 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
202 if (result == 0) {
203 result = io_open(fip_dev_handle, spec, &local_image_handle);
204 if (result == 0) {
205 VERBOSE("Using FIP\n");
206 io_close(local_image_handle);
207 }
208 }
209 return result;
210}
211
212static int open_memmap(const uintptr_t spec)
213{
214 int result;
215 uintptr_t local_image_handle;
216
217 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
218 if (result == 0) {
219 result = io_open(memmap_dev_handle, spec, &local_image_handle);
220 if (result == 0) {
221 VERBOSE("Using Memmap\n");
222 io_close(local_image_handle);
223 }
224 }
225 return result;
226}
227
228void plat_rpi3_io_setup(void)
229{
230 int io_result;
231
232 io_result = register_io_dev_fip(&fip_dev_con);
233 assert(io_result == 0);
234
235 io_result = register_io_dev_memmap(&memmap_dev_con);
236 assert(io_result == 0);
237
238 /* Open connections to devices and cache the handles */
239 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
240 &fip_dev_handle);
241 assert(io_result == 0);
242
243 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
244 &memmap_dev_handle);
245 assert(io_result == 0);
246
247 /* Ignore improbable errors in release builds */
248 (void)io_result;
249}
250
251/*
252 * Return an IO device handle and specification which can be used to access
253 * an image. Use this to enforce platform load policy
254 */
255int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
256 uintptr_t *image_spec)
257{
258 int result;
259 const struct plat_io_policy *policy;
260
261 assert(image_id < ARRAY_SIZE(policies));
262
263 policy = &policies[image_id];
264 result = policy->check(policy->image_spec);
265 if (result == 0) {
266 *image_spec = policy->image_spec;
267 *dev_handle = *(policy->dev_handle);
268 }
269
270 return result;
271}