bl2_io_storage.c 16.4 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
8
9
#include <string.h>

10
#include <platform_def.h>
11
12
13
14
15
16

#include <arch_helpers.h>
#include <common/debug.h>
#include <drivers/io/io_block.h>
#include <drivers/io/io_driver.h>
#include <drivers/io/io_dummy.h>
17
#include <drivers/io/io_mtd.h>
18
19
20
#include <drivers/io/io_storage.h>
#include <drivers/mmc.h>
#include <drivers/partition/partition.h>
21
#include <drivers/raw_nand.h>
22
#include <drivers/spi_nand.h>
23
#include <drivers/spi_nor.h>
24
25
#include <drivers/st/io_mmc.h>
#include <drivers/st/io_stm32image.h>
26
#include <drivers/st/stm32_fmc2_nand.h>
27
#include <drivers/st/stm32_qspi.h>
28
29
30
31
32
#include <drivers/st/stm32_sdmmc2.h>
#include <lib/mmio.h>
#include <lib/utils.h>
#include <plat/common/platform.h>

33
/* IO devices */
34
#ifndef AARCH32_SP_OPTEE
35
36
37
static const io_dev_connector_t *dummy_dev_con;
static uintptr_t dummy_dev_handle;
static uintptr_t dummy_dev_spec;
38
#endif
39

40
static uintptr_t image_dev_handle;
41
static uintptr_t storage_dev_handle;
42

43
#if STM32MP_SDMMC || STM32MP_EMMC
44
static struct mmc_device_info mmc_info;
45
46
47
48
49
static io_block_spec_t gpt_block_spec = {
	.offset = 0,
	.length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */
};

50
static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
51
52
53
54
55
56
57
58
59
60
61
62
63
64

static const io_block_dev_spec_t mmc_block_dev_spec = {
	/* It's used as temp buffer in block driver */
	.buffer = {
		.offset = (size_t)&block_buffer,
		.length = MMC_BLOCK_SIZE,
	},
	.ops = {
		.read = mmc_read_blocks,
		.write = NULL,
	},
	.block_size = MMC_BLOCK_SIZE,
};

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#if STM32MP_EMMC_BOOT
static io_block_spec_t emmc_boot_ssbl_block_spec = {
	.offset = PLAT_EMMC_BOOT_SSBL_OFFSET,
	.length = MMC_BLOCK_SIZE, /* We are interested only in first 4 bytes */
};

static const io_block_dev_spec_t mmc_block_dev_boot_part_spec = {
	/* It's used as temp buffer in block driver */
	.buffer = {
		.offset = (size_t)&block_buffer,
		.length = MMC_BLOCK_SIZE,
	},
	.ops = {
		.read = mmc_boot_part_read_blocks,
		.write = NULL,
	},
	.block_size = MMC_BLOCK_SIZE,
};
#endif

static struct io_mmc_dev_spec mmc_device_spec = {
	.use_boot_part = false,
};

89
static const io_dev_connector_t *mmc_dev_con;
90
#endif /* STM32MP_SDMMC || STM32MP_EMMC */
91

92
93
94
95
96
97
98
99
100
#if STM32MP_SPI_NOR
static io_mtd_dev_spec_t spi_nor_dev_spec = {
	.ops = {
		.init = spi_nor_init,
		.read = spi_nor_read,
	},
};
#endif

101
102
103
104
105
106
107
108
109
110
111
#if STM32MP_RAW_NAND
static io_mtd_dev_spec_t nand_dev_spec = {
	.ops = {
		.init = nand_raw_init,
		.read = nand_read,
	},
};

static const io_dev_connector_t *nand_dev_con;
#endif

112
113
114
115
116
117
118
#if STM32MP_SPI_NAND
static io_mtd_dev_spec_t spi_nand_dev_spec = {
	.ops = {
		.init = spi_nand_init,
		.read = nand_read,
	},
};
119
#endif
120

121
#if STM32MP_SPI_NAND || STM32MP_SPI_NOR
122
123
124
static const io_dev_connector_t *spi_dev_con;
#endif

Yann Gautier's avatar
Yann Gautier committed
125
126
127
128
129
130
#ifdef AARCH32_SP_OPTEE
static const struct stm32image_part_info optee_header_partition_spec = {
	.name = OPTEE_HEADER_IMAGE_NAME,
	.binary_type = OPTEE_HEADER_BINARY_TYPE,
};

131
132
133
static const struct stm32image_part_info optee_core_partition_spec = {
	.name = OPTEE_CORE_IMAGE_NAME,
	.binary_type = OPTEE_CORE_BINARY_TYPE,
Yann Gautier's avatar
Yann Gautier committed
134
135
136
137
138
139
140
};

static const struct stm32image_part_info optee_paged_partition_spec = {
	.name = OPTEE_PAGED_IMAGE_NAME,
	.binary_type = OPTEE_PAGED_BINARY_TYPE,
};
#else
Yann Gautier's avatar
Yann Gautier committed
141
142
static const io_block_spec_t bl32_block_spec = {
	.offset = BL32_BASE,
143
	.length = STM32MP_BL32_SIZE
Yann Gautier's avatar
Yann Gautier committed
144
};
Yann Gautier's avatar
Yann Gautier committed
145
#endif
Yann Gautier's avatar
Yann Gautier committed
146

147
148
149
150
151
static const struct stm32image_part_info bl33_partition_spec = {
	.name = BL33_IMAGE_NAME,
	.binary_type = BL33_BINARY_TYPE,
};

Yann Gautier's avatar
Yann Gautier committed
152
153
enum {
	IMG_IDX_BL33,
Yann Gautier's avatar
Yann Gautier committed
154
155
#ifdef AARCH32_SP_OPTEE
	IMG_IDX_OPTEE_HEADER,
156
	IMG_IDX_OPTEE_CORE,
Yann Gautier's avatar
Yann Gautier committed
157
158
	IMG_IDX_OPTEE_PAGED,
#endif
Yann Gautier's avatar
Yann Gautier committed
159
160
161
	IMG_IDX_NUM
};

162
static struct stm32image_device_info stm32image_dev_info_spec __unused = {
163
164
165
166
167
	.lba_size = MMC_BLOCK_SIZE,
	.part_info[IMG_IDX_BL33] = {
		.name = BL33_IMAGE_NAME,
		.binary_type = BL33_BINARY_TYPE,
	},
Yann Gautier's avatar
Yann Gautier committed
168
169
170
171
172
#ifdef AARCH32_SP_OPTEE
	.part_info[IMG_IDX_OPTEE_HEADER] = {
		.name = OPTEE_HEADER_IMAGE_NAME,
		.binary_type = OPTEE_HEADER_BINARY_TYPE,
	},
173
174
175
	.part_info[IMG_IDX_OPTEE_CORE] = {
		.name = OPTEE_CORE_IMAGE_NAME,
		.binary_type = OPTEE_CORE_BINARY_TYPE,
Yann Gautier's avatar
Yann Gautier committed
176
177
178
179
180
181
	},
	.part_info[IMG_IDX_OPTEE_PAGED] = {
		.name = OPTEE_PAGED_IMAGE_NAME,
		.binary_type = OPTEE_PAGED_BINARY_TYPE,
	},
#endif
182
183
};

Yann Gautier's avatar
Yann Gautier committed
184
185
186
static io_block_spec_t stm32image_block_spec = {
	.offset = 0,
	.length = 0,
187
188
};

189
static const io_dev_connector_t *stm32image_dev_con __unused;
190

191
#ifndef AARCH32_SP_OPTEE
192
static int open_dummy(const uintptr_t spec);
193
#endif
194
195
static int open_image(const uintptr_t spec);
static int open_storage(const uintptr_t spec);
196
197
198
199
200
201
202
203

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

static const struct plat_io_policy policies[] = {
Yann Gautier's avatar
Yann Gautier committed
204
205
206
207
208
209
210
211
#ifdef AARCH32_SP_OPTEE
	[BL32_IMAGE_ID] = {
		.dev_handle = &image_dev_handle,
		.image_spec = (uintptr_t)&optee_header_partition_spec,
		.check = open_image
	},
	[BL32_EXTRA1_IMAGE_ID] = {
		.dev_handle = &image_dev_handle,
212
		.image_spec = (uintptr_t)&optee_core_partition_spec,
Yann Gautier's avatar
Yann Gautier committed
213
214
215
216
217
218
219
220
		.check = open_image
	},
	[BL32_EXTRA2_IMAGE_ID] = {
		.dev_handle = &image_dev_handle,
		.image_spec = (uintptr_t)&optee_paged_partition_spec,
		.check = open_image
	},
#else
221
222
223
224
225
	[BL32_IMAGE_ID] = {
		.dev_handle = &dummy_dev_handle,
		.image_spec = (uintptr_t)&bl32_block_spec,
		.check = open_dummy
	},
Yann Gautier's avatar
Yann Gautier committed
226
#endif
227
228
229
230
231
	[BL33_IMAGE_ID] = {
		.dev_handle = &image_dev_handle,
		.image_spec = (uintptr_t)&bl33_partition_spec,
		.check = open_image
	},
232
#if STM32MP_SDMMC || STM32MP_EMMC
233
234
235
236
237
	[GPT_IMAGE_ID] = {
		.dev_handle = &storage_dev_handle,
		.image_spec = (uintptr_t)&gpt_block_spec,
		.check = open_storage
	},
238
#endif
239
240
241
242
243
	[STM32_IMAGE_ID] = {
		.dev_handle = &storage_dev_handle,
		.image_spec = (uintptr_t)&stm32image_block_spec,
		.check = open_storage
	}
244
245
};

246
#ifndef AARCH32_SP_OPTEE
247
248
249
250
static int open_dummy(const uintptr_t spec)
{
	return io_dev_init(dummy_dev_handle, 0);
}
251
#endif
252

253
254
255
256
257
258
259
260
261
262
static int open_image(const uintptr_t spec)
{
	return io_dev_init(image_dev_handle, 0);
}

static int open_storage(const uintptr_t spec)
{
	return io_dev_init(storage_dev_handle, 0);
}

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
292
293
294
#if STM32MP_EMMC_BOOT
static uint32_t get_boot_part_ssbl_header(void)
{
	uint32_t magic = 0;
	int io_result;
	size_t bytes_read;

	io_result = register_io_dev_block(&mmc_dev_con);
	if (io_result != 0) {
		panic();
	}

	io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_boot_part_spec,
				&storage_dev_handle);
	assert(io_result == 0);

	io_result = io_open(storage_dev_handle, (uintptr_t) &emmc_boot_ssbl_block_spec,
			    &image_dev_handle);
	assert(io_result == 0);

	io_result = io_read(image_dev_handle, (uintptr_t) &magic, sizeof(magic),
			    &bytes_read);
	assert(io_result == 0);
	assert(bytes_read == sizeof(magic));

	io_result = io_dev_close(storage_dev_handle);
	assert(io_result == 0);

	return magic;
}
#endif

295
296
297
298
299
300
301
302
303
static void print_boot_device(boot_api_context_t *boot_context)
{
	switch (boot_context->boot_interface_selected) {
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
		INFO("Using SDMMC\n");
		break;
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
		INFO("Using EMMC\n");
		break;
304
305
306
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
		INFO("Using QSPI NOR\n");
		break;
307
308
309
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
		INFO("Using FMC NAND\n");
		break;
310
311
312
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
		INFO("Using SPI NAND\n");
		break;
313
314
315
316
317
318
319
320
321
322
323
	default:
		ERROR("Boot interface not found\n");
		panic();
		break;
	}

	if (boot_context->boot_interface_instance != 0U) {
		INFO("  Instance %d\n", boot_context->boot_interface_instance);
	}
}

324
#if STM32MP_SDMMC || STM32MP_EMMC
325
326
static void boot_mmc(enum mmc_device_type mmc_dev_type,
		     uint16_t boot_interface_instance)
327
328
{
	int io_result __unused;
Yann Gautier's avatar
Yann Gautier committed
329
330
	uint8_t idx;
	struct stm32image_part_info *part;
331
	struct stm32_sdmmc2_params params;
332
333
	const partition_entry_t *entry __unused;
	uint32_t magic __unused;
334

335
	zeromem(&params, sizeof(struct stm32_sdmmc2_params));
336

337
	mmc_info.mmc_dev_type = mmc_dev_type;
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

	switch (boot_interface_instance) {
	case 1:
		params.reg_base = STM32MP_SDMMC1_BASE;
		break;
	case 2:
		params.reg_base = STM32MP_SDMMC2_BASE;
		break;
	case 3:
		params.reg_base = STM32MP_SDMMC3_BASE;
		break;
	default:
		WARN("SDMMC instance not found, using default\n");
		if (mmc_dev_type == MMC_IS_SD) {
			params.reg_base = STM32MP_SDMMC1_BASE;
		} else {
			params.reg_base = STM32MP_SDMMC2_BASE;
		}
		break;
357
358
	}

359
	params.device_info = &mmc_info;
360
361
362
363
	if (stm32_sdmmc2_mmc_init(&params) != 0) {
		ERROR("SDMMC%u init failed\n", boot_interface_instance);
		panic();
	}
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
	stm32image_dev_info_spec.device_size =
		stm32_sdmmc2_mmc_get_device_size();

#if STM32MP_EMMC_BOOT
	magic = get_boot_part_ssbl_header();

	if (magic == BOOT_API_IMAGE_HEADER_MAGIC_NB) {
		VERBOSE("%s, header found, jump to emmc load\n", __func__);
		idx = IMG_IDX_BL33;
		part = &stm32image_dev_info_spec.part_info[idx];
		part->part_offset = PLAT_EMMC_BOOT_SSBL_OFFSET;
		part->bkp_offset = 0U;
		mmc_device_spec.use_boot_part = true;

		goto emmc_boot;
	} else {
		WARN("%s: Can't find STM32 header on a boot partition\n", __func__);
	}
#endif

385
386
387
388
389
390
391
392
	/* Open MMC as a block device to read GPT table */
	io_result = register_io_dev_block(&mmc_dev_con);
	if (io_result != 0) {
		panic();
	}

	io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
				&storage_dev_handle);
393
	assert(io_result == 0);
394

395
	partition_init(GPT_IMAGE_ID);
396

397
398
	io_result = io_dev_close(storage_dev_handle);
	assert(io_result == 0);
399

400
401
402
403
404
	for (idx = 0U; idx < IMG_IDX_NUM; idx++) {
		part = &stm32image_dev_info_spec.part_info[idx];
		entry = get_partition_entry(part->name);
		if (entry == NULL) {
			ERROR("Partition %s not found\n", part->name);
405
406
			panic();
		}
407

408
409
410
		part->part_offset = entry->start;
		part->bkp_offset = 0U;
	}
411

412
413
414
#if STM32MP_EMMC_BOOT
emmc_boot:
#endif
415
416
417
418
419
420
	/*
	 * Re-open MMC with io_mmc, for better perfs compared to
	 * io_block.
	 */
	io_result = register_io_dev_mmc(&mmc_dev_con);
	assert(io_result == 0);
421

422
423
	io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_device_spec,
				&storage_dev_handle);
424
	assert(io_result == 0);
425

426
427
	io_result = register_io_dev_stm32image(&stm32image_dev_con);
	assert(io_result == 0);
428

429
430
431
432
433
	io_result = io_dev_open(stm32image_dev_con,
				(uintptr_t)&stm32image_dev_info_spec,
				&image_dev_handle);
	assert(io_result == 0);
}
434
#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier's avatar
Yann Gautier committed
435

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#if STM32MP_SPI_NOR
static void boot_spi_nor(boot_api_context_t *boot_context)
{
	int io_result __unused;
	uint8_t idx;
	struct stm32image_part_info *part;

	io_result = stm32_qspi_init();
	assert(io_result == 0);

	io_result = register_io_dev_mtd(&spi_dev_con);
	assert(io_result == 0);

	/* Open connections to device */
	io_result = io_dev_open(spi_dev_con,
				(uintptr_t)&spi_nor_dev_spec,
				&storage_dev_handle);
	assert(io_result == 0);

	stm32image_dev_info_spec.device_size = spi_nor_dev_spec.device_size;

	idx = IMG_IDX_BL33;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NOR_BL33_OFFSET;
	part->bkp_offset = 0U;

#ifdef AARCH32_SP_OPTEE
	idx = IMG_IDX_OPTEE_HEADER;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NOR_TEEH_OFFSET;
	part->bkp_offset = 0U;

	idx = IMG_IDX_OPTEE_PAGED;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NOR_TEED_OFFSET;
	part->bkp_offset = 0U;

473
	idx = IMG_IDX_OPTEE_CORE;
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NOR_TEEX_OFFSET;
	part->bkp_offset = 0U;
#endif

	io_result = register_io_dev_stm32image(&stm32image_dev_con);
	assert(io_result == 0);

	io_result = io_dev_open(stm32image_dev_con,
				(uintptr_t)&stm32image_dev_info_spec,
				&image_dev_handle);
	assert(io_result == 0);
}
#endif /* STM32MP_SPI_NOR */

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#if STM32MP_RAW_NAND
static void boot_fmc2_nand(boot_api_context_t *boot_context)
{
	int io_result __unused;
	uint8_t idx;
	struct stm32image_part_info *part;

	io_result = stm32_fmc2_init();
	assert(io_result == 0);

	/* Register the IO device on this platform */
	io_result = register_io_dev_mtd(&nand_dev_con);
	assert(io_result == 0);

	/* Open connections to device */
	io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
				&storage_dev_handle);
	assert(io_result == 0);

	stm32image_dev_info_spec.device_size = nand_dev_spec.device_size;

	idx = IMG_IDX_BL33;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_BL33_OFFSET;
	part->bkp_offset = nand_dev_spec.erase_size;

#ifdef AARCH32_SP_OPTEE
	idx = IMG_IDX_OPTEE_HEADER;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEEH_OFFSET;
	part->bkp_offset = nand_dev_spec.erase_size;

	idx = IMG_IDX_OPTEE_PAGED;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEED_OFFSET;
	part->bkp_offset = nand_dev_spec.erase_size;

526
	idx = IMG_IDX_OPTEE_CORE;
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEEX_OFFSET;
	part->bkp_offset = nand_dev_spec.erase_size;
#endif

	io_result = register_io_dev_stm32image(&stm32image_dev_con);
	assert(io_result == 0);

	io_result = io_dev_open(stm32image_dev_con,
				(uintptr_t)&stm32image_dev_info_spec,
				&image_dev_handle);
	assert(io_result == 0);
}
#endif /* STM32MP_RAW_NAND */

542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#if STM32MP_SPI_NAND
static void boot_spi_nand(boot_api_context_t *boot_context)
{
	int io_result __unused;
	uint8_t idx;
	struct stm32image_part_info *part;

	io_result = stm32_qspi_init();
	assert(io_result == 0);

	io_result = register_io_dev_mtd(&spi_dev_con);
	assert(io_result == 0);

	/* Open connections to device */
	io_result = io_dev_open(spi_dev_con,
				(uintptr_t)&spi_nand_dev_spec,
				&storage_dev_handle);
	assert(io_result == 0);

	stm32image_dev_info_spec.device_size =
		spi_nand_dev_spec.device_size;

	idx = IMG_IDX_BL33;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_BL33_OFFSET;
	part->bkp_offset = spi_nand_dev_spec.erase_size;

#ifdef AARCH32_SP_OPTEE
	idx = IMG_IDX_OPTEE_HEADER;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEEH_OFFSET;
	part->bkp_offset = spi_nand_dev_spec.erase_size;

	idx = IMG_IDX_OPTEE_PAGED;
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEED_OFFSET;
	part->bkp_offset = spi_nand_dev_spec.erase_size;

580
	idx = IMG_IDX_OPTEE_CORE;
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
	part = &stm32image_dev_info_spec.part_info[idx];
	part->part_offset = STM32MP_NAND_TEEX_OFFSET;
	part->bkp_offset = spi_nand_dev_spec.erase_size;
#endif

	io_result = register_io_dev_stm32image(&stm32image_dev_con);
	assert(io_result == 0);

	io_result = io_dev_open(stm32image_dev_con,
				(uintptr_t)&stm32image_dev_info_spec,
				&image_dev_handle);
	assert(io_result == 0);
}
#endif /* STM32MP_SPI_NAND */

596
597
598
599
600
void stm32mp_io_setup(void)
{
	int io_result __unused;
	boot_api_context_t *boot_context =
		(boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautier's avatar
Yann Gautier committed
601

602
	print_boot_device(boot_context);
603

604
605
606
607
608
	if ((boot_context->boot_partition_used_toboot == 1U) ||
	    (boot_context->boot_partition_used_toboot == 2U)) {
		INFO("Boot used partition fsbl%d\n",
		     boot_context->boot_partition_used_toboot);
	}
609

610
#ifndef AARCH32_SP_OPTEE
611
612
	io_result = register_io_dev_dummy(&dummy_dev_con);
	assert(io_result == 0);
613

614
615
616
	io_result = io_dev_open(dummy_dev_con, dummy_dev_spec,
				&dummy_dev_handle);
	assert(io_result == 0);
617
#endif
618

619
	switch (boot_context->boot_interface_selected) {
620
#if STM32MP_SDMMC
621
622
623
624
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
		dmbsy();
		boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
		break;
625
626
#endif
#if STM32MP_EMMC
627
628
629
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
		dmbsy();
		boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
630
		break;
631
#endif
632
633
634
635
636
637
#if STM32MP_SPI_NOR
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
		dmbsy();
		boot_spi_nor(boot_context);
		break;
#endif
638
639
640
641
642
643
#if STM32MP_RAW_NAND
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
		dmbsy();
		boot_fmc2_nand(boot_context);
		break;
#endif
644
645
646
647
648
649
#if STM32MP_SPI_NAND
	case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
		dmbsy();
		boot_spi_nand(boot_context);
		break;
#endif
650
651
652
653
654
655

	default:
		ERROR("Boot interface %d not supported\n",
		      boot_context->boot_interface_selected);
		break;
	}
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
}

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

	assert(image_id < ARRAY_SIZE(policies));

	policy = &policies[image_id];
	rc = policy->check(policy->image_spec);
	if (rc == 0) {
		*image_spec = policy->image_spec;
		*dev_handle = *(policy->dev_handle);
	}

	return rc;
}