blob: 3b5d620dd73b3ed1e32445f40f21a6529eb7ac66 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
2 * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <debug.h>
8#include <io_driver.h>
9#include <io_storage.h>
10#include <io_semihosting.h>
11#include <platform_def.h>
12#include <string.h>
13#include "io_common.h"
14#include "io_rcar.h"
15#include "io_memdrv.h"
16#include "io_emmcdrv.h"
17#include "io_private.h"
18
19static uintptr_t emmcdrv_dev_handle;
20static uintptr_t memdrv_dev_handle;
21static uintptr_t rcar_dev_handle;
22
23static uintptr_t boot_io_drv_id;
24
25static const io_block_spec_t rcar_block_spec = {
26 .offset = FLASH0_BASE,
27 .length = FLASH0_SIZE
28};
29
30static const io_block_spec_t bl2_file_spec = {
31 .offset = BL2_IMAGE_ID,
32};
33
34static const io_block_spec_t bl31_file_spec = {
35 .offset = BL31_IMAGE_ID,
36};
37
38static const io_block_spec_t bl32_file_spec = {
39 .offset = BL32_IMAGE_ID,
40};
41
42static const io_block_spec_t bl33_file_spec = {
43 .offset = BL33_IMAGE_ID,
44};
45
46static const io_block_spec_t bl332_file_spec = {
47 .offset = BL332_IMAGE_ID,
48};
49
50static const io_block_spec_t bl333_file_spec = {
51 .offset = BL333_IMAGE_ID,
52};
53
54static const io_block_spec_t bl334_file_spec = {
55 .offset = BL334_IMAGE_ID,
56};
57
58static const io_block_spec_t bl335_file_spec = {
59 .offset = BL335_IMAGE_ID,
60};
61
62static const io_block_spec_t bl336_file_spec = {
63 .offset = BL336_IMAGE_ID,
64};
65
66static const io_block_spec_t bl337_file_spec = {
67 .offset = BL337_IMAGE_ID,
68};
69
70static const io_block_spec_t bl338_file_spec = {
71 .offset = BL338_IMAGE_ID,
72};
73
74#if TRUSTED_BOARD_BOOT
75static const io_block_spec_t trusted_key_cert_file_spec = {
76 .offset = TRUSTED_KEY_CERT_ID,
77};
78
79static const io_block_spec_t bl31_key_cert_file_spec = {
80 .offset = SOC_FW_KEY_CERT_ID,
81};
82
83static const io_block_spec_t bl32_key_cert_file_spec = {
84 .offset = TRUSTED_OS_FW_KEY_CERT_ID,
85};
86
87static const io_block_spec_t bl33_key_cert_file_spec = {
88 .offset = NON_TRUSTED_FW_KEY_CERT_ID,
89};
90
91static const io_block_spec_t bl332_key_cert_file_spec = {
92 .offset = BL332_KEY_CERT_ID,
93};
94
95static const io_block_spec_t bl333_key_cert_file_spec = {
96 .offset = BL333_KEY_CERT_ID,
97};
98
99static const io_block_spec_t bl334_key_cert_file_spec = {
100 .offset = BL334_KEY_CERT_ID,
101};
102
103static const io_block_spec_t bl335_key_cert_file_spec = {
104 .offset = BL335_KEY_CERT_ID,
105};
106
107static const io_block_spec_t bl336_key_cert_file_spec = {
108 .offset = BL336_KEY_CERT_ID,
109};
110
111static const io_block_spec_t bl337_key_cert_file_spec = {
112 .offset = BL337_KEY_CERT_ID,
113};
114
115static const io_block_spec_t bl338_key_cert_file_spec = {
116 .offset = BL338_KEY_CERT_ID,
117};
118
119static const io_block_spec_t bl31_cert_file_spec = {
120 .offset = SOC_FW_CONTENT_CERT_ID,
121};
122
123static const io_block_spec_t bl32_cert_file_spec = {
124 .offset = TRUSTED_OS_FW_CONTENT_CERT_ID,
125};
126
127static const io_block_spec_t bl33_cert_file_spec = {
128 .offset = NON_TRUSTED_FW_CONTENT_CERT_ID,
129};
130
131static const io_block_spec_t bl332_cert_file_spec = {
132 .offset = BL332_CERT_ID,
133};
134
135static const io_block_spec_t bl333_cert_file_spec = {
136 .offset = BL333_CERT_ID,
137};
138
139static const io_block_spec_t bl334_cert_file_spec = {
140 .offset = BL334_CERT_ID,
141};
142
143static const io_block_spec_t bl335_cert_file_spec = {
144 .offset = BL335_CERT_ID,
145};
146
147static const io_block_spec_t bl336_cert_file_spec = {
148 .offset = BL336_CERT_ID,
149};
150
151static const io_block_spec_t bl337_cert_file_spec = {
152 .offset = BL337_CERT_ID,
153};
154
155static const io_block_spec_t bl338_cert_file_spec = {
156 .offset = BL338_CERT_ID,
157};
158#endif
159
160static int32_t open_emmcdrv(const uintptr_t spec);
161static int32_t open_memmap(const uintptr_t spec);
162static int32_t open_rcar(const uintptr_t spec);
163
164struct plat_io_policy {
165 uintptr_t *dev_handle;
166 uintptr_t image_spec;
167 int32_t(*check) (const uintptr_t spec);
168};
169
170static const struct plat_io_policy policies[] = {
171 [FIP_IMAGE_ID] = {
172 &memdrv_dev_handle,
173 (uintptr_t) &rcar_block_spec,
174 &open_memmap},
175 [BL2_IMAGE_ID] = {
176 &rcar_dev_handle,
177 (uintptr_t) &bl2_file_spec,
178 &open_rcar},
179 [BL31_IMAGE_ID] = {
180 &rcar_dev_handle,
181 (uintptr_t) &bl31_file_spec,
182 &open_rcar},
183 [BL32_IMAGE_ID] = {
184 &rcar_dev_handle,
185 (uintptr_t) &bl32_file_spec,
186 &open_rcar},
187 [BL33_IMAGE_ID] = {
188 &rcar_dev_handle,
189 (uintptr_t) &bl33_file_spec,
190 &open_rcar},
191 [BL332_IMAGE_ID] = {
192 &rcar_dev_handle,
193 (uintptr_t) &bl332_file_spec,
194 &open_rcar},
195 [BL333_IMAGE_ID] = {
196 &rcar_dev_handle,
197 (uintptr_t) &bl333_file_spec,
198 &open_rcar},
199 [BL334_IMAGE_ID] = {
200 &rcar_dev_handle,
201 (uintptr_t) &bl334_file_spec,
202 &open_rcar},
203 [BL335_IMAGE_ID] = {
204 &rcar_dev_handle,
205 (uintptr_t) &bl335_file_spec,
206 &open_rcar},
207 [BL336_IMAGE_ID] = {
208 &rcar_dev_handle,
209 (uintptr_t) &bl336_file_spec,
210 &open_rcar},
211 [BL337_IMAGE_ID] = {
212 &rcar_dev_handle,
213 (uintptr_t) &bl337_file_spec,
214 &open_rcar},
215 [BL338_IMAGE_ID] = {
216 &rcar_dev_handle,
217 (uintptr_t) &bl338_file_spec,
218 &open_rcar},
219#if TRUSTED_BOARD_BOOT
220 [TRUSTED_KEY_CERT_ID] = {
221 &rcar_dev_handle,
222 (uintptr_t) &trusted_key_cert_file_spec,
223 &open_rcar},
224 [SOC_FW_KEY_CERT_ID] = {
225 &rcar_dev_handle,
226 (uintptr_t) &bl31_key_cert_file_spec,
227 &open_rcar},
228 [TRUSTED_OS_FW_KEY_CERT_ID] = {
229 &rcar_dev_handle,
230 (uintptr_t) &bl32_key_cert_file_spec,
231 &open_rcar},
232 [NON_TRUSTED_FW_KEY_CERT_ID] = {
233 &rcar_dev_handle,
234 (uintptr_t) &bl33_key_cert_file_spec,
235 &open_rcar},
236 [BL332_KEY_CERT_ID] = {
237 &rcar_dev_handle,
238 (uintptr_t) &bl332_key_cert_file_spec,
239 &open_rcar},
240 [BL333_KEY_CERT_ID] = {
241 &rcar_dev_handle,
242 (uintptr_t) &bl333_key_cert_file_spec,
243 &open_rcar},
244 [BL334_KEY_CERT_ID] = {
245 &rcar_dev_handle,
246 (uintptr_t) &bl334_key_cert_file_spec,
247 &open_rcar},
248 [BL335_KEY_CERT_ID] = {
249 &rcar_dev_handle,
250 (uintptr_t) &bl335_key_cert_file_spec,
251 &open_rcar},
252 [BL336_KEY_CERT_ID] = {
253 &rcar_dev_handle,
254 (uintptr_t) &bl336_key_cert_file_spec,
255 &open_rcar},
256 [BL337_KEY_CERT_ID] = {
257 &rcar_dev_handle,
258 (uintptr_t) &bl337_key_cert_file_spec,
259 &open_rcar},
260 [BL338_KEY_CERT_ID] = {
261 &rcar_dev_handle,
262 (uintptr_t) &bl338_key_cert_file_spec,
263 &open_rcar},
264 [SOC_FW_CONTENT_CERT_ID] = {
265 &rcar_dev_handle,
266 (uintptr_t) &bl31_cert_file_spec,
267 &open_rcar},
268 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
269 &rcar_dev_handle,
270 (uintptr_t) &bl32_cert_file_spec,
271 &open_rcar},
272 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
273 &rcar_dev_handle,
274 (uintptr_t) &bl33_cert_file_spec,
275 &open_rcar},
276 [BL332_CERT_ID] = {
277 &rcar_dev_handle,
278 (uintptr_t) &bl332_cert_file_spec,
279 &open_rcar},
280 [BL333_CERT_ID] = {
281 &rcar_dev_handle,
282 (uintptr_t) &bl333_cert_file_spec,
283 &open_rcar},
284 [BL334_CERT_ID] = {
285 &rcar_dev_handle,
286 (uintptr_t) &bl334_cert_file_spec,
287 &open_rcar},
288 [BL335_CERT_ID] = {
289 &rcar_dev_handle,
290 (uintptr_t) &bl335_cert_file_spec,
291 &open_rcar},
292 [BL336_CERT_ID] = {
293 &rcar_dev_handle,
294 (uintptr_t) &bl336_cert_file_spec,
295 &open_rcar},
296 [BL337_CERT_ID] = {
297 &rcar_dev_handle,
298 (uintptr_t) &bl337_cert_file_spec,
299 &open_rcar},
300 [BL338_CERT_ID] = {
301 &rcar_dev_handle,
302 (uintptr_t) &bl338_cert_file_spec,
303 &open_rcar}, {
304#else
305 {
306#endif
307 0, 0, 0}
308};
309
310static io_drv_spec_t io_drv_spec_memdrv = {
311 FLASH0_BASE,
312 FLASH0_SIZE,
313 0,
314};
315
316static io_drv_spec_t io_drv_spec_emmcdrv = {
317 0,
318 0,
319 0,
320};
321
322static struct plat_io_policy drv_policies[]
323 __attribute__ ((section(".data"))) = {
324 /* FLASH_DEV_ID */
325 {
326 &memdrv_dev_handle,
327 (uintptr_t) &io_drv_spec_memdrv, &open_memmap,},
328 /* EMMC_DEV_ID */
329 {
330 &emmcdrv_dev_handle,
331 (uintptr_t) &io_drv_spec_emmcdrv, &open_emmcdrv,}
332};
333
334static int32_t open_rcar(const uintptr_t spec)
335{
336 return io_dev_init(rcar_dev_handle, boot_io_drv_id);
337}
338
339static int32_t open_memmap(const uintptr_t spec)
340{
341 uintptr_t handle;
342 int32_t result;
343
344 result = io_dev_init(memdrv_dev_handle, 0);
345 if (result != IO_SUCCESS)
346 return result;
347
348 result = io_open(memdrv_dev_handle, spec, &handle);
349 if (result == IO_SUCCESS)
350 io_close(handle);
351
352 return result;
353}
354
355static int32_t open_emmcdrv(const uintptr_t spec)
356{
357 return io_dev_init(emmcdrv_dev_handle, 0);
358}
359
360void rcar_io_setup(void)
361{
362 const io_dev_connector_t *memmap;
363 const io_dev_connector_t *rcar;
364
365 boot_io_drv_id = FLASH_DEV_ID;
366
367 rcar_register_io_dev(&rcar);
368 rcar_register_io_dev_memdrv(&memmap);
369 io_dev_open(rcar, 0, &rcar_dev_handle);
370 io_dev_open(memmap, 0, &memdrv_dev_handle);
371}
372
373void rcar_io_emmc_setup(void)
374{
375 const io_dev_connector_t *rcar;
376 const io_dev_connector_t *emmc;
377
378 boot_io_drv_id = EMMC_DEV_ID;
379
380 rcar_register_io_dev(&rcar);
381 rcar_register_io_dev_emmcdrv(&emmc);
382 io_dev_open(rcar, 0, &rcar_dev_handle);
383 io_dev_open(emmc, 0, &emmcdrv_dev_handle);
384}
385
386int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
387 uintptr_t *image_spec)
388{
389 const struct plat_io_policy *policy;
390 int result;
391
392 policy = &policies[image_id];
393
394 result = policy->check(policy->image_spec);
395 if (result != IO_SUCCESS)
396 return result;
397
398 *image_spec = policy->image_spec;
399 *dev_handle = *(policy->dev_handle);
400
401 return IO_SUCCESS;
402}
403
404int32_t plat_get_drv_source(uint32_t io_drv_id, uintptr_t *dev_handle,
405 uintptr_t *image_spec)
406{
407 const struct plat_io_policy *policy;
408 int32_t result;
409
410 policy = &drv_policies[io_drv_id];
411
412 result = policy->check(policy->image_spec);
413 if (result != IO_SUCCESS)
414 return result;
415
416 *image_spec = policy->image_spec;
417 *dev_handle = *(policy->dev_handle);
418
419 return IO_SUCCESS;
420}