blob: 109d321502b3cb7155b3e6d316e96b156a1df286 [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"
Soby Mathew96a1c6b2018-01-15 14:45:33 +000023#define HW_CONFIG_NAME "hw_config.dtb"
Juan Castillo3a66aca2015-04-13 17:36:19 +010024
25#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000026#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010027#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Juan Castillobe801202015-12-03 10:19:21 +000028#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
29#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
30#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
31#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
32#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
33#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010034#endif /* TRUSTED_BOARD_BOOT */
James Morrissey9d72b4e2014-02-10 17:04:32 +000035
James Morrissey9d72b4e2014-02-10 17:04:32 +000036/* IO devices */
Dan Handleya4cb68e2014-04-23 13:47:06 +010037static const io_dev_connector_t *sh_dev_con;
Dan Handleya4cb68e2014-04-23 13:47:06 +010038static uintptr_t sh_dev_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000039
Juan Castillo3a66aca2015-04-13 17:36:19 +010040static const io_file_spec_t sh_file_spec[] = {
41 [BL2_IMAGE_ID] = {
42 .path = BL2_IMAGE_NAME,
43 .mode = FOPEN_MODE_RB
44 },
45 [BL31_IMAGE_ID] = {
46 .path = BL31_IMAGE_NAME,
47 .mode = FOPEN_MODE_RB
48 },
49 [BL32_IMAGE_ID] = {
50 .path = BL32_IMAGE_NAME,
51 .mode = FOPEN_MODE_RB
52 },
53 [BL33_IMAGE_ID] = {
54 .path = BL33_IMAGE_NAME,
55 .mode = FOPEN_MODE_RB
56 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +000057 [TB_FW_CONFIG_ID] = {
58 .path = TB_FW_CONFIG_NAME,
59 .mode = FOPEN_MODE_RB
60 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +000061 [HW_CONFIG_ID] = {
62 .path = HW_CONFIG_NAME,
63 .mode = FOPEN_MODE_RB
64 },
Juan Castillo3a66aca2015-04-13 17:36:19 +010065#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000066 [TRUSTED_BOOT_FW_CERT_ID] = {
67 .path = TRUSTED_BOOT_FW_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010068 .mode = FOPEN_MODE_RB
69 },
70 [TRUSTED_KEY_CERT_ID] = {
71 .path = TRUSTED_KEY_CERT_NAME,
72 .mode = FOPEN_MODE_RB
73 },
Juan Castillobe801202015-12-03 10:19:21 +000074 [SOC_FW_KEY_CERT_ID] = {
75 .path = SOC_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010076 .mode = FOPEN_MODE_RB
77 },
Juan Castillobe801202015-12-03 10:19:21 +000078 [TRUSTED_OS_FW_KEY_CERT_ID] = {
79 .path = TOS_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010080 .mode = FOPEN_MODE_RB
81 },
Juan Castillobe801202015-12-03 10:19:21 +000082 [NON_TRUSTED_FW_KEY_CERT_ID] = {
83 .path = NT_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010084 .mode = FOPEN_MODE_RB
85 },
Juan Castillobe801202015-12-03 10:19:21 +000086 [SOC_FW_CONTENT_CERT_ID] = {
87 .path = SOC_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010088 .mode = FOPEN_MODE_RB
89 },
Juan Castillobe801202015-12-03 10:19:21 +000090 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
91 .path = TOS_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010092 .mode = FOPEN_MODE_RB
93 },
Juan Castillobe801202015-12-03 10:19:21 +000094 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
95 .path = NT_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010096 .mode = FOPEN_MODE_RB
97 },
98#endif /* TRUSTED_BOARD_BOOT */
99};
100
Harry Liebel561cd332014-02-14 14:42:48 +0000101
Dan Handleya4cb68e2014-04-23 13:47:06 +0100102static int open_semihosting(const uintptr_t spec)
Harry Liebel561cd332014-02-14 14:42:48 +0000103{
Juan Castillo6e762062015-11-02 10:47:01 +0000104 int result;
Dan Handleya4cb68e2014-04-23 13:47:06 +0100105 uintptr_t local_image_handle;
Harry Liebel561cd332014-02-14 14:42:48 +0000106
107 /* See if the file exists on semi-hosting.*/
Dan Handley2b6b5742015-03-19 19:17:53 +0000108 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000109 if (result == 0) {
Harry Liebel561cd332014-02-14 14:42:48 +0000110 result = io_open(sh_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000111 if (result == 0) {
Dan Handley91b624e2014-07-29 17:14:00 +0100112 VERBOSE("Using Semi-hosting IO\n");
Harry Liebel561cd332014-02-14 14:42:48 +0000113 io_close(local_image_handle);
114 }
115 }
116 return result;
117}
118
Dan Handley2b6b5742015-03-19 19:17:53 +0000119void plat_arm_io_setup(void)
Harry Liebel561cd332014-02-14 14:42:48 +0000120{
Dan Handley2b6b5742015-03-19 19:17:53 +0000121 int io_result;
Harry Liebel561cd332014-02-14 14:42:48 +0000122
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000123 io_result = arm_io_setup();
124 if (io_result < 0) {
125 panic();
126 }
Harry Liebel561cd332014-02-14 14:42:48 +0000127
Dan Handley2b6b5742015-03-19 19:17:53 +0000128 /* Register the additional IO devices on this platform */
129 io_result = register_io_dev_sh(&sh_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000130 if (io_result < 0) {
131 panic();
132 }
Harry Liebel561cd332014-02-14 14:42:48 +0000133
134 /* Open connections to devices and cache the handles */
Dan Handley2b6b5742015-03-19 19:17:53 +0000135 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +0000136 if (io_result < 0) {
137 panic();
138 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000139}
140
Juan Castillo3a66aca2015-04-13 17:36:19 +0100141/*
142 * FVP provides semihosting as an alternative to load images
143 */
144int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
145 uintptr_t *image_spec)
James Morrissey9d72b4e2014-02-10 17:04:32 +0000146{
Juan Castillo3a66aca2015-04-13 17:36:19 +0100147 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
Juan Castillo6e762062015-11-02 10:47:01 +0000148 if (result == 0) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000149 *dev_handle = sh_dev_handle;
Juan Castillo3a66aca2015-04-13 17:36:19 +0100150 *image_spec = (uintptr_t)&sh_file_spec[image_id];
151 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000152
James Morrissey9d72b4e2014-02-10 17:04:32 +0000153 return result;
154}