1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
6 #define LOG_CATEGORY LOGC_ARCH
16 #include <asm/cache.h>
17 #include <asm/global_data.h>
19 #include <asm/arch/sys_proto.h>
21 #include <linux/libfdt.h>
23 u32 spl_boot_device(void)
27 boot_mode = get_bootmode();
31 case BOOT_FLASH_EMMC_1:
32 return BOOT_DEVICE_MMC1;
34 case BOOT_FLASH_EMMC_2:
35 return BOOT_DEVICE_MMC2;
36 case BOOT_SERIAL_UART_1:
37 case BOOT_SERIAL_UART_2:
38 case BOOT_SERIAL_UART_3:
39 case BOOT_SERIAL_UART_4:
40 case BOOT_SERIAL_UART_5:
41 case BOOT_SERIAL_UART_6:
42 case BOOT_SERIAL_UART_7:
43 case BOOT_SERIAL_UART_8:
44 return BOOT_DEVICE_UART;
45 case BOOT_SERIAL_USB_OTG:
46 return BOOT_DEVICE_DFU;
47 case BOOT_FLASH_NAND_FMC:
48 return BOOT_DEVICE_NAND;
49 case BOOT_FLASH_NOR_QSPI:
50 return BOOT_DEVICE_SPI;
51 case BOOT_FLASH_SPINAND_1:
52 return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
55 return BOOT_DEVICE_MMC1;
58 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
60 return MMCSD_MODE_RAW;
63 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
64 int spl_mmc_boot_partition(const u32 boot_device)
66 switch (boot_device) {
67 case BOOT_DEVICE_MMC1:
68 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
69 case BOOT_DEVICE_MMC2:
70 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
77 #ifdef CONFIG_SPL_DISPLAY_PRINT
78 void spl_display_print(void)
80 DECLARE_GLOBAL_DATA_PTR;
83 /* same code than show_board_info() but not compiled for SPL
84 * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
86 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
88 log_info("Model: %s\n", model);
92 __weak int board_early_init_f(void)
97 uint32_t stm32mp_get_dram_size(void)
103 if (uclass_get_device(UCLASS_RAM, 0, &dev))
106 ret = ram_get_info(dev, &ram);
113 static int optee_get_reserved_memory(uint32_t *start, uint32_t *size)
115 phys_size_t fdt_mem_size;
116 fdt_addr_t fdt_start;
119 node = ofnode_path("/reserved-memory/optee");
120 if (!ofnode_valid(node))
123 fdt_start = ofnode_get_addr_size(node, "reg", &fdt_mem_size);
125 *size = fdt_mem_size;
126 return (fdt_start < 0) ? fdt_start : 0;
129 #define CFG_SHMEM_SIZE 0x200000
130 #define STM32_TZC_NSID_ALL 0xffff
131 #define STM32_TZC_FILTER_ALL 3
133 void stm32_init_tzc_for_optee(void)
135 const uint32_t dram_size = stm32mp_get_dram_size();
136 const uintptr_t dram_top = STM32_DDR_BASE + (dram_size - 1);
137 uint32_t optee_base, optee_size, tee_shmem_base;
138 const uintptr_t tzc = STM32_TZC_BASE;
142 panic("Cannot determine DRAM size from devicetree\n");
144 ret = optee_get_reserved_memory(&optee_base, &optee_size);
145 if (ret < 0 || optee_size <= CFG_SHMEM_SIZE)
146 panic("Invalid OPTEE reserved memory in devicetree\n");
148 tee_shmem_base = optee_base + optee_size - CFG_SHMEM_SIZE;
150 const struct tzc_region optee_config[] = {
152 .base = STM32_DDR_BASE,
153 .top = optee_base - 1,
154 .sec_mode = TZC_ATTR_SEC_NONE,
155 .nsec_id = STM32_TZC_NSID_ALL,
156 .filters_mask = STM32_TZC_FILTER_ALL,
159 .top = tee_shmem_base - 1,
160 .sec_mode = TZC_ATTR_SEC_RW,
162 .filters_mask = STM32_TZC_FILTER_ALL,
164 .base = tee_shmem_base,
166 .sec_mode = TZC_ATTR_SEC_NONE,
167 .nsec_id = STM32_TZC_NSID_ALL,
168 .filters_mask = STM32_TZC_FILTER_ALL,
176 tzc_configure(tzc, optee_config);
177 tzc_dump_config(tzc);
182 void spl_board_prepare_for_optee(void *fdt)
184 stm32_init_tzc_for_optee();
187 void board_init_f(ulong dummy)
194 ret = spl_early_init();
196 log_debug("spl_early_init() failed: %d\n", ret);
200 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
202 log_debug("Clock init failed: %d\n", ret);
206 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
208 log_debug("Reset init failed: %d\n", ret);
212 ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
214 log_debug("%s: Cannot find pinctrl device\n", __func__);
218 /* enable console uart printing */
219 preloader_console_init();
221 ret = board_early_init_f();
223 log_debug("board_early_init_f() failed: %d\n", ret);
227 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
229 log_err("DRAM init failed: %d\n", ret);
234 * activate cache on DDR only when DDR is fully initialized
235 * to avoid speculative access and issue in get_ram_size()
237 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
238 mmu_set_region_dcache_behaviour(STM32_DDR_BASE,
239 CONFIG_DDR_CACHEABLE_SIZE,
240 DCACHE_DEFAULT_OPTION);
243 void spl_board_prepare_for_boot(void)
248 void spl_board_prepare_for_linux(void)