blob: d5d0ff506c82b5a93e3a65b671b4cb55fea81b0e [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001/*
Yann Gautierd6b75ea2024-01-05 11:45:31 +01002 * Copyright (c) 2015-2024, 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>
Sughosh Ganub721f8a2021-12-01 16:45:11 +053013#include <drivers/fwu/fwu.h>
14#include <drivers/fwu/fwu_metadata.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <drivers/io/io_block.h>
16#include <drivers/io/io_driver.h>
Lionel Debieve5adcd502022-10-05 16:51:12 +020017#include <drivers/io/io_encrypted.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020018#include <drivers/io/io_fip.h>
Patrick Delaunay9c5ee782021-07-06 14:07:56 +020019#include <drivers/io/io_memmap.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010020#include <drivers/io/io_mtd.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <drivers/io/io_storage.h>
22#include <drivers/mmc.h>
Sughosh Ganub721f8a2021-12-01 16:45:11 +053023#include <drivers/partition/efi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000024#include <drivers/partition/partition.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010025#include <drivers/raw_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020026#include <drivers/spi_nand.h>
Lionel Debievecb0dbc42019-09-25 09:11:31 +020027#include <drivers/spi_nor.h>
Lionel Debieve402a46b2019-11-04 12:28:15 +010028#include <drivers/st/stm32_fmc2_nand.h>
Lionel Debieve186b0462019-09-24 18:30:12 +020029#include <drivers/st/stm32_qspi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000030#include <drivers/st/stm32_sdmmc2.h>
Patrick Delaunay9c5ee782021-07-06 14:07:56 +020031#include <drivers/usb_device.h>
Yann Gautier29f1f942021-07-13 18:07:41 +020032#include <lib/fconf/fconf.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000033#include <lib/mmio.h>
34#include <lib/utils.h>
35#include <plat/common/platform.h>
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020036#include <tools_share/firmware_image_package.h>
37
38#include <platform_def.h>
Patrick Delaunay9c5ee782021-07-06 14:07:56 +020039#include <stm32cubeprogrammer.h>
Lionel Debieve5e111c52022-02-24 18:58:46 +010040#include <stm32mp_efi.h>
Yann Gautier29f1f942021-07-13 18:07:41 +020041#include <stm32mp_fconf_getter.h>
Yann Gautier8636a5f2022-05-06 15:27:32 +020042#include <stm32mp_io_storage.h>
Patrick Delaunay9c5ee782021-07-06 14:07:56 +020043#include <usb_dfu.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000044
Yann Gautier4b0c72a2018-07-16 10:54:09 +020045/* IO devices */
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020046uintptr_t fip_dev_handle;
47uintptr_t storage_dev_handle;
Yann Gautier4b0c72a2018-07-16 10:54:09 +020048
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020049static const io_dev_connector_t *fip_dev_con;
Yann Gautierd6b75ea2024-01-05 11:45:31 +010050static uint32_t nand_block_sz __maybe_unused;
Yann Gautier8244e1d2018-10-15 09:36:58 +020051
Lionel Debieve5adcd502022-10-05 16:51:12 +020052#ifndef DECRYPTION_SUPPORT_none
53static const io_dev_connector_t *enc_dev_con;
54uintptr_t enc_dev_handle;
55#endif
56
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020057#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautierac22dd52021-03-22 14:22:14 +010058static struct mmc_device_info mmc_info;
Yann Gautier8244e1d2018-10-15 09:36:58 +020059
Yann Gautier438c4c62023-08-17 11:44:07 +020060static uint8_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
Yann Gautier8244e1d2018-10-15 09:36:58 +020061
Yann Gautiera3bd8d12021-06-18 11:33:26 +020062static io_block_dev_spec_t mmc_block_dev_spec = {
Yann Gautier8244e1d2018-10-15 09:36:58 +020063 /* It's used as temp buffer in block driver */
64 .buffer = {
65 .offset = (size_t)&block_buffer,
66 .length = MMC_BLOCK_SIZE,
67 },
68 .ops = {
69 .read = mmc_read_blocks,
70 .write = NULL,
71 },
72 .block_size = MMC_BLOCK_SIZE,
73};
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +020074
Yann Gautier8244e1d2018-10-15 09:36:58 +020075static const io_dev_connector_t *mmc_dev_con;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +020076#endif /* STM32MP_SDMMC || STM32MP_EMMC */
Yann Gautier8244e1d2018-10-15 09:36:58 +020077
Lionel Debievecb0dbc42019-09-25 09:11:31 +020078#if STM32MP_SPI_NOR
79static io_mtd_dev_spec_t spi_nor_dev_spec = {
80 .ops = {
81 .init = spi_nor_init,
82 .read = spi_nor_read,
83 },
84};
85#endif
86
Lionel Debieve402a46b2019-11-04 12:28:15 +010087#if STM32MP_RAW_NAND
88static io_mtd_dev_spec_t nand_dev_spec = {
89 .ops = {
90 .init = nand_raw_init,
91 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +020092 .seek = nand_seek_bb
Lionel Debieve402a46b2019-11-04 12:28:15 +010093 },
94};
95
96static const io_dev_connector_t *nand_dev_con;
97#endif
98
Lionel Debieve186b0462019-09-24 18:30:12 +020099#if STM32MP_SPI_NAND
100static io_mtd_dev_spec_t spi_nand_dev_spec = {
101 .ops = {
102 .init = spi_nand_init,
103 .read = nand_read,
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200104 .seek = nand_seek_bb
Lionel Debieve186b0462019-09-24 18:30:12 +0200105 },
106};
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200107#endif
Lionel Debieve186b0462019-09-24 18:30:12 +0200108
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200109#if STM32MP_SPI_NAND || STM32MP_SPI_NOR
Lionel Debieve186b0462019-09-24 18:30:12 +0200110static const io_dev_connector_t *spi_dev_con;
111#endif
112
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200113#if STM32MP_UART_PROGRAMMER || STM32MP_USB_PROGRAMMER
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200114static const io_dev_connector_t *memmap_dev_con;
115#endif
116
Yann Gautier29f1f942021-07-13 18:07:41 +0200117io_block_spec_t image_block_spec = {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200118 .offset = 0U,
119 .length = 0U,
120};
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200121
Yann Gautier29f1f942021-07-13 18:07:41 +0200122int open_fip(const uintptr_t spec)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200123{
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200124 return io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200125}
Yann Gautier8244e1d2018-10-15 09:36:58 +0200126
Lionel Debieve5adcd502022-10-05 16:51:12 +0200127#ifndef DECRYPTION_SUPPORT_none
128int open_enc_fip(const uintptr_t spec)
129{
130 int result;
131 uintptr_t local_image_handle;
132
133 result = io_dev_init(enc_dev_handle, (uintptr_t)ENC_IMAGE_ID);
134 if (result != 0) {
135 return result;
136 }
137
138 result = io_open(enc_dev_handle, spec, &local_image_handle);
139 if (result != 0) {
140 return result;
141 }
142
143 VERBOSE("Using encrypted FIP\n");
144 io_close(local_image_handle);
145
146 return 0;
147}
148#endif
149
Yann Gautier29f1f942021-07-13 18:07:41 +0200150int open_storage(const uintptr_t spec)
Yann Gautier8244e1d2018-10-15 09:36:58 +0200151{
152 return io_dev_init(storage_dev_handle, 0);
153}
Vyacheslav Yurkove43a0802021-06-04 10:10:51 +0200154
Ahmad Fatoumbd685282022-05-19 07:42:33 +0200155#if STM32MP_EMMC_BOOT
156static uint32_t get_boot_part_fip_header(void)
157{
158 io_block_spec_t emmc_boot_fip_block_spec = {
159 .offset = STM32MP_EMMC_BOOT_FIP_OFFSET,
160 .length = MMC_BLOCK_SIZE, /* We are interested only in first 4 bytes */
161 };
162 uint32_t magic = 0U;
163 int io_result;
164 size_t bytes_read;
165 uintptr_t fip_hdr_handle;
166
167 io_result = io_open(storage_dev_handle, (uintptr_t)&emmc_boot_fip_block_spec,
168 &fip_hdr_handle);
169 assert(io_result == 0);
170
171 io_result = io_read(fip_hdr_handle, (uintptr_t)&magic, sizeof(magic),
172 &bytes_read);
173 if ((io_result != 0) || (bytes_read != sizeof(magic))) {
174 panic();
175 }
176
177 io_close(fip_hdr_handle);
178
179 VERBOSE("%s: eMMC boot magic at offset 256K: %08x\n",
180 __func__, magic);
181
182 return magic;
183}
184#endif
185
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200186static void print_boot_device(boot_api_context_t *boot_context)
187{
188 switch (boot_context->boot_interface_selected) {
189 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
190 INFO("Using SDMMC\n");
191 break;
192 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
193 INFO("Using EMMC\n");
194 break;
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200195 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_SPI:
196 INFO("Using SPI NOR\n");
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200197 break;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100198 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
199 INFO("Using FMC NAND\n");
200 break;
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200201 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_SPI:
Lionel Debieve186b0462019-09-24 18:30:12 +0200202 INFO("Using SPI NAND\n");
203 break;
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200204 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_UART:
205 INFO("Using UART\n");
206 break;
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200207 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_USB:
208 INFO("Using USB\n");
209 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200210 default:
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200211 ERROR("Boot interface %u not found\n",
212 boot_context->boot_interface_selected);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200213 panic();
214 break;
215 }
216
217 if (boot_context->boot_interface_instance != 0U) {
218 INFO(" Instance %d\n", boot_context->boot_interface_instance);
219 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200220}
221
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200222#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200223static void boot_mmc(enum mmc_device_type mmc_dev_type,
224 uint16_t boot_interface_instance)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200225{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100226 int io_result __maybe_unused;
Yann Gautier8244e1d2018-10-15 09:36:58 +0200227 struct stm32_sdmmc2_params params;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200228
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200229 zeromem(&params, sizeof(struct stm32_sdmmc2_params));
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200230
Yann Gautierac22dd52021-03-22 14:22:14 +0100231 mmc_info.mmc_dev_type = mmc_dev_type;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200232
233 switch (boot_interface_instance) {
234 case 1:
235 params.reg_base = STM32MP_SDMMC1_BASE;
236 break;
237 case 2:
238 params.reg_base = STM32MP_SDMMC2_BASE;
239 break;
240 case 3:
241 params.reg_base = STM32MP_SDMMC3_BASE;
242 break;
243 default:
244 WARN("SDMMC instance not found, using default\n");
245 if (mmc_dev_type == MMC_IS_SD) {
246 params.reg_base = STM32MP_SDMMC1_BASE;
247 } else {
248 params.reg_base = STM32MP_SDMMC2_BASE;
249 }
250 break;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200251 }
252
Yann Gautierb218faa2019-08-14 16:44:48 +0200253 if (mmc_dev_type != MMC_IS_EMMC) {
254 params.flags = MMC_FLAG_SD_CMD6;
255 }
256
Yann Gautierac22dd52021-03-22 14:22:14 +0100257 params.device_info = &mmc_info;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200258 if (stm32_sdmmc2_mmc_init(&params) != 0) {
259 ERROR("SDMMC%u init failed\n", boot_interface_instance);
260 panic();
261 }
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200262
Ahmad Fatoumbd685282022-05-19 07:42:33 +0200263 /* Open MMC as a block device to read FIP */
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200264 io_result = register_io_dev_block(&mmc_dev_con);
265 if (io_result != 0) {
266 panic();
267 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200268
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200269 io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec,
270 &storage_dev_handle);
271 assert(io_result == 0);
Ahmad Fatoumbd685282022-05-19 07:42:33 +0200272
273#if STM32MP_EMMC_BOOT
274 if (mmc_dev_type == MMC_IS_EMMC) {
275 io_result = mmc_part_switch_current_boot();
276 assert(io_result == 0);
277
278 if (get_boot_part_fip_header() != TOC_HEADER_NAME) {
279 WARN("%s: Can't find FIP header on eMMC boot partition. Trying GPT\n",
280 __func__);
281 io_result = mmc_part_switch_user();
282 assert(io_result == 0);
283 return;
284 }
285
286 VERBOSE("%s: FIP header found on eMMC boot partition\n",
287 __func__);
288 image_block_spec.offset = STM32MP_EMMC_BOOT_FIP_OFFSET;
Yann Gautier637cd9e2022-09-02 08:36:40 +0200289 image_block_spec.length = mmc_boot_part_size() - STM32MP_EMMC_BOOT_FIP_OFFSET;
Ahmad Fatoumbd685282022-05-19 07:42:33 +0200290 }
291#endif
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{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100298 int io_result __maybe_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
Yann Gautierd6b75ea2024-01-05 11:45:31 +0100314#if STM32MP_RAW_NAND || STM32MP_SPI_NAND
315/*
316 * This function returns 0 if it can find an alternate
317 * image to be loaded or a negative errno otherwise.
318 */
319static int try_nand_backup_partitions(unsigned int image_id)
320{
321 static unsigned int backup_id;
322 static unsigned int backup_block_nb;
323
324 /* Check if NAND storage used */
325 if (nand_block_sz == 0U) {
326 return -ENODEV;
327 }
328
329 if (backup_id != image_id) {
330 backup_block_nb = PLATFORM_MTD_MAX_PART_SIZE / nand_block_sz;
331 backup_id = image_id;
332 }
333
334 if (backup_block_nb-- == 0U) {
335 return -ENOSPC;
336 }
337
338 image_block_spec.offset += nand_block_sz;
339
340 return 0;
341}
342
343static const struct plat_try_images_ops try_img_ops = {
344 .next_instance = try_nand_backup_partitions,
345};
346#endif /* STM32MP_RAW_NAND || STM32MP_SPI_NAND */
347
Lionel Debieve402a46b2019-11-04 12:28:15 +0100348#if STM32MP_RAW_NAND
349static void boot_fmc2_nand(boot_api_context_t *boot_context)
350{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100351 int io_result __maybe_unused;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100352
Yann Gautierd6b75ea2024-01-05 11:45:31 +0100353 plat_setup_try_img_ops(&try_img_ops);
354
Lionel Debieve402a46b2019-11-04 12:28:15 +0100355 io_result = stm32_fmc2_init();
356 assert(io_result == 0);
357
358 /* Register the IO device on this platform */
359 io_result = register_io_dev_mtd(&nand_dev_con);
360 assert(io_result == 0);
361
362 /* Open connections to device */
363 io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec,
364 &storage_dev_handle);
365 assert(io_result == 0);
Yann Gautierd6b75ea2024-01-05 11:45:31 +0100366
367 nand_block_sz = nand_dev_spec.erase_size;
Lionel Debieve402a46b2019-11-04 12:28:15 +0100368}
369#endif /* STM32MP_RAW_NAND */
370
Lionel Debieve186b0462019-09-24 18:30:12 +0200371#if STM32MP_SPI_NAND
372static void boot_spi_nand(boot_api_context_t *boot_context)
373{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100374 int io_result __maybe_unused;
Lionel Debieve186b0462019-09-24 18:30:12 +0200375
Yann Gautierd6b75ea2024-01-05 11:45:31 +0100376 plat_setup_try_img_ops(&try_img_ops);
377
Lionel Debieve186b0462019-09-24 18:30:12 +0200378 io_result = stm32_qspi_init();
379 assert(io_result == 0);
380
381 io_result = register_io_dev_mtd(&spi_dev_con);
382 assert(io_result == 0);
383
384 /* Open connections to device */
385 io_result = io_dev_open(spi_dev_con,
386 (uintptr_t)&spi_nand_dev_spec,
387 &storage_dev_handle);
388 assert(io_result == 0);
Yann Gautierd6b75ea2024-01-05 11:45:31 +0100389
390 nand_block_sz = spi_nand_dev_spec.erase_size;
Lionel Debieve186b0462019-09-24 18:30:12 +0200391}
392#endif /* STM32MP_SPI_NAND */
393
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200394#if STM32MP_UART_PROGRAMMER || STM32MP_USB_PROGRAMMER
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200395static void mmap_io_setup(void)
396{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100397 int io_result __maybe_unused;
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200398
399 io_result = register_io_dev_memmap(&memmap_dev_con);
400 assert(io_result == 0);
401
402 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
403 &storage_dev_handle);
404 assert(io_result == 0);
405}
406
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200407#if STM32MP_UART_PROGRAMMER
408static void stm32cubeprogrammer_uart(void)
409{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100410 int ret __maybe_unused;
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200411 boot_api_context_t *boot_context =
412 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
413 uintptr_t uart_base;
414
415 uart_base = get_uart_address(boot_context->boot_interface_instance);
416 ret = stm32cubeprog_uart_load(uart_base, DWL_BUFFER_BASE, DWL_BUFFER_SIZE);
417 assert(ret == 0);
418}
419#endif
420
421#if STM32MP_USB_PROGRAMMER
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200422static void stm32cubeprogrammer_usb(void)
423{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100424 int ret __maybe_unused;
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200425 struct usb_handle *pdev;
426
427 /* Init USB on platform */
428 pdev = usb_dfu_plat_init();
429
430 ret = stm32cubeprog_usb_load(pdev, DWL_BUFFER_BASE, DWL_BUFFER_SIZE);
431 assert(ret == 0);
432}
433#endif
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200434#endif /* STM32MP_UART_PROGRAMMER || STM32MP_USB_PROGRAMMER */
435
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200436void stm32mp_io_setup(void)
437{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100438 int io_result __maybe_unused;
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200439 boot_api_context_t *boot_context =
440 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautierf9d40d52019-01-17 14:41:46 +0100441
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200442 print_boot_device(boot_context);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200443
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200444 if ((boot_context->boot_partition_used_toboot == 1U) ||
445 (boot_context->boot_partition_used_toboot == 2U)) {
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200446 INFO("Boot used partition fsbl%u\n",
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200447 boot_context->boot_partition_used_toboot);
448 }
Yann Gautier8244e1d2018-10-15 09:36:58 +0200449
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200450 io_result = register_io_dev_fip(&fip_dev_con);
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200451 assert(io_result == 0);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200452
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200453 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
454 &fip_dev_handle);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200455
Lionel Debieve5adcd502022-10-05 16:51:12 +0200456#ifndef DECRYPTION_SUPPORT_none
457 io_result = register_io_dev_enc(&enc_dev_con);
458 assert(io_result == 0);
459
460 io_result = io_dev_open(enc_dev_con, (uintptr_t)NULL,
461 &enc_dev_handle);
462 assert(io_result == 0);
463#endif
464
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200465 switch (boot_context->boot_interface_selected) {
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200466#if STM32MP_SDMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200467 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
468 dmbsy();
469 boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance);
470 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200471#endif
472#if STM32MP_EMMC
Yann Gautiereae3fbf2019-04-23 13:34:03 +0200473 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
474 dmbsy();
475 boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance);
Yann Gautier8244e1d2018-10-15 09:36:58 +0200476 break;
Nicolas Le Bayon3f42cad2019-09-03 09:52:05 +0200477#endif
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200478#if STM32MP_SPI_NOR
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200479 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_SPI:
Lionel Debievecb0dbc42019-09-25 09:11:31 +0200480 dmbsy();
481 boot_spi_nor(boot_context);
482 break;
483#endif
Lionel Debieve402a46b2019-11-04 12:28:15 +0100484#if STM32MP_RAW_NAND
485 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
486 dmbsy();
487 boot_fmc2_nand(boot_context);
488 break;
489#endif
Lionel Debieve186b0462019-09-24 18:30:12 +0200490#if STM32MP_SPI_NAND
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200491 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_SPI:
Lionel Debieve186b0462019-09-24 18:30:12 +0200492 dmbsy();
493 boot_spi_nand(boot_context);
494 break;
495#endif
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200496#if STM32MP_UART_PROGRAMMER || STM32MP_USB_PROGRAMMER
497#if STM32MP_UART_PROGRAMMER
498 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_UART:
499#endif
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200500#if STM32MP_USB_PROGRAMMER
501 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_USB:
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200502#endif
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200503 dmbsy();
504 mmap_io_setup();
505 break;
506#endif
Yann Gautier8244e1d2018-10-15 09:36:58 +0200507
508 default:
509 ERROR("Boot interface %d not supported\n",
510 boot_context->boot_interface_selected);
Yann Gautier4c2b73d2021-06-30 17:04:22 +0200511 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200512 break;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200513 }
514}
515
516int bl2_plat_handle_pre_image_load(unsigned int image_id)
517{
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100518 static bool gpt_init_done __maybe_unused;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200519 uint16_t boot_itf = stm32mp_get_boot_itf_selected();
520
521 switch (boot_itf) {
522#if STM32MP_SDMMC || STM32MP_EMMC
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200523 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
Ahmad Fatoumbd685282022-05-19 07:42:33 +0200524#if STM32MP_EMMC_BOOT
525 if (image_block_spec.offset == STM32MP_EMMC_BOOT_FIP_OFFSET) {
526 break;
527 }
528#endif
529 /* fallthrough */
530 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200531 if (!gpt_init_done) {
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530532/*
533 * With FWU Multi Bank feature enabled, the selection of
534 * the image to boot will be done by fwu_init calling the
535 * platform hook, plat_fwu_set_images_source.
536 */
537#if !PSA_FWU_SUPPORT
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200538 const partition_entry_t *entry;
Sughosh Ganu52794a32024-02-02 15:35:18 +0530539 const struct efi_guid fip_guid = STM32MP_FIP_GUID;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200540
541 partition_init(GPT_IMAGE_ID);
Sughosh Ganu52794a32024-02-02 15:35:18 +0530542 entry = get_partition_entry_by_type(&fip_guid);
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200543 if (entry == NULL) {
Lionel Debieve5e111c52022-02-24 18:58:46 +0100544 entry = get_partition_entry(FIP_IMAGE_NAME);
545 if (entry == NULL) {
546 ERROR("Could NOT find the %s partition!\n",
547 FIP_IMAGE_NAME);
548
549 return -ENOENT;
550 }
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200551 }
552
553 image_block_spec.offset = entry->start;
554 image_block_spec.length = entry->length;
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530555#endif
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200556 gpt_init_done = true;
Yann Gautiera3bd8d12021-06-18 11:33:26 +0200557 } else {
558 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100559
Yann Gautierc6f77b02022-05-06 09:50:43 +0200560 assert(bl_mem_params != NULL);
Yann Gautiera3bd8d12021-06-18 11:33:26 +0200561
562 mmc_block_dev_spec.buffer.offset = bl_mem_params->image_info.image_base;
563 mmc_block_dev_spec.buffer.length = bl_mem_params->image_info.image_max_size;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200564 }
565
566 break;
567#endif
568
569#if STM32MP_RAW_NAND || STM32MP_SPI_NAND
570#if STM32MP_RAW_NAND
571 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC:
572#endif
573#if STM32MP_SPI_NAND
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200574 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_SPI:
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200575#endif
576 image_block_spec.offset = STM32MP_NAND_FIP_OFFSET;
577 break;
578#endif
579
580#if STM32MP_SPI_NOR
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200581 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_SPI:
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100582/*
583 * With FWU Multi Bank feature enabled, the selection of
584 * the image to boot will be done by fwu_init calling the
585 * platform hook, plat_fwu_set_images_source.
586 */
587#if !PSA_FWU_SUPPORT
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200588 image_block_spec.offset = STM32MP_NOR_FIP_OFFSET;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100589#endif
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200590 break;
591#endif
592
Patrick Delaunaye50571b2021-10-28 13:48:52 +0200593#if STM32MP_UART_PROGRAMMER
594 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_UART:
595 if (image_id == FW_CONFIG_ID) {
596 stm32cubeprogrammer_uart();
597 /* FIP loaded at DWL address */
598 image_block_spec.offset = DWL_BUFFER_BASE;
599 image_block_spec.length = DWL_BUFFER_SIZE;
600 }
601 break;
602#endif
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200603#if STM32MP_USB_PROGRAMMER
604 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_USB:
605 if (image_id == FW_CONFIG_ID) {
606 stm32cubeprogrammer_usb();
607 /* FIP loaded at DWL address */
608 image_block_spec.offset = DWL_BUFFER_BASE;
609 image_block_spec.length = DWL_BUFFER_SIZE;
610 }
611 break;
612#endif
613
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200614 default:
615 ERROR("FIP Not found\n");
616 panic();
Yann Gautier8244e1d2018-10-15 09:36:58 +0200617 }
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200618
619 return 0;
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200620}
621
622/*
623 * Return an IO device handle and specification which can be used to access
624 * an image. Use this to enforce platform load policy.
625 */
626int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
627 uintptr_t *image_spec)
628{
629 int rc;
630 const struct plat_io_policy *policy;
631
Yann Gautier29f1f942021-07-13 18:07:41 +0200632 policy = FCONF_GET_PROPERTY(stm32mp, io_policies, image_id);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200633 rc = policy->check(policy->image_spec);
634 if (rc == 0) {
635 *image_spec = policy->image_spec;
636 *dev_handle = *(policy->dev_handle);
637 }
638
639 return rc;
640}
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530641
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100642#if (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530643/*
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100644 * In each boot in non-trial mode, we set the BKP register to
645 * FWU_MAX_TRIAL_REBOOT, and return the active_index from metadata.
646 *
647 * As long as the update agent didn't update the "accepted" field in metadata
648 * (i.e. we are in trial mode), we select the new active_index.
649 * To avoid infinite boot loop at trial boot we decrement a BKP register.
650 * If this counter is 0:
651 * - an unexpected TAMPER event raised (that resets the BKP registers to 0)
652 * - a power-off occurs before the update agent was able to update the
653 * "accepted' field
654 * - we already boot FWU_MAX_TRIAL_REBOOT times in trial mode.
655 * we select the previous_active_index.
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530656 */
657uint32_t plat_fwu_get_boot_idx(void)
658{
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100659 /*
660 * Select boot index and update boot counter only once per boot
661 * even if this function is called several times.
662 */
663 static uint32_t boot_idx = INVALID_BOOT_IDX;
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100664
665 if (boot_idx == INVALID_BOOT_IDX) {
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530666 const struct fwu_metadata *data = fwu_get_metadata();
667
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100668 boot_idx = data->active_index;
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530669
Sughosh Ganu63576f02024-02-01 16:56:27 +0530670 if (data->bank_state[boot_idx] == FWU_BANK_STATE_VALID) {
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100671 if (stm32_get_and_dec_fwu_trial_boot_cnt() == 0U) {
672 WARN("Trial FWU fails %u times\n",
673 FWU_MAX_TRIAL_REBOOT);
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530674 boot_idx = fwu_get_alternate_boot_bank();
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100675 }
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530676 } else if (data->bank_state[boot_idx] ==
677 FWU_BANK_STATE_ACCEPTED) {
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100678 stm32_set_max_fwu_trial_boot_cnt();
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530679 } else {
680 ERROR("The active bank(%u) of the platform is in Invalid State.\n",
681 boot_idx);
682 boot_idx = fwu_get_alternate_boot_bank();
683 stm32_clear_fwu_trial_boot_cnt();
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100684 }
685 }
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530686
Nicolas Toromanoff5a937cd2022-02-07 10:12:04 +0100687 return boot_idx;
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530688}
689
Sughosh Ganu52794a32024-02-02 15:35:18 +0530690static void *stm32_get_image_spec(const struct efi_guid *img_type_guid)
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530691{
692 unsigned int i;
693
694 for (i = 0U; i < MAX_NUMBER_IDS; i++) {
Sughosh Ganu52794a32024-02-02 15:35:18 +0530695 if ((guidcmp(&policies[i].img_type_guid, img_type_guid)) == 0) {
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530696 return (void *)policies[i].image_spec;
697 }
698 }
699
700 return NULL;
701}
702
703void plat_fwu_set_images_source(const struct fwu_metadata *metadata)
704{
705 unsigned int i;
706 uint32_t boot_idx;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100707 const partition_entry_t *entry __maybe_unused;
Sughosh Ganu52794a32024-02-02 15:35:18 +0530708 const struct fwu_image_entry *img_entry;
709 const void *img_type_guid;
710 const void *img_guid;
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530711 io_block_spec_t *image_spec;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100712 const uint16_t boot_itf = stm32mp_get_boot_itf_selected();
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530713
714 boot_idx = plat_fwu_get_boot_idx();
715 assert(boot_idx < NR_OF_FW_BANKS);
Sughosh Ganuda28e4c2024-02-20 14:20:41 +0530716 VERBOSE("Selecting to boot from bank %u\n", boot_idx);
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530717
Sughosh Ganu52794a32024-02-02 15:35:18 +0530718 img_entry = (void *)&metadata->fw_desc.img_entry;
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530719 for (i = 0U; i < NR_OF_IMAGES_IN_FW_BANK; i++) {
Sughosh Ganu52794a32024-02-02 15:35:18 +0530720 img_type_guid = &img_entry[i].img_type_guid;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100721
Sughosh Ganu52794a32024-02-02 15:35:18 +0530722 img_guid = &img_entry[i].img_bank_info[boot_idx].img_guid;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100723
Sughosh Ganu52794a32024-02-02 15:35:18 +0530724 image_spec = stm32_get_image_spec(img_type_guid);
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530725 if (image_spec == NULL) {
726 ERROR("Unable to get image spec for the image in the metadata\n");
727 panic();
728 }
729
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100730 switch (boot_itf) {
731#if (STM32MP_SDMMC || STM32MP_EMMC)
732 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
733 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
Sughosh Ganu52794a32024-02-02 15:35:18 +0530734 entry = get_partition_entry_by_guid(img_guid);
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100735 if (entry == NULL) {
736 ERROR("No partition with the uuid mentioned in metadata\n");
737 panic();
738 }
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530739
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100740 image_spec->offset = entry->start;
741 image_spec->length = entry->length;
742 break;
743#endif
744#if STM32MP_SPI_NOR
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200745 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_SPI:
Sughosh Ganu52794a32024-02-02 15:35:18 +0530746 if (guidcmp(img_guid, &STM32MP_NOR_FIP_A_GUID) == 0) {
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100747 image_spec->offset = STM32MP_NOR_FIP_A_OFFSET;
Sughosh Ganu52794a32024-02-02 15:35:18 +0530748 } else if (guidcmp(img_guid, &STM32MP_NOR_FIP_B_GUID) == 0) {
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100749 image_spec->offset = STM32MP_NOR_FIP_B_OFFSET;
750 } else {
751 ERROR("Invalid uuid mentioned in metadata\n");
752 panic();
753 }
754 break;
755#endif
756 default:
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530757 panic();
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100758 break;
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530759 }
Sughosh Ganub721f8a2021-12-01 16:45:11 +0530760 }
761}
Sughosh Ganud1f87132021-12-01 16:46:34 +0530762
763static int plat_set_image_source(unsigned int image_id,
764 uintptr_t *handle,
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100765 uintptr_t *image_spec)
Sughosh Ganud1f87132021-12-01 16:46:34 +0530766{
767 struct plat_io_policy *policy;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100768 io_block_spec_t *spec __maybe_unused;
769 const partition_entry_t *entry __maybe_unused;
770 const uint16_t boot_itf = stm32mp_get_boot_itf_selected();
Sughosh Ganud1f87132021-12-01 16:46:34 +0530771
772 policy = &policies[image_id];
Sughosh Ganud1f87132021-12-01 16:46:34 +0530773 spec = (io_block_spec_t *)policy->image_spec;
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100774
775 switch (boot_itf) {
776#if (STM32MP_SDMMC || STM32MP_EMMC)
777 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
778 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
779 partition_init(GPT_IMAGE_ID);
780
781 if (image_id == FWU_METADATA_IMAGE_ID) {
782 entry = get_partition_entry(METADATA_PART_1);
783 } else {
784 entry = get_partition_entry(METADATA_PART_2);
785 }
786
787 if (entry == NULL) {
788 ERROR("Unable to find a metadata partition\n");
789 return -ENOENT;
790 }
791
792 spec->offset = entry->start;
793 spec->length = entry->length;
794 break;
795#endif
796
797#if STM32MP_SPI_NOR
Yann Gautiercdb0ec92020-08-31 15:00:19 +0200798 case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_SPI:
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100799 if (image_id == FWU_METADATA_IMAGE_ID) {
800 spec->offset = STM32MP_NOR_METADATA1_OFFSET;
801 } else {
802 spec->offset = STM32MP_NOR_METADATA2_OFFSET;
803 }
804
805 spec->length = sizeof(struct fwu_metadata);
806 break;
807#endif
808 default:
809 panic();
810 break;
811 }
Sughosh Ganud1f87132021-12-01 16:46:34 +0530812
813 *image_spec = policy->image_spec;
814 *handle = *policy->dev_handle;
815
816 return 0;
817}
818
819int plat_fwu_set_metadata_image_source(unsigned int image_id,
820 uintptr_t *handle,
821 uintptr_t *image_spec)
822{
Sughosh Ganud1f87132021-12-01 16:46:34 +0530823 assert((image_id == FWU_METADATA_IMAGE_ID) ||
824 (image_id == BKUP_FWU_METADATA_IMAGE_ID));
825
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100826 return plat_set_image_source(image_id, handle, image_spec);
Sughosh Ganud1f87132021-12-01 16:46:34 +0530827}
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +0100828#endif /* (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT */