arm_fconf_io.c 10 KB
Newer Older
1
/*
2
 * Copyright (c) 2019-2021, ARM Limited. All rights reserved.
3
4
5
6
7
8
9
10
11
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>

#include <common/debug.h>
#include <common/fdt_wrappers.h>
#include <drivers/io/io_storage.h>
12
#include <drivers/partition/partition.h>
13
14
15
16
17
18
19
20
#include <lib/object_pool.h>
#include <libfdt.h>
#include <tools_share/firmware_image_package.h>

#include <plat/arm/common/arm_fconf_getter.h>
#include <plat/arm/common/arm_fconf_io_storage.h>
#include <platform_def.h>

21
22
23
24
25
#if PSA_FWU_SUPPORT
/* metadata entry details */
static io_block_spec_t fwu_metadata_spec;
#endif /* PSA_FWU_SUPPORT */

26
27
28
29
30
31
32
33
io_block_spec_t fip_block_spec = {
/*
 * This is fixed FIP address used by BL1, BL2 loads partition table
 * to get FIP address.
 */
#if ARM_GPT_SUPPORT
	.offset = PLAT_ARM_FLASH_IMAGE_BASE + PLAT_ARM_FIP_OFFSET_IN_GPT,
#else
34
	.offset = PLAT_ARM_FLASH_IMAGE_BASE,
35
#endif /* ARM_GPT_SUPPORT */
36
	.length = PLAT_ARM_FLASH_IMAGE_MAX_SIZE
37
38
};

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#if ARM_GPT_SUPPORT
static const io_block_spec_t gpt_spec = {
	.offset         = PLAT_ARM_FLASH_IMAGE_BASE,
	/*
	 * PLAT_PARTITION_BLOCK_SIZE = 512
	 * PLAT_PARTITION_MAX_ENTRIES = 128
	 * each sector has 4 partition entries, and there are
	 * 2 reserved sectors i.e. protective MBR and primary
	 * GPT header hence length gets calculated as,
	 * length = 512 * (128/4 + 2)
	 */
	.length         = PLAT_PARTITION_BLOCK_SIZE *
			  (PLAT_PARTITION_MAX_ENTRIES / 4 + 2),
};
#endif /* ARM_GPT_SUPPORT */

55
56
57
const io_uuid_spec_t arm_uuid_spec[MAX_NUMBER_IDS] = {
	[BL2_IMAGE_ID] = {UUID_TRUSTED_BOOT_FIRMWARE_BL2},
	[TB_FW_CONFIG_ID] = {UUID_TB_FW_CONFIG},
58
	[FW_CONFIG_ID] = {UUID_FW_CONFIG},
Louis Mayencourt's avatar
Louis Mayencourt committed
59
60
61
62
63
64
65
66
67
68
69
70
#if !ARM_IO_IN_DTB
	[SCP_BL2_IMAGE_ID] = {UUID_SCP_FIRMWARE_SCP_BL2},
	[BL31_IMAGE_ID] = {UUID_EL3_RUNTIME_FIRMWARE_BL31},
	[BL32_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32},
	[BL32_EXTRA1_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA1},
	[BL32_EXTRA2_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA2},
	[BL33_IMAGE_ID] = {UUID_NON_TRUSTED_FIRMWARE_BL33},
	[HW_CONFIG_ID] = {UUID_HW_CONFIG},
	[SOC_FW_CONFIG_ID] = {UUID_SOC_FW_CONFIG},
	[TOS_FW_CONFIG_ID] = {UUID_TOS_FW_CONFIG},
	[NT_FW_CONFIG_ID] = {UUID_NT_FW_CONFIG},
#endif /* ARM_IO_IN_DTB */
71
72
#if TRUSTED_BOARD_BOOT
	[TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT},
Louis Mayencourt's avatar
Louis Mayencourt committed
73
74
75
76
77
78
79
80
81
82
#if !ARM_IO_IN_DTB
	[TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT},
	[SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT},
	[SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT},
	[TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT},
	[NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT},
	[SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT},
	[SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT},
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT},
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT},
83
#if defined(SPD_spmd)
84
	[SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT},
85
	[PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT},
86
#endif
Louis Mayencourt's avatar
Louis Mayencourt committed
87
#endif /* ARM_IO_IN_DTB */
88
89
90
91
92
#endif /* TRUSTED_BOARD_BOOT */
};

/* By default, ARM platforms load images from the FIP */
struct plat_io_policy policies[MAX_NUMBER_IDS] = {
93
94
95
96
97
98
99
#if ARM_GPT_SUPPORT
	[GPT_IMAGE_ID] = {
		&memmap_dev_handle,
		(uintptr_t)&gpt_spec,
		open_memmap
	},
#endif /* ARM_GPT_SUPPORT */
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#if PSA_FWU_SUPPORT
	[FWU_METADATA_IMAGE_ID] = {
		&memmap_dev_handle,
		/* filled runtime from partition information */
		(uintptr_t)&fwu_metadata_spec,
		open_memmap
	},
	[BKUP_FWU_METADATA_IMAGE_ID] = {
		&memmap_dev_handle,
		/* filled runtime from partition information */
		(uintptr_t)&fwu_metadata_spec,
		open_memmap
	},
#endif /* PSA_FWU_SUPPORT */
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
	[FIP_IMAGE_ID] = {
		&memmap_dev_handle,
		(uintptr_t)&fip_block_spec,
		open_memmap
	},
	[BL2_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID],
		open_fip
	},
	[TB_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID],
		open_fip
	},
129
130
131
132
133
	[FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[FW_CONFIG_ID],
		open_fip
	},
Louis Mayencourt's avatar
Louis Mayencourt committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#if !ARM_IO_IN_DTB
	[SCP_BL2_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID],
		open_fip
	},
	[BL31_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID],
		open_fip
	},
	[BL32_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID],
		open_fip
	},
	[BL32_EXTRA1_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID],
		open_fip
	},
	[BL32_EXTRA2_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID],
		open_fip
	},
	[BL33_IMAGE_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID],
		open_fip
	},
	[HW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[HW_CONFIG_ID],
		open_fip
	},
	[SOC_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID],
		open_fip
	},
	[TOS_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID],
		open_fip
	},
	[NT_FW_CONFIG_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID],
		open_fip
	},
#endif /* ARM_IO_IN_DTB */
186
187
188
189
190
191
#if TRUSTED_BOARD_BOOT
	[TRUSTED_BOOT_FW_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID],
		open_fip
	},
Louis Mayencourt's avatar
Louis Mayencourt committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#if !ARM_IO_IN_DTB
	[TRUSTED_KEY_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID],
		open_fip
	},
	[SCP_FW_KEY_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID],
		open_fip
	},
	[SOC_FW_KEY_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID],
		open_fip
	},
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID],
		open_fip
	},
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID],
		open_fip
	},
	[SCP_FW_CONTENT_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID],
		open_fip
	},
	[SOC_FW_CONTENT_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID],
		open_fip
	},
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID],
		open_fip
	},
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID],
		open_fip
	},
238
#if defined(SPD_spmd)
239
	[SIP_SP_CONTENT_CERT_ID] = {
240
		&fip_dev_handle,
241
		(uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID],
242
243
		open_fip
	},
244
245
246
247
248
	[PLAT_SP_CONTENT_CERT_ID] = {
		&fip_dev_handle,
		(uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID],
		open_fip
	},
249
#endif
Louis Mayencourt's avatar
Louis Mayencourt committed
250
#endif /* ARM_IO_IN_DTB */
251
252
253
254
255
256
#endif /* TRUSTED_BOARD_BOOT */
};

#ifdef IMAGE_BL2

#if TRUSTED_BOARD_BOOT
257
#define FCONF_ARM_IO_UUID_NUMBER	U(21)
258
#else
Louis Mayencourt's avatar
Louis Mayencourt committed
259
#define FCONF_ARM_IO_UUID_NUMBER	U(10)
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#endif

static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);

struct policies_load_info {
	unsigned int image_id;
	const char *name;
};

/* image id to property name table */
static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = {
	{SCP_BL2_IMAGE_ID, "scp_bl2_uuid"},
	{BL31_IMAGE_ID, "bl31_uuid"},
	{BL32_IMAGE_ID, "bl32_uuid"},
	{BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
	{BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
	{BL33_IMAGE_ID, "bl33_uuid"},
	{HW_CONFIG_ID, "hw_cfg_uuid"},
	{SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
	{TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
	{NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"},
#if TRUSTED_BOARD_BOOT
	{TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
	{SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"},
	{SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"},
	{TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
	{NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
	{SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"},
	{SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"},
	{TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
	{NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
292
#if defined(SPD_spmd)
293
	{SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"},
294
	{PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"},
295
#endif
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#endif /* TRUSTED_BOARD_BOOT */
};

int fconf_populate_arm_io_policies(uintptr_t config)
{
	int err, node;
	unsigned int i;

	union uuid_helper_t uuid_helper;
	io_uuid_spec_t *uuid_ptr;

	/* As libfdt uses void *, we can't avoid this cast */
	const void *dtb = (void *)config;

	/* Assert the node offset point to "arm,io-fip-handle" compatible property */
	const char *compatible_str = "arm,io-fip-handle";
	node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
	if (node < 0) {
		ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
		return node;
	}

	/* Locate the uuid cells and read the value for all the load info uuid */
	for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
		uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
321
322
		err = fdtw_read_uuid(dtb, node, load_info[i].name, 16,
				     (uint8_t *)&uuid_helper);
323
324
325
326
327
		if (err < 0) {
			WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
			return err;
		}

328
329
		VERBOSE("FCONF: arm-io_policies.%s cell found with value = "
			"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
330
			load_info[i].name,
331
332
333
334
335
336
337
338
339
340
			uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
			uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
			uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
			uuid_helper.uuid_struct.time_hi_and_version[0],
			uuid_helper.uuid_struct.time_hi_and_version[1],
			uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
			uuid_helper.uuid_struct.clock_seq_low,
			uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
			uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
			uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]);
341
342
343
344
345
346
347
348
349

		uuid_ptr->uuid = uuid_helper.uuid_struct;
		policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
		policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
		policies[load_info[i].image_id].check = open_fip;
	}
	return 0;
}

Louis Mayencourt's avatar
Louis Mayencourt committed
350
#if ARM_IO_IN_DTB
351
FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
Louis Mayencourt's avatar
Louis Mayencourt committed
352
#endif /* ARM_IO_IN_DTB */
353
354

#endif /* IMAGE_BL2 */