blob: 01c289db80e89b1e00b2e54ae677dfed553521f2 [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001/*
Yann Gautierac22dd52021-03-22 14:22:14 +01002 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Yann Gautier4b0c72a2018-07-16 10:54:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautier4b0c72a2018-07-16 10:54:09 +02007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <string.h>
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <arch_helpers.h>
11#include <common/debug.h>
12#include <drivers/io/io_block.h>
13#include <drivers/io/io_driver.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020014#include <drivers/io/io_fip.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010015#include <drivers/io/io_mtd.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <drivers/io/io_storage.h>
17#include <drivers/mmc.h>
18#include <drivers/partition/partition.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010019#include <drivers/raw_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020020#include <drivers/spi_nand.h>
Lionel Debievecb0dbc42019-09-25 09:11:31 +020021#include <drivers/spi_nor.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000022#include <drivers/st/io_mmc.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010023#include <drivers/st/stm32_fmc2_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020024#include <drivers/st/stm32_qspi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include <drivers/st/stm32_sdmmc2.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000026#include <lib/mmio.h>
27#include <lib/utils.h>
28#include <plat/common/platform.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020029#include <tools_share/firmware_image_package.h>
30
31#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000032
Yann Gautier4b0c72a2018-07-16 10:54:09 +020033/* IO devices */
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020034uintptr_t fip_dev_handle;
35uintptr_t storage_dev_handle;
Yann Gautier4b0c72a2018-07-16 10:54:09 +020036
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020037static const io_dev_connector_t *fip_dev_con;
Yann Gautier8244e1d2018-10-15 09:36:58 +020038
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020039#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautierac22dd52021-03-22 14:22:14 +010040static struct mmc_device_info mmc_info;
Yann Gautier8244e1d2018-10-15 09:36:58 +020041static io_block_spec_t gpt_block_spec = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020042 .offset = 0U,
43 .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */
Yann Gautier8244e1d2018-10-15 09:36:58 +020044};
45
Yann Gautierf9af3bc2018-11-09 15:57:18 +010046static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
Yann Gautier8244e1d2018-10-15 09:36:58 +020047
48static const io_block_dev_spec_t mmc_block_dev_spec = {
49 /* It's used as temp buffer in block driver */
50 .buffer = {
51 .offset = (size_t)&block_buffer,
52 .length = MMC_BLOCK_SIZE,
53 },
54 .ops = {
55 .read = mmc_read_blocks,
56 .write = NULL,
57 },
58 .block_size = MMC_BLOCK_SIZE,
59};
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +020060
Yann Gautier8244e1d2018-10-15 09:36:58 +020061static const io_dev_connector_t *mmc_dev_con;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020062#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier8244e1d2018-10-15 09:36:58 +020063
Lionel Debievecb0dbc42019-09-25 09:11:31 +020064#if STM32MP_SPI_NOR
65static io_mtd_dev_spec_t spi_nor_dev_spec = {
66 .ops = {
67 .init = spi_nor_init,
68 .read = spi_nor_read,
69 },
70};
71#endif
72
Lionel Debieve402a46b2019-11-04 12:28:15 +010073#if STM32MP_RAW_NAND
74static io_mtd_dev_spec_t nand_dev_spec = {
75 .ops = {
76 .init = nand_raw_init,
77 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020078 .seek = nand_seek_bb
Lionel Debieve402a46b2019-11-04 12:28:15 +010079 },
80};
81
82static const io_dev_connector_t *nand_dev_con;
83#endif
84
Lionel Debieve186b0462019-09-24 18:30:12 +020085#if STM32MP_SPI_NAND
86static io_mtd_dev_spec_t spi_nand_dev_spec = {
87 .ops = {
88 .init = spi_nand_init,
89 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020090 .seek = nand_seek_bb
Lionel Debieve186b0462019-09-24 18:30:12 +020091 },
92};
Lionel Debievecb0dbc42019-09-25 09:11:31 +020093#endif
Lionel Debieve186b0462019-09-24 18:30:12 +020094
Lionel Debievecb0dbc42019-09-25 09:11:31 +020095#if STM32MP_SPI_NAND || STM32MP_SPI_NOR
Lionel Debieve186b0462019-09-24 18:30:12 +020096static const io_dev_connector_t *spi_dev_con;
97#endif
98
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020099static const io_uuid_spec_t bl33_partition_spec = {
100 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33
Yann Gautierb3386f72019-04-19 09:41:01 +0200101};
102
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200103static const io_uuid_spec_t tos_fw_config_uuid_spec = {
104 .uuid = UUID_TOS_FW_CONFIG,
Yann Gautierf9d40d52019-01-17 14:41:46 +0100105};
106
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200107static const io_uuid_spec_t hw_config_uuid_spec = {
108 .uuid = UUID_HW_CONFIG,
Yann Gautier8244e1d2018-10-15 09:36:58 +0200109};
110
Yann Gautierb3386f72019-04-19 09:41:01 +0200111#ifdef AARCH32_SP_OPTEE
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200112static const io_uuid_spec_t optee_header_partition_spec = {
113 .uuid = UUID_SECURE_PAYLOAD_BL32
Yann Gautierf9d40d52019-01-17 14:41:46 +0100114};
115
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200116static const io_uuid_spec_t optee_core_partition_spec = {
117 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1
Yann Gautier8244e1d2018-10-15 09:36:58 +0200118};
119
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200120static const io_uuid_spec_t optee_paged_partition_spec = {
121 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200122};
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200123#else
124static const io_uuid_spec_t bl32_partition_spec = {
125 .uuid = UUID_SECURE_PAYLOAD_BL32
126};
127#endif
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200128
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200129static io_block_spec_t image_block_spec = {
130 .offset = 0U,
131 .length = 0U,
132};
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200133
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200134static int open_fip(const uintptr_t spec);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200135static int open_storage(const uintptr_t spec);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200136
137struct plat_io_policy {
138 uintptr_t *dev_handle;
139 uintptr_t image_spec;
140 int (*check)(const uintptr_t spec);
141};
142
143static const struct plat_io_policy policies[] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200144 [FIP_IMAGE_ID] = {
145 .dev_handle = &storage_dev_handle,
146 .image_spec = (uintptr_t)&image_block_spec,
147 .check = open_storage
148 },
Yann Gautierb3386f72019-04-19 09:41:01 +0200149#ifdef AARCH32_SP_OPTEE
150 [BL32_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200151 .dev_handle = &fip_dev_handle,
Yann Gautierb3386f72019-04-19 09:41:01 +0200152 .image_spec = (uintptr_t)&optee_header_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200153 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200154 },
155 [BL32_EXTRA1_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200156 .dev_handle = &fip_dev_handle,
Yann Gautierebf15ba2021-05-19 16:10:25 +0200157 .image_spec = (uintptr_t)&optee_core_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200158 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200159 },
160 [BL32_EXTRA2_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200161 .dev_handle = &fip_dev_handle,
Yann Gautierb3386f72019-04-19 09:41:01 +0200162 .image_spec = (uintptr_t)&optee_paged_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200163 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200164 },
165#else
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200166 [BL32_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200167 .dev_handle = &fip_dev_handle,
168 .image_spec = (uintptr_t)&bl32_partition_spec,
169 .check = open_fip
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200170 },
Yann Gautierb3386f72019-04-19 09:41:01 +0200171#endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200172 [BL33_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200173 .dev_handle = &fip_dev_handle,
Yann Gautier8244e1d2018-10-15 09:36:58 +0200174 .image_spec = (uintptr_t)&bl33_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200175 .check = open_fip
176 },
177 [TOS_FW_CONFIG_ID] = {
178 .dev_handle = &fip_dev_handle,
179 .image_spec = (uintptr_t)&tos_fw_config_uuid_spec,
180 .check = open_fip
181 },
182 [HW_CONFIG_ID] = {
183 .dev_handle = &fip_dev_handle,
184 .image_spec = (uintptr_t)&hw_config_uuid_spec,
185 .check = open_fip
Yann Gautier8244e1d2018-10-15 09:36:58 +0200186 },
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200187#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautier8244e1d2018-10-15 09:36:58 +0200188 [GPT_IMAGE_ID] = {
189 .dev_handle = &storage_dev_handle,
190 .image_spec = (uintptr_t)&gpt_block_spec,
191 .check = open_storage
192 },
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200193#endif
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200194};
195
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200196static int open_fip(const uintptr_t spec)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200197{
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200198 return io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200199}
Yann Gautier8244e1d2018-10-15 09:36:58 +0200200
201static int open_storage(const uintptr_t spec)
202{
203 return io_dev_init(storage_dev_handle, 0);
204}
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +0200205
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200206static void print_boot_device(boot_api_context_t *boot_context)
207{
208 switch (boot_context->boot_interface_selected) {
209 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
210 INFO("Using SDMMC\n");
211 break;
212 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
213 INFO("Using EMMC\n");
214 break;
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200215 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
216 INFO("Using QSPI NOR\n");
217 break;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100218 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
219 INFO("Using FMC NAND\n");
220 break;
Lionel Debieve186b0462019-09-24 18:30:12 +0200221 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
222 INFO("Using SPI NAND\n");
223 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200224 default:
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200225 ERROR("Boot interface %u not found\n",
226 boot_context->boot_interface_selected);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200227 panic();
228 break;
229 }
230
231 if (boot_context->boot_interface_instance != 0U) {
232 INFO(" Instance %d\n", boot_context->boot_interface_instance);
233 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200234}
235
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200236#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200237static void boot_mmc(enum mmc_device_type mmc_dev_type,
238 uint16_t boot_interface_instance)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200239{
240 int io_result __unused;
Yann Gautier8244e1d2018-10-15 09:36:58 +0200241 struct stm32_sdmmc2_params params;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200242
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200243 zeromem(&params, sizeof(struct stm32_sdmmc2_params));
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200244
Yann Gautierac22dd52021-03-22 14:22:14 +0100245 mmc_info.mmc_dev_type = mmc_dev_type;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200246
247 switch (boot_interface_instance) {
248 case 1:
249 params.reg_base = STM32MP_SDMMC1_BASE;
250 break;
251 case 2:
252 params.reg_base = STM32MP_SDMMC2_BASE;
253 break;
254 case 3:
255 params.reg_base = STM32MP_SDMMC3_BASE;
256 break;
257 default:
258 WARN("SDMMC instance not found, using default\n");
259 if (mmc_dev_type == MMC_IS_SD) {
260 params.reg_base = STM32MP_SDMMC1_BASE;
261 } else {
262 params.reg_base = STM32MP_SDMMC2_BASE;
263 }
264 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200265 }
266
Yann Gautierac22dd52021-03-22 14:22:14 +0100267 params.device_info = &mmc_info;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200268 if (stm32_sdmmc2_mmc_init(&params) != 0) {
269 ERROR("SDMMC%u init failed\n", boot_interface_instance);
270 panic();
271 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200272
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200273 /* Open MMC as a block device to read GPT table */
274 io_result = register_io_dev_block(&mmc_dev_con);
275 if (io_result != 0) {
276 panic();
277 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200278
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200279 io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
280 &storage_dev_handle);
281 assert(io_result == 0);
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200282}
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200283#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier8244e1d2018-10-15 09:36:58 +0200284
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200285#if STM32MP_SPI_NOR
286static void boot_spi_nor(boot_api_context_t *boot_context)
287{
288 int io_result __unused;
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200289
290 io_result = stm32_qspi_init();
291 assert(io_result == 0);
292
293 io_result = register_io_dev_mtd(&spi_dev_con);
294 assert(io_result == 0);
295
296 /* Open connections to device */
297 io_result = io_dev_open(spi_dev_con,
298 (uintptr_t)&spi_nor_dev_spec,
299 &storage_dev_handle);
300 assert(io_result == 0);
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200301}
302#endif /* STM32MP_SPI_NOR */
303
Lionel Debieve402a46b2019-11-04 12:28:15 +0100304#if STM32MP_RAW_NAND
305static void boot_fmc2_nand(boot_api_context_t *boot_context)
306{
307 int io_result __unused;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100308
309 io_result = stm32_fmc2_init();
310 assert(io_result == 0);
311
312 /* Register the IO device on this platform */
313 io_result = register_io_dev_mtd(&nand_dev_con);
314 assert(io_result == 0);
315
316 /* Open connections to device */
317 io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
318 &storage_dev_handle);
319 assert(io_result == 0);
Lionel Debieve402a46b2019-11-04 12:28:15 +0100320}
321#endif /* STM32MP_RAW_NAND */
322
Lionel Debieve186b0462019-09-24 18:30:12 +0200323#if STM32MP_SPI_NAND
324static void boot_spi_nand(boot_api_context_t *boot_context)
325{
326 int io_result __unused;
Lionel Debieve186b0462019-09-24 18:30:12 +0200327
328 io_result = stm32_qspi_init();
329 assert(io_result == 0);
330
331 io_result = register_io_dev_mtd(&spi_dev_con);
332 assert(io_result == 0);
333
334 /* Open connections to device */
335 io_result = io_dev_open(spi_dev_con,
336 (uintptr_t)&spi_nand_dev_spec,
337 &storage_dev_handle);
338 assert(io_result == 0);
Lionel Debieve186b0462019-09-24 18:30:12 +0200339}
340#endif /* STM32MP_SPI_NAND */
341
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200342void stm32mp_io_setup(void)
343{
344 int io_result __unused;
345 boot_api_context_t *boot_context =
346 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautierf9d40d52019-01-17 14:41:46 +0100347
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200348 print_boot_device(boot_context);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200349
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200350 if ((boot_context->boot_partition_used_toboot == 1U) ||
351 (boot_context->boot_partition_used_toboot == 2U)) {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200352 INFO("Boot used partition fsbl%u\n",
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200353 boot_context->boot_partition_used_toboot);
354 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200355
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200356 io_result = register_io_dev_fip(&fip_dev_con);
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200357 assert(io_result == 0);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200358
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200359 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
360 &fip_dev_handle);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200361
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200362 switch (boot_context->boot_interface_selected) {
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200363#if STM32MP_SDMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200364 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
365 dmbsy();
366 boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
367 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200368#endif
369#if STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200370 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
371 dmbsy();
372 boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200373 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200374#endif
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200375#if STM32MP_SPI_NOR
376 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
377 dmbsy();
378 boot_spi_nor(boot_context);
379 break;
380#endif
Lionel Debieve402a46b2019-11-04 12:28:15 +0100381#if STM32MP_RAW_NAND
382 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
383 dmbsy();
384 boot_fmc2_nand(boot_context);
385 break;
386#endif
Lionel Debieve186b0462019-09-24 18:30:12 +0200387#if STM32MP_SPI_NAND
388 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
389 dmbsy();
390 boot_spi_nand(boot_context);
391 break;
392#endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200393
394 default:
395 ERROR("Boot interface %d not supported\n",
396 boot_context->boot_interface_selected);
Yann Gautier4c2b73d2021-06-30 17:04:22 +0200397 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200398 break;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200399 }
400}
401
402int bl2_plat_handle_pre_image_load(unsigned int image_id)
403{
404 static bool gpt_init_done __unused;
405 uint16_t boot_itf = stm32mp_get_boot_itf_selected();
406
407 switch (boot_itf) {
408#if STM32MP_SDMMC || STM32MP_EMMC
409 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
410 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
411 if (!gpt_init_done) {
412 const partition_entry_t *entry;
413
414 partition_init(GPT_IMAGE_ID);
415 entry = get_partition_entry(FIP_IMAGE_NAME);
416 if (entry == NULL) {
417 ERROR("Could NOT find the %s partition!\n",
418 FIP_IMAGE_NAME);
419 return -ENOENT;
420 }
421
422 image_block_spec.offset = entry->start;
423 image_block_spec.length = entry->length;
424
425 gpt_init_done = true;
426 }
427
428 break;
429#endif
430
431#if STM32MP_RAW_NAND || STM32MP_SPI_NAND
432#if STM32MP_RAW_NAND
433 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
434#endif
435#if STM32MP_SPI_NAND
436 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
437#endif
438 image_block_spec.offset = STM32MP_NAND_FIP_OFFSET;
439 break;
440#endif
441
442#if STM32MP_SPI_NOR
443 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
444 image_block_spec.offset = STM32MP_NOR_FIP_OFFSET;
445 break;
446#endif
447
448 default:
449 ERROR("FIP Not found\n");
450 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200451 }
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200452
453 return 0;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200454}
455
456/*
457 * Return an IO device handle and specification which can be used to access
458 * an image. Use this to enforce platform load policy.
459 */
460int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
461 uintptr_t *image_spec)
462{
463 int rc;
464 const struct plat_io_policy *policy;
465
466 assert(image_id < ARRAY_SIZE(policies));
467
468 policy = &policies[image_id];
469 rc = policy->check(policy->image_spec);
470 if (rc == 0) {
471 *image_spec = policy->image_spec;
472 *dev_handle = *(policy->dev_handle);
473 }
474
475 return rc;
476}