fvp_io_storage.c 3.63 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
#define HW_CONFIG_NAME			"hw_config.dtb"
24
25

#if TRUSTED_BOARD_BOOT
26
#define TRUSTED_BOOT_FW_CERT_NAME	"tb_fw.crt"
27
#define TRUSTED_KEY_CERT_NAME		"trusted_key.crt"
28
29
30
31
32
33
#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"
34
#endif /* TRUSTED_BOARD_BOOT */
35
36

/* IO devices */
37
38
static const io_dev_connector_t *sh_dev_con;
static uintptr_t sh_dev_handle;
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
	},
57
58
	[TB_FW_CONFIG_ID] = {
		.path = TB_FW_CONFIG_NAME,
59
60
61
62
		.mode = FOPEN_MODE_RB
	},
	[HW_CONFIG_ID] = {
		.path = HW_CONFIG_NAME,
63
64
		.mode = FOPEN_MODE_RB
	},
65
#if TRUSTED_BOARD_BOOT
66
67
	[TRUSTED_BOOT_FW_CERT_ID] = {
		.path = TRUSTED_BOOT_FW_CERT_NAME,
68
69
70
71
72
73
		.mode = FOPEN_MODE_RB
	},
	[TRUSTED_KEY_CERT_ID] = {
		.path = TRUSTED_KEY_CERT_NAME,
		.mode = FOPEN_MODE_RB
	},
74
75
	[SOC_FW_KEY_CERT_ID] = {
		.path = SOC_FW_KEY_CERT_NAME,
76
77
		.mode = FOPEN_MODE_RB
	},
78
79
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		.path = TOS_FW_KEY_CERT_NAME,
80
81
		.mode = FOPEN_MODE_RB
	},
82
83
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		.path = NT_FW_KEY_CERT_NAME,
84
85
		.mode = FOPEN_MODE_RB
	},
86
87
	[SOC_FW_CONTENT_CERT_ID] = {
		.path = SOC_FW_CONTENT_CERT_NAME,
88
89
		.mode = FOPEN_MODE_RB
	},
90
91
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		.path = TOS_FW_CONTENT_CERT_NAME,
92
93
		.mode = FOPEN_MODE_RB
	},
94
95
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		.path = NT_FW_CONTENT_CERT_NAME,
96
97
98
99
100
		.mode = FOPEN_MODE_RB
	},
#endif /* TRUSTED_BOARD_BOOT */
};

101

102
static int open_semihosting(const uintptr_t spec)
103
{
104
	int result;
105
	uintptr_t local_image_handle;
106
107

	/* See if the file exists on semi-hosting.*/
108
	result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
109
	if (result == 0) {
110
		result = io_open(sh_dev_handle, spec, &local_image_handle);
111
		if (result == 0) {
Dan Handley's avatar
Dan Handley committed
112
			VERBOSE("Using Semi-hosting IO\n");
113
114
115
116
117
118
			io_close(local_image_handle);
		}
	}
	return result;
}

119
void plat_arm_io_setup(void)
120
{
121
	int io_result;
122

123
124
125
126
	io_result = arm_io_setup();
	if (io_result < 0) {
		panic();
	}
127

128
129
	/* Register the additional IO devices on this platform */
	io_result = register_io_dev_sh(&sh_dev_con);
130
131
132
	if (io_result < 0) {
		panic();
	}
133

134
	/* Open connections to devices and cache the handles */
135
	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
136
137
138
	if (io_result < 0) {
		panic();
	}
139
140
}

141
142
143
144
145
/*
 * 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)
146
{
147
	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
148
	if (result == 0) {
149
		*dev_handle = sh_dev_handle;
150
151
		*image_spec = (uintptr_t)&sh_file_spec[image_id];
	}
152

153
154
	return result;
}