Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | dca6154 | 2021-02-10 18:19:23 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/bl_common.h> |
| 14 | #include <common/debug.h> |
| 15 | #include <common/desc_image_load.h> |
| 16 | #include <drivers/delay_timer.h> |
| 17 | #include <drivers/generic_delay_timer.h> |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 18 | #include <drivers/st/bsec.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | #include <drivers/st/stm32_console.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 20 | #include <drivers/st/stm32_iwdg.h> |
Yann Gautier | a45433b | 2019-01-16 18:31:00 +0100 | [diff] [blame] | 21 | #include <drivers/st/stm32mp_pmic.h> |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 22 | #include <drivers/st/stm32mp_reset.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <drivers/st/stm32mp1_clk.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 24 | #include <drivers/st/stm32mp1_pwr.h> |
| 25 | #include <drivers/st/stm32mp1_ram.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 26 | #include <lib/mmio.h> |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 27 | #include <lib/optee_utils.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 28 | #include <lib/xlat_tables/xlat_tables_v2.h> |
| 29 | #include <plat/common/platform.h> |
| 30 | |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 31 | #include <stm32mp1_context.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 32 | #include <stm32mp1_dbgmcu.h> |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 33 | |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 34 | #define RESET_TIMEOUT_US_1MS 1000U |
| 35 | |
Andre Przywara | 678c6fa | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 36 | static console_t console; |
Lionel Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 37 | static struct stm32mp_auth_ops stm32mp1_auth_ops; |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 38 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 39 | static void print_reset_reason(void) |
| 40 | { |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 41 | uint32_t rstsr = mmio_read_32(stm32mp_rcc_base() + RCC_MP_RSTSCLRR); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 42 | |
| 43 | if (rstsr == 0U) { |
| 44 | WARN("Reset reason unknown\n"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | INFO("Reset reason (0x%x):\n", rstsr); |
| 49 | |
| 50 | if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) == 0U) { |
| 51 | if ((rstsr & RCC_MP_RSTSCLRR_STDBYRSTF) != 0U) { |
| 52 | INFO("System exits from STANDBY\n"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if ((rstsr & RCC_MP_RSTSCLRR_CSTDBYRSTF) != 0U) { |
| 57 | INFO("MPU exits from CSTANDBY\n"); |
| 58 | return; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if ((rstsr & RCC_MP_RSTSCLRR_PORRSTF) != 0U) { |
| 63 | INFO(" Power-on Reset (rst_por)\n"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | if ((rstsr & RCC_MP_RSTSCLRR_BORRSTF) != 0U) { |
| 68 | INFO(" Brownout Reset (rst_bor)\n"); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | if ((rstsr & RCC_MP_RSTSCLRR_MCSYSRSTF) != 0U) { |
| 73 | if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) != 0U) { |
| 74 | INFO(" System reset generated by MCU (MCSYSRST)\n"); |
| 75 | } else { |
| 76 | INFO(" Local reset generated by MCU (MCSYSRST)\n"); |
| 77 | } |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if ((rstsr & RCC_MP_RSTSCLRR_MPSYSRSTF) != 0U) { |
| 82 | INFO(" System reset generated by MPU (MPSYSRST)\n"); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if ((rstsr & RCC_MP_RSTSCLRR_HCSSRSTF) != 0U) { |
| 87 | INFO(" Reset due to a clock failure on HSE\n"); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | if ((rstsr & RCC_MP_RSTSCLRR_IWDG1RSTF) != 0U) { |
| 92 | INFO(" IWDG1 Reset (rst_iwdg1)\n"); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | if ((rstsr & RCC_MP_RSTSCLRR_IWDG2RSTF) != 0U) { |
| 97 | INFO(" IWDG2 Reset (rst_iwdg2)\n"); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | if ((rstsr & RCC_MP_RSTSCLRR_MPUP0RSTF) != 0U) { |
| 102 | INFO(" MPU Processor 0 Reset\n"); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | if ((rstsr & RCC_MP_RSTSCLRR_MPUP1RSTF) != 0U) { |
| 107 | INFO(" MPU Processor 1 Reset\n"); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if ((rstsr & RCC_MP_RSTSCLRR_PADRSTF) != 0U) { |
| 112 | INFO(" Pad Reset from NRST\n"); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if ((rstsr & RCC_MP_RSTSCLRR_VCORERSTF) != 0U) { |
| 117 | INFO(" Reset due to a failure of VDD_CORE\n"); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | ERROR(" Unidentified reset reason\n"); |
| 122 | } |
| 123 | |
| 124 | void bl2_el3_early_platform_setup(u_register_t arg0, |
| 125 | u_register_t arg1 __unused, |
| 126 | u_register_t arg2 __unused, |
| 127 | u_register_t arg3 __unused) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 128 | { |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 129 | stm32mp_save_boot_ctx_address(arg0); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void bl2_platform_setup(void) |
| 133 | { |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 134 | int ret; |
| 135 | |
Yann Gautier | f3928f6 | 2019-02-14 11:15:03 +0100 | [diff] [blame] | 136 | if (dt_pmic_status() > 0) { |
Yann Gautier | bb836ee | 2018-07-16 17:55:07 +0200 | [diff] [blame] | 137 | initialize_pmic(); |
| 138 | } |
| 139 | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 140 | ret = stm32mp1_ddr_probe(); |
| 141 | if (ret < 0) { |
| 142 | ERROR("Invalid DDR init: error %d\n", ret); |
| 143 | panic(); |
| 144 | } |
| 145 | |
Yann Gautier | f3bd87e | 2020-09-04 15:55:53 +0200 | [diff] [blame] | 146 | /* Map DDR for binary load, now with cacheable attribute */ |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 147 | ret = mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE, |
Yann Gautier | f3bd87e | 2020-09-04 15:55:53 +0200 | [diff] [blame] | 148 | STM32MP_DDR_MAX_SIZE, MT_MEMORY | MT_RW | MT_SECURE); |
| 149 | if (ret < 0) { |
| 150 | ERROR("DDR mapping: error %d\n", ret); |
| 151 | panic(); |
| 152 | } |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 153 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 154 | #ifdef AARCH32_SP_OPTEE |
| 155 | INFO("BL2 runs OP-TEE setup\n"); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 156 | #else |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 157 | INFO("BL2 runs SP_MIN setup\n"); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 158 | #endif |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void bl2_el3_plat_arch_setup(void) |
| 162 | { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 163 | int32_t result; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 164 | struct dt_node_info dt_uart_info; |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 165 | const char *board_model; |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 166 | boot_api_context_t *boot_context = |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 167 | (boot_api_context_t *)stm32mp_get_boot_ctx_address(); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 168 | uint32_t clk_rate; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 169 | uintptr_t pwr_base; |
| 170 | uintptr_t rcc_base; |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 171 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 172 | mmap_add_region(BL_CODE_BASE, BL_CODE_BASE, |
| 173 | BL_CODE_END - BL_CODE_BASE, |
| 174 | MT_CODE | MT_SECURE); |
| 175 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 176 | #ifdef AARCH32_SP_OPTEE |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 177 | mmap_add_region(STM32MP_OPTEE_BASE, STM32MP_OPTEE_BASE, |
| 178 | STM32MP_OPTEE_SIZE, |
| 179 | MT_MEMORY | MT_RW | MT_SECURE); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 180 | #endif |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 181 | /* Prevent corruption of preloaded Device Tree */ |
| 182 | mmap_add_region(DTB_BASE, DTB_BASE, |
| 183 | DTB_LIMIT - DTB_BASE, |
Yann Gautier | 3d33df6 | 2019-12-17 17:11:10 +0100 | [diff] [blame] | 184 | MT_RO_DATA | MT_SECURE); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 185 | |
| 186 | configure_mmu(); |
| 187 | |
Yann Gautier | 05773eb | 2020-08-24 11:51:50 +0200 | [diff] [blame] | 188 | if (dt_open_and_check(STM32MP_DTB_BASE) < 0) { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 189 | panic(); |
| 190 | } |
| 191 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 192 | pwr_base = stm32mp_pwr_base(); |
| 193 | rcc_base = stm32mp_rcc_base(); |
| 194 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 195 | /* |
| 196 | * Disable the backup domain write protection. |
| 197 | * The protection is enable at each reset by hardware |
| 198 | * and must be disabled by software. |
| 199 | */ |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 200 | mmio_setbits_32(pwr_base + PWR_CR1, PWR_CR1_DBP); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 201 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 202 | while ((mmio_read_32(pwr_base + PWR_CR1) & PWR_CR1_DBP) == 0U) { |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 203 | ; |
| 204 | } |
| 205 | |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 206 | if (bsec_probe() != 0) { |
| 207 | panic(); |
| 208 | } |
| 209 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 210 | /* Reset backup domain on cold boot cases */ |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 211 | if ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_RTCSRC_MASK) == 0U) { |
| 212 | mmio_setbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 213 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 214 | while ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_VSWRST) == |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 215 | 0U) { |
| 216 | ; |
| 217 | } |
| 218 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 219 | mmio_clrbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Yann Gautier | ed34232 | 2019-02-15 17:33:27 +0100 | [diff] [blame] | 222 | /* Disable MCKPROT */ |
| 223 | mmio_clrbits_32(rcc_base + RCC_TZCR, RCC_TZCR_MCKPROT); |
| 224 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 225 | generic_delay_timer_init(); |
| 226 | |
Yann Gautier | 9aea69e | 2018-07-24 17:13:36 +0200 | [diff] [blame] | 227 | if (stm32mp1_clk_probe() < 0) { |
| 228 | panic(); |
| 229 | } |
| 230 | |
| 231 | if (stm32mp1_clk_init() < 0) { |
| 232 | panic(); |
| 233 | } |
| 234 | |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 235 | stm32mp1_syscfg_init(); |
| 236 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 237 | result = dt_get_stdout_uart_info(&dt_uart_info); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 238 | |
| 239 | if ((result <= 0) || |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 240 | (dt_uart_info.status == 0U) || |
| 241 | (dt_uart_info.clock < 0) || |
| 242 | (dt_uart_info.reset < 0)) { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 243 | goto skip_console_init; |
| 244 | } |
| 245 | |
| 246 | if (dt_set_stdout_pinctrl() != 0) { |
| 247 | goto skip_console_init; |
| 248 | } |
| 249 | |
Yann Gautier | e4a3c35 | 2019-02-14 10:53:33 +0100 | [diff] [blame] | 250 | stm32mp_clk_enable((unsigned long)dt_uart_info.clock); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 251 | |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 252 | if (stm32mp_reset_assert((uint32_t)dt_uart_info.reset, |
| 253 | RESET_TIMEOUT_US_1MS) != 0) { |
| 254 | panic(); |
| 255 | } |
| 256 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 257 | udelay(2); |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 258 | |
| 259 | if (stm32mp_reset_deassert((uint32_t)dt_uart_info.reset, |
| 260 | RESET_TIMEOUT_US_1MS) != 0) { |
| 261 | panic(); |
| 262 | } |
| 263 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 264 | mdelay(1); |
| 265 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 266 | clk_rate = stm32mp_clk_get_rate((unsigned long)dt_uart_info.clock); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 267 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 268 | if (console_stm32_register(dt_uart_info.base, clk_rate, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 269 | STM32MP_UART_BAUDRATE, &console) == 0) { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 270 | panic(); |
| 271 | } |
| 272 | |
Andre Przywara | 678c6fa | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 273 | console_set_scope(&console, CONSOLE_FLAG_BOOT | |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 274 | CONSOLE_FLAG_CRASH | CONSOLE_FLAG_TRANSLATE_CRLF); |
| 275 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 276 | stm32mp_print_cpuinfo(); |
| 277 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 278 | board_model = dt_get_board_model(); |
| 279 | if (board_model != NULL) { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 280 | NOTICE("Model: %s\n", board_model); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 283 | stm32mp_print_boardinfo(); |
| 284 | |
Lionel Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 285 | if (boot_context->auth_status != BOOT_API_CTX_AUTH_NO) { |
| 286 | NOTICE("Bootrom authentication %s\n", |
| 287 | (boot_context->auth_status == BOOT_API_CTX_AUTH_FAILED) ? |
| 288 | "failed" : "succeeded"); |
| 289 | } |
| 290 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 291 | skip_console_init: |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 292 | if (stm32_iwdg_init() < 0) { |
| 293 | panic(); |
| 294 | } |
| 295 | |
| 296 | stm32_iwdg_refresh(); |
| 297 | |
| 298 | result = stm32mp1_dbgmcu_freeze_iwdg2(); |
| 299 | if (result != 0) { |
| 300 | INFO("IWDG2 freeze error : %i\n", result); |
| 301 | } |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 302 | |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 303 | if (stm32_save_boot_interface(boot_context->boot_interface_selected, |
| 304 | boot_context->boot_interface_instance) != |
| 305 | 0) { |
| 306 | ERROR("Cannot save boot interface\n"); |
| 307 | } |
| 308 | |
Lionel Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 309 | stm32mp1_auth_ops.check_key = boot_context->bootrom_ecdsa_check_key; |
| 310 | stm32mp1_auth_ops.verify_signature = |
| 311 | boot_context->bootrom_ecdsa_verify_signature; |
| 312 | |
| 313 | stm32mp_init_auth(&stm32mp1_auth_ops); |
| 314 | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 315 | stm32mp1_arch_security_setup(); |
| 316 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 317 | print_reset_reason(); |
| 318 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 319 | stm32mp_io_setup(); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 320 | } |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 321 | |
| 322 | #if defined(AARCH32_SP_OPTEE) |
| 323 | /******************************************************************************* |
| 324 | * This function can be used by the platforms to update/use image |
| 325 | * information for given `image_id`. |
| 326 | ******************************************************************************/ |
| 327 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 328 | { |
| 329 | int err = 0; |
| 330 | bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id); |
| 331 | bl_mem_params_node_t *bl32_mem_params; |
| 332 | bl_mem_params_node_t *pager_mem_params; |
| 333 | bl_mem_params_node_t *paged_mem_params; |
| 334 | |
| 335 | assert(bl_mem_params != NULL); |
| 336 | |
| 337 | switch (image_id) { |
| 338 | case BL32_IMAGE_ID: |
| 339 | bl_mem_params->ep_info.pc = |
| 340 | bl_mem_params->image_info.image_base; |
| 341 | |
| 342 | pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID); |
| 343 | assert(pager_mem_params != NULL); |
| 344 | pager_mem_params->image_info.image_base = STM32MP_OPTEE_BASE; |
| 345 | pager_mem_params->image_info.image_max_size = |
| 346 | STM32MP_OPTEE_SIZE; |
| 347 | |
| 348 | paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID); |
| 349 | assert(paged_mem_params != NULL); |
| 350 | paged_mem_params->image_info.image_base = STM32MP_DDR_BASE + |
Yann Gautier | cd40f32 | 2020-02-26 13:36:07 +0100 | [diff] [blame] | 351 | stm32mp_get_ddr_ns_size(); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 352 | paged_mem_params->image_info.image_max_size = |
| 353 | STM32MP_DDR_S_SIZE; |
| 354 | |
| 355 | err = parse_optee_header(&bl_mem_params->ep_info, |
| 356 | &pager_mem_params->image_info, |
| 357 | &paged_mem_params->image_info); |
| 358 | if (err) { |
| 359 | ERROR("OPTEE header parse error.\n"); |
| 360 | panic(); |
| 361 | } |
| 362 | |
| 363 | /* Set optee boot info from parsed header data */ |
| 364 | bl_mem_params->ep_info.pc = |
| 365 | pager_mem_params->image_info.image_base; |
| 366 | bl_mem_params->ep_info.args.arg0 = |
| 367 | paged_mem_params->image_info.image_base; |
| 368 | bl_mem_params->ep_info.args.arg1 = 0; /* Unused */ |
| 369 | bl_mem_params->ep_info.args.arg2 = 0; /* No DT supported */ |
| 370 | break; |
| 371 | |
| 372 | case BL33_IMAGE_ID: |
| 373 | bl32_mem_params = get_bl_mem_params_node(BL32_IMAGE_ID); |
| 374 | assert(bl32_mem_params != NULL); |
| 375 | bl32_mem_params->ep_info.lr_svc = bl_mem_params->ep_info.pc; |
| 376 | break; |
| 377 | |
| 378 | default: |
| 379 | /* Do nothing in default case */ |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | return err; |
| 384 | } |
Yann Gautier | d2d9b96 | 2021-08-16 11:58:01 +0200 | [diff] [blame] | 385 | |
| 386 | void bl2_el3_plat_prepare_exit(void) |
| 387 | { |
| 388 | stm32mp1_security_setup(); |
| 389 | } |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 390 | #endif |