blob: 77b143fbf35da1418cdc4a4ae6e717cf6398958e [file] [log] [blame]
Yann Gautier35527fb2023-06-14 10:40:59 +02001/*
Yann Gautiercb0d6b52024-01-04 10:58:18 +01002 * Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
Yann Gautier35527fb2023-06-14 10:40:59 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <cdefs.h>
8#include <stdint.h>
9
Yann Gautier197ac782024-01-03 14:28:23 +010010#include <common/debug.h>
Yann Gautierdb77f8b2024-05-21 11:46:59 +020011#include <drivers/clk.h>
Yann Gautierc3a75342024-05-21 12:03:56 +020012#include <drivers/st/regulator_fixed.h>
Yann Gautierdb77f8b2024-05-21 11:46:59 +020013#include <lib/fconf/fconf.h>
14#include <lib/fconf/fconf_dyn_cfg_getter.h>
15#include <lib/mmio.h>
16#include <lib/xlat_tables/xlat_tables_v2.h>
Yann Gautiercb0d6b52024-01-04 10:58:18 +010017#include <plat/common/platform.h>
18
Yann Gautier197ac782024-01-03 14:28:23 +010019#include <platform_def.h>
Yann Gautier87a940e2023-06-14 18:05:47 +020020#include <stm32mp_common.h>
Yann Gautierdb77f8b2024-05-21 11:46:59 +020021#include <stm32mp_dt.h>
22
23#define BOOT_CTX_ADDR 0x0e000020UL
24
25static void print_reset_reason(void)
26{
27 uint32_t rstsr = mmio_read_32(stm32mp_rcc_base() + RCC_C1BOOTRSTSCLRR);
28
29 if (rstsr == 0U) {
30 WARN("Reset reason unknown\n");
31 return;
32 }
33
34 INFO("Reset reason (0x%x):\n", rstsr);
35
36 if ((rstsr & RCC_C1BOOTRSTSCLRR_PADRSTF) == 0U) {
37 if ((rstsr & RCC_C1BOOTRSTSCLRR_STBYC1RSTF) != 0U) {
38 INFO("System exits from Standby for CA35\n");
39 return;
40 }
41
42 if ((rstsr & RCC_C1BOOTRSTSCLRR_D1STBYRSTF) != 0U) {
43 INFO("D1 domain exits from DStandby\n");
44 return;
45 }
46 }
47
48 if ((rstsr & RCC_C1BOOTRSTSCLRR_PORRSTF) != 0U) {
49 INFO(" Power-on Reset (rst_por)\n");
50 return;
51 }
52
53 if ((rstsr & RCC_C1BOOTRSTSCLRR_BORRSTF) != 0U) {
54 INFO(" Brownout Reset (rst_bor)\n");
55 return;
56 }
57
58 if ((rstsr & RCC_C1BOOTRSTSSETR_SYSC2RSTF) != 0U) {
59 INFO(" System reset (SYSRST) by M33\n");
60 return;
61 }
62
63 if ((rstsr & RCC_C1BOOTRSTSSETR_SYSC1RSTF) != 0U) {
64 INFO(" System reset (SYSRST) by A35\n");
65 return;
66 }
67
68 if ((rstsr & RCC_C1BOOTRSTSCLRR_HCSSRSTF) != 0U) {
69 INFO(" Clock failure on HSE\n");
70 return;
71 }
72
73 if ((rstsr & RCC_C1BOOTRSTSCLRR_IWDG1SYSRSTF) != 0U) {
74 INFO(" IWDG1 system reset (rst_iwdg1)\n");
75 return;
76 }
77
78 if ((rstsr & RCC_C1BOOTRSTSCLRR_IWDG2SYSRSTF) != 0U) {
79 INFO(" IWDG2 system reset (rst_iwdg2)\n");
80 return;
81 }
82
83 if ((rstsr & RCC_C1BOOTRSTSCLRR_IWDG3SYSRSTF) != 0U) {
84 INFO(" IWDG3 system reset (rst_iwdg3)\n");
85 return;
86 }
87
88 if ((rstsr & RCC_C1BOOTRSTSCLRR_IWDG4SYSRSTF) != 0U) {
89 INFO(" IWDG4 system reset (rst_iwdg4)\n");
90 return;
91 }
92
93 if ((rstsr & RCC_C1BOOTRSTSCLRR_IWDG5SYSRSTF) != 0U) {
94 INFO(" IWDG5 system reset (rst_iwdg5)\n");
95 return;
96 }
97
98 if ((rstsr & RCC_C1BOOTRSTSCLRR_C1P1RSTF) != 0U) {
99 INFO(" A35 processor core 1 reset\n");
100 return;
101 }
102
103 if ((rstsr & RCC_C1BOOTRSTSCLRR_PADRSTF) != 0U) {
104 INFO(" Pad Reset from NRST\n");
105 return;
106 }
107
108 if ((rstsr & RCC_C1BOOTRSTSCLRR_VCORERSTF) != 0U) {
109 INFO(" Reset due to a failure of VDD_CORE\n");
110 return;
111 }
112
113 if ((rstsr & RCC_C1BOOTRSTSCLRR_C1RSTF) != 0U) {
114 INFO(" A35 processor reset\n");
115 return;
116 }
117
118 ERROR(" Unidentified reset reason\n");
119}
Yann Gautier87a940e2023-06-14 18:05:47 +0200120
Yann Gautier35527fb2023-06-14 10:40:59 +0200121void bl2_el3_early_platform_setup(u_register_t arg0 __unused,
122 u_register_t arg1 __unused,
123 u_register_t arg2 __unused,
124 u_register_t arg3 __unused)
125{
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200126 stm32mp_save_boot_ctx_address(BOOT_CTX_ADDR);
Yann Gautier35527fb2023-06-14 10:40:59 +0200127}
128
129void bl2_platform_setup(void)
130{
131}
132
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200133static void reset_backup_domain(void)
134{
135 uintptr_t pwr_base = stm32mp_pwr_base();
136 uintptr_t rcc_base = stm32mp_rcc_base();
137
138 /*
139 * Disable the backup domain write protection.
140 * The protection is enable at each reset by hardware
141 * and must be disabled by software.
142 */
143 mmio_setbits_32(pwr_base + PWR_BDCR1, PWR_BDCR1_DBD3P);
144
145 while ((mmio_read_32(pwr_base + PWR_BDCR1) & PWR_BDCR1_DBD3P) == 0U) {
146 ;
147 }
148
149 /* Reset backup domain on cold boot cases */
150 if ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_RTCCKEN) == 0U) {
151 mmio_setbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST);
152
153 while ((mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_VSWRST) == 0U) {
154 ;
155 }
156
157 mmio_clrbits_32(rcc_base + RCC_BDCR, RCC_BDCR_VSWRST);
158 }
159}
160
Yann Gautier35527fb2023-06-14 10:40:59 +0200161void bl2_el3_plat_arch_setup(void)
162{
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200163 const char *board_model;
164 boot_api_context_t *boot_context =
165 (boot_api_context_t *)stm32mp_get_boot_ctx_address();
166
Yann Gautier197ac782024-01-03 14:28:23 +0100167 if (stm32_otp_probe() != 0U) {
Yann Gautier47ea3032024-01-18 11:39:19 +0100168 EARLY_ERROR("OTP probe failed\n");
Yann Gautier197ac782024-01-03 14:28:23 +0100169 panic();
170 }
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200171
172 mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
173 BL_CODE_END - BL_CODE_BASE,
174 MT_CODE | MT_SECURE);
175
176 configure_mmu();
177
178 /* Prevent corruption of preloaded Device Tree */
179 mmap_add_dynamic_region(DTB_BASE, DTB_BASE,
180 DTB_LIMIT - DTB_BASE,
181 MT_RO_DATA | MT_SECURE);
182
183 if (dt_open_and_check(STM32MP_DTB_BASE) < 0) {
184 panic();
185 }
186
187 reset_backup_domain();
188
189 if (stm32mp2_clk_init() < 0) {
190 panic();
191 }
192
193 stm32_save_boot_info(boot_context);
194
195 if (stm32mp_uart_console_setup() != 0) {
196 goto skip_console_init;
197 }
198
Yann Gautier381b2a62024-06-21 14:49:47 +0200199 stm32mp_print_cpuinfo();
200
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200201 board_model = dt_get_board_model();
202 if (board_model != NULL) {
203 NOTICE("Model: %s\n", board_model);
204 }
205
Yann Gautiercdaced32022-04-15 16:15:25 +0200206 stm32mp_print_boardinfo();
207
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200208 print_reset_reason();
209
210skip_console_init:
Yann Gautierc3a75342024-05-21 12:03:56 +0200211 if (fixed_regulator_register() != 0) {
212 panic();
213 }
214
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200215 fconf_populate("TB_FW", STM32MP_DTB_BASE);
216
217 stm32mp_io_setup();
Yann Gautier35527fb2023-06-14 10:40:59 +0200218}