fvp_io_storage.c 4.13 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
 */

#include <assert.h>
8
9
10
11
12
13

#include <common/debug.h>
#include <drivers/io/io_driver.h>
#include <drivers/io/io_semihosting.h>
#include <drivers/io/io_storage.h>
#include <lib/semihosting.h>
14
#include <plat/arm/common/plat_arm.h>
15
16
#include <plat/common/common_def.h>

17
18
19
20
21
/* Semihosting filenames */
#define BL2_IMAGE_NAME			"bl2.bin"
#define BL31_IMAGE_NAME			"bl31.bin"
#define BL32_IMAGE_NAME			"bl32.bin"
#define BL33_IMAGE_NAME			"bl33.bin"
22
#define TB_FW_CONFIG_NAME		"fvp_tb_fw_config.dtb"
23
24
25
26
#define SOC_FW_CONFIG_NAME		"fvp_soc_fw_config.dtb"
#define TOS_FW_CONFIG_NAME		"fvp_tsp_fw_config.dtb"
#define NT_FW_CONFIG_NAME		"fvp_nt_fw_config.dtb"
#define FW_CONFIG_NAME			"fvp_fw_config.dtb"
27
#define HW_CONFIG_NAME			"hw_config.dtb"
28
29

#if TRUSTED_BOARD_BOOT
30
#define TRUSTED_BOOT_FW_CERT_NAME	"tb_fw.crt"
31
#define TRUSTED_KEY_CERT_NAME		"trusted_key.crt"
32
33
34
35
36
37
#define SOC_FW_KEY_CERT_NAME		"soc_fw_key.crt"
#define TOS_FW_KEY_CERT_NAME		"tos_fw_key.crt"
#define NT_FW_KEY_CERT_NAME		"nt_fw_key.crt"
#define SOC_FW_CONTENT_CERT_NAME	"soc_fw_content.crt"
#define TOS_FW_CONTENT_CERT_NAME	"tos_fw_content.crt"
#define NT_FW_CONTENT_CERT_NAME		"nt_fw_content.crt"
38
#endif /* TRUSTED_BOARD_BOOT */
39
40

/* IO devices */
41
42
static const io_dev_connector_t *sh_dev_con;
static uintptr_t sh_dev_handle;
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
static const io_file_spec_t sh_file_spec[] = {
	[BL2_IMAGE_ID] = {
		.path = BL2_IMAGE_NAME,
		.mode = FOPEN_MODE_RB
	},
	[BL31_IMAGE_ID] = {
		.path = BL31_IMAGE_NAME,
		.mode = FOPEN_MODE_RB
	},
	[BL32_IMAGE_ID] = {
		.path = BL32_IMAGE_NAME,
		.mode = FOPEN_MODE_RB
	},
	[BL33_IMAGE_ID] = {
		.path = BL33_IMAGE_NAME,
		.mode = FOPEN_MODE_RB
	},
61
62
	[TB_FW_CONFIG_ID] = {
		.path = TB_FW_CONFIG_NAME,
63
64
		.mode = FOPEN_MODE_RB
	},
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	[SOC_FW_CONFIG_ID] = {
		.path = SOC_FW_CONFIG_NAME,
		.mode = FOPEN_MODE_RB
	},
	[TOS_FW_CONFIG_ID] = {
		.path = TOS_FW_CONFIG_NAME,
		.mode = FOPEN_MODE_RB
	},
	[NT_FW_CONFIG_ID] = {
		.path = NT_FW_CONFIG_NAME,
		.mode = FOPEN_MODE_RB
	},
	[FW_CONFIG_ID] = {
		.path = FW_CONFIG_NAME,
		.mode = FOPEN_MODE_RB
	},
81
82
	[HW_CONFIG_ID] = {
		.path = HW_CONFIG_NAME,
83
84
		.mode = FOPEN_MODE_RB
	},
85
#if TRUSTED_BOARD_BOOT
86
87
	[TRUSTED_BOOT_FW_CERT_ID] = {
		.path = TRUSTED_BOOT_FW_CERT_NAME,
88
89
90
91
92
93
		.mode = FOPEN_MODE_RB
	},
	[TRUSTED_KEY_CERT_ID] = {
		.path = TRUSTED_KEY_CERT_NAME,
		.mode = FOPEN_MODE_RB
	},
94
95
	[SOC_FW_KEY_CERT_ID] = {
		.path = SOC_FW_KEY_CERT_NAME,
96
97
		.mode = FOPEN_MODE_RB
	},
98
99
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		.path = TOS_FW_KEY_CERT_NAME,
100
101
		.mode = FOPEN_MODE_RB
	},
102
103
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		.path = NT_FW_KEY_CERT_NAME,
104
105
		.mode = FOPEN_MODE_RB
	},
106
107
	[SOC_FW_CONTENT_CERT_ID] = {
		.path = SOC_FW_CONTENT_CERT_NAME,
108
109
		.mode = FOPEN_MODE_RB
	},
110
111
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		.path = TOS_FW_CONTENT_CERT_NAME,
112
113
		.mode = FOPEN_MODE_RB
	},
114
115
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		.path = NT_FW_CONTENT_CERT_NAME,
116
117
118
119
120
		.mode = FOPEN_MODE_RB
	},
#endif /* TRUSTED_BOARD_BOOT */
};

121

122
static int open_semihosting(const uintptr_t spec)
123
{
124
	int result;
125
	uintptr_t local_image_handle;
126
127

	/* See if the file exists on semi-hosting.*/
128
	result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
129
	if (result == 0) {
130
		result = io_open(sh_dev_handle, spec, &local_image_handle);
131
		if (result == 0) {
Dan Handley's avatar
Dan Handley committed
132
			VERBOSE("Using Semi-hosting IO\n");
133
134
135
136
137
138
			io_close(local_image_handle);
		}
	}
	return result;
}

139
void plat_arm_io_setup(void)
140
{
141
	int io_result;
142

143
144
145
146
	io_result = arm_io_setup();
	if (io_result < 0) {
		panic();
	}
147

148
149
	/* Register the additional IO devices on this platform */
	io_result = register_io_dev_sh(&sh_dev_con);
150
151
152
	if (io_result < 0) {
		panic();
	}
153

154
	/* Open connections to devices and cache the handles */
155
	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
156
157
158
	if (io_result < 0) {
		panic();
	}
159
160
}

161
162
163
164
165
/*
 * FVP provides semihosting as an alternative to load images
 */
int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
				  uintptr_t *image_spec)
166
{
167
	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
168
	if (result == 0) {
169
		*dev_handle = sh_dev_handle;
170
171
		*image_spec = (uintptr_t)&sh_file_spec[image_id];
	}
172

173
174
	return result;
}