2 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <common_def.h>
10 #include <io_driver.h>
11 #include <io_semihosting.h>
12 #include <io_storage.h>
14 #include <semihosting.h> /* For FOPEN_MODE_... */
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"
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 */
36 static const io_dev_connector_t
*sh_dev_con
;
37 static uintptr_t sh_dev_handle
;
39 static const io_file_spec_t sh_file_spec
[] = {
41 .path
= BL2_IMAGE_NAME
,
45 .path
= BL31_IMAGE_NAME
,
49 .path
= BL32_IMAGE_NAME
,
53 .path
= BL33_IMAGE_NAME
,
57 .path
= TB_FW_CONFIG_NAME
,
61 .path
= HW_CONFIG_NAME
,
64 #if TRUSTED_BOARD_BOOT
65 [TRUSTED_BOOT_FW_CERT_ID
] = {
66 .path
= TRUSTED_BOOT_FW_CERT_NAME
,
69 [TRUSTED_KEY_CERT_ID
] = {
70 .path
= TRUSTED_KEY_CERT_NAME
,
73 [SOC_FW_KEY_CERT_ID
] = {
74 .path
= SOC_FW_KEY_CERT_NAME
,
77 [TRUSTED_OS_FW_KEY_CERT_ID
] = {
78 .path
= TOS_FW_KEY_CERT_NAME
,
81 [NON_TRUSTED_FW_KEY_CERT_ID
] = {
82 .path
= NT_FW_KEY_CERT_NAME
,
85 [SOC_FW_CONTENT_CERT_ID
] = {
86 .path
= SOC_FW_CONTENT_CERT_NAME
,
89 [TRUSTED_OS_FW_CONTENT_CERT_ID
] = {
90 .path
= TOS_FW_CONTENT_CERT_NAME
,
93 [NON_TRUSTED_FW_CONTENT_CERT_ID
] = {
94 .path
= NT_FW_CONTENT_CERT_NAME
,
97 #endif /* TRUSTED_BOARD_BOOT */
101 static int open_semihosting(const uintptr_t spec
)
104 uintptr_t local_image_handle
;
106 /* See if the file exists on semi-hosting.*/
107 result
= io_dev_init(sh_dev_handle
, (uintptr_t)NULL
);
109 result
= io_open(sh_dev_handle
, spec
, &local_image_handle
);
111 VERBOSE("Using Semi-hosting IO\n");
112 io_close(local_image_handle
);
118 void plat_arm_io_setup(void)
124 /* Register the additional IO devices on this platform */
125 io_result
= register_io_dev_sh(&sh_dev_con
);
126 assert(io_result
== 0);
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);
132 /* Ignore improbable errors in release builds */
137 * FVP provides semihosting as an alternative to load images
139 int plat_arm_get_alt_image_source(unsigned int image_id
, uintptr_t *dev_handle
,
140 uintptr_t *image_spec
)
142 int result
= open_semihosting((const uintptr_t)&sh_file_spec
[image_id
]);
144 *dev_handle
= sh_dev_handle
;
145 *image_spec
= (uintptr_t)&sh_file_spec
[image_id
];