2018-05-06 22:27:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
2018-03-12 09:46:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, STMicroelectronics - All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:29 +00:00
|
|
|
#define LOG_CATEGORY LOGC_ARCH
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <common.h>
|
2020-04-30 14:30:21 +00:00
|
|
|
#include <cpu_func.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <dm.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2021-07-15 19:19:26 +00:00
|
|
|
#include <ram.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <spl.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-03-20 09:54:54 +00:00
|
|
|
#include <asm/io.h>
|
2019-02-27 16:01:14 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2021-07-15 19:19:26 +00:00
|
|
|
#include <mach/tzc.h>
|
2019-02-27 16:01:14 +00:00
|
|
|
#include <linux/libfdt.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
2018-03-20 09:54:54 +00:00
|
|
|
u32 boot_mode;
|
|
|
|
|
2019-02-27 16:01:12 +00:00
|
|
|
boot_mode = get_bootmode();
|
2018-03-20 09:54:54 +00:00
|
|
|
|
|
|
|
switch (boot_mode) {
|
|
|
|
case BOOT_FLASH_SD_1:
|
|
|
|
case BOOT_FLASH_EMMC_1:
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
case BOOT_FLASH_SD_2:
|
|
|
|
case BOOT_FLASH_EMMC_2:
|
|
|
|
return BOOT_DEVICE_MMC2;
|
2019-02-27 16:01:12 +00:00
|
|
|
case BOOT_SERIAL_UART_1:
|
|
|
|
case BOOT_SERIAL_UART_2:
|
|
|
|
case BOOT_SERIAL_UART_3:
|
|
|
|
case BOOT_SERIAL_UART_4:
|
|
|
|
case BOOT_SERIAL_UART_5:
|
|
|
|
case BOOT_SERIAL_UART_6:
|
|
|
|
case BOOT_SERIAL_UART_7:
|
|
|
|
case BOOT_SERIAL_UART_8:
|
|
|
|
return BOOT_DEVICE_UART;
|
|
|
|
case BOOT_SERIAL_USB_OTG:
|
2021-12-06 20:58:08 +00:00
|
|
|
return BOOT_DEVICE_DFU;
|
2019-02-27 16:01:12 +00:00
|
|
|
case BOOT_FLASH_NAND_FMC:
|
|
|
|
return BOOT_DEVICE_NAND;
|
|
|
|
case BOOT_FLASH_NOR_QSPI:
|
|
|
|
return BOOT_DEVICE_SPI;
|
2020-03-18 08:22:52 +00:00
|
|
|
case BOOT_FLASH_SPINAND_1:
|
|
|
|
return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */
|
2018-03-20 09:54:54 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
}
|
|
|
|
|
2021-07-12 10:06:49 +00:00
|
|
|
u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
|
2018-03-12 09:46:10 +00:00
|
|
|
{
|
|
|
|
return MMCSD_MODE_RAW;
|
|
|
|
}
|
|
|
|
|
2020-10-12 14:11:09 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
|
2020-04-15 09:33:31 +00:00
|
|
|
int spl_mmc_boot_partition(const u32 boot_device)
|
2018-03-20 09:54:54 +00:00
|
|
|
{
|
|
|
|
switch (boot_device) {
|
|
|
|
case BOOT_DEVICE_MMC1:
|
|
|
|
return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
|
|
|
|
case BOOT_DEVICE_MMC2:
|
|
|
|
return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2020-10-12 14:11:09 +00:00
|
|
|
#endif
|
2018-03-20 09:54:54 +00:00
|
|
|
|
2019-02-27 16:01:14 +00:00
|
|
|
#ifdef CONFIG_SPL_DISPLAY_PRINT
|
|
|
|
void spl_display_print(void)
|
|
|
|
{
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
const char *model;
|
|
|
|
|
|
|
|
/* same code than show_board_info() but not compiled for SPL
|
|
|
|
* see CONFIG_DISPLAY_BOARDINFO & common/board_info.c
|
|
|
|
*/
|
|
|
|
model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
|
|
|
|
if (model)
|
2020-11-06 18:01:29 +00:00
|
|
|
log_info("Model: %s\n", model);
|
2019-02-27 16:01:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 11:18:10 +00:00
|
|
|
__weak int board_early_init_f(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-15 19:19:26 +00:00
|
|
|
uint32_t stm32mp_get_dram_size(void)
|
|
|
|
{
|
|
|
|
struct ram_info ram;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (uclass_get_device(UCLASS_RAM, 0, &dev))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = ram_get_info(dev, &ram);
|
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ram.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int optee_get_reserved_memory(uint32_t *start, uint32_t *size)
|
|
|
|
{
|
|
|
|
phys_size_t fdt_mem_size;
|
|
|
|
fdt_addr_t fdt_start;
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
node = ofnode_path("/reserved-memory/optee");
|
|
|
|
if (!ofnode_valid(node))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fdt_start = ofnode_get_addr_size(node, "reg", &fdt_mem_size);
|
|
|
|
*start = fdt_start;
|
|
|
|
*size = fdt_mem_size;
|
|
|
|
return (fdt_start < 0) ? fdt_start : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CFG_SHMEM_SIZE 0x200000
|
|
|
|
#define STM32_TZC_NSID_ALL 0xffff
|
|
|
|
#define STM32_TZC_FILTER_ALL 3
|
|
|
|
|
|
|
|
void stm32_init_tzc_for_optee(void)
|
|
|
|
{
|
|
|
|
const uint32_t dram_size = stm32mp_get_dram_size();
|
|
|
|
const uintptr_t dram_top = STM32_DDR_BASE + (dram_size - 1);
|
|
|
|
uint32_t optee_base, optee_size, tee_shmem_base;
|
|
|
|
const uintptr_t tzc = STM32_TZC_BASE;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dram_size == 0)
|
|
|
|
panic("Cannot determine DRAM size from devicetree\n");
|
|
|
|
|
|
|
|
ret = optee_get_reserved_memory(&optee_base, &optee_size);
|
|
|
|
if (ret < 0 || optee_size <= CFG_SHMEM_SIZE)
|
|
|
|
panic("Invalid OPTEE reserved memory in devicetree\n");
|
|
|
|
|
|
|
|
tee_shmem_base = optee_base + optee_size - CFG_SHMEM_SIZE;
|
|
|
|
|
|
|
|
const struct tzc_region optee_config[] = {
|
|
|
|
{
|
|
|
|
.base = STM32_DDR_BASE,
|
|
|
|
.top = optee_base - 1,
|
|
|
|
.sec_mode = TZC_ATTR_SEC_NONE,
|
|
|
|
.nsec_id = STM32_TZC_NSID_ALL,
|
|
|
|
.filters_mask = STM32_TZC_FILTER_ALL,
|
|
|
|
}, {
|
|
|
|
.base = optee_base,
|
|
|
|
.top = tee_shmem_base - 1,
|
|
|
|
.sec_mode = TZC_ATTR_SEC_RW,
|
|
|
|
.nsec_id = 0,
|
|
|
|
.filters_mask = STM32_TZC_FILTER_ALL,
|
|
|
|
}, {
|
|
|
|
.base = tee_shmem_base,
|
|
|
|
.top = dram_top,
|
|
|
|
.sec_mode = TZC_ATTR_SEC_NONE,
|
|
|
|
.nsec_id = STM32_TZC_NSID_ALL,
|
|
|
|
.filters_mask = STM32_TZC_FILTER_ALL,
|
|
|
|
}, {
|
|
|
|
.top = 0,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
flush_dcache_all();
|
|
|
|
|
|
|
|
tzc_configure(tzc, optee_config);
|
|
|
|
tzc_dump_config(tzc);
|
|
|
|
|
|
|
|
dcache_disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void spl_board_prepare_for_optee(void *fdt)
|
|
|
|
{
|
|
|
|
stm32_init_tzc_for_optee();
|
|
|
|
}
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
void board_init_f(ulong dummy)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
arch_cpu_init();
|
2022-05-20 16:24:42 +00:00
|
|
|
mach_cpu_init();
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
ret = spl_early_init();
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("spl_early_init() failed: %d\n", ret);
|
2018-03-12 09:46:10 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_CLK, 0, &dev);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("Clock init failed: %d\n", ret);
|
2020-04-22 12:29:10 +00:00
|
|
|
hang();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_RESET, 0, &dev);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("Reset init failed: %d\n", ret);
|
2020-04-22 12:29:10 +00:00
|
|
|
hang();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("%s: Cannot find pinctrl device\n", __func__);
|
2020-04-22 12:29:10 +00:00
|
|
|
hang();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable console uart printing */
|
|
|
|
preloader_console_init();
|
|
|
|
|
2020-04-22 11:18:10 +00:00
|
|
|
ret = board_early_init_f();
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("board_early_init_f() failed: %d\n", ret);
|
2020-04-22 11:18:10 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
ret = uclass_get_device(UCLASS_RAM, 0, &dev);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_err("DRAM init failed: %d\n", ret);
|
2019-02-27 16:01:17 +00:00
|
|
|
hang();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
2020-04-30 14:30:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* activate cache on DDR only when DDR is fully initialized
|
|
|
|
* to avoid speculative access and issue in get_ram_size()
|
|
|
|
*/
|
|
|
|
if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
|
2020-09-04 10:55:19 +00:00
|
|
|
mmu_set_region_dcache_behaviour(STM32_DDR_BASE,
|
|
|
|
CONFIG_DDR_CACHEABLE_SIZE,
|
2020-04-30 14:30:21 +00:00
|
|
|
DCACHE_DEFAULT_OPTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
void spl_board_prepare_for_boot(void)
|
|
|
|
{
|
|
|
|
dcache_disable();
|
|
|
|
}
|
|
|
|
|
2020-07-07 12:21:53 +00:00
|
|
|
void spl_board_prepare_for_linux(void)
|
2020-04-30 14:30:21 +00:00
|
|
|
{
|
|
|
|
dcache_disable();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|