fvp_io_storage.c 3.58 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2018, 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
#include <common_def.h>
9
#include <debug.h>
10
#include <io_driver.h>
11
#include <io_semihosting.h>
12
#include <io_storage.h>
13
#include <plat_arm.h>
14
15
16
17
18
19
20
#include <semihosting.h>	/* For FOPEN_MODE_... */

/* 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"
21
#define TB_FW_CONFIG_NAME		"fvp_tb_fw_config.dtb"
22
#define HW_CONFIG_NAME			"hw_config.dtb"
23
24

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

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

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

100

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

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

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

122
	arm_io_setup();
123

124
125
	/* Register the additional IO devices on this platform */
	io_result = register_io_dev_sh(&sh_dev_con);
126
	assert(io_result == 0);
127

128
	/* Open connections to devices and cache the handles */
129
	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
130
	assert(io_result == 0);
131

132
133
134
135
	/* Ignore improbable errors in release builds */
	(void)io_result;
}

136
137
138
139
140
/*
 * 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)
141
{
142
	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
143
	if (result == 0) {
144
		*dev_handle = sh_dev_handle;
145
146
		*image_spec = (uintptr_t)&sh_file_spec[image_id];
	}
147

148
149
	return result;
}