blob: e186b3083872359cc442379ebd007aacc00adc90 [file] [log] [blame]
James Morrissey9d72b4e2014-02-10 17:04:32 +00001/*
Soby Mathew7c6df5b2018-01-15 14:43:42 +00002 * Copyright (c) 2014-2018, 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>
14#include <plat/common/common_def.h>
15
Dan Handley2b6b5742015-03-19 19:17:53 +000016#include <plat_arm.h>
Juan Castillo3a66aca2015-04-13 17:36:19 +010017
18/* Semihosting filenames */
19#define BL2_IMAGE_NAME "bl2.bin"
20#define BL31_IMAGE_NAME "bl31.bin"
21#define BL32_IMAGE_NAME "bl32.bin"
22#define BL33_IMAGE_NAME "bl33.bin"
Soby Mathew7c6df5b2018-01-15 14:43:42 +000023#define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
Soby Mathew96a1c6b2018-01-15 14:45:33 +000024#define HW_CONFIG_NAME "hw_config.dtb"
Juan Castillo3a66aca2015-04-13 17:36:19 +010025
26#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000027#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010028#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Juan Castillobe801202015-12-03 10:19:21 +000029#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
30#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
31#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
32#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
33#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
34#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010035#endif /* TRUSTED_BOARD_BOOT */
James Morrissey9d72b4e2014-02-10 17:04:32 +000036
James Morrissey9d72b4e2014-02-10 17:04:32 +000037/* IO devices */
Dan Handleya4cb68e2014-04-23 13:47:06 +010038static const io_dev_connector_t *sh_dev_con;
Dan Handleya4cb68e2014-04-23 13:47:06 +010039static uintptr_t sh_dev_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000040
Juan Castillo3a66aca2015-04-13 17:36:19 +010041static const io_file_spec_t sh_file_spec[] = {
42 [BL2_IMAGE_ID] = {
43 .path = BL2_IMAGE_NAME,
44 .mode = FOPEN_MODE_RB
45 },
46 [BL31_IMAGE_ID] = {
47 .path = BL31_IMAGE_NAME,
48 .mode = FOPEN_MODE_RB
49 },
50 [BL32_IMAGE_ID] = {
51 .path = BL32_IMAGE_NAME,
52 .mode = FOPEN_MODE_RB
53 },
54 [BL33_IMAGE_ID] = {
55 .path = BL33_IMAGE_NAME,
56 .mode = FOPEN_MODE_RB
57 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +000058 [TB_FW_CONFIG_ID] = {
59 .path = TB_FW_CONFIG_NAME,
60 .mode = FOPEN_MODE_RB
61 },
Soby Mathew96a1c6b2018-01-15 14:45:33 +000062 [HW_CONFIG_ID] = {
63 .path = HW_CONFIG_NAME,
64 .mode = FOPEN_MODE_RB
65 },
Juan Castillo3a66aca2015-04-13 17:36:19 +010066#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000067 [TRUSTED_BOOT_FW_CERT_ID] = {
68 .path = TRUSTED_BOOT_FW_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010069 .mode = FOPEN_MODE_RB
70 },
71 [TRUSTED_KEY_CERT_ID] = {
72 .path = TRUSTED_KEY_CERT_NAME,
73 .mode = FOPEN_MODE_RB
74 },
Juan Castillobe801202015-12-03 10:19:21 +000075 [SOC_FW_KEY_CERT_ID] = {
76 .path = SOC_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010077 .mode = FOPEN_MODE_RB
78 },
Juan Castillobe801202015-12-03 10:19:21 +000079 [TRUSTED_OS_FW_KEY_CERT_ID] = {
80 .path = TOS_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010081 .mode = FOPEN_MODE_RB
82 },
Juan Castillobe801202015-12-03 10:19:21 +000083 [NON_TRUSTED_FW_KEY_CERT_ID] = {
84 .path = NT_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010085 .mode = FOPEN_MODE_RB
86 },
Juan Castillobe801202015-12-03 10:19:21 +000087 [SOC_FW_CONTENT_CERT_ID] = {
88 .path = SOC_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010089 .mode = FOPEN_MODE_RB
90 },
Juan Castillobe801202015-12-03 10:19:21 +000091 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
92 .path = TOS_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010093 .mode = FOPEN_MODE_RB
94 },
Juan Castillobe801202015-12-03 10:19:21 +000095 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
96 .path = NT_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010097 .mode = FOPEN_MODE_RB
98 },
99#endif /* TRUSTED_BOARD_BOOT */
100};
101
Harry Liebel561cd332014-02-14 14:42:48 +0000102
Dan Handleya4cb68e2014-04-23 13:47:06 +0100103static int open_semihosting(const uintptr_t spec)
Harry Liebel561cd332014-02-14 14:42:48 +0000104{
Juan Castillo6e762062015-11-02 10:47:01 +0000105 int result;
Dan Handleya4cb68e2014-04-23 13:47:06 +0100106 uintptr_t local_image_handle;
Harry Liebel561cd332014-02-14 14:42:48 +0000107
108 /* See if the file exists on semi-hosting.*/
Dan Handley2b6b5742015-03-19 19:17:53 +0000109 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000110 if (result == 0) {
Harry Liebel561cd332014-02-14 14:42:48 +0000111 result = io_open(sh_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000112 if (result == 0) {
Dan Handley91b624e2014-07-29 17:14:00 +0100113 VERBOSE("Using Semi-hosting IO\n");
Harry Liebel561cd332014-02-14 14:42:48 +0000114 io_close(local_image_handle);
115 }
116 }
117 return result;
118}
119
Dan Handley2b6b5742015-03-19 19:17:53 +0000120void plat_arm_io_setup(void)
Harry Liebel561cd332014-02-14 14:42:48 +0000121{
Dan Handley2b6b5742015-03-19 19:17:53 +0000122 int io_result;
Harry Liebel561cd332014-02-14 14:42:48 +0000123
Dan Handley2b6b5742015-03-19 19:17:53 +0000124 arm_io_setup();
Harry Liebel561cd332014-02-14 14:42:48 +0000125
Dan Handley2b6b5742015-03-19 19:17:53 +0000126 /* Register the additional IO devices on this platform */
127 io_result = register_io_dev_sh(&sh_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000128 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000129
130 /* Open connections to devices and cache the handles */
Dan Handley2b6b5742015-03-19 19:17:53 +0000131 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000132 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000133
James Morrissey9d72b4e2014-02-10 17:04:32 +0000134 /* Ignore improbable errors in release builds */
135 (void)io_result;
136}
137
Juan Castillo3a66aca2015-04-13 17:36:19 +0100138/*
139 * FVP provides semihosting as an alternative to load images
140 */
141int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
142 uintptr_t *image_spec)
James Morrissey9d72b4e2014-02-10 17:04:32 +0000143{
Juan Castillo3a66aca2015-04-13 17:36:19 +0100144 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
Juan Castillo6e762062015-11-02 10:47:01 +0000145 if (result == 0) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000146 *dev_handle = sh_dev_handle;
Juan Castillo3a66aca2015-04-13 17:36:19 +0100147 *image_spec = (uintptr_t)&sh_file_spec[image_id];
148 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000149
James Morrissey9d72b4e2014-02-10 17:04:32 +0000150 return result;
151}