blob: ff6687e1348c21e4b3bca4bca87351a73f336392 [file] [log] [blame]
Ying-Chun Liu (PaulLiu)a9c4e022019-04-17 16:09:26 +01001/*
2 * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8
9#include <drivers/io/io_block.h>
10#include <drivers/io/io_driver.h>
11#include <drivers/io/io_fip.h>
12#include <drivers/io/io_driver.h>
13#include <drivers/io/io_memmap.h>
14#include <drivers/mmc.h>
15#include <lib/utils_def.h>
16#include <tbbr_img_def.h>
17#include <tools_share/firmware_image_package.h>
18
19#include <platform_def.h>
20
21static const io_dev_connector_t *fip_dev_con;
22static uintptr_t fip_dev_handle;
23
24#ifndef IMX8MM_FIP_MMAP
25static const io_dev_connector_t *mmc_dev_con;
26static uintptr_t mmc_dev_handle;
27
28static const io_block_spec_t mmc_fip_spec = {
29 .offset = IMX8MM_FIP_MMC_BASE,
30 .length = IMX8MM_FIP_SIZE
31};
32
33static const io_block_dev_spec_t mmc_dev_spec = {
34 /* It's used as temp buffer in block driver. */
35 .buffer = {
36 .offset = IMX8MM_FIP_BASE,
37 /* do we need a new value? */
38 .length = IMX8MM_FIP_SIZE
39 },
40 .ops = {
41 .read = mmc_read_blocks,
42 .write = mmc_write_blocks,
43 },
44 .block_size = MMC_BLOCK_SIZE,
45};
46
47static int open_mmc(const uintptr_t spec);
48
49#else
50static const io_dev_connector_t *memmap_dev_con;
51static uintptr_t memmap_dev_handle;
52
53static const io_block_spec_t fip_block_spec = {
54 .offset = IMX8MM_FIP_BASE,
55 .length = IMX8MM_FIP_SIZE
56};
57static int open_memmap(const uintptr_t spec);
58#endif
59
60static int open_fip(const uintptr_t spec);
61
62static const io_uuid_spec_t bl31_uuid_spec = {
63 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
64};
65
66static const io_uuid_spec_t bl32_uuid_spec = {
67 .uuid = UUID_SECURE_PAYLOAD_BL32,
68};
69
70static const io_uuid_spec_t bl32_extra1_uuid_spec = {
71 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
72};
73
74static const io_uuid_spec_t bl32_extra2_uuid_spec = {
75 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
76};
77
78static const io_uuid_spec_t bl33_uuid_spec = {
79 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
80};
81
82#if TRUSTED_BOARD_BOOT
83static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
84 .uuid = UUID_TRUSTED_BOOT_FW_CERT,
85};
86
87static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
88 .uuid = UUID_TRUSTED_KEY_CERT,
89};
90
91static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
92 .uuid = UUID_SOC_FW_KEY_CERT,
93};
94
95static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
96 .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
97};
98
99static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
100 .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
101};
102
103static const io_uuid_spec_t soc_fw_content_cert_uuid_spec = {
104 .uuid = UUID_SOC_FW_CONTENT_CERT,
105};
106
107static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
108 .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
109};
110
111static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
112 .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
113};
114#endif /* TRUSTED_BOARD_BOOT */
115
116struct plat_io_policy {
117 uintptr_t *dev_handle;
118 uintptr_t image_spec;
119 int (*check)(const uintptr_t spec);
120};
121
122static const struct plat_io_policy policies[] = {
123#ifndef IMX8MM_FIP_MMAP
124 [FIP_IMAGE_ID] = {
125 &mmc_dev_handle,
126 (uintptr_t)&mmc_fip_spec,
127 open_mmc
128 },
129#else
130 [FIP_IMAGE_ID] = {
131 &memmap_dev_handle,
132 (uintptr_t)&fip_block_spec,
133 open_memmap
134 },
135#endif
136 [BL31_IMAGE_ID] = {
137 &fip_dev_handle,
138 (uintptr_t)&bl31_uuid_spec,
139 open_fip
140 },
141 [BL32_IMAGE_ID] = {
142 &fip_dev_handle,
143 (uintptr_t)&bl32_uuid_spec,
144 open_fip
145 },
146 [BL32_EXTRA1_IMAGE_ID] = {
147 &fip_dev_handle,
148 (uintptr_t)&bl32_extra1_uuid_spec,
149 open_fip
150 },
151 [BL32_EXTRA2_IMAGE_ID] = {
152 &fip_dev_handle,
153 (uintptr_t)&bl32_extra2_uuid_spec,
154 open_fip
155 },
156 [BL33_IMAGE_ID] = {
157 &fip_dev_handle,
158 (uintptr_t)&bl33_uuid_spec,
159 open_fip
160 },
161#if TRUSTED_BOARD_BOOT
162 [TRUSTED_BOOT_FW_CERT_ID] = {
163 &fip_dev_handle,
164 (uintptr_t)&tb_fw_cert_uuid_spec,
165 open_fip
166 },
167 [SOC_FW_KEY_CERT_ID] = {
168 &fip_dev_handle,
169 (uintptr_t)&soc_fw_key_cert_uuid_spec,
170 open_fip
171 },
172 [TRUSTED_KEY_CERT_ID] = {
173 &fip_dev_handle,
174 (uintptr_t)&trusted_key_cert_uuid_spec,
175 open_fip
176 },
177 [TRUSTED_OS_FW_KEY_CERT_ID] = {
178 &fip_dev_handle,
179 (uintptr_t)&tos_fw_key_cert_uuid_spec,
180 open_fip
181 },
182 [NON_TRUSTED_FW_KEY_CERT_ID] = {
183 &fip_dev_handle,
184 (uintptr_t)&nt_fw_key_cert_uuid_spec,
185 open_fip
186 },
187 [SOC_FW_CONTENT_CERT_ID] = {
188 &fip_dev_handle,
189 (uintptr_t)&soc_fw_content_cert_uuid_spec,
190 open_fip
191 },
192 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
193 &fip_dev_handle,
194 (uintptr_t)&tos_fw_cert_uuid_spec,
195 open_fip
196 },
197 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
198 &fip_dev_handle,
199 (uintptr_t)&nt_fw_cert_uuid_spec,
200 open_fip
201 },
202#endif /* TRUSTED_BOARD_BOOT */
203};
204
205static int open_fip(const uintptr_t spec)
206{
207 int result;
208 uintptr_t local_image_handle;
209
210 /* See if a Firmware Image Package is available */
211 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
212 if (result == 0) {
213 result = io_open(fip_dev_handle, spec, &local_image_handle);
214 if (result == 0) {
215 VERBOSE("Using FIP\n");
216 io_close(local_image_handle);
217 }
218 }
219 return result;
220}
221
222#ifndef IMX8MM_FIP_MMAP
223static int open_mmc(const uintptr_t spec)
224{
225 int result;
226 uintptr_t local_handle;
227
228 result = io_dev_init(mmc_dev_handle, (uintptr_t)NULL);
229 if (result == 0) {
230 result = io_open(mmc_dev_handle, spec, &local_handle);
231 if (result == 0) {
232 io_close(local_handle);
233 }
234 }
235 return result;
236}
237#else
238static int open_memmap(const uintptr_t spec)
239{
240 int result;
241 uintptr_t local_image_handle;
242
243 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
244 if (result == 0) {
245 result = io_open(memmap_dev_handle, spec, &local_image_handle);
246 if (result == 0) {
247 VERBOSE("Using Memmap\n");
248 io_close(local_image_handle);
249 }
250 }
251 return result;
252}
253#endif
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 assert(result == 0);
266
267 *image_spec = policy->image_spec;
268 *dev_handle = *policy->dev_handle;
269
270 return result;
271}
272
273void plat_imx8mm_io_setup(void)
274{
275 int result __unused;
276
277#ifndef IMX8MM_FIP_MMAP
278 result = register_io_dev_block(&mmc_dev_con);
279 assert(result == 0);
280
281 result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_dev_spec,
282 &mmc_dev_handle);
283 assert(result == 0);
284
285#else
286 result = register_io_dev_memmap(&memmap_dev_con);
287 assert(result == 0);
288
289 result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
290 &memmap_dev_handle);
291 assert(result == 0);
292#endif
293
294 result = register_io_dev_fip(&fip_dev_con);
295 assert(result == 0);
296
297 result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
298 &fip_dev_handle);
299 assert(result == 0);
300}