blob: 4eef51c31f350595e79467411bf90a9d563aec74 [file] [log] [blame]
James Morrissey9d72b4e2014-02-10 17:04:32 +00001/*
Louis Mayencourt7d24ce12020-01-29 14:43:06 +00002 * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
James Morrissey9d72b4e2014-02-10 17:04:32 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
James Morrissey9d72b4e2014-02-10 17:04:32 +00005 */
6
7#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <common/debug.h>
10#include <drivers/io/io_driver.h>
11#include <drivers/io/io_semihosting.h>
12#include <drivers/io/io_storage.h>
13#include <lib/semihosting.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000014#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <plat/common/common_def.h>
16
Juan Castillo3a66aca2015-04-13 17:36:19 +010017/* Semihosting filenames */
18#define BL2_IMAGE_NAME "bl2.bin"
19#define BL31_IMAGE_NAME "bl31.bin"
20#define BL32_IMAGE_NAME "bl32.bin"
21#define BL33_IMAGE_NAME "bl33.bin"
Soby Mathew7c6df5b2018-01-15 14:43:42 +000022#define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
Stas Sergeevc4f7c902021-07-26 13:19:39 +030023#define SOC_FW_CONFIG_NAME "fvp_soc_fw_config.dtb"
24#define TOS_FW_CONFIG_NAME "fvp_tsp_fw_config.dtb"
25#define NT_FW_CONFIG_NAME "fvp_nt_fw_config.dtb"
26#define FW_CONFIG_NAME "fvp_fw_config.dtb"
Soby Mathew96a1c6b2018-01-15 14:45:33 +000027#define HW_CONFIG_NAME "hw_config.dtb"
Juan Castillo3a66aca2015-04-13 17:36:19 +010028
29#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000030#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010031#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Juan Castillobe801202015-12-03 10:19:21 +000032#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
33#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
34#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
35#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
36#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
37#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010038#endif /* TRUSTED_BOARD_BOOT */
James Morrissey9d72b4e2014-02-10 17:04:32 +000039
James Morrissey9d72b4e2014-02-10 17:04:32 +000040/* IO devices */
Dan Handleya4cb68e2014-04-23 13:47:06 +010041static const io_dev_connector_t *sh_dev_con;
Dan Handleya4cb68e2014-04-23 13:47:06 +010042static uintptr_t sh_dev_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000043
Juan Castillo3a66aca2015-04-13 17:36:19 +010044static const io_file_spec_t sh_file_spec[] = {
45 [BL2_IMAGE_ID] = {
46 .path = BL2_IMAGE_NAME,
47 .mode = FOPEN_MODE_RB
48 },
49 [BL31_IMAGE_ID] = {
50 .path = BL31_IMAGE_NAME,
51 .mode = FOPEN_MODE_RB
52 },
53 [BL32_IMAGE_ID] = {
54 .path = BL32_IMAGE_NAME,
55 .mode = FOPEN_MODE_RB
56 },
57 [BL33_IMAGE_ID] = {
58 .path = BL33_IMAGE_NAME,
59 .mode = FOPEN_MODE_RB
60 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +000061 [TB_FW_CONFIG_ID] = {
62 .path = TB_FW_CONFIG_NAME,
63 .mode = FOPEN_MODE_RB
64 },
Stas Sergeevc4f7c902021-07-26 13:19:39 +030065 [SOC_FW_CONFIG_ID] = {
66 .path = SOC_FW_CONFIG_NAME,
67 .mode = FOPEN_MODE_RB
68 },
69 [TOS_FW_CONFIG_ID] = {
70 .path = TOS_FW_CONFIG_NAME,
71 .mode = FOPEN_MODE_RB
72 },
73 [NT_FW_CONFIG_ID] = {
74 .path = NT_FW_CONFIG_NAME,
75 .mode = FOPEN_MODE_RB
76 },
77 [FW_CONFIG_ID] = {
78 .path = FW_CONFIG_NAME,
79 .mode = FOPEN_MODE_RB
80 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +000081 [HW_CONFIG_ID] = {
82 .path = HW_CONFIG_NAME,
83 .mode = FOPEN_MODE_RB
84 },
Juan Castillo3a66aca2015-04-13 17:36:19 +010085#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000086 [TRUSTED_BOOT_FW_CERT_ID] = {
87 .path = TRUSTED_BOOT_FW_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010088 .mode = FOPEN_MODE_RB
89 },
90 [TRUSTED_KEY_CERT_ID] = {
91 .path = TRUSTED_KEY_CERT_NAME,
92 .mode = FOPEN_MODE_RB
93 },
Juan Castillobe801202015-12-03 10:19:21 +000094 [SOC_FW_KEY_CERT_ID] = {
95 .path = SOC_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010096 .mode = FOPEN_MODE_RB
97 },
Juan Castillobe801202015-12-03 10:19:21 +000098 [TRUSTED_OS_FW_KEY_CERT_ID] = {
99 .path = TOS_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100100 .mode = FOPEN_MODE_RB
101 },
Juan Castillobe801202015-12-03 10:19:21 +0000102 [NON_TRUSTED_FW_KEY_CERT_ID] = {
103 .path = NT_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100104 .mode = FOPEN_MODE_RB
105 },
Juan Castillobe801202015-12-03 10:19:21 +0000106 [SOC_FW_CONTENT_CERT_ID] = {
107 .path = SOC_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100108 .mode = FOPEN_MODE_RB
109 },
Juan Castillobe801202015-12-03 10:19:21 +0000110 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
111 .path = TOS_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100112 .mode = FOPEN_MODE_RB
113 },
Juan Castillobe801202015-12-03 10:19:21 +0000114 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
115 .path = NT_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100116 .mode = FOPEN_MODE_RB
117 },
118#endif /* TRUSTED_BOARD_BOOT */
119};
120
Harry Liebel561cd332014-02-14 14:42:48 +0000121
Dan Handleya4cb68e2014-04-23 13:47:06 +0100122static int open_semihosting(const uintptr_t spec)
Harry Liebel561cd332014-02-14 14:42:48 +0000123{
Juan Castillo6e762062015-11-02 10:47:01 +0000124 int result;
Dan Handleya4cb68e2014-04-23 13:47:06 +0100125 uintptr_t local_image_handle;
Harry Liebel561cd332014-02-14 14:42:48 +0000126
127 /* See if the file exists on semi-hosting.*/
Dan Handley2b6b5742015-03-19 19:17:53 +0000128 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000129 if (result == 0) {
Harry Liebel561cd332014-02-14 14:42:48 +0000130 result = io_open(sh_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000131 if (result == 0) {
Dan Handley91b624e2014-07-29 17:14:00 +0100132 VERBOSE("Using Semi-hosting IO\n");
Harry Liebel561cd332014-02-14 14:42:48 +0000133 io_close(local_image_handle);
134 }
135 }
136 return result;
137}
138
Dan Handley2b6b5742015-03-19 19:17:53 +0000139void plat_arm_io_setup(void)
Harry Liebel561cd332014-02-14 14:42:48 +0000140{
Dan Handley2b6b5742015-03-19 19:17:53 +0000141 int io_result;
Harry Liebel561cd332014-02-14 14:42:48 +0000142
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000143 io_result = arm_io_setup();
144 if (io_result < 0) {
145 panic();
146 }
Harry Liebel561cd332014-02-14 14:42:48 +0000147
Dan Handley2b6b5742015-03-19 19:17:53 +0000148 /* Register the additional IO devices on this platform */
149 io_result = register_io_dev_sh(&sh_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000150 if (io_result < 0) {
151 panic();
152 }
Harry Liebel561cd332014-02-14 14:42:48 +0000153
154 /* Open connections to devices and cache the handles */
Dan Handley2b6b5742015-03-19 19:17:53 +0000155 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000156 if (io_result < 0) {
157 panic();
158 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000159}
160
Juan Castillo3a66aca2015-04-13 17:36:19 +0100161/*
162 * FVP provides semihosting as an alternative to load images
163 */
164int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
165 uintptr_t *image_spec)
James Morrissey9d72b4e2014-02-10 17:04:32 +0000166{
Juan Castillo3a66aca2015-04-13 17:36:19 +0100167 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
Juan Castillo6e762062015-11-02 10:47:01 +0000168 if (result == 0) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000169 *dev_handle = sh_dev_handle;
Juan Castillo3a66aca2015-04-13 17:36:19 +0100170 *image_spec = (uintptr_t)&sh_file_spec[image_id];
171 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000172
James Morrissey9d72b4e2014-02-10 17:04:32 +0000173 return result;
174}