blob: 7eaf0ed98b65049c67aba859f5dd3b991a17b12c [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001/*
Yann Gautierdca61542021-02-10 18:19:23 +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>
Yann Gautier658775c2021-07-06 10:00:44 +02008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
Yann Gautier4b0c72a2018-07-16 10:54:09 +020011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
13#include <arch_helpers.h>
14#include <common/bl_common.h>
15#include <common/debug.h>
16#include <common/desc_image_load.h>
17#include <drivers/delay_timer.h>
18#include <drivers/generic_delay_timer.h>
Yann Gautiera3bd8d12021-06-18 11:33:26 +020019#include <drivers/mmc.h>
Yann Gautier3edc7c32019-05-20 19:17:08 +020020#include <drivers/st/bsec.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <drivers/st/stm32_console.h>
Yann Gautier091eab52019-06-04 18:06:34 +020022#include <drivers/st/stm32_iwdg.h>
Yann Gautiera45433b2019-01-16 18:31:00 +010023#include <drivers/st/stm32mp_pmic.h>
Yann Gautiera2e2a302019-02-14 11:13:39 +010024#include <drivers/st/stm32mp_reset.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include <drivers/st/stm32mp1_clk.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000026#include <drivers/st/stm32mp1_pwr.h>
27#include <drivers/st/stm32mp1_ram.h>
Yann Gautier658775c2021-07-06 10:00:44 +020028#include <lib/fconf/fconf.h>
29#include <lib/fconf/fconf_dyn_cfg_getter.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000030#include <lib/mmio.h>
Yann Gautierb3386f72019-04-19 09:41:01 +020031#include <lib/optee_utils.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000032#include <lib/xlat_tables/xlat_tables_v2.h>
33#include <plat/common/platform.h>
34
Yann Gautier8593e442018-11-14 18:46:15 +010035#include <stm32mp1_context.h>
Yann Gautier091eab52019-06-04 18:06:34 +020036#include <stm32mp1_dbgmcu.h>
Yann Gautier4b0c72a2018-07-16 10:54:09 +020037
Etienne Carrieref02647a2019-12-08 08:14:40 +010038#define RESET_TIMEOUT_US_1MS 1000U
39
Andre Przywara678c6fa2020-01-25 00:58:35 +000040static console_t console;
Lionel Debieve7bd96f42019-09-03 12:22:23 +020041static struct stm32mp_auth_ops stm32mp1_auth_ops;
Yann Gautier8593e442018-11-14 18:46:15 +010042
Yann Gautierf9d40d52019-01-17 14:41:46 +010043static void print_reset_reason(void)
44{
Yann Gautier3d78a2e2019-02-14 11:01:20 +010045 uint32_t rstsr = mmio_read_32(stm32mp_rcc_base() + RCC_MP_RSTSCLRR);
Yann Gautierf9d40d52019-01-17 14:41:46 +010046
47 if (rstsr == 0U) {
48 WARN("Reset reason unknown\n");
49 return;
50 }
51
52 INFO("Reset reason (0x%x):\n", rstsr);
53
54 if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) == 0U) {
55 if ((rstsr & RCC_MP_RSTSCLRR_STDBYRSTF) != 0U) {
56 INFO("System exits from STANDBY\n");
57 return;
58 }
59
60 if ((rstsr & RCC_MP_RSTSCLRR_CSTDBYRSTF) != 0U) {
61 INFO("MPU exits from CSTANDBY\n");
62 return;
63 }
64 }
65
66 if ((rstsr & RCC_MP_RSTSCLRR_PORRSTF) != 0U) {
67 INFO(" Power-on Reset (rst_por)\n");
68 return;
69 }
70
71 if ((rstsr & RCC_MP_RSTSCLRR_BORRSTF) != 0U) {
72 INFO(" Brownout Reset (rst_bor)\n");
73 return;
74 }
75
76 if ((rstsr & RCC_MP_RSTSCLRR_MCSYSRSTF) != 0U) {
77 if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) != 0U) {
78 INFO(" System reset generated by MCU (MCSYSRST)\n");
79 } else {
80 INFO(" Local reset generated by MCU (MCSYSRST)\n");
81 }
82 return;
83 }
84
85 if ((rstsr & RCC_MP_RSTSCLRR_MPSYSRSTF) != 0U) {
86 INFO(" System reset generated by MPU (MPSYSRST)\n");
87 return;
88 }
89
90 if ((rstsr & RCC_MP_RSTSCLRR_HCSSRSTF) != 0U) {
91 INFO(" Reset due to a clock failure on HSE\n");
92 return;
93 }
94
95 if ((rstsr & RCC_MP_RSTSCLRR_IWDG1RSTF) != 0U) {
96 INFO(" IWDG1 Reset (rst_iwdg1)\n");
97 return;
98 }
99
100 if ((rstsr & RCC_MP_RSTSCLRR_IWDG2RSTF) != 0U) {
101 INFO(" IWDG2 Reset (rst_iwdg2)\n");
102 return;
103 }
104
105 if ((rstsr & RCC_MP_RSTSCLRR_MPUP0RSTF) != 0U) {
106 INFO(" MPU Processor 0 Reset\n");
107 return;
108 }
109
110 if ((rstsr & RCC_MP_RSTSCLRR_MPUP1RSTF) != 0U) {
111 INFO(" MPU Processor 1 Reset\n");
112 return;
113 }
114
115 if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) != 0U) {
116 INFO(" Pad Reset from NRST\n");
117 return;
118 }
119
120 if ((rstsr & RCC_MP_RSTSCLRR_VCORERSTF) != 0U) {
121 INFO(" Reset due to a failure of VDD_CORE\n");
122 return;
123 }
124
125 ERROR(" Unidentified reset reason\n");
126}
127
128void bl2_el3_early_platform_setup(u_register_t arg0,
129 u_register_t arg1 __unused,
130 u_register_t arg2 __unused,
131 u_register_t arg3 __unused)
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200132{
Yann Gautiera2e2a302019-02-14 11:13:39 +0100133 stm32mp_save_boot_ctx_address(arg0);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200134}
135
136void bl2_platform_setup(void)
137{
Yann Gautiercaf575b2018-07-24 17:18:19 +0200138 int ret;
139
Yann Gautierf3928f62019-02-14 11:15:03 +0100140 if (dt_pmic_status() > 0) {
Yann Gautierbb836ee2018-07-16 17:55:07 +0200141 initialize_pmic();
142 }
143
Yann Gautiercaf575b2018-07-24 17:18:19 +0200144 ret = stm32mp1_ddr_probe();
145 if (ret < 0) {
146 ERROR("Invalid DDR init: error %d\n", ret);
147 panic();
148 }
149
Yann Gautierf3bd87e2020-09-04 15:55:53 +0200150 /* Map DDR for binary load, now with cacheable attribute */
Yann Gautiera55169b2020-01-10 18:18:59 +0100151 ret = mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE,
Yann Gautierf3bd87e2020-09-04 15:55:53 +0200152 STM32MP_DDR_MAX_SIZE, MT_MEMORY | MT_RW | MT_SECURE);
153 if (ret < 0) {
154 ERROR("DDR mapping: error %d\n", ret);
155 panic();
156 }
Yann Gautiera55169b2020-01-10 18:18:59 +0100157
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200158#if STM32MP_USE_STM32IMAGE
Yann Gautierb3386f72019-04-19 09:41:01 +0200159#ifdef AARCH32_SP_OPTEE
160 INFO("BL2 runs OP-TEE setup\n");
Yann Gautierb3386f72019-04-19 09:41:01 +0200161#else
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200162 INFO("BL2 runs SP_MIN setup\n");
Yann Gautierb3386f72019-04-19 09:41:01 +0200163#endif
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200164#endif /* STM32MP_USE_STM32IMAGE */
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200165}
166
167void bl2_el3_plat_arch_setup(void)
168{
Yann Gautier69035a82018-07-05 16:48:16 +0200169 int32_t result;
Yann Gautierf9d40d52019-01-17 14:41:46 +0100170 struct dt_node_info dt_uart_info;
Yann Gautier69035a82018-07-05 16:48:16 +0200171 const char *board_model;
Yann Gautier41934662018-07-20 11:36:05 +0200172 boot_api_context_t *boot_context =
Yann Gautiera2e2a302019-02-14 11:13:39 +0100173 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
Yann Gautier69035a82018-07-05 16:48:16 +0200174 uint32_t clk_rate;
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100175 uintptr_t pwr_base;
176 uintptr_t rcc_base;
Yann Gautier41934662018-07-20 11:36:05 +0200177
Yann Gautierf9d40d52019-01-17 14:41:46 +0100178 mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
179 BL_CODE_END - BL_CODE_BASE,
180 MT_CODE | MT_SECURE);
181
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200182#if STM32MP_USE_STM32IMAGE
Yann Gautierb3386f72019-04-19 09:41:01 +0200183#ifdef AARCH32_SP_OPTEE
Yann Gautierb3386f72019-04-19 09:41:01 +0200184 mmap_add_region(STM32MP_OPTEE_BASE, STM32MP_OPTEE_BASE,
185 STM32MP_OPTEE_SIZE,
186 MT_MEMORY | MT_RW | MT_SECURE);
Yann Gautier90f84d72021-07-13 14:44:09 +0200187#else
188 /* Prevent corruption of preloaded BL32 */
189 mmap_add_region(BL32_BASE, BL32_BASE,
190 BL32_LIMIT - BL32_BASE,
191 MT_RO_DATA | MT_SECURE);
Yann Gautierb3386f72019-04-19 09:41:01 +0200192#endif
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200193#endif /* STM32MP_USE_STM32IMAGE */
194
Yann Gautierf9d40d52019-01-17 14:41:46 +0100195 /* Prevent corruption of preloaded Device Tree */
196 mmap_add_region(DTB_BASE, DTB_BASE,
197 DTB_LIMIT - DTB_BASE,
Yann Gautier3d33df62019-12-17 17:11:10 +0100198 MT_RO_DATA | MT_SECURE);
Yann Gautierf9d40d52019-01-17 14:41:46 +0100199
200 configure_mmu();
201
Yann Gautier05773eb2020-08-24 11:51:50 +0200202 if (dt_open_and_check(STM32MP_DTB_BASE) < 0) {
Yann Gautierf9d40d52019-01-17 14:41:46 +0100203 panic();
204 }
205
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100206 pwr_base = stm32mp_pwr_base();
207 rcc_base = stm32mp_rcc_base();
208
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200209 /*
210 * Disable the backup domain write protection.
211 * The protection is enable at each reset by hardware
212 * and must be disabled by software.
213 */
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100214 mmio_setbits_32(pwr_base + PWR_CR1, PWR_CR1_DBP);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200215
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100216 while ((mmio_read_32(pwr_base + PWR_CR1) & PWR_CR1_DBP) == 0U) {
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200217 ;
218 }
219
Yann Gautier3edc7c32019-05-20 19:17:08 +0200220 if (bsec_probe() != 0) {
221 panic();
222 }
223
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200224 /* Reset backup domain on cold boot cases */
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100225 if ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_RTCSRC_MASK) == 0U) {
226 mmio_setbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200227
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100228 while ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_VSWRST) ==
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200229 0U) {
230 ;
231 }
232
Yann Gautier3d78a2e2019-02-14 11:01:20 +0100233 mmio_clrbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST);
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200234 }
235
Yann Gautiered342322019-02-15 17:33:27 +0100236 /* Disable MCKPROT */
237 mmio_clrbits_32(rcc_base + RCC_TZCR, RCC_TZCR_MCKPROT);
238
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200239 generic_delay_timer_init();
240
Yann Gautier9aea69e2018-07-24 17:13:36 +0200241 if (stm32mp1_clk_probe() < 0) {
242 panic();
243 }
244
245 if (stm32mp1_clk_init() < 0) {
246 panic();
247 }
248
Yann Gautier3edc7c32019-05-20 19:17:08 +0200249 stm32mp1_syscfg_init();
250
Yann Gautierf9d40d52019-01-17 14:41:46 +0100251 result = dt_get_stdout_uart_info(&dt_uart_info);
Yann Gautier69035a82018-07-05 16:48:16 +0200252
253 if ((result <= 0) ||
Yann Gautierf9d40d52019-01-17 14:41:46 +0100254 (dt_uart_info.status == 0U) ||
255 (dt_uart_info.clock < 0) ||
256 (dt_uart_info.reset < 0)) {
Yann Gautier69035a82018-07-05 16:48:16 +0200257 goto skip_console_init;
258 }
259
260 if (dt_set_stdout_pinctrl() != 0) {
261 goto skip_console_init;
262 }
263
Yann Gautiere4a3c352019-02-14 10:53:33 +0100264 stm32mp_clk_enable((unsigned long)dt_uart_info.clock);
Yann Gautier69035a82018-07-05 16:48:16 +0200265
Etienne Carrieref02647a2019-12-08 08:14:40 +0100266 if (stm32mp_reset_assert((uint32_t)dt_uart_info.reset,
267 RESET_TIMEOUT_US_1MS) != 0) {
268 panic();
269 }
270
Yann Gautier69035a82018-07-05 16:48:16 +0200271 udelay(2);
Etienne Carrieref02647a2019-12-08 08:14:40 +0100272
273 if (stm32mp_reset_deassert((uint32_t)dt_uart_info.reset,
274 RESET_TIMEOUT_US_1MS) != 0) {
275 panic();
276 }
277
Yann Gautier69035a82018-07-05 16:48:16 +0200278 mdelay(1);
279
Yann Gautiera2e2a302019-02-14 11:13:39 +0100280 clk_rate = stm32mp_clk_get_rate((unsigned long)dt_uart_info.clock);
Yann Gautier69035a82018-07-05 16:48:16 +0200281
Yann Gautierf9d40d52019-01-17 14:41:46 +0100282 if (console_stm32_register(dt_uart_info.base, clk_rate,
Yann Gautiera2e2a302019-02-14 11:13:39 +0100283 STM32MP_UART_BAUDRATE, &console) == 0) {
Yann Gautier69035a82018-07-05 16:48:16 +0200284 panic();
285 }
286
Andre Przywara678c6fa2020-01-25 00:58:35 +0000287 console_set_scope(&console, CONSOLE_FLAG_BOOT |
Yann Gautiera30e5f72019-09-04 11:55:10 +0200288 CONSOLE_FLAG_CRASH | CONSOLE_FLAG_TRANSLATE_CRLF);
289
Yann Gautierc7374052019-06-04 18:02:37 +0200290 stm32mp_print_cpuinfo();
291
Yann Gautier69035a82018-07-05 16:48:16 +0200292 board_model = dt_get_board_model();
293 if (board_model != NULL) {
Yann Gautierf9d40d52019-01-17 14:41:46 +0100294 NOTICE("Model: %s\n", board_model);
Yann Gautier69035a82018-07-05 16:48:16 +0200295 }
296
Yann Gautier35dc0772019-05-13 18:34:48 +0200297 stm32mp_print_boardinfo();
298
Lionel Debieve7bd96f42019-09-03 12:22:23 +0200299 if (boot_context->auth_status != BOOT_API_CTX_AUTH_NO) {
300 NOTICE("Bootrom authentication %s\n",
301 (boot_context->auth_status == BOOT_API_CTX_AUTH_FAILED) ?
302 "failed" : "succeeded");
303 }
304
Yann Gautier69035a82018-07-05 16:48:16 +0200305skip_console_init:
Yann Gautier091eab52019-06-04 18:06:34 +0200306 if (stm32_iwdg_init() < 0) {
307 panic();
308 }
309
310 stm32_iwdg_refresh();
311
312 result = stm32mp1_dbgmcu_freeze_iwdg2();
313 if (result != 0) {
314 INFO("IWDG2 freeze error : %i\n", result);
315 }
Yann Gautier69035a82018-07-05 16:48:16 +0200316
Yann Gautier41934662018-07-20 11:36:05 +0200317 if (stm32_save_boot_interface(boot_context->boot_interface_selected,
318 boot_context->boot_interface_instance) !=
319 0) {
320 ERROR("Cannot save boot interface\n");
321 }
322
Lionel Debieve7bd96f42019-09-03 12:22:23 +0200323 stm32mp1_auth_ops.check_key = boot_context->bootrom_ecdsa_check_key;
324 stm32mp1_auth_ops.verify_signature =
325 boot_context->bootrom_ecdsa_verify_signature;
326
327 stm32mp_init_auth(&stm32mp1_auth_ops);
328
Yann Gautiercaf575b2018-07-24 17:18:19 +0200329 stm32mp1_arch_security_setup();
330
Yann Gautierf9d40d52019-01-17 14:41:46 +0100331 print_reset_reason();
332
Yann Gautier29f1f942021-07-13 18:07:41 +0200333#if !STM32MP_USE_STM32IMAGE
334 fconf_populate("TB_FW", STM32MP_DTB_BASE);
335#endif /* !STM32MP_USE_STM32IMAGE */
336
Yann Gautiera2e2a302019-02-14 11:13:39 +0100337 stm32mp_io_setup();
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200338}
Yann Gautierb3386f72019-04-19 09:41:01 +0200339
Yann Gautierb3386f72019-04-19 09:41:01 +0200340/*******************************************************************************
341 * This function can be used by the platforms to update/use image
342 * information for given `image_id`.
343 ******************************************************************************/
344int bl2_plat_handle_post_image_load(unsigned int image_id)
345{
346 int err = 0;
347 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
348 bl_mem_params_node_t *bl32_mem_params;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200349 bl_mem_params_node_t *pager_mem_params __unused;
350 bl_mem_params_node_t *paged_mem_params __unused;
Yann Gautier658775c2021-07-06 10:00:44 +0200351#if !STM32MP_USE_STM32IMAGE
352 const struct dyn_cfg_dtb_info_t *config_info;
353 bl_mem_params_node_t *tos_fw_mem_params;
354 unsigned int i;
355 unsigned long long ddr_top __unused;
356 const unsigned int image_ids[] = {
357 BL32_IMAGE_ID,
358 BL33_IMAGE_ID,
359 HW_CONFIG_ID,
360 TOS_FW_CONFIG_ID,
361 };
362#endif /* !STM32MP_USE_STM32IMAGE */
Yann Gautierb3386f72019-04-19 09:41:01 +0200363
364 assert(bl_mem_params != NULL);
365
366 switch (image_id) {
Yann Gautier658775c2021-07-06 10:00:44 +0200367#if !STM32MP_USE_STM32IMAGE
368 case FW_CONFIG_ID:
369 /* Set global DTB info for fixed fw_config information */
370 set_config_info(STM32MP_FW_CONFIG_BASE, STM32MP_FW_CONFIG_MAX_SIZE, FW_CONFIG_ID);
371 fconf_populate("FW_CONFIG", STM32MP_FW_CONFIG_BASE);
372
373 /* Iterate through all the fw config IDs */
374 for (i = 0U; i < ARRAY_SIZE(image_ids); i++) {
375 bl_mem_params = get_bl_mem_params_node(image_ids[i]);
376 assert(bl_mem_params != NULL);
377
378 config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, image_ids[i]);
379 if (config_info == NULL) {
380 continue;
381 }
382
383 bl_mem_params->image_info.image_base = config_info->config_addr;
384 bl_mem_params->image_info.image_max_size = config_info->config_max_size;
385
386 bl_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
387
388 switch (image_ids[i]) {
389 case BL32_IMAGE_ID:
390 bl_mem_params->ep_info.pc = config_info->config_addr;
391
392 /* In case of OPTEE, initialize address space with tos_fw addr */
393 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
394 pager_mem_params->image_info.image_base = config_info->config_addr;
395 pager_mem_params->image_info.image_max_size =
396 config_info->config_max_size;
397
398 /* Init base and size for pager if exist */
399 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
400 paged_mem_params->image_info.image_base = STM32MP_DDR_BASE +
401 (dt_get_ddr_size() - STM32MP_DDR_S_SIZE -
402 STM32MP_DDR_SHMEM_SIZE);
403 paged_mem_params->image_info.image_max_size = STM32MP_DDR_S_SIZE;
404 break;
405
406 case BL33_IMAGE_ID:
407 bl_mem_params->ep_info.pc = config_info->config_addr;
408 break;
409
410 case HW_CONFIG_ID:
411 case TOS_FW_CONFIG_ID:
412 break;
413
414 default:
415 return -EINVAL;
416 }
417 }
418 break;
419#endif /* !STM32MP_USE_STM32IMAGE */
420
Yann Gautierb3386f72019-04-19 09:41:01 +0200421 case BL32_IMAGE_ID:
Yann Gautier90f84d72021-07-13 14:44:09 +0200422 if (optee_header_is_valid(bl_mem_params->image_info.image_base)) {
423 /* BL32 is OP-TEE header */
424 bl_mem_params->ep_info.pc = bl_mem_params->image_info.image_base;
425 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
426 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
427 assert((pager_mem_params != NULL) && (paged_mem_params != NULL));
Yann Gautierb3386f72019-04-19 09:41:01 +0200428
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200429#if STM32MP_USE_STM32IMAGE && defined(AARCH32_SP_OPTEE)
Yann Gautier90f84d72021-07-13 14:44:09 +0200430 /* Set OP-TEE extra image load areas at run-time */
431 pager_mem_params->image_info.image_base = STM32MP_OPTEE_BASE;
432 pager_mem_params->image_info.image_max_size = STM32MP_OPTEE_SIZE;
Yann Gautierb3386f72019-04-19 09:41:01 +0200433
Yann Gautier90f84d72021-07-13 14:44:09 +0200434 paged_mem_params->image_info.image_base = STM32MP_DDR_BASE +
435 dt_get_ddr_size() -
436 STM32MP_DDR_S_SIZE -
437 STM32MP_DDR_SHMEM_SIZE;
438 paged_mem_params->image_info.image_max_size = STM32MP_DDR_S_SIZE;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200439#endif /* STM32MP_USE_STM32IMAGE && defined(AARCH32_SP_OPTEE) */
Yann Gautierb3386f72019-04-19 09:41:01 +0200440
Yann Gautier90f84d72021-07-13 14:44:09 +0200441 err = parse_optee_header(&bl_mem_params->ep_info,
442 &pager_mem_params->image_info,
443 &paged_mem_params->image_info);
444 if (err) {
445 ERROR("OPTEE header parse error.\n");
446 panic();
447 }
Yann Gautierb3386f72019-04-19 09:41:01 +0200448
Yann Gautier90f84d72021-07-13 14:44:09 +0200449 /* Set optee boot info from parsed header data */
450 bl_mem_params->ep_info.args.arg0 = paged_mem_params->image_info.image_base;
451 bl_mem_params->ep_info.args.arg1 = 0; /* Unused */
452 bl_mem_params->ep_info.args.arg2 = 0; /* No DT supported */
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200453 } else {
454#if !STM32MP_USE_STM32IMAGE
455 bl_mem_params->ep_info.pc = bl_mem_params->image_info.image_base;
Yann Gautier658775c2021-07-06 10:00:44 +0200456 tos_fw_mem_params = get_bl_mem_params_node(TOS_FW_CONFIG_ID);
457 bl_mem_params->image_info.image_max_size +=
458 tos_fw_mem_params->image_info.image_max_size;
Yann Gautier0ed7b2a2021-05-19 18:48:16 +0200459#endif /* !STM32MP_USE_STM32IMAGE */
460 bl_mem_params->ep_info.args.arg0 = 0;
Yann Gautier90f84d72021-07-13 14:44:09 +0200461 }
Yann Gautierb3386f72019-04-19 09:41:01 +0200462 break;
463
464 case BL33_IMAGE_ID:
465 bl32_mem_params = get_bl_mem_params_node(BL32_IMAGE_ID);
466 assert(bl32_mem_params != NULL);
467 bl32_mem_params->ep_info.lr_svc = bl_mem_params->ep_info.pc;
468 break;
469
470 default:
471 /* Do nothing in default case */
472 break;
473 }
474
Yann Gautiera3bd8d12021-06-18 11:33:26 +0200475#if STM32MP_SDMMC || STM32MP_EMMC
476 /*
477 * Invalidate remaining data read from MMC but not flushed by load_image_flush().
478 * We take the worst case which is 2 MMC blocks.
479 */
480 if ((image_id != FW_CONFIG_ID) &&
481 ((bl_mem_params->image_info.h.attr & IMAGE_ATTRIB_SKIP_LOADING) == 0U)) {
482 inv_dcache_range(bl_mem_params->image_info.image_base +
483 bl_mem_params->image_info.image_size,
484 2U * MMC_BLOCK_SIZE);
485 }
486#endif /* STM32MP_SDMMC || STM32MP_EMMC */
487
Yann Gautierb3386f72019-04-19 09:41:01 +0200488 return err;
489}
Yann Gautierd2d9b962021-08-16 11:58:01 +0200490
491void bl2_el3_plat_prepare_exit(void)
492{
Patrick Delaunay9c5ee782021-07-06 14:07:56 +0200493 uint16_t boot_itf = stm32mp_get_boot_itf_selected();
494
495 switch (boot_itf) {
496#if STM32MP_USB_PROGRAMMER
497 case BOOT_API_CTX_BOOT_INTERFACE_SEL_SERIAL_USB:
498 /* Invalidate the downloaded buffer used with io_memmap */
499 inv_dcache_range(DWL_BUFFER_BASE, DWL_BUFFER_SIZE);
500 break;
501#endif
502 default:
503 /* Do nothing in default case */
504 break;
505 }
506
Yann Gautierd2d9b962021-08-16 11:58:01 +0200507 stm32mp1_security_setup();
508}