blob: 55574fd4bebfee80663a3b8d9a5f0bade6ccae81 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay85b53972018-03-12 10:46:10 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay85b53972018-03-12 10:46:10 +01004 */
Patrick Delaunayba779402020-11-06 19:01:29 +01005
6#define LOG_CATEGORY LOGC_ARCH
7
Patrick Delaunay85b53972018-03-12 10:46:10 +01008#include <common.h>
9#include <clk.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070010#include <cpu_func.h>
Patrick Delaunay82168e82018-05-17 14:50:46 +020011#include <debug_uart.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060013#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Patrick Delaunayc9468742021-05-07 14:50:35 +020015#include <lmb.h>
Patrick Delaunayf3674a42018-05-17 15:24:07 +020016#include <misc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <net.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060018#include <spl.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010019#include <asm/io.h>
20#include <asm/arch/stm32.h>
Patrick Delaunay01e3afe2018-03-19 19:09:21 +010021#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060022#include <asm/global_data.h>
Patrick Delaunayf3674a42018-05-17 15:24:07 +020023#include <dm/device.h>
Patrick Delaunayc5d15652018-03-20 10:54:53 +010024#include <dm/uclass.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060025#include <linux/bitops.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060026#include <linux/printk.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010027
Patrick Delaunay8e6985b2020-04-30 16:30:20 +020028/*
29 * early TLB into the .data section so that it not get cleared
30 * with 16kB allignment (see TTBR0_BASE_ADDR_MASK)
31 */
32u8 early_tlb[PGTABLE_SIZE] __section(".data") __aligned(0x4000);
33
Patrick Delaunayc9468742021-05-07 14:50:35 +020034struct lmb lmb;
35
Patrick Delaunay18660a62019-02-27 17:01:12 +010036u32 get_bootmode(void)
37{
38 /* read bootmode from TAMP backup register */
39 return (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_MODE_MASK) >>
40 TAMP_BOOT_MODE_SHIFT;
Patrick Delaunayc5d15652018-03-20 10:54:53 +010041}
42
Igor Opaniuk100e0ec2023-11-06 11:41:52 +010043u32 get_bootauth(void)
44{
45 /* read boot auth status and partition from TAMP backup register */
46 return (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_AUTH_MASK) >>
47 TAMP_BOOT_AUTH_SHIFT;
48}
49
Patrick Delaunayc5d15652018-03-20 10:54:53 +010050/*
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010051 * weak function overidde: set the DDR/SYSRAM executable before to enable the
52 * MMU and configure DACR, for early early_enable_caches (SPL or pre-reloc)
53 */
54void dram_bank_mmu_setup(int bank)
55{
56 struct bd_info *bd = gd->bd;
57 int i;
58 phys_addr_t start;
59 phys_size_t size;
Patrick Delaunayc9468742021-05-07 14:50:35 +020060 bool use_lmb = false;
61 enum dcache_option option;
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010062
63 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
Patrick Delaunay123687c2022-05-20 18:24:46 +020064/* STM32_SYSRAM_BASE exist only when SPL is supported */
65#ifdef CONFIG_SPL
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010066 start = ALIGN_DOWN(STM32_SYSRAM_BASE, MMU_SECTION_SIZE);
67 size = ALIGN(STM32_SYSRAM_SIZE, MMU_SECTION_SIZE);
Patrick Delaunay123687c2022-05-20 18:24:46 +020068#endif
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010069 } else if (gd->flags & GD_FLG_RELOC) {
70 /* bd->bi_dram is available only after relocation */
71 start = bd->bi_dram[bank].start;
72 size = bd->bi_dram[bank].size;
Patrick Delaunayc9468742021-05-07 14:50:35 +020073 use_lmb = true;
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010074 } else {
75 /* mark cacheable and executable the beggining of the DDR */
76 start = STM32_DDR_BASE;
77 size = CONFIG_DDR_CACHEABLE_SIZE;
78 }
79
80 for (i = start >> MMU_SECTION_SHIFT;
81 i < (start >> MMU_SECTION_SHIFT) + (size >> MMU_SECTION_SHIFT);
Patrick Delaunayc9468742021-05-07 14:50:35 +020082 i++) {
83 option = DCACHE_DEFAULT_OPTION;
84 if (use_lmb && lmb_is_reserved_flags(&lmb, i << MMU_SECTION_SHIFT, LMB_NOMAP))
85 option = 0; /* INVALID ENTRY in TLB */
86 set_section_dcache(i, option);
87 }
Patrick Delaunay4ad5a122021-02-05 13:53:33 +010088}
89/*
Patrick Delaunay8e6985b2020-04-30 16:30:20 +020090 * initialize the MMU and activate cache in SPL or in U-Boot pre-reloc stage
91 * MMU/TLB is updated in enable_caches() for U-Boot after relocation
92 * or is deactivated in U-Boot entry function start.S::cpu_init_cp15
93 */
94static void early_enable_caches(void)
95{
96 /* I-cache is already enabled in start.S: cpu_init_cp15 */
97
98 if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
99 return;
100
Bhupesh Sharma58af3fb2023-08-22 13:21:11 +0530101#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Patrice Chotard18a87162021-02-24 13:53:27 +0100102 gd->arch.tlb_size = PGTABLE_SIZE;
103 gd->arch.tlb_addr = (unsigned long)&early_tlb;
Bhupesh Sharma58af3fb2023-08-22 13:21:11 +0530104#endif
Patrick Delaunay8e6985b2020-04-30 16:30:20 +0200105
Patrick Delaunay4ad5a122021-02-05 13:53:33 +0100106 /* enable MMU (default configuration) */
Patrick Delaunay8e6985b2020-04-30 16:30:20 +0200107 dcache_enable();
Patrick Delaunay8e6985b2020-04-30 16:30:20 +0200108}
109
110/*
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100111 * Early system init
112 */
Patrick Delaunay85b53972018-03-12 10:46:10 +0100113int arch_cpu_init(void)
114{
Patrick Delaunay8e6985b2020-04-30 16:30:20 +0200115 early_enable_caches();
116
Patrick Delaunay85b53972018-03-12 10:46:10 +0100117 /* early armv7 timer init: needed for polling */
118 timer_init();
119
Patrick Delaunaye4bdd542022-05-20 18:24:42 +0200120 return 0;
121}
122
123/* weak function for SOC specific initialization */
124__weak void stm32mp_cpu_init(void)
125{
126}
127
128int mach_cpu_init(void)
129{
130 u32 boot_mode;
131
132 stm32mp_cpu_init();
Patrick Delaunay82168e82018-05-17 14:50:46 +0200133
Patrick Delaunay82168e82018-05-17 14:50:46 +0200134 boot_mode = get_bootmode();
135
Patrick Delaunay29b2e2e2021-02-25 13:37:01 +0100136 if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL) &&
137 (boot_mode & TAMP_BOOT_DEVICE_MASK) == BOOT_SERIAL_UART)
Patrick Delaunay82168e82018-05-17 14:50:46 +0200138 gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
Patrick Delaunayd8299de2021-10-11 09:52:51 +0200139 else if (IS_ENABLED(CONFIG_DEBUG_UART) && IS_ENABLED(CONFIG_SPL_BUILD))
Patrick Delaunay82168e82018-05-17 14:50:46 +0200140 debug_uart_init();
Patrick Delaunay85b53972018-03-12 10:46:10 +0100141
142 return 0;
143}
144
Patrick Delaunay58e95532018-03-19 19:09:20 +0100145void enable_caches(void)
146{
Patrick Delaunayc9468742021-05-07 14:50:35 +0200147 /* parse device tree when data cache is still activated */
148 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
149
Patrick Delaunay8e6985b2020-04-30 16:30:20 +0200150 /* I-cache is already enabled in start.S: icache_enable() not needed */
151
152 /* deactivate the data cache, early enabled in arch_cpu_init() */
153 dcache_disable();
154 /*
155 * update MMU after relocation and enable the data cache
156 * warning: the TLB location udpated in board_f.c::reserve_mmu
157 */
Patrick Delaunay58e95532018-03-19 19:09:20 +0100158 dcache_enable();
159}
160
Patrick Delaunayd8299de2021-10-11 09:52:51 +0200161/* used when CONFIG_DISPLAY_CPUINFO is activated */
Patrick Delaunay3e738f22020-02-12 19:37:43 +0100162int print_cpuinfo(void)
163{
164 char name[SOC_NAME_SIZE];
165
166 get_soc_name(name);
167 printf("CPU: %s\n", name);
Patrick Delaunay85b53972018-03-12 10:46:10 +0100168
169 return 0;
170}
Patrick Delaunay85b53972018-03-12 10:46:10 +0100171
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100172static void setup_boot_mode(void)
173{
Patrick Delaunay18660a62019-02-27 17:01:12 +0100174 const u32 serial_addr[] = {
175 STM32_USART1_BASE,
176 STM32_USART2_BASE,
177 STM32_USART3_BASE,
178 STM32_UART4_BASE,
179 STM32_UART5_BASE,
180 STM32_USART6_BASE,
181 STM32_UART7_BASE,
182 STM32_UART8_BASE
183 };
Patrick Delaunay5c2f6d72021-07-06 17:19:45 +0200184 const u32 sdmmc_addr[] = {
185 STM32_SDMMC1_BASE,
186 STM32_SDMMC2_BASE,
187 STM32_SDMMC3_BASE
188 };
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100189 char cmd[60];
190 u32 boot_ctx = readl(TAMP_BOOT_CONTEXT);
191 u32 boot_mode =
192 (boot_ctx & TAMP_BOOT_MODE_MASK) >> TAMP_BOOT_MODE_SHIFT;
Patrick Delaunay1b03eb02019-06-21 15:26:39 +0200193 unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1;
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100194 u32 forced_mode = (boot_ctx & TAMP_BOOT_FORCED_MASK);
Patrick Delaunay18660a62019-02-27 17:01:12 +0100195 struct udevice *dev;
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100196
Patrick Delaunayba779402020-11-06 19:01:29 +0100197 log_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d forced=%x\n",
198 __func__, boot_ctx, boot_mode, instance, forced_mode);
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100199 switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {
200 case BOOT_SERIAL_UART:
Rasmus Villemoes6d83f3c2023-03-24 08:55:19 +0100201 if (instance >= ARRAY_SIZE(serial_addr))
Patrick Delaunay18660a62019-02-27 17:01:12 +0100202 break;
Patrick Delaunaye2592992021-02-25 13:37:03 +0100203 /* serial : search associated node in devicetree */
Patrick Delaunay18660a62019-02-27 17:01:12 +0100204 sprintf(cmd, "serial@%x", serial_addr[instance]);
Patrick Delaunaye2592992021-02-25 13:37:03 +0100205 if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev)) {
Patrick Delaunay7540d872021-02-25 13:37:02 +0100206 /* restore console on error */
207 if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL))
208 gd->flags &= ~(GD_FLG_SILENT |
209 GD_FLG_DISABLE_CONSOLE);
Patrick Delaunay643e4042021-04-06 09:27:39 +0200210 log_err("uart%d = %s not found in device tree!\n",
211 instance + 1, cmd);
Patrick Delaunay18660a62019-02-27 17:01:12 +0100212 break;
Patrick Delaunay7540d872021-02-25 13:37:02 +0100213 }
Patrick Delaunaye2592992021-02-25 13:37:03 +0100214 sprintf(cmd, "%d", dev_seq(dev));
Patrick Delaunay18660a62019-02-27 17:01:12 +0100215 env_set("boot_device", "serial");
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100216 env_set("boot_instance", cmd);
Patrick Delaunay18660a62019-02-27 17:01:12 +0100217
218 /* restore console on uart when not used */
Patrick Delaunay29b2e2e2021-02-25 13:37:01 +0100219 if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL) && gd->cur_serial_dev != dev) {
Patrick Delaunay18660a62019-02-27 17:01:12 +0100220 gd->flags &= ~(GD_FLG_SILENT |
221 GD_FLG_DISABLE_CONSOLE);
Patrick Delaunay643e4042021-04-06 09:27:39 +0200222 log_info("serial boot with console enabled!\n");
Patrick Delaunay18660a62019-02-27 17:01:12 +0100223 }
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100224 break;
225 case BOOT_SERIAL_USB:
226 env_set("boot_device", "usb");
227 env_set("boot_instance", "0");
228 break;
229 case BOOT_FLASH_SD:
230 case BOOT_FLASH_EMMC:
Rasmus Villemoes6d83f3c2023-03-24 08:55:19 +0100231 if (instance >= ARRAY_SIZE(sdmmc_addr))
Patrick Delaunay5c2f6d72021-07-06 17:19:45 +0200232 break;
233 /* search associated sdmmc node in devicetree */
234 sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);
235 if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) {
236 printf("mmc%d = %s not found in device tree!\n",
237 instance, cmd);
238 break;
239 }
240 sprintf(cmd, "%d", dev_seq(dev));
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100241 env_set("boot_device", "mmc");
242 env_set("boot_instance", cmd);
243 break;
244 case BOOT_FLASH_NAND:
245 env_set("boot_device", "nand");
246 env_set("boot_instance", "0");
247 break;
Patrick Delaunayb5a7ca22020-03-18 09:22:52 +0100248 case BOOT_FLASH_SPINAND:
249 env_set("boot_device", "spi-nand");
250 env_set("boot_instance", "0");
251 break;
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100252 case BOOT_FLASH_NOR:
253 env_set("boot_device", "nor");
254 env_set("boot_instance", "0");
255 break;
256 default:
Patrick Delaunay02e91972021-07-08 10:53:56 +0200257 env_set("boot_device", "invalid");
258 env_set("boot_instance", "");
259 log_err("unexpected boot mode = %x\n", boot_mode);
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100260 break;
261 }
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100262
263 switch (forced_mode) {
264 case BOOT_FASTBOOT:
Patrick Delaunay643e4042021-04-06 09:27:39 +0200265 log_info("Enter fastboot!\n");
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100266 env_set("preboot", "env set preboot; fastboot 0");
267 break;
268 case BOOT_STM32PROG:
269 env_set("boot_device", "usb");
270 env_set("boot_instance", "0");
271 break;
272 case BOOT_UMS_MMC0:
273 case BOOT_UMS_MMC1:
274 case BOOT_UMS_MMC2:
Patrick Delaunay643e4042021-04-06 09:27:39 +0200275 log_info("Enter UMS!\n");
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100276 instance = forced_mode - BOOT_UMS_MMC0;
277 sprintf(cmd, "env set preboot; ums 0 mmc %d", instance);
278 env_set("preboot", cmd);
279 break;
280 case BOOT_RECOVERY:
281 env_set("preboot", "env set preboot; run altbootcmd");
282 break;
283 case BOOT_NORMAL:
284 break;
285 default:
Patrick Delaunayba779402020-11-06 19:01:29 +0100286 log_debug("unexpected forced boot mode = %x\n", forced_mode);
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100287 break;
288 }
289
290 /* clear TAMP for next reboot */
291 clrsetbits_le32(TAMP_BOOT_CONTEXT, TAMP_BOOT_FORCED_MASK, BOOT_NORMAL);
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200292}
293
294/*
295 * If there is no MAC address in the environment, then it will be initialized
296 * (silently) from the value in the OTP.
297 */
Marek Vasut187cae22019-12-18 16:52:19 +0100298__weak int setup_mac_address(void)
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200299{
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200300 int ret;
301 int i;
Patrick Delaunay6425f582022-05-20 18:24:47 +0200302 u32 otp[3];
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200303 uchar enetaddr[6];
304 struct udevice *dev;
Patrick Delaunay6425f582022-05-20 18:24:47 +0200305 int nb_eth, nb_otp, index;
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200306
Patrick Delaunayd8299de2021-10-11 09:52:51 +0200307 if (!IS_ENABLED(CONFIG_NET))
308 return 0;
309
Patrick Delaunay6425f582022-05-20 18:24:47 +0200310 nb_eth = get_eth_nb();
311
312 /* 6 bytes for each MAC addr and 4 bytes for each OTP */
313 nb_otp = DIV_ROUND_UP(6 * nb_eth, 4);
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200314
315 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700316 DM_DRIVER_GET(stm32mp_bsec),
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200317 &dev);
318 if (ret)
319 return ret;
320
Patrick Delaunay6425f582022-05-20 18:24:47 +0200321 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp);
Simon Glass587dc402018-11-06 15:21:39 -0700322 if (ret < 0)
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200323 return ret;
324
Patrick Delaunay6425f582022-05-20 18:24:47 +0200325 for (index = 0; index < nb_eth; index++) {
326 /* MAC already in environment */
327 if (eth_env_get_enetaddr_by_index("eth", index, enetaddr))
328 continue;
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200329
Patrick Delaunay6425f582022-05-20 18:24:47 +0200330 for (i = 0; i < 6; i++)
331 enetaddr[i] = ((uint8_t *)&otp)[i + 6 * index];
332
333 if (!is_valid_ethaddr(enetaddr)) {
334 log_err("invalid MAC address %d in OTP %pM\n",
335 index, enetaddr);
336 return -EINVAL;
337 }
338 log_debug("OTP MAC address %d = %pM\n", index, enetaddr);
339 ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr);
340 if (ret) {
341 log_err("Failed to set mac address %pM from OTP: %d\n",
342 enetaddr, ret);
343 return ret;
344 }
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200345 }
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200346
347 return 0;
348}
349
350static int setup_serial_number(void)
351{
352 char serial_string[25];
353 u32 otp[3] = {0, 0, 0 };
354 struct udevice *dev;
355 int ret;
356
357 if (env_get("serial#"))
358 return 0;
359
360 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700361 DM_DRIVER_GET(stm32mp_bsec),
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200362 &dev);
363 if (ret)
364 return ret;
365
Patrick Delaunay10263a52019-02-27 17:01:29 +0100366 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200367 otp, sizeof(otp));
Simon Glass587dc402018-11-06 15:21:39 -0700368 if (ret < 0)
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200369 return ret;
370
Patrick Delaunayaf5564a2019-02-27 17:01:25 +0100371 sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200372 env_set("serial#", serial_string);
373
374 return 0;
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100375}
376
Patrick Delaunaye4bdd542022-05-20 18:24:42 +0200377__weak void stm32mp_misc_init(void)
Marek Vasut0eda28c2021-03-31 14:15:09 +0200378{
Igor Opaniuk100e0ec2023-11-06 11:41:52 +0100379}
380
381static int setup_boot_auth_info(void)
382{
383 char buf[10];
384 u32 bootauth = get_bootauth();
385
386 snprintf(buf, sizeof(buf), "%d", bootauth >> 4);
387 env_set("boot_auth", buf);
388
389 snprintf(buf, sizeof(buf), "%d", bootauth &
390 (u32)TAMP_BOOT_PARTITION_MASK);
391 env_set("boot_part", buf);
392
393 return 0;
Marek Vasut0eda28c2021-03-31 14:15:09 +0200394}
395
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100396int arch_misc_init(void)
397{
Igor Opaniuk100e0ec2023-11-06 11:41:52 +0100398 setup_boot_auth_info();
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100399 setup_boot_mode();
Patrick Delaunayf3674a42018-05-17 15:24:07 +0200400 setup_mac_address();
401 setup_serial_number();
Patrick Delaunaye4bdd542022-05-20 18:24:42 +0200402 stm32mp_misc_init();
Patrick Delaunayc5d15652018-03-20 10:54:53 +0100403
404 return 0;
405}
Marek Vasutefdedcb2023-01-12 18:58:40 +0100406
407/*
408 * Without forcing the ".data" section, this would get saved in ".bss". BSS
409 * will be cleared soon after, so it's not suitable.
410 */
411static uintptr_t rom_api_table __section(".data");
412static uintptr_t nt_fw_dtb __section(".data");
413
414/*
415 * The ROM gives us the API location in r0 when starting. This is only available
416 * during SPL, as there isn't (yet) a mechanism to pass this on to u-boot. Save
417 * the FDT address provided by TF-A in r2 at boot time. This function is called
418 * from start.S
419 */
420void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
421 unsigned long r3)
422{
423 if (IS_ENABLED(CONFIG_STM32_ECDSA_VERIFY))
424 rom_api_table = r0;
425
426 if (IS_ENABLED(CONFIG_TFABOOT))
427 nt_fw_dtb = r2;
428
429 save_boot_params_ret();
430}
431
432uintptr_t get_stm32mp_rom_api_table(void)
433{
434 return rom_api_table;
435}
436
437uintptr_t get_stm32mp_bl2_dtb(void)
438{
439 return nt_fw_dtb;
440}
Marek Vasut7cf2c332023-01-12 18:58:41 +0100441
442#ifdef CONFIG_SPL_BUILD
443void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
444{
445 typedef void __noreturn (*image_entry_stm32_t)(u32 romapi);
446 uintptr_t romapi = get_stm32mp_rom_api_table();
447
448 image_entry_stm32_t image_entry =
449 (image_entry_stm32_t)spl_image->entry_point;
450
451 printf("image entry point: 0x%lx\n", spl_image->entry_point);
452 image_entry(romapi);
453}
454#endif