blob: 6c7618abab32a98f3981495788b9603b69ce23af [file] [log] [blame]
Yann Gautier4353bb22018-07-16 10:54:09 +02001/*
Yann Gautiercddf1bd2021-03-22 14:22:14 +01002 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Yann Gautier4353bb22018-07-16 10:54:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautier4353bb22018-07-16 10:54:09 +02007#include <assert.h>
Yann Gautier4353bb22018-07-16 10:54:09 +02008#include <string.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000010#include <arch_helpers.h>
11#include <common/debug.h>
Yann Gautier18b415b2021-06-18 11:33:26 +020012#include <common/desc_image_load.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000013#include <drivers/io/io_block.h>
14#include <drivers/io/io_driver.h>
Yann Gautier1d204ee2021-05-19 18:48:16 +020015#include <drivers/io/io_fip.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010016#include <drivers/io/io_mtd.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000017#include <drivers/io/io_storage.h>
18#include <drivers/mmc.h>
19#include <drivers/partition/partition.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010020#include <drivers/raw_nand.h>
Lionel Debieve57044222019-09-24 18:30:12 +020021#include <drivers/spi_nand.h>
Lionel Debieveb1b218f2019-09-25 09:11:31 +020022#include <drivers/spi_nor.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000023#include <drivers/st/io_mmc.h>
Lionel Debieve12e21df2019-11-04 12:28:15 +010024#include <drivers/st/stm32_fmc2_nand.h>
Lionel Debieve57044222019-09-24 18:30:12 +020025#include <drivers/st/stm32_qspi.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000026#include <drivers/st/stm32_sdmmc2.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000027#include <lib/mmio.h>
28#include <lib/utils.h>
29#include <plat/common/platform.h>
Yann Gautier1d204ee2021-05-19 18:48:16 +020030#include <tools_share/firmware_image_package.h>
31
32#include <platform_def.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000033
Yann Gautier4353bb22018-07-16 10:54:09 +020034/* IO devices */
Yann Gautier1d204ee2021-05-19 18:48:16 +020035uintptr_t fip_dev_handle;
36uintptr_t storage_dev_handle;
Yann Gautier4353bb22018-07-16 10:54:09 +020037
Yann Gautier1d204ee2021-05-19 18:48:16 +020038static const io_dev_connector_t *fip_dev_con;
Yann Gautieraec7de42018-10-15 09:36:58 +020039
Nicolas Le Bayon46554b62019-09-03 09:52:05 +020040#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautiercddf1bd2021-03-22 14:22:14 +010041static struct mmc_device_info mmc_info;
Yann Gautieraec7de42018-10-15 09:36:58 +020042static io_block_spec_t gpt_block_spec = {
Yann Gautier1d204ee2021-05-19 18:48:16 +020043 .offset = 0U,
44 .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */
Yann Gautieraec7de42018-10-15 09:36:58 +020045};
46
Yann Gautier3e6fab42018-11-09 15:57:18 +010047static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
Yann Gautieraec7de42018-10-15 09:36:58 +020048
Yann Gautier18b415b2021-06-18 11:33:26 +020049static io_block_dev_spec_t mmc_block_dev_spec = {
Yann Gautieraec7de42018-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};
61
Yann Gautieraec7de42018-10-15 09:36:58 +020062static const io_dev_connector_t *mmc_dev_con;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +020063#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautieraec7de42018-10-15 09:36:58 +020064
Lionel Debieveb1b218f2019-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 Debieve12e21df2019-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 Gautier1d204ee2021-05-19 18:48:16 +020079 .seek = nand_seek_bb
Lionel Debieve12e21df2019-11-04 12:28:15 +010080 },
81};
82
83static const io_dev_connector_t *nand_dev_con;
84#endif
85
Lionel Debieve57044222019-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 Gautier1d204ee2021-05-19 18:48:16 +020091 .seek = nand_seek_bb
Lionel Debieve57044222019-09-24 18:30:12 +020092 },
93};
Lionel Debieveb1b218f2019-09-25 09:11:31 +020094#endif
Lionel Debieve57044222019-09-24 18:30:12 +020095
Lionel Debieveb1b218f2019-09-25 09:11:31 +020096#if STM32MP_SPI_NAND || STM32MP_SPI_NOR
Lionel Debieve57044222019-09-24 18:30:12 +020097static const io_dev_connector_t *spi_dev_con;
98#endif
99
Yann Gautier1d204ee2021-05-19 18:48:16 +0200100static const io_uuid_spec_t bl33_partition_spec = {
101 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33
102};
103
104static const io_uuid_spec_t tos_fw_config_uuid_spec = {
105 .uuid = UUID_TOS_FW_CONFIG,
106};
107
108static const io_uuid_spec_t hw_config_uuid_spec = {
109 .uuid = UUID_HW_CONFIG,
110};
111
Yann Gautier1989a192019-04-19 09:41:01 +0200112#ifdef AARCH32_SP_OPTEE
Yann Gautier1d204ee2021-05-19 18:48:16 +0200113static const io_uuid_spec_t optee_header_partition_spec = {
114 .uuid = UUID_SECURE_PAYLOAD_BL32
Yann Gautier1989a192019-04-19 09:41:01 +0200115};
116
Yann Gautier1d204ee2021-05-19 18:48:16 +0200117static const io_uuid_spec_t optee_core_partition_spec = {
118 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1
Yann Gautier1989a192019-04-19 09:41:01 +0200119};
120
Yann Gautier1d204ee2021-05-19 18:48:16 +0200121static const io_uuid_spec_t optee_paged_partition_spec = {
122 .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2
Yann Gautier1989a192019-04-19 09:41:01 +0200123};
124#else
Yann Gautier1d204ee2021-05-19 18:48:16 +0200125static const io_uuid_spec_t bl32_partition_spec = {
126 .uuid = UUID_SECURE_PAYLOAD_BL32
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100127};
Yann Gautier1989a192019-04-19 09:41:01 +0200128#endif
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100129
Yann Gautier1d204ee2021-05-19 18:48:16 +0200130static io_block_spec_t image_block_spec = {
131 .offset = 0U,
132 .length = 0U,
Yann Gautieraec7de42018-10-15 09:36:58 +0200133};
134
Yann Gautier1d204ee2021-05-19 18:48:16 +0200135static int open_fip(const uintptr_t spec);
Yann Gautieraec7de42018-10-15 09:36:58 +0200136static int open_storage(const uintptr_t spec);
Yann Gautier4353bb22018-07-16 10:54:09 +0200137
138struct plat_io_policy {
139 uintptr_t *dev_handle;
140 uintptr_t image_spec;
141 int (*check)(const uintptr_t spec);
142};
143
144static const struct plat_io_policy policies[] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200145 [FIP_IMAGE_ID] = {
146 .dev_handle = &storage_dev_handle,
147 .image_spec = (uintptr_t)&image_block_spec,
148 .check = open_storage
149 },
Yann Gautier1989a192019-04-19 09:41:01 +0200150#ifdef AARCH32_SP_OPTEE
151 [BL32_IMAGE_ID] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200152 .dev_handle = &fip_dev_handle,
Yann Gautier1989a192019-04-19 09:41:01 +0200153 .image_spec = (uintptr_t)&optee_header_partition_spec,
Yann Gautier1d204ee2021-05-19 18:48:16 +0200154 .check = open_fip
Yann Gautier1989a192019-04-19 09:41:01 +0200155 },
156 [BL32_EXTRA1_IMAGE_ID] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200157 .dev_handle = &fip_dev_handle,
Yann Gautier06c3b102021-05-19 16:10:25 +0200158 .image_spec = (uintptr_t)&optee_core_partition_spec,
Yann Gautier1d204ee2021-05-19 18:48:16 +0200159 .check = open_fip
Yann Gautier1989a192019-04-19 09:41:01 +0200160 },
161 [BL32_EXTRA2_IMAGE_ID] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200162 .dev_handle = &fip_dev_handle,
Yann Gautier1989a192019-04-19 09:41:01 +0200163 .image_spec = (uintptr_t)&optee_paged_partition_spec,
Yann Gautier1d204ee2021-05-19 18:48:16 +0200164 .check = open_fip
Yann Gautier1989a192019-04-19 09:41:01 +0200165 },
166#else
Yann Gautier4353bb22018-07-16 10:54:09 +0200167 [BL32_IMAGE_ID] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200168 .dev_handle = &fip_dev_handle,
169 .image_spec = (uintptr_t)&bl32_partition_spec,
170 .check = open_fip
Yann Gautier4353bb22018-07-16 10:54:09 +0200171 },
Yann Gautier1989a192019-04-19 09:41:01 +0200172#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200173 [BL33_IMAGE_ID] = {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200174 .dev_handle = &fip_dev_handle,
Yann Gautieraec7de42018-10-15 09:36:58 +0200175 .image_spec = (uintptr_t)&bl33_partition_spec,
Yann Gautier1d204ee2021-05-19 18:48:16 +0200176 .check = open_fip
177 },
178 [TOS_FW_CONFIG_ID] = {
179 .dev_handle = &fip_dev_handle,
180 .image_spec = (uintptr_t)&tos_fw_config_uuid_spec,
181 .check = open_fip
182 },
183 [HW_CONFIG_ID] = {
184 .dev_handle = &fip_dev_handle,
185 .image_spec = (uintptr_t)&hw_config_uuid_spec,
186 .check = open_fip
Yann Gautieraec7de42018-10-15 09:36:58 +0200187 },
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200188#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200189 [GPT_IMAGE_ID] = {
190 .dev_handle = &storage_dev_handle,
191 .image_spec = (uintptr_t)&gpt_block_spec,
192 .check = open_storage
193 },
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200194#endif
Yann Gautier4353bb22018-07-16 10:54:09 +0200195};
196
Yann Gautier1d204ee2021-05-19 18:48:16 +0200197static int open_fip(const uintptr_t spec)
Yann Gautier4353bb22018-07-16 10:54:09 +0200198{
Yann Gautier1d204ee2021-05-19 18:48:16 +0200199 return io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Yann Gautieraec7de42018-10-15 09:36:58 +0200200}
201
202static int open_storage(const uintptr_t spec)
203{
204 return io_dev_init(storage_dev_handle, 0);
205}
206
Yann Gautier4353bb22018-07-16 10:54:09 +0200207static void print_boot_device(boot_api_context_t *boot_context)
208{
209 switch (boot_context->boot_interface_selected) {
210 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
211 INFO("Using SDMMC\n");
212 break;
213 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
214 INFO("Using EMMC\n");
215 break;
Lionel Debieveb1b218f2019-09-25 09:11:31 +0200216 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
217 INFO("Using QSPI NOR\n");
218 break;
Lionel Debieve12e21df2019-11-04 12:28:15 +0100219 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
220 INFO("Using FMC NAND\n");
221 break;
Lionel Debieve57044222019-09-24 18:30:12 +0200222 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
223 INFO("Using SPI NAND\n");
224 break;
Yann Gautier4353bb22018-07-16 10:54:09 +0200225 default:
Yann Gautier1d204ee2021-05-19 18:48:16 +0200226 ERROR("Boot interface %u not found\n",
227 boot_context->boot_interface_selected);
Yann Gautier4353bb22018-07-16 10:54:09 +0200228 panic();
229 break;
230 }
231
232 if (boot_context->boot_interface_instance != 0U) {
233 INFO(" Instance %d\n", boot_context->boot_interface_instance);
234 }
235}
236
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200237#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautier0b1aa772019-04-23 13:34:03 +0200238static void boot_mmc(enum mmc_device_type mmc_dev_type,
239 uint16_t boot_interface_instance)
Yann Gautier4353bb22018-07-16 10:54:09 +0200240{
241 int io_result __unused;
Yann Gautieraec7de42018-10-15 09:36:58 +0200242 struct stm32_sdmmc2_params params;
Yann Gautier0b1aa772019-04-23 13:34:03 +0200243
Yann Gautier0b1aa772019-04-23 13:34:03 +0200244 zeromem(&params, sizeof(struct stm32_sdmmc2_params));
245
Yann Gautiercddf1bd2021-03-22 14:22:14 +0100246 mmc_info.mmc_dev_type = mmc_dev_type;
Yann Gautier0b1aa772019-04-23 13:34:03 +0200247
248 switch (boot_interface_instance) {
249 case 1:
250 params.reg_base = STM32MP_SDMMC1_BASE;
251 break;
252 case 2:
253 params.reg_base = STM32MP_SDMMC2_BASE;
254 break;
255 case 3:
256 params.reg_base = STM32MP_SDMMC3_BASE;
257 break;
258 default:
259 WARN("SDMMC instance not found, using default\n");
260 if (mmc_dev_type == MMC_IS_SD) {
261 params.reg_base = STM32MP_SDMMC1_BASE;
262 } else {
263 params.reg_base = STM32MP_SDMMC2_BASE;
264 }
265 break;
266 }
267
Yann Gautiercddf1bd2021-03-22 14:22:14 +0100268 params.device_info = &mmc_info;
Yann Gautier0b1aa772019-04-23 13:34:03 +0200269 if (stm32_sdmmc2_mmc_init(&params) != 0) {
270 ERROR("SDMMC%u init failed\n", boot_interface_instance);
271 panic();
272 }
273
274 /* Open MMC as a block device to read GPT table */
275 io_result = register_io_dev_block(&mmc_dev_con);
276 if (io_result != 0) {
277 panic();
278 }
279
280 io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
281 &storage_dev_handle);
282 assert(io_result == 0);
Yann Gautier0b1aa772019-04-23 13:34:03 +0200283}
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200284#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier0b1aa772019-04-23 13:34:03 +0200285
Lionel Debieveb1b218f2019-09-25 09:11:31 +0200286#if STM32MP_SPI_NOR
287static void boot_spi_nor(boot_api_context_t *boot_context)
288{
289 int io_result __unused;
Lionel Debieveb1b218f2019-09-25 09:11:31 +0200290
291 io_result = stm32_qspi_init();
292 assert(io_result == 0);
293
294 io_result = register_io_dev_mtd(&spi_dev_con);
295 assert(io_result == 0);
296
297 /* Open connections to device */
298 io_result = io_dev_open(spi_dev_con,
299 (uintptr_t)&spi_nor_dev_spec,
300 &storage_dev_handle);
301 assert(io_result == 0);
Lionel Debieveb1b218f2019-09-25 09:11:31 +0200302}
303#endif /* STM32MP_SPI_NOR */
304
Lionel Debieve12e21df2019-11-04 12:28:15 +0100305#if STM32MP_RAW_NAND
306static void boot_fmc2_nand(boot_api_context_t *boot_context)
307{
308 int io_result __unused;
Lionel Debieve12e21df2019-11-04 12:28:15 +0100309
310 io_result = stm32_fmc2_init();
311 assert(io_result == 0);
312
313 /* Register the IO device on this platform */
314 io_result = register_io_dev_mtd(&nand_dev_con);
315 assert(io_result == 0);
316
317 /* Open connections to device */
318 io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
319 &storage_dev_handle);
320 assert(io_result == 0);
Lionel Debieve12e21df2019-11-04 12:28:15 +0100321}
322#endif /* STM32MP_RAW_NAND */
323
Lionel Debieve57044222019-09-24 18:30:12 +0200324#if STM32MP_SPI_NAND
325static void boot_spi_nand(boot_api_context_t *boot_context)
326{
327 int io_result __unused;
Lionel Debieve57044222019-09-24 18:30:12 +0200328
329 io_result = stm32_qspi_init();
330 assert(io_result == 0);
331
332 io_result = register_io_dev_mtd(&spi_dev_con);
333 assert(io_result == 0);
334
335 /* Open connections to device */
336 io_result = io_dev_open(spi_dev_con,
337 (uintptr_t)&spi_nand_dev_spec,
338 &storage_dev_handle);
339 assert(io_result == 0);
Lionel Debieve57044222019-09-24 18:30:12 +0200340}
341#endif /* STM32MP_SPI_NAND */
342
Yann Gautier0b1aa772019-04-23 13:34:03 +0200343void stm32mp_io_setup(void)
344{
345 int io_result __unused;
Yann Gautier4353bb22018-07-16 10:54:09 +0200346 boot_api_context_t *boot_context =
Yann Gautier3f9c9782019-02-14 11:13:39 +0100347 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautier4353bb22018-07-16 10:54:09 +0200348
Yann Gautier4353bb22018-07-16 10:54:09 +0200349 print_boot_device(boot_context);
350
351 if ((boot_context->boot_partition_used_toboot == 1U) ||
352 (boot_context->boot_partition_used_toboot == 2U)) {
Yann Gautier1d204ee2021-05-19 18:48:16 +0200353 INFO("Boot used partition fsbl%u\n",
Yann Gautier4353bb22018-07-16 10:54:09 +0200354 boot_context->boot_partition_used_toboot);
355 }
356
Yann Gautier1d204ee2021-05-19 18:48:16 +0200357 io_result = register_io_dev_fip(&fip_dev_con);
Yann Gautier4353bb22018-07-16 10:54:09 +0200358 assert(io_result == 0);
359
Yann Gautier1d204ee2021-05-19 18:48:16 +0200360 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
361 &fip_dev_handle);
Yann Gautieraec7de42018-10-15 09:36:58 +0200362
363 switch (boot_context->boot_interface_selected) {
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200364#if STM32MP_SDMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200365 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
Yann Gautier0b1aa772019-04-23 13:34:03 +0200366 dmbsy();
367 boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
368 break;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200369#endif
370#if STM32MP_EMMC
Yann Gautieraec7de42018-10-15 09:36:58 +0200371 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
Yann Gautier59a1cdf2019-01-17 14:41:46 +0100372 dmbsy();
Yann Gautier0b1aa772019-04-23 13:34:03 +0200373 boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
Yann Gautieraec7de42018-10-15 09:36:58 +0200374 break;
Nicolas Le Bayon46554b62019-09-03 09:52:05 +0200375#endif
Lionel Debieveb1b218f2019-09-25 09:11:31 +0200376#if STM32MP_SPI_NOR
377 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
378 dmbsy();
379 boot_spi_nor(boot_context);
380 break;
381#endif
Lionel Debieve12e21df2019-11-04 12:28:15 +0100382#if STM32MP_RAW_NAND
383 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
384 dmbsy();
385 boot_fmc2_nand(boot_context);
386 break;
387#endif
Lionel Debieve57044222019-09-24 18:30:12 +0200388#if STM32MP_SPI_NAND
389 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
390 dmbsy();
391 boot_spi_nand(boot_context);
392 break;
393#endif
Yann Gautieraec7de42018-10-15 09:36:58 +0200394
395 default:
396 ERROR("Boot interface %d not supported\n",
397 boot_context->boot_interface_selected);
Yann Gautier71693a62021-06-30 17:04:22 +0200398 panic();
Yann Gautieraec7de42018-10-15 09:36:58 +0200399 break;
400 }
Yann Gautier4353bb22018-07-16 10:54:09 +0200401}
402
Yann Gautier1d204ee2021-05-19 18:48:16 +0200403int bl2_plat_handle_pre_image_load(unsigned int image_id)
404{
405 static bool gpt_init_done __unused;
406 uint16_t boot_itf = stm32mp_get_boot_itf_selected();
407
408 switch (boot_itf) {
409#if STM32MP_SDMMC || STM32MP_EMMC
410 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
411 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
412 if (!gpt_init_done) {
413 const partition_entry_t *entry;
414
415 partition_init(GPT_IMAGE_ID);
416 entry = get_partition_entry(FIP_IMAGE_NAME);
417 if (entry == NULL) {
418 ERROR("Could NOT find the %s partition!\n",
419 FIP_IMAGE_NAME);
420 return -ENOENT;
421 }
422
423 image_block_spec.offset = entry->start;
424 image_block_spec.length = entry->length;
425
426 gpt_init_done = true;
Yann Gautier18b415b2021-06-18 11:33:26 +0200427 } else {
428 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
429
430 mmc_block_dev_spec.buffer.offset = bl_mem_params->image_info.image_base;
431 mmc_block_dev_spec.buffer.length = bl_mem_params->image_info.image_max_size;
Yann Gautier1d204ee2021-05-19 18:48:16 +0200432 }
433
434 break;
435#endif
436
437#if STM32MP_RAW_NAND || STM32MP_SPI_NAND
438#if STM32MP_RAW_NAND
439 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
440#endif
441#if STM32MP_SPI_NAND
442 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI:
443#endif
444 image_block_spec.offset = STM32MP_NAND_FIP_OFFSET;
445 break;
446#endif
447
448#if STM32MP_SPI_NOR
449 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI:
450 image_block_spec.offset = STM32MP_NOR_FIP_OFFSET;
451 break;
452#endif
453
454 default:
455 ERROR("FIP Not found\n");
456 panic();
457 }
458
459 return 0;
460}
461
Yann Gautier4353bb22018-07-16 10:54:09 +0200462/*
463 * Return an IO device handle and specification which can be used to access
464 * an image. Use this to enforce platform load policy.
465 */
466int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
467 uintptr_t *image_spec)
468{
469 int rc;
470 const struct plat_io_policy *policy;
471
472 assert(image_id < ARRAY_SIZE(policies));
473
474 policy = &policies[image_id];
475 rc = policy->check(policy->image_spec);
476 if (rc == 0) {
477 *image_spec = policy->image_spec;
478 *dev_handle = *(policy->dev_handle);
479 }
480
481 return rc;
482}