fvp_io_storage.c 3.61 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
9
10
11
12
13
14
15

#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>
#include <plat/common/common_def.h>

16
#include <plat_arm.h>
17
18
19
20
21
22

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

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

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

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

102

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

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

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

124
	arm_io_setup();
125

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

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

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

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

150
151
	return result;
}