fvp_io_storage.c 3.47 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
23

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

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

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

95

96
static int open_semihosting(const uintptr_t spec)
97
{
98
	int result;
99
	uintptr_t local_image_handle;
100
101

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

113
void plat_arm_io_setup(void)
114
{
115
	int io_result;
116

117
	arm_io_setup();
118

119
120
	/* Register the additional IO devices on this platform */
	io_result = register_io_dev_sh(&sh_dev_con);
121
	assert(io_result == 0);
122

123
	/* Open connections to devices and cache the handles */
124
	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
125
	assert(io_result == 0);
126

127
128
129
130
	/* Ignore improbable errors in release builds */
	(void)io_result;
}

131
132
133
134
135
/*
 * 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)
136
{
137
	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
138
	if (result == 0) {
139
		*dev_handle = sh_dev_handle;
140
141
		*image_spec = (uintptr_t)&sh_file_spec[image_id];
	}
142

143
144
	return result;
}