blob: 7e66deb72e1b2ca8d61ad34d4b3ab44abbd93718 [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_IMAGE_ID] = {
137 &fip_dev_handle,
138 (uintptr_t)&bl32_uuid_spec,
139 open_fip
140 },
141 [BL32_EXTRA1_IMAGE_ID] = {
142 &fip_dev_handle,
143 (uintptr_t)&bl32_extra1_uuid_spec,
144 open_fip
145 },
146 [BL32_EXTRA2_IMAGE_ID] = {
147 &fip_dev_handle,
148 (uintptr_t)&bl32_extra2_uuid_spec,
149 open_fip
150 },
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000151 [BL33_IMAGE_ID] = {
152 &fip_dev_handle,
153 (uintptr_t)&bl33_uuid_spec,
154 open_fip
155 },
156#if TRUSTED_BOARD_BOOT
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800157 [TRUSTED_BOOT_FW_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000158 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800159 (uintptr_t)&tb_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000160 open_fip
161 },
162 [TRUSTED_KEY_CERT_ID] = {
163 &fip_dev_handle,
164 (uintptr_t)&trusted_key_cert_uuid_spec,
165 open_fip
166 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800167 [SOC_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)&soc_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 [TRUSTED_OS_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)&tos_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 [NON_TRUSTED_FW_KEY_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)&nt_fw_key_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 [SOC_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)&soc_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 [TRUSTED_OS_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)&tos_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000190 open_fip
191 },
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800192 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000193 &fip_dev_handle,
Ying-Chun Liu (PaulLiu)9128df62018-07-04 02:26:48 +0800194 (uintptr_t)&nt_fw_cert_uuid_spec,
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000195 open_fip
196 },
197#endif /* TRUSTED_BOARD_BOOT */
198};
199
200static int open_fip(const uintptr_t spec)
201{
202 int result;
203 uintptr_t local_image_handle;
204
205 /* See if a Firmware Image Package is available */
206 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
207 if (result == 0) {
208 result = io_open(fip_dev_handle, spec, &local_image_handle);
209 if (result == 0) {
210 VERBOSE("Using FIP\n");
211 io_close(local_image_handle);
212 }
213 }
214 return result;
215}
216
217static int open_memmap(const uintptr_t spec)
218{
219 int result;
220 uintptr_t local_image_handle;
221
222 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
223 if (result == 0) {
224 result = io_open(memmap_dev_handle, spec, &local_image_handle);
225 if (result == 0) {
226 VERBOSE("Using Memmap\n");
227 io_close(local_image_handle);
228 }
229 }
230 return result;
231}
232
233void plat_rpi3_io_setup(void)
234{
235 int io_result;
236
237 io_result = register_io_dev_fip(&fip_dev_con);
238 assert(io_result == 0);
239
240 io_result = register_io_dev_memmap(&memmap_dev_con);
241 assert(io_result == 0);
242
243 /* Open connections to devices and cache the handles */
244 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
245 &fip_dev_handle);
246 assert(io_result == 0);
247
248 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
249 &memmap_dev_handle);
250 assert(io_result == 0);
251
252 /* Ignore improbable errors in release builds */
253 (void)io_result;
254}
255
256/*
257 * Return an IO device handle and specification which can be used to access
258 * an image. Use this to enforce platform load policy
259 */
260int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
261 uintptr_t *image_spec)
262{
263 int result;
264 const struct plat_io_policy *policy;
265
266 assert(image_id < ARRAY_SIZE(policies));
267
268 policy = &policies[image_id];
269 result = policy->check(policy->image_spec);
270 if (result == 0) {
271 *image_spec = policy->image_spec;
272 *dev_handle = *(policy->dev_handle);
273 }
274
275 return result;
276}