arm_io_storage.c 7.87 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-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
8
#include <assert.h>
#include <string.h>
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <platform_def.h>

#include <common/debug.h>
#include <drivers/io/io_driver.h>
#include <drivers/io/io_fip.h>
#include <drivers/io/io_memmap.h>
#include <drivers/io/io_storage.h>
#include <lib/utils.h>
#include <plat/common/platform.h>
#include <tools_share/firmware_image_package.h>

#include <plat_arm.h>
22
23
24
25
26
27
28
29
30
31
32
33

/* IO devices */
static const io_dev_connector_t *fip_dev_con;
static uintptr_t fip_dev_handle;
static const io_dev_connector_t *memmap_dev_con;
static uintptr_t memmap_dev_handle;

static const io_block_spec_t fip_block_spec = {
	.offset = PLAT_ARM_FIP_BASE,
	.length = PLAT_ARM_FIP_MAX_SIZE
};

34
35
static const io_uuid_spec_t bl2_uuid_spec = {
	.uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
36
37
};

38
39
static const io_uuid_spec_t scp_bl2_uuid_spec = {
	.uuid = UUID_SCP_FIRMWARE_SCP_BL2,
40
41
};

42
43
static const io_uuid_spec_t bl31_uuid_spec = {
	.uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
44
45
};

46
47
static const io_uuid_spec_t bl32_uuid_spec = {
	.uuid = UUID_SECURE_PAYLOAD_BL32,
48
49
};

50
51
52
53
54
55
56
57
static const io_uuid_spec_t bl32_extra1_uuid_spec = {
	.uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
};

static const io_uuid_spec_t bl32_extra2_uuid_spec = {
	.uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
};

58
59
static const io_uuid_spec_t bl33_uuid_spec = {
	.uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
60
61
};

62
63
64
65
static const io_uuid_spec_t tb_fw_config_uuid_spec = {
	.uuid = UUID_TB_FW_CONFIG,
};

66
67
68
69
static const io_uuid_spec_t hw_config_uuid_spec = {
	.uuid = UUID_HW_CONFIG,
};

70
71
72
73
74
75
76
77
78
79
80
81
static const io_uuid_spec_t soc_fw_config_uuid_spec = {
	.uuid = UUID_SOC_FW_CONFIG,
};

static const io_uuid_spec_t tos_fw_config_uuid_spec = {
	.uuid = UUID_TOS_FW_CONFIG,
};

static const io_uuid_spec_t nt_fw_config_uuid_spec = {
	.uuid = UUID_NT_FW_CONFIG,
};

82
#if TRUSTED_BOARD_BOOT
83
84
static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
	.uuid = UUID_TRUSTED_BOOT_FW_CERT,
85
86
};

87
88
static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
	.uuid = UUID_TRUSTED_KEY_CERT,
89
90
};

91
92
static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = {
	.uuid = UUID_SCP_FW_KEY_CERT,
93
94
};

95
96
static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
	.uuid = UUID_SOC_FW_KEY_CERT,
97
98
};

99
100
static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
	.uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
101
102
};

103
104
static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
	.uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
105
106
};

107
108
static const io_uuid_spec_t scp_fw_cert_uuid_spec = {
	.uuid = UUID_SCP_FW_CONTENT_CERT,
109
110
};

111
112
static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
	.uuid = UUID_SOC_FW_CONTENT_CERT,
113
114
};

115
116
static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
	.uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
117
118
};

119
120
static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
	.uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
121
122
123
};
#endif /* TRUSTED_BOARD_BOOT */

124

125
126
127
128
129
130
131
132
133
static int open_fip(const uintptr_t spec);
static int open_memmap(const uintptr_t spec);

struct plat_io_policy {
	uintptr_t *dev_handle;
	uintptr_t image_spec;
	int (*check)(const uintptr_t spec);
};

134
/* By default, ARM platforms load images from the FIP */
135
static const struct plat_io_policy policies[] = {
136
	[FIP_IMAGE_ID] = {
137
138
139
		&memmap_dev_handle,
		(uintptr_t)&fip_block_spec,
		open_memmap
140
141
	},
	[BL2_IMAGE_ID] = {
142
		&fip_dev_handle,
143
		(uintptr_t)&bl2_uuid_spec,
144
		open_fip
145
	},
146
	[SCP_BL2_IMAGE_ID] = {
147
		&fip_dev_handle,
148
		(uintptr_t)&scp_bl2_uuid_spec,
149
		open_fip
150
151
	},
	[BL31_IMAGE_ID] = {
152
		&fip_dev_handle,
153
		(uintptr_t)&bl31_uuid_spec,
154
		open_fip
155
156
	},
	[BL32_IMAGE_ID] = {
157
		&fip_dev_handle,
158
		(uintptr_t)&bl32_uuid_spec,
159
		open_fip
160
	},
161
162
163
164
165
166
167
168
169
170
	[BL32_EXTRA1_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&bl32_extra1_uuid_spec,
		open_fip
	},
	[BL32_EXTRA2_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&bl32_extra2_uuid_spec,
		open_fip
	},
171
	[BL33_IMAGE_ID] = {
172
		&fip_dev_handle,
173
		(uintptr_t)&bl33_uuid_spec,
174
		open_fip
175
	},
176
177
178
179
180
	[TB_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&tb_fw_config_uuid_spec,
		open_fip
	},
181
182
183
184
185
	[HW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&hw_config_uuid_spec,
		open_fip
	},
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	[SOC_FW_CONFIG_ID] = {
			&fip_dev_handle,
			(uintptr_t)&soc_fw_config_uuid_spec,
			open_fip
	},
	[TOS_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&tos_fw_config_uuid_spec,
		open_fip
	},
	[NT_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&nt_fw_config_uuid_spec,
		open_fip
	},
201
#if TRUSTED_BOARD_BOOT
202
	[TRUSTED_BOOT_FW_CERT_ID] = {
203
		&fip_dev_handle,
204
		(uintptr_t)&tb_fw_cert_uuid_spec,
205
		open_fip
206
207
	},
	[TRUSTED_KEY_CERT_ID] = {
208
		&fip_dev_handle,
209
		(uintptr_t)&trusted_key_cert_uuid_spec,
210
		open_fip
211
	},
212
	[SCP_FW_KEY_CERT_ID] = {
213
		&fip_dev_handle,
214
		(uintptr_t)&scp_fw_key_cert_uuid_spec,
215
		open_fip
216
	},
217
	[SOC_FW_KEY_CERT_ID] = {
218
		&fip_dev_handle,
219
		(uintptr_t)&soc_fw_key_cert_uuid_spec,
220
		open_fip
221
	},
222
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
223
		&fip_dev_handle,
224
		(uintptr_t)&tos_fw_key_cert_uuid_spec,
225
		open_fip
226
	},
227
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
228
		&fip_dev_handle,
229
		(uintptr_t)&nt_fw_key_cert_uuid_spec,
230
		open_fip
231
	},
232
	[SCP_FW_CONTENT_CERT_ID] = {
233
		&fip_dev_handle,
234
		(uintptr_t)&scp_fw_cert_uuid_spec,
235
		open_fip
236
	},
237
	[SOC_FW_CONTENT_CERT_ID] = {
238
		&fip_dev_handle,
239
		(uintptr_t)&soc_fw_cert_uuid_spec,
240
		open_fip
241
	},
242
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
243
		&fip_dev_handle,
244
		(uintptr_t)&tos_fw_cert_uuid_spec,
245
		open_fip
246
	},
247
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
248
		&fip_dev_handle,
249
		(uintptr_t)&nt_fw_cert_uuid_spec,
250
		open_fip
251
	},
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#endif /* TRUSTED_BOARD_BOOT */
};


/* Weak definitions may be overridden in specific ARM standard platform */
#pragma weak plat_arm_io_setup
#pragma weak plat_arm_get_alt_image_source


static int open_fip(const uintptr_t spec)
{
	int result;
	uintptr_t local_image_handle;

	/* See if a Firmware Image Package is available */
267
	result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
268
	if (result == 0) {
269
		result = io_open(fip_dev_handle, spec, &local_image_handle);
270
		if (result == 0) {
271
272
273
274
275
276
277
278
279
280
281
282
283
284
			VERBOSE("Using FIP\n");
			io_close(local_image_handle);
		}
	}
	return result;
}


static int open_memmap(const uintptr_t spec)
{
	int result;
	uintptr_t local_image_handle;

	result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
285
	if (result == 0) {
286
		result = io_open(memmap_dev_handle, spec, &local_image_handle);
287
		if (result == 0) {
288
289
290
291
292
293
294
295
296
297
298
299
300
			VERBOSE("Using Memmap\n");
			io_close(local_image_handle);
		}
	}
	return result;
}


void arm_io_setup(void)
{
	int io_result;

	io_result = register_io_dev_fip(&fip_dev_con);
301
	assert(io_result == 0);
302
303

	io_result = register_io_dev_memmap(&memmap_dev_con);
304
	assert(io_result == 0);
305
306
307
308

	/* Open connections to devices and cache the handles */
	io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
				&fip_dev_handle);
309
	assert(io_result == 0);
310
311
312

	io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
				&memmap_dev_handle);
313
	assert(io_result == 0);
314
315
316
317
318
319
320
321
322
323
324

	/* Ignore improbable errors in release builds */
	(void)io_result;
}

void plat_arm_io_setup(void)
{
	arm_io_setup();
}

int plat_arm_get_alt_image_source(
325
326
327
	unsigned int image_id __unused,
	uintptr_t *dev_handle __unused,
	uintptr_t *image_spec __unused)
328
329
{
	/* By default do not try an alternative */
330
	return -ENOENT;
331
332
333
334
}

/* Return an IO device handle and specification which can be used to access
 * an image. Use this to enforce platform load policy */
335
int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
336
337
			  uintptr_t *image_spec)
{
338
	int result;
339
340
	const struct plat_io_policy *policy;

341
342
343
344
	assert(image_id < ARRAY_SIZE(policies));

	policy = &policies[image_id];
	result = policy->check(policy->image_spec);
345
	if (result == 0) {
346
347
		*image_spec = policy->image_spec;
		*dev_handle = *(policy->dev_handle);
348
	} else {
349
350
351
		VERBOSE("Trying alternative IO\n");
		result = plat_arm_get_alt_image_source(image_id, dev_handle,
						       image_spec);
352
	}
353

354
355
	return result;
}
356
357
358
359
360
361
362
363
364
365
366
367
368
369

/*
 * See if a Firmware Image Package is available,
 * by checking if TOC is valid or not.
 */
int arm_io_is_toc_valid(void)
{
	int result;

	result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);

	return (result == 0);
}