fvp_io_storage.c 3.34 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2015, 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
21
22
#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"

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

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

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
	},
#if TRUSTED_BOARD_BOOT
55
56
	[TRUSTED_BOOT_FW_CERT_ID] = {
		.path = TRUSTED_BOOT_FW_CERT_NAME,
57
58
59
60
61
62
		.mode = FOPEN_MODE_RB
	},
	[TRUSTED_KEY_CERT_ID] = {
		.path = TRUSTED_KEY_CERT_NAME,
		.mode = FOPEN_MODE_RB
	},
63
64
	[SOC_FW_KEY_CERT_ID] = {
		.path = SOC_FW_KEY_CERT_NAME,
65
66
		.mode = FOPEN_MODE_RB
	},
67
68
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		.path = TOS_FW_KEY_CERT_NAME,
69
70
		.mode = FOPEN_MODE_RB
	},
71
72
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		.path = NT_FW_KEY_CERT_NAME,
73
74
		.mode = FOPEN_MODE_RB
	},
75
76
	[SOC_FW_CONTENT_CERT_ID] = {
		.path = SOC_FW_CONTENT_CERT_NAME,
77
78
		.mode = FOPEN_MODE_RB
	},
79
80
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		.path = TOS_FW_CONTENT_CERT_NAME,
81
82
		.mode = FOPEN_MODE_RB
	},
83
84
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		.path = NT_FW_CONTENT_CERT_NAME,
85
86
87
88
89
		.mode = FOPEN_MODE_RB
	},
#endif /* TRUSTED_BOARD_BOOT */
};

90

91
static int open_semihosting(const uintptr_t spec)
92
{
93
	int result;
94
	uintptr_t local_image_handle;
95
96

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

108
void plat_arm_io_setup(void)
109
{
110
	int io_result;
111

112
	arm_io_setup();
113

114
115
	/* Register the additional IO devices on this platform */
	io_result = register_io_dev_sh(&sh_dev_con);
116
	assert(io_result == 0);
117

118
	/* Open connections to devices and cache the handles */
119
	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
120
	assert(io_result == 0);
121

122
123
124
125
	/* Ignore improbable errors in release builds */
	(void)io_result;
}

126
127
128
129
130
/*
 * 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)
131
{
132
	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
133
	if (result == 0) {
134
		*dev_handle = sh_dev_handle;
135
136
		*image_spec = (uintptr_t)&sh_file_spec[image_id];
	}
137

138
139
	return result;
}