11c7c3bcde19c2cda822eb57053e871901f42728
[project/bcm63xx/atf.git] / plat / arm / board / fvp / fvp_io_storage.c
1 /*
2 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <assert.h>
8 #include <common_def.h>
9 #include <debug.h>
10 #include <io_driver.h>
11 #include <io_semihosting.h>
12 #include <io_storage.h>
13 #include <plat_arm.h>
14 #include <semihosting.h> /* For FOPEN_MODE_... */
15
16 /* Semihosting filenames */
17 #define BL2_IMAGE_NAME "bl2.bin"
18 #define BL31_IMAGE_NAME "bl31.bin"
19 #define BL32_IMAGE_NAME "bl32.bin"
20 #define BL33_IMAGE_NAME "bl33.bin"
21 #define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
22 #define HW_CONFIG_NAME "hw_config.dtb"
23
24 #if TRUSTED_BOARD_BOOT
25 #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
26 #define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
27 #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
28 #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
29 #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
30 #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
31 #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
32 #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
33 #endif /* TRUSTED_BOARD_BOOT */
34
35 /* IO devices */
36 static const io_dev_connector_t *sh_dev_con;
37 static uintptr_t sh_dev_handle;
38
39 static const io_file_spec_t sh_file_spec[] = {
40 [BL2_IMAGE_ID] = {
41 .path = BL2_IMAGE_NAME,
42 .mode = FOPEN_MODE_RB
43 },
44 [BL31_IMAGE_ID] = {
45 .path = BL31_IMAGE_NAME,
46 .mode = FOPEN_MODE_RB
47 },
48 [BL32_IMAGE_ID] = {
49 .path = BL32_IMAGE_NAME,
50 .mode = FOPEN_MODE_RB
51 },
52 [BL33_IMAGE_ID] = {
53 .path = BL33_IMAGE_NAME,
54 .mode = FOPEN_MODE_RB
55 },
56 [TB_FW_CONFIG_ID] = {
57 .path = TB_FW_CONFIG_NAME,
58 .mode = FOPEN_MODE_RB
59 },
60 [HW_CONFIG_ID] = {
61 .path = HW_CONFIG_NAME,
62 .mode = FOPEN_MODE_RB
63 },
64 #if TRUSTED_BOARD_BOOT
65 [TRUSTED_BOOT_FW_CERT_ID] = {
66 .path = TRUSTED_BOOT_FW_CERT_NAME,
67 .mode = FOPEN_MODE_RB
68 },
69 [TRUSTED_KEY_CERT_ID] = {
70 .path = TRUSTED_KEY_CERT_NAME,
71 .mode = FOPEN_MODE_RB
72 },
73 [SOC_FW_KEY_CERT_ID] = {
74 .path = SOC_FW_KEY_CERT_NAME,
75 .mode = FOPEN_MODE_RB
76 },
77 [TRUSTED_OS_FW_KEY_CERT_ID] = {
78 .path = TOS_FW_KEY_CERT_NAME,
79 .mode = FOPEN_MODE_RB
80 },
81 [NON_TRUSTED_FW_KEY_CERT_ID] = {
82 .path = NT_FW_KEY_CERT_NAME,
83 .mode = FOPEN_MODE_RB
84 },
85 [SOC_FW_CONTENT_CERT_ID] = {
86 .path = SOC_FW_CONTENT_CERT_NAME,
87 .mode = FOPEN_MODE_RB
88 },
89 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
90 .path = TOS_FW_CONTENT_CERT_NAME,
91 .mode = FOPEN_MODE_RB
92 },
93 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
94 .path = NT_FW_CONTENT_CERT_NAME,
95 .mode = FOPEN_MODE_RB
96 },
97 #endif /* TRUSTED_BOARD_BOOT */
98 };
99
100
101 static int open_semihosting(const uintptr_t spec)
102 {
103 int result;
104 uintptr_t local_image_handle;
105
106 /* See if the file exists on semi-hosting.*/
107 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
108 if (result == 0) {
109 result = io_open(sh_dev_handle, spec, &local_image_handle);
110 if (result == 0) {
111 VERBOSE("Using Semi-hosting IO\n");
112 io_close(local_image_handle);
113 }
114 }
115 return result;
116 }
117
118 void plat_arm_io_setup(void)
119 {
120 int io_result;
121
122 arm_io_setup();
123
124 /* Register the additional IO devices on this platform */
125 io_result = register_io_dev_sh(&sh_dev_con);
126 assert(io_result == 0);
127
128 /* Open connections to devices and cache the handles */
129 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
130 assert(io_result == 0);
131
132 /* Ignore improbable errors in release builds */
133 (void)io_result;
134 }
135
136 /*
137 * FVP provides semihosting as an alternative to load images
138 */
139 int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
140 uintptr_t *image_spec)
141 {
142 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
143 if (result == 0) {
144 *dev_handle = sh_dev_handle;
145 *image_spec = (uintptr_t)&sh_file_spec[image_id];
146 }
147
148 return result;
149 }