blob: 817f44972c112a3eeaae72a513e736a1580a4b15 [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>
Yann Gautiera3bd8d12021-06-18 11:33:26 +020012#include <common/desc_image_load.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <drivers/io/io_block.h>
14#include <drivers/io/io_driver.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020015#include <drivers/io/io_fip.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010016#include <drivers/io/io_mtd.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <drivers/io/io_storage.h>
18#include <drivers/mmc.h>
19#include <drivers/partition/partition.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010020#include <drivers/raw_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020021#include <drivers/spi_nand.h>
Lionel Debievecb0dbc42019-09-25 09:11:31 +020022#include <drivers/spi_nor.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000023#include <drivers/st/io_mmc.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010024#include <drivers/st/stm32_fmc2_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020025#include <drivers/st/stm32_qspi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000026#include <drivers/st/stm32_sdmmc2.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000027#include <lib/mmio.h>
28#include <lib/utils.h>
29#include <plat/common/platform.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020030#include <tools_share/firmware_image_package.h>
31
32#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000033
Yann Gautier4b0c72a2018-07-16 10:54:09 +020034/* IO devices */
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020035uintptr_t fip_dev_handle;
36uintptr_t storage_dev_handle;
Yann Gautier4b0c72a2018-07-16 10:54:09 +020037
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020038static const io_dev_connector_t *fip_dev_con;
Yann Gautier8244e1d2018-10-15 09:36:58 +020039
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020040#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautierac22dd52021-03-22 14:22:14 +010041static struct mmc_device_info mmc_info;
Yann Gautier8244e1d2018-10-15 09:36:58 +020042static io_block_spec_t gpt_block_spec = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020043 .offset = 0U,
44 .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */
Yann Gautier8244e1d2018-10-15 09:36:58 +020045};
46
Yann Gautierf9af3bc2018-11-09 15:57:18 +010047static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
Yann Gautier8244e1d2018-10-15 09:36:58 +020048
Yann Gautiera3bd8d12021-06-18 11:33:26 +020049static io_block_dev_spec_t mmc_block_dev_spec = {
Yann Gautier8244e1d2018-10-15 09:36:58 +020050 /* It's used as temp buffer in block driver */
51 .buffer = {
52 .offset = (size_t)&block_buffer,
53 .length = MMC_BLOCK_SIZE,
54 },
55 .ops = {
56 .read = mmc_read_blocks,
57 .write = NULL,
58 },
59 .block_size = MMC_BLOCK_SIZE,
60};
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +020061
Yann Gautier8244e1d2018-10-15 09:36:58 +020062static const io_dev_connector_t *mmc_dev_con;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020063#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier8244e1d2018-10-15 09:36:58 +020064
Lionel Debievecb0dbc42019-09-25 09:11:31 +020065#if STM32MP_SPI_NOR
66static io_mtd_dev_spec_t spi_nor_dev_spec = {
67 .ops = {
68 .init = spi_nor_init,
69 .read = spi_nor_read,
70 },
71};
72#endif
73
Lionel Debieve402a46b2019-11-04 12:28:15 +010074#if STM32MP_RAW_NAND
75static io_mtd_dev_spec_t nand_dev_spec = {
76 .ops = {
77 .init = nand_raw_init,
78 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020079 .seek = nand_seek_bb
Lionel Debieve402a46b2019-11-04 12:28:15 +010080 },
81};
82
83static const io_dev_connector_t *nand_dev_con;
84#endif
85
Lionel Debieve186b0462019-09-24 18:30:12 +020086#if STM32MP_SPI_NAND
87static io_mtd_dev_spec_t spi_nand_dev_spec = {
88 .ops = {
89 .init = spi_nand_init,
90 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020091 .seek = nand_seek_bb
Lionel Debieve186b0462019-09-24 18:30:12 +020092 },
93};
Lionel Debievecb0dbc42019-09-25 09:11:31 +020094#endif
Lionel Debieve186b0462019-09-24 18:30:12 +020095
Lionel Debievecb0dbc42019-09-25 09:11:31 +020096#if STM32MP_SPI_NAND || STM32MP_SPI_NOR
Lionel Debieve186b0462019-09-24 18:30:12 +020097static const io_dev_connector_t *spi_dev_con;
98#endif
99
Yann Gautier658775c2021-07-06 10:00:44 +0200100static const io_uuid_spec_t fw_config_uuid_spec = {
101 .uuid = UUID_FW_CONFIG,
102};
103
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200104static const io_uuid_spec_t bl33_partition_spec = {
105 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33
Yann Gautierb3386f72019-04-19 09:41:01 +0200106};
107
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200108static const io_uuid_spec_t tos_fw_config_uuid_spec = {
109 .uuid = UUID_TOS_FW_CONFIG,
Yann Gautierf9d40d52019-01-17 14:41:46 +0100110};
111
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200112static const io_uuid_spec_t hw_config_uuid_spec = {
113 .uuid = UUID_HW_CONFIG,
Yann Gautier8244e1d2018-10-15 09:36:58 +0200114};
115
Yann Gautierb3386f72019-04-19 09:41:01 +0200116#ifdef AARCH32_SP_OPTEE
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200117static const io_uuid_spec_t optee_header_partition_spec = {
118 .uuid = UUID_SECURE_PAYLOAD_BL32
Yann Gautierf9d40d52019-01-17 14:41:46 +0100119};
120
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200121static const io_uuid_spec_t optee_core_partition_spec = {
122 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1
Yann Gautier8244e1d2018-10-15 09:36:58 +0200123};
124
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200125static const io_uuid_spec_t optee_paged_partition_spec = {
126 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200127};
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200128#else
129static const io_uuid_spec_t bl32_partition_spec = {
130 .uuid = UUID_SECURE_PAYLOAD_BL32
131};
132#endif
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200133
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200134static io_block_spec_t image_block_spec = {
135 .offset = 0U,
136 .length = 0U,
137};
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200138
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200139static int open_fip(const uintptr_t spec);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200140static int open_storage(const uintptr_t spec);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200141
142struct plat_io_policy {
143 uintptr_t *dev_handle;
144 uintptr_t image_spec;
145 int (*check)(const uintptr_t spec);
146};
147
148static const struct plat_io_policy policies[] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200149 [FIP_IMAGE_ID] = {
150 .dev_handle = &storage_dev_handle,
151 .image_spec = (uintptr_t)&image_block_spec,
152 .check = open_storage
153 },
Yann Gautierb3386f72019-04-19 09:41:01 +0200154#ifdef AARCH32_SP_OPTEE
155 [BL32_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200156 .dev_handle = &fip_dev_handle,
Yann Gautierb3386f72019-04-19 09:41:01 +0200157 .image_spec = (uintptr_t)&optee_header_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200158 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200159 },
160 [BL32_EXTRA1_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200161 .dev_handle = &fip_dev_handle,
Yann Gautierebf15ba2021-05-19 16:10:25 +0200162 .image_spec = (uintptr_t)&optee_core_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200163 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200164 },
165 [BL32_EXTRA2_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200166 .dev_handle = &fip_dev_handle,
Yann Gautierb3386f72019-04-19 09:41:01 +0200167 .image_spec = (uintptr_t)&optee_paged_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200168 .check = open_fip
Yann Gautierb3386f72019-04-19 09:41:01 +0200169 },
170#else
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200171 [BL32_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200172 .dev_handle = &fip_dev_handle,
173 .image_spec = (uintptr_t)&bl32_partition_spec,
174 .check = open_fip
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200175 },
Yann Gautierb3386f72019-04-19 09:41:01 +0200176#endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200177 [BL33_IMAGE_ID] = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200178 .dev_handle = &fip_dev_handle,
Yann Gautier8244e1d2018-10-15 09:36:58 +0200179 .image_spec = (uintptr_t)&bl33_partition_spec,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200180 .check = open_fip
181 },
Yann Gautier658775c2021-07-06 10:00:44 +0200182 [FW_CONFIG_ID] = {
183 .dev_handle = &fip_dev_handle,
184 .image_spec = (uintptr_t)&fw_config_uuid_spec,
185 .check = open_fip
186 },
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200187 [TOS_FW_CONFIG_ID] = {
188 .dev_handle = &fip_dev_handle,
189 .image_spec = (uintptr_t)&tos_fw_config_uuid_spec,
190 .check = open_fip
191 },
192 [HW_CONFIG_ID] = {
193 .dev_handle = &fip_dev_handle,
194 .image_spec = (uintptr_t)&hw_config_uuid_spec,
195 .check = open_fip
Yann Gautier8244e1d2018-10-15 09:36:58 +0200196 },
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200197#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautier8244e1d2018-10-15 09:36:58 +0200198 [GPT_IMAGE_ID] = {
199 .dev_handle = &storage_dev_handle,
200 .image_spec = (uintptr_t)&gpt_block_spec,
201 .check = open_storage
202 },
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200203#endif
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200204};
205
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200206static int open_fip(const uintptr_t spec)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200207{
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200208 return io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200209}
Yann Gautier8244e1d2018-10-15 09:36:58 +0200210
211static int open_storage(const uintptr_t spec)
212{
213 return io_dev_init(storage_dev_handle, 0);
214}
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +0200215
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200216static void print_boot_device(boot_api_context_t *boot_context)
217{
218 switch (boot_context->boot_interface_selected) {
219 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
220 INFO("Using SDMMC\n");
221 break;
222 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
223 INFO("Using EMMC\n");
224 break;
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200225 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
226 INFO("Using QSPI NOR\n");
227 break;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100228 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
229 INFO("Using FMC NAND\n");
230 break;
Lionel Debieve186b0462019-09-24 18:30:12 +0200231 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
232 INFO("Using SPI NAND\n");
233 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200234 default:
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200235 ERROR("Boot interface %u not found\n",
236 boot_context->boot_interface_selected);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200237 panic();
238 break;
239 }
240
241 if (boot_context->boot_interface_instance != 0U) {
242 INFO(" Instance %d\n", boot_context->boot_interface_instance);
243 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200244}
245
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200246#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200247static void boot_mmc(enum mmc_device_type mmc_dev_type,
248 uint16_t boot_interface_instance)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200249{
250 int io_result __unused;
Yann Gautier8244e1d2018-10-15 09:36:58 +0200251 struct stm32_sdmmc2_params params;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200252
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200253 zeromem(&params, sizeof(struct stm32_sdmmc2_params));
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200254
Yann Gautierac22dd52021-03-22 14:22:14 +0100255 mmc_info.mmc_dev_type = mmc_dev_type;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200256
257 switch (boot_interface_instance) {
258 case 1:
259 params.reg_base = STM32MP_SDMMC1_BASE;
260 break;
261 case 2:
262 params.reg_base = STM32MP_SDMMC2_BASE;
263 break;
264 case 3:
265 params.reg_base = STM32MP_SDMMC3_BASE;
266 break;
267 default:
268 WARN("SDMMC instance not found, using default\n");
269 if (mmc_dev_type == MMC_IS_SD) {
270 params.reg_base = STM32MP_SDMMC1_BASE;
271 } else {
272 params.reg_base = STM32MP_SDMMC2_BASE;
273 }
274 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200275 }
276
Yann Gautierac22dd52021-03-22 14:22:14 +0100277 params.device_info = &mmc_info;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200278 if (stm32_sdmmc2_mmc_init(&params) != 0) {
279 ERROR("SDMMC%u init failed\n", boot_interface_instance);
280 panic();
281 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200282
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200283 /* Open MMC as a block device to read GPT table */
284 io_result = register_io_dev_block(&mmc_dev_con);
285 if (io_result != 0) {
286 panic();
287 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200288
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200289 io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
290 &storage_dev_handle);
291 assert(io_result == 0);
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200292}
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200293#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier8244e1d2018-10-15 09:36:58 +0200294
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200295#if STM32MP_SPI_NOR
296static void boot_spi_nor(boot_api_context_t *boot_context)
297{
298 int io_result __unused;
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200299
300 io_result = stm32_qspi_init();
301 assert(io_result == 0);
302
303 io_result = register_io_dev_mtd(&spi_dev_con);
304 assert(io_result == 0);
305
306 /* Open connections to device */
307 io_result = io_dev_open(spi_dev_con,
308 (uintptr_t)&spi_nor_dev_spec,
309 &storage_dev_handle);
310 assert(io_result == 0);
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200311}
312#endif /* STM32MP_SPI_NOR */
313
Lionel Debieve402a46b2019-11-04 12:28:15 +0100314#if STM32MP_RAW_NAND
315static void boot_fmc2_nand(boot_api_context_t *boot_context)
316{
317 int io_result __unused;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100318
319 io_result = stm32_fmc2_init();
320 assert(io_result == 0);
321
322 /* Register the IO device on this platform */
323 io_result = register_io_dev_mtd(&nand_dev_con);
324 assert(io_result == 0);
325
326 /* Open connections to device */
327 io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
328 &storage_dev_handle);
329 assert(io_result == 0);
Lionel Debieve402a46b2019-11-04 12:28:15 +0100330}
331#endif /* STM32MP_RAW_NAND */
332
Lionel Debieve186b0462019-09-24 18:30:12 +0200333#if STM32MP_SPI_NAND
334static void boot_spi_nand(boot_api_context_t *boot_context)
335{
336 int io_result __unused;
Lionel Debieve186b0462019-09-24 18:30:12 +0200337
338 io_result = stm32_qspi_init();
339 assert(io_result == 0);
340
341 io_result = register_io_dev_mtd(&spi_dev_con);
342 assert(io_result == 0);
343
344 /* Open connections to device */
345 io_result = io_dev_open(spi_dev_con,
346 (uintptr_t)&spi_nand_dev_spec,
347 &storage_dev_handle);
348 assert(io_result == 0);
Lionel Debieve186b0462019-09-24 18:30:12 +0200349}
350#endif /* STM32MP_SPI_NAND */
351
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200352void stm32mp_io_setup(void)
353{
354 int io_result __unused;
355 boot_api_context_t *boot_context =
356 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautierf9d40d52019-01-17 14:41:46 +0100357
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200358 print_boot_device(boot_context);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200359
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200360 if ((boot_context->boot_partition_used_toboot == 1U) ||
361 (boot_context->boot_partition_used_toboot == 2U)) {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200362 INFO("Boot used partition fsbl%u\n",
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200363 boot_context->boot_partition_used_toboot);
364 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200365
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200366 io_result = register_io_dev_fip(&fip_dev_con);
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200367 assert(io_result == 0);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200368
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200369 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
370 &fip_dev_handle);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200371
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200372 switch (boot_context->boot_interface_selected) {
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200373#if STM32MP_SDMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200374 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
375 dmbsy();
376 boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
377 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200378#endif
379#if STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200380 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
381 dmbsy();
382 boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200383 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200384#endif
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200385#if STM32MP_SPI_NOR
386 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
387 dmbsy();
388 boot_spi_nor(boot_context);
389 break;
390#endif
Lionel Debieve402a46b2019-11-04 12:28:15 +0100391#if STM32MP_RAW_NAND
392 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
393 dmbsy();
394 boot_fmc2_nand(boot_context);
395 break;
396#endif
Lionel Debieve186b0462019-09-24 18:30:12 +0200397#if STM32MP_SPI_NAND
398 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
399 dmbsy();
400 boot_spi_nand(boot_context);
401 break;
402#endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200403
404 default:
405 ERROR("Boot interface %d not supported\n",
406 boot_context->boot_interface_selected);
Yann Gautier4c2b73d2021-06-30 17:04:22 +0200407 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200408 break;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200409 }
410}
411
412int bl2_plat_handle_pre_image_load(unsigned int image_id)
413{
414 static bool gpt_init_done __unused;
415 uint16_t boot_itf = stm32mp_get_boot_itf_selected();
416
417 switch (boot_itf) {
418#if STM32MP_SDMMC || STM32MP_EMMC
419 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
420 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
421 if (!gpt_init_done) {
422 const partition_entry_t *entry;
423
424 partition_init(GPT_IMAGE_ID);
425 entry = get_partition_entry(FIP_IMAGE_NAME);
426 if (entry == NULL) {
427 ERROR("Could NOT find the %s partition!\n",
428 FIP_IMAGE_NAME);
429 return -ENOENT;
430 }
431
432 image_block_spec.offset = entry->start;
433 image_block_spec.length = entry->length;
434
435 gpt_init_done = true;
Yann Gautiera3bd8d12021-06-18 11:33:26 +0200436 } else {
437 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
438
439 mmc_block_dev_spec.buffer.offset = bl_mem_params->image_info.image_base;
440 mmc_block_dev_spec.buffer.length = bl_mem_params->image_info.image_max_size;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200441 }
442
443 break;
444#endif
445
446#if STM32MP_RAW_NAND || STM32MP_SPI_NAND
447#if STM32MP_RAW_NAND
448 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
449#endif
450#if STM32MP_SPI_NAND
451 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
452#endif
453 image_block_spec.offset = STM32MP_NAND_FIP_OFFSET;
454 break;
455#endif
456
457#if STM32MP_SPI_NOR
458 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
459 image_block_spec.offset = STM32MP_NOR_FIP_OFFSET;
460 break;
461#endif
462
463 default:
464 ERROR("FIP Not found\n");
465 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200466 }
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200467
468 return 0;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200469}
470
471/*
472 * Return an IO device handle and specification which can be used to access
473 * an image. Use this to enforce platform load policy.
474 */
475int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
476 uintptr_t *image_spec)
477{
478 int rc;
479 const struct plat_io_policy *policy;
480
481 assert(image_id < ARRAY_SIZE(policies));
482
483 policy = &policies[image_id];
484 rc = policy->check(policy->image_spec);
485 if (rc == 0) {
486 *image_spec = policy->image_spec;
487 *dev_handle = *(policy->dev_handle);
488 }
489
490 return rc;
491}