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> |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <string.h> |
| 10 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 11 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
| 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 Gautier | a3bd8d1 | 2021-06-18 11:33:26 +0200 | [diff] [blame] | 19 | #include <drivers/mmc.h> |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 20 | #include <drivers/st/bsec.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 21 | #include <drivers/st/stm32_console.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 22 | #include <drivers/st/stm32_iwdg.h> |
Yann Gautier | a45433b | 2019-01-16 18:31:00 +0100 | [diff] [blame] | 23 | #include <drivers/st/stm32mp_pmic.h> |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 24 | #include <drivers/st/stm32mp_reset.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 25 | #include <drivers/st/stm32mp1_clk.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 26 | #include <drivers/st/stm32mp1_pwr.h> |
| 27 | #include <drivers/st/stm32mp1_ram.h> |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 28 | #include <lib/fconf/fconf.h> |
| 29 | #include <lib/fconf/fconf_dyn_cfg_getter.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 30 | #include <lib/mmio.h> |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 31 | #include <lib/optee_utils.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 32 | #include <lib/xlat_tables/xlat_tables_v2.h> |
| 33 | #include <plat/common/platform.h> |
| 34 | |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 35 | #include <stm32mp1_context.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 36 | #include <stm32mp1_dbgmcu.h> |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 37 | |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 38 | #define RESET_TIMEOUT_US_1MS 1000U |
| 39 | |
Andre Przywara | 678c6fa | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 40 | static console_t console; |
Lionel Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 41 | static struct stm32mp_auth_ops stm32mp1_auth_ops; |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 42 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 43 | static void print_reset_reason(void) |
| 44 | { |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 45 | uint32_t rstsr = mmio_read_32(stm32mp_rcc_base() + RCC_MP_RSTSCLRR); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 46 | |
| 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 | |
| 128 | void 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 Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 132 | { |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 133 | stm32mp_save_boot_ctx_address(arg0); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void bl2_platform_setup(void) |
| 137 | { |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 138 | int ret; |
| 139 | |
Yann Gautier | f3928f6 | 2019-02-14 11:15:03 +0100 | [diff] [blame] | 140 | if (dt_pmic_status() > 0) { |
Yann Gautier | bb836ee | 2018-07-16 17:55:07 +0200 | [diff] [blame] | 141 | initialize_pmic(); |
| 142 | } |
| 143 | |
Yann Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 144 | ret = stm32mp1_ddr_probe(); |
| 145 | if (ret < 0) { |
| 146 | ERROR("Invalid DDR init: error %d\n", ret); |
| 147 | panic(); |
| 148 | } |
| 149 | |
Yann Gautier | f3bd87e | 2020-09-04 15:55:53 +0200 | [diff] [blame] | 150 | /* Map DDR for binary load, now with cacheable attribute */ |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 151 | ret = mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE, |
Yann Gautier | f3bd87e | 2020-09-04 15:55:53 +0200 | [diff] [blame] | 152 | 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 Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 157 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 158 | #if STM32MP_USE_STM32IMAGE |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 159 | #ifdef AARCH32_SP_OPTEE |
| 160 | INFO("BL2 runs OP-TEE setup\n"); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 161 | #else |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 162 | INFO("BL2 runs SP_MIN setup\n"); |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 163 | #endif |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 164 | #endif /* STM32MP_USE_STM32IMAGE */ |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void bl2_el3_plat_arch_setup(void) |
| 168 | { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 169 | int32_t result; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 170 | struct dt_node_info dt_uart_info; |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 171 | const char *board_model; |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 172 | boot_api_context_t *boot_context = |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 173 | (boot_api_context_t *)stm32mp_get_boot_ctx_address(); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 174 | uint32_t clk_rate; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 175 | uintptr_t pwr_base; |
| 176 | uintptr_t rcc_base; |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 177 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 178 | mmap_add_region(BL_CODE_BASE, BL_CODE_BASE, |
| 179 | BL_CODE_END - BL_CODE_BASE, |
| 180 | MT_CODE | MT_SECURE); |
| 181 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 182 | #if STM32MP_USE_STM32IMAGE |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 183 | #ifdef AARCH32_SP_OPTEE |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 184 | mmap_add_region(STM32MP_OPTEE_BASE, STM32MP_OPTEE_BASE, |
| 185 | STM32MP_OPTEE_SIZE, |
| 186 | MT_MEMORY | MT_RW | MT_SECURE); |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 187 | #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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 192 | #endif |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 193 | #endif /* STM32MP_USE_STM32IMAGE */ |
| 194 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 195 | /* Prevent corruption of preloaded Device Tree */ |
| 196 | mmap_add_region(DTB_BASE, DTB_BASE, |
| 197 | DTB_LIMIT - DTB_BASE, |
Yann Gautier | 3d33df6 | 2019-12-17 17:11:10 +0100 | [diff] [blame] | 198 | MT_RO_DATA | MT_SECURE); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 199 | |
| 200 | configure_mmu(); |
| 201 | |
Yann Gautier | 05773eb | 2020-08-24 11:51:50 +0200 | [diff] [blame] | 202 | if (dt_open_and_check(STM32MP_DTB_BASE) < 0) { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 203 | panic(); |
| 204 | } |
| 205 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 206 | pwr_base = stm32mp_pwr_base(); |
| 207 | rcc_base = stm32mp_rcc_base(); |
| 208 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 209 | /* |
| 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 Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 214 | mmio_setbits_32(pwr_base + PWR_CR1, PWR_CR1_DBP); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 215 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 216 | while ((mmio_read_32(pwr_base + PWR_CR1) & PWR_CR1_DBP) == 0U) { |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 217 | ; |
| 218 | } |
| 219 | |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 220 | if (bsec_probe() != 0) { |
| 221 | panic(); |
| 222 | } |
| 223 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 224 | /* Reset backup domain on cold boot cases */ |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 225 | 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 Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 227 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 228 | while ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_VSWRST) == |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 229 | 0U) { |
| 230 | ; |
| 231 | } |
| 232 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 233 | mmio_clrbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Yann Gautier | ed34232 | 2019-02-15 17:33:27 +0100 | [diff] [blame] | 236 | /* Disable MCKPROT */ |
| 237 | mmio_clrbits_32(rcc_base + RCC_TZCR, RCC_TZCR_MCKPROT); |
| 238 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 239 | generic_delay_timer_init(); |
| 240 | |
Yann Gautier | 9aea69e | 2018-07-24 17:13:36 +0200 | [diff] [blame] | 241 | if (stm32mp1_clk_probe() < 0) { |
| 242 | panic(); |
| 243 | } |
| 244 | |
| 245 | if (stm32mp1_clk_init() < 0) { |
| 246 | panic(); |
| 247 | } |
| 248 | |
Yann Gautier | 3edc7c3 | 2019-05-20 19:17:08 +0200 | [diff] [blame] | 249 | stm32mp1_syscfg_init(); |
| 250 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 251 | result = dt_get_stdout_uart_info(&dt_uart_info); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 252 | |
| 253 | if ((result <= 0) || |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 254 | (dt_uart_info.status == 0U) || |
| 255 | (dt_uart_info.clock < 0) || |
| 256 | (dt_uart_info.reset < 0)) { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 257 | goto skip_console_init; |
| 258 | } |
| 259 | |
| 260 | if (dt_set_stdout_pinctrl() != 0) { |
| 261 | goto skip_console_init; |
| 262 | } |
| 263 | |
Yann Gautier | e4a3c35 | 2019-02-14 10:53:33 +0100 | [diff] [blame] | 264 | stm32mp_clk_enable((unsigned long)dt_uart_info.clock); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 265 | |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 266 | if (stm32mp_reset_assert((uint32_t)dt_uart_info.reset, |
| 267 | RESET_TIMEOUT_US_1MS) != 0) { |
| 268 | panic(); |
| 269 | } |
| 270 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 271 | udelay(2); |
Etienne Carriere | f02647a | 2019-12-08 08:14:40 +0100 | [diff] [blame] | 272 | |
| 273 | if (stm32mp_reset_deassert((uint32_t)dt_uart_info.reset, |
| 274 | RESET_TIMEOUT_US_1MS) != 0) { |
| 275 | panic(); |
| 276 | } |
| 277 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 278 | mdelay(1); |
| 279 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 280 | clk_rate = stm32mp_clk_get_rate((unsigned long)dt_uart_info.clock); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 281 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 282 | if (console_stm32_register(dt_uart_info.base, clk_rate, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 283 | STM32MP_UART_BAUDRATE, &console) == 0) { |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 284 | panic(); |
| 285 | } |
| 286 | |
Andre Przywara | 678c6fa | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 287 | console_set_scope(&console, CONSOLE_FLAG_BOOT | |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 288 | CONSOLE_FLAG_CRASH | CONSOLE_FLAG_TRANSLATE_CRLF); |
| 289 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 290 | stm32mp_print_cpuinfo(); |
| 291 | |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 292 | board_model = dt_get_board_model(); |
| 293 | if (board_model != NULL) { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 294 | NOTICE("Model: %s\n", board_model); |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 297 | stm32mp_print_boardinfo(); |
| 298 | |
Lionel Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 299 | 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 Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 305 | skip_console_init: |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 306 | 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 Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 316 | |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 317 | 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 Debieve | 7bd96f4 | 2019-09-03 12:22:23 +0200 | [diff] [blame] | 323 | 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 Gautier | caf575b | 2018-07-24 17:18:19 +0200 | [diff] [blame] | 329 | stm32mp1_arch_security_setup(); |
| 330 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 331 | print_reset_reason(); |
| 332 | |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 333 | #if !STM32MP_USE_STM32IMAGE |
| 334 | fconf_populate("TB_FW", STM32MP_DTB_BASE); |
| 335 | #endif /* !STM32MP_USE_STM32IMAGE */ |
| 336 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 337 | stm32mp_io_setup(); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 338 | } |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 339 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 340 | /******************************************************************************* |
| 341 | * This function can be used by the platforms to update/use image |
| 342 | * information for given `image_id`. |
| 343 | ******************************************************************************/ |
| 344 | int 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 Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 349 | bl_mem_params_node_t *pager_mem_params __unused; |
| 350 | bl_mem_params_node_t *paged_mem_params __unused; |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 351 | #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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 363 | |
| 364 | assert(bl_mem_params != NULL); |
| 365 | |
| 366 | switch (image_id) { |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 367 | #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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 421 | case BL32_IMAGE_ID: |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 422 | 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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 428 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 429 | #if STM32MP_USE_STM32IMAGE && defined(AARCH32_SP_OPTEE) |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 430 | /* 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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 433 | |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 434 | 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 Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 439 | #endif /* STM32MP_USE_STM32IMAGE && defined(AARCH32_SP_OPTEE) */ |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 440 | |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 441 | 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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 448 | |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 449 | /* 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 Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 453 | } else { |
| 454 | #if !STM32MP_USE_STM32IMAGE |
| 455 | bl_mem_params->ep_info.pc = bl_mem_params->image_info.image_base; |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 456 | 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 Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 459 | #endif /* !STM32MP_USE_STM32IMAGE */ |
| 460 | bl_mem_params->ep_info.args.arg0 = 0; |
Yann Gautier | 90f84d7 | 2021-07-13 14:44:09 +0200 | [diff] [blame] | 461 | } |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 462 | 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 Gautier | a3bd8d1 | 2021-06-18 11:33:26 +0200 | [diff] [blame] | 475 | #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 Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 488 | return err; |
| 489 | } |
Yann Gautier | d2d9b96 | 2021-08-16 11:58:01 +0200 | [diff] [blame] | 490 | |
| 491 | void bl2_el3_plat_prepare_exit(void) |
| 492 | { |
Patrick Delaunay | 9c5ee78 | 2021-07-06 14:07:56 +0200 | [diff] [blame] | 493 | 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 Gautier | d2d9b96 | 2021-08-16 11:58:01 +0200 | [diff] [blame] | 507 | stm32mp1_security_setup(); |
| 508 | } |