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>
|
|
|
|
#include <clk.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2018-05-17 12:50:46 +00:00
|
|
|
#include <debug_uart.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2021-05-07 12:50:35 +00:00
|
|
|
#include <lmb.h>
|
2018-05-17 13:24:07 +00:00
|
|
|
#include <misc.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <net.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <asm/io.h>
|
2020-06-16 16:27:44 +00:00
|
|
|
#include <asm/arch/bsec.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <asm/arch/stm32.h>
|
2018-03-19 18:09:21 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-05-17 13:24:07 +00:00
|
|
|
#include <dm/device.h>
|
2018-03-20 09:54:53 +00:00
|
|
|
#include <dm/uclass.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
/* RCC register */
|
|
|
|
#define RCC_TZCR (STM32_RCC_BASE + 0x00)
|
|
|
|
#define RCC_DBGCFGR (STM32_RCC_BASE + 0x080C)
|
|
|
|
#define RCC_BDCR (STM32_RCC_BASE + 0x0140)
|
|
|
|
#define RCC_MP_APB5ENSETR (STM32_RCC_BASE + 0x0208)
|
2019-02-27 16:01:26 +00:00
|
|
|
#define RCC_MP_AHB5ENSETR (STM32_RCC_BASE + 0x0210)
|
2018-03-19 18:09:20 +00:00
|
|
|
#define RCC_BDCR_VSWRST BIT(31)
|
|
|
|
#define RCC_BDCR_RTCSRC GENMASK(17, 16)
|
|
|
|
#define RCC_DBGCFGR_DBGCKEN BIT(8)
|
2018-03-12 09:46:10 +00:00
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
/* Security register */
|
2018-03-12 09:46:10 +00:00
|
|
|
#define ETZPC_TZMA1_SIZE (STM32_ETZPC_BASE + 0x04)
|
|
|
|
#define ETZPC_DECPROT0 (STM32_ETZPC_BASE + 0x10)
|
|
|
|
|
|
|
|
#define TZC_GATE_KEEPER (STM32_TZC_BASE + 0x008)
|
|
|
|
#define TZC_REGION_ATTRIBUTE0 (STM32_TZC_BASE + 0x110)
|
|
|
|
#define TZC_REGION_ID_ACCESS0 (STM32_TZC_BASE + 0x114)
|
|
|
|
|
|
|
|
#define TAMP_CR1 (STM32_TAMP_BASE + 0x00)
|
|
|
|
|
|
|
|
#define PWR_CR1 (STM32_PWR_BASE + 0x00)
|
2019-10-30 13:38:30 +00:00
|
|
|
#define PWR_MCUCR (STM32_PWR_BASE + 0x14)
|
2018-03-12 09:46:10 +00:00
|
|
|
#define PWR_CR1_DBP BIT(8)
|
2019-10-30 13:38:30 +00:00
|
|
|
#define PWR_MCUCR_SBF BIT(6)
|
2018-03-12 09:46:10 +00:00
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
/* DBGMCU register */
|
2018-03-19 18:09:21 +00:00
|
|
|
#define DBGMCU_IDC (STM32_DBGMCU_BASE + 0x00)
|
2018-03-19 18:09:20 +00:00
|
|
|
#define DBGMCU_APB4FZ1 (STM32_DBGMCU_BASE + 0x2C)
|
|
|
|
#define DBGMCU_APB4FZ1_IWDG2 BIT(2)
|
2018-03-19 18:09:21 +00:00
|
|
|
#define DBGMCU_IDC_DEV_ID_MASK GENMASK(11, 0)
|
|
|
|
#define DBGMCU_IDC_DEV_ID_SHIFT 0
|
|
|
|
#define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16)
|
|
|
|
#define DBGMCU_IDC_REV_ID_SHIFT 16
|
2018-03-12 09:46:10 +00:00
|
|
|
|
2019-02-27 16:01:26 +00:00
|
|
|
/* GPIOZ registers */
|
|
|
|
#define GPIOZ_SECCFGR 0x54004030
|
|
|
|
|
2018-03-20 09:54:53 +00:00
|
|
|
/* boot interface from Bootrom
|
|
|
|
* - boot instance = bit 31:16
|
|
|
|
* - boot device = bit 15:0
|
|
|
|
*/
|
|
|
|
#define BOOTROM_PARAM_ADDR 0x2FFC0078
|
|
|
|
#define BOOTROM_MODE_MASK GENMASK(15, 0)
|
|
|
|
#define BOOTROM_MODE_SHIFT 0
|
|
|
|
#define BOOTROM_INSTANCE_MASK GENMASK(31, 16)
|
|
|
|
#define BOOTROM_INSTANCE_SHIFT 16
|
|
|
|
|
2019-02-27 16:01:13 +00:00
|
|
|
/* Device Part Number (RPN) = OTP_DATA1 lower 8 bits */
|
|
|
|
#define RPN_SHIFT 0
|
|
|
|
#define RPN_MASK GENMASK(7, 0)
|
|
|
|
|
|
|
|
/* Package = bit 27:29 of OTP16
|
|
|
|
* - 100: LBGA448 (FFI) => AA = LFBGA 18x18mm 448 balls p. 0.8mm
|
|
|
|
* - 011: LBGA354 (LCI) => AB = LFBGA 16x16mm 359 balls p. 0.8mm
|
|
|
|
* - 010: TFBGA361 (FFC) => AC = TFBGA 12x12mm 361 balls p. 0.5mm
|
|
|
|
* - 001: TFBGA257 (LCC) => AD = TFBGA 10x10mm 257 balls p. 0.5mm
|
|
|
|
* - others: Reserved
|
|
|
|
*/
|
|
|
|
#define PKG_SHIFT 27
|
|
|
|
#define PKG_MASK GENMASK(2, 0)
|
|
|
|
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
/*
|
|
|
|
* early TLB into the .data section so that it not get cleared
|
|
|
|
* with 16kB allignment (see TTBR0_BASE_ADDR_MASK)
|
|
|
|
*/
|
|
|
|
u8 early_tlb[PGTABLE_SIZE] __section(".data") __aligned(0x4000);
|
|
|
|
|
2021-05-07 12:50:35 +00:00
|
|
|
struct lmb lmb;
|
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
|
2020-04-01 07:07:33 +00:00
|
|
|
#ifndef CONFIG_TFABOOT
|
2018-03-12 09:46:10 +00:00
|
|
|
static void security_init(void)
|
|
|
|
{
|
|
|
|
/* Disable the backup domain write protection */
|
|
|
|
/* the protection is enable at each reset by hardware */
|
|
|
|
/* And must be disable by software */
|
|
|
|
setbits_le32(PWR_CR1, PWR_CR1_DBP);
|
|
|
|
|
|
|
|
while (!(readl(PWR_CR1) & PWR_CR1_DBP))
|
|
|
|
;
|
|
|
|
|
|
|
|
/* If RTC clock isn't enable so this is a cold boot then we need
|
|
|
|
* to reset the backup domain
|
|
|
|
*/
|
|
|
|
if (!(readl(RCC_BDCR) & RCC_BDCR_RTCSRC)) {
|
|
|
|
setbits_le32(RCC_BDCR, RCC_BDCR_VSWRST);
|
|
|
|
while (!(readl(RCC_BDCR) & RCC_BDCR_VSWRST))
|
|
|
|
;
|
|
|
|
clrbits_le32(RCC_BDCR, RCC_BDCR_VSWRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allow non secure access in Write/Read for all peripheral */
|
|
|
|
writel(GENMASK(25, 0), ETZPC_DECPROT0);
|
|
|
|
|
|
|
|
/* Open SYSRAM for no secure access */
|
|
|
|
writel(0x0, ETZPC_TZMA1_SIZE);
|
|
|
|
|
|
|
|
/* enable TZC1 TZC2 clock */
|
|
|
|
writel(BIT(11) | BIT(12), RCC_MP_APB5ENSETR);
|
|
|
|
|
|
|
|
/* Region 0 set to no access by default */
|
|
|
|
/* bit 0 / 16 => nsaid0 read/write Enable
|
|
|
|
* bit 1 / 17 => nsaid1 read/write Enable
|
|
|
|
* ...
|
|
|
|
* bit 15 / 31 => nsaid15 read/write Enable
|
|
|
|
*/
|
|
|
|
writel(0xFFFFFFFF, TZC_REGION_ID_ACCESS0);
|
|
|
|
/* bit 30 / 31 => Secure Global Enable : write/read */
|
|
|
|
/* bit 0 / 1 => Region Enable for filter 0/1 */
|
|
|
|
writel(BIT(0) | BIT(1) | BIT(30) | BIT(31), TZC_REGION_ATTRIBUTE0);
|
|
|
|
|
|
|
|
/* Enable Filter 0 and 1 */
|
|
|
|
setbits_le32(TZC_GATE_KEEPER, BIT(0) | BIT(1));
|
|
|
|
|
|
|
|
/* RCC trust zone deactivated */
|
|
|
|
writel(0x0, RCC_TZCR);
|
|
|
|
|
|
|
|
/* TAMP: deactivate the internal tamper
|
|
|
|
* Bit 23 ITAMP8E: monotonic counter overflow
|
|
|
|
* Bit 20 ITAMP5E: RTC calendar overflow
|
|
|
|
* Bit 19 ITAMP4E: HSE monitoring
|
|
|
|
* Bit 18 ITAMP3E: LSE monitoring
|
|
|
|
* Bit 16 ITAMP1E: RTC power domain supply monitoring
|
|
|
|
*/
|
|
|
|
writel(0x0, TAMP_CR1);
|
2019-02-27 16:01:26 +00:00
|
|
|
|
|
|
|
/* GPIOZ: deactivate the security */
|
|
|
|
writel(BIT(0), RCC_MP_AHB5ENSETR);
|
|
|
|
writel(0x0, GPIOZ_SECCFGR);
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
2020-04-01 07:07:33 +00:00
|
|
|
#endif /* CONFIG_TFABOOT */
|
2018-03-12 09:46:10 +00:00
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
/*
|
2018-03-12 09:46:10 +00:00
|
|
|
* Debug init
|
2018-03-19 18:09:20 +00:00
|
|
|
*/
|
2018-03-12 09:46:10 +00:00
|
|
|
static void dbgmcu_init(void)
|
|
|
|
{
|
2020-06-16 16:27:44 +00:00
|
|
|
/*
|
|
|
|
* Freeze IWDG2 if Cortex-A7 is in debug mode
|
|
|
|
* done in TF-A for TRUSTED boot and
|
|
|
|
* DBGMCU access is controlled by BSEC_DENABLE.DBGSWENABLE
|
|
|
|
*/
|
2020-07-24 09:13:31 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_TFABOOT) && bsec_dbgswenable()) {
|
|
|
|
setbits_le32(RCC_DBGCFGR, RCC_DBGCFGR_DBGCKEN);
|
2020-06-16 16:27:44 +00:00
|
|
|
setbits_le32(DBGMCU_APB4FZ1, DBGMCU_APB4FZ1_IWDG2);
|
2020-07-24 09:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
|
|
|
dbgmcu_init();
|
2018-03-12 09:46:10 +00:00
|
|
|
}
|
|
|
|
#endif /* !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) */
|
|
|
|
|
2020-04-01 07:07:33 +00:00
|
|
|
#if !defined(CONFIG_TFABOOT) && \
|
2019-02-12 10:44:39 +00:00
|
|
|
(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
|
2019-02-27 16:01:12 +00:00
|
|
|
/* get bootmode from ROM code boot context: saved in TAMP register */
|
|
|
|
static void update_bootmode(void)
|
|
|
|
{
|
|
|
|
u32 boot_mode;
|
2018-03-20 09:54:53 +00:00
|
|
|
u32 bootrom_itf = readl(BOOTROM_PARAM_ADDR);
|
|
|
|
u32 bootrom_device, bootrom_instance;
|
|
|
|
|
2019-02-27 16:01:12 +00:00
|
|
|
/* enable TAMP clock = RTCAPBEN */
|
|
|
|
writel(BIT(8), RCC_MP_APB5ENSETR);
|
|
|
|
|
|
|
|
/* read bootrom context */
|
2018-03-20 09:54:53 +00:00
|
|
|
bootrom_device =
|
|
|
|
(bootrom_itf & BOOTROM_MODE_MASK) >> BOOTROM_MODE_SHIFT;
|
|
|
|
bootrom_instance =
|
|
|
|
(bootrom_itf & BOOTROM_INSTANCE_MASK) >> BOOTROM_INSTANCE_SHIFT;
|
|
|
|
boot_mode =
|
|
|
|
((bootrom_device << BOOT_TYPE_SHIFT) & BOOT_TYPE_MASK) |
|
|
|
|
((bootrom_instance << BOOT_INSTANCE_SHIFT) &
|
|
|
|
BOOT_INSTANCE_MASK);
|
|
|
|
|
|
|
|
/* save the boot mode in TAMP backup register */
|
|
|
|
clrsetbits_le32(TAMP_BOOT_CONTEXT,
|
|
|
|
TAMP_BOOT_MODE_MASK,
|
|
|
|
boot_mode << TAMP_BOOT_MODE_SHIFT);
|
2019-02-27 16:01:12 +00:00
|
|
|
}
|
2018-03-20 09:54:53 +00:00
|
|
|
#endif
|
2019-02-27 16:01:12 +00:00
|
|
|
|
|
|
|
u32 get_bootmode(void)
|
|
|
|
{
|
|
|
|
/* read bootmode from TAMP backup register */
|
|
|
|
return (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_MODE_MASK) >>
|
|
|
|
TAMP_BOOT_MODE_SHIFT;
|
2018-03-20 09:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 12:53:33 +00:00
|
|
|
/*
|
|
|
|
* weak function overidde: set the DDR/SYSRAM executable before to enable the
|
|
|
|
* MMU and configure DACR, for early early_enable_caches (SPL or pre-reloc)
|
|
|
|
*/
|
|
|
|
void dram_bank_mmu_setup(int bank)
|
|
|
|
{
|
|
|
|
struct bd_info *bd = gd->bd;
|
|
|
|
int i;
|
|
|
|
phys_addr_t start;
|
|
|
|
phys_size_t size;
|
2021-05-07 12:50:35 +00:00
|
|
|
bool use_lmb = false;
|
|
|
|
enum dcache_option option;
|
2021-02-05 12:53:33 +00:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD)) {
|
|
|
|
start = ALIGN_DOWN(STM32_SYSRAM_BASE, MMU_SECTION_SIZE);
|
|
|
|
size = ALIGN(STM32_SYSRAM_SIZE, MMU_SECTION_SIZE);
|
|
|
|
} else if (gd->flags & GD_FLG_RELOC) {
|
|
|
|
/* bd->bi_dram is available only after relocation */
|
|
|
|
start = bd->bi_dram[bank].start;
|
|
|
|
size = bd->bi_dram[bank].size;
|
2021-05-07 12:50:35 +00:00
|
|
|
use_lmb = true;
|
2021-02-05 12:53:33 +00:00
|
|
|
} else {
|
|
|
|
/* mark cacheable and executable the beggining of the DDR */
|
|
|
|
start = STM32_DDR_BASE;
|
|
|
|
size = CONFIG_DDR_CACHEABLE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = start >> MMU_SECTION_SHIFT;
|
|
|
|
i < (start >> MMU_SECTION_SHIFT) + (size >> MMU_SECTION_SHIFT);
|
2021-05-07 12:50:35 +00:00
|
|
|
i++) {
|
|
|
|
option = DCACHE_DEFAULT_OPTION;
|
|
|
|
if (use_lmb && lmb_is_reserved_flags(&lmb, i << MMU_SECTION_SHIFT, LMB_NOMAP))
|
|
|
|
option = 0; /* INVALID ENTRY in TLB */
|
|
|
|
set_section_dcache(i, option);
|
|
|
|
}
|
2021-02-05 12:53:33 +00:00
|
|
|
}
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
/*
|
|
|
|
* initialize the MMU and activate cache in SPL or in U-Boot pre-reloc stage
|
|
|
|
* MMU/TLB is updated in enable_caches() for U-Boot after relocation
|
|
|
|
* or is deactivated in U-Boot entry function start.S::cpu_init_cp15
|
|
|
|
*/
|
|
|
|
static void early_enable_caches(void)
|
|
|
|
{
|
|
|
|
/* I-cache is already enabled in start.S: cpu_init_cp15 */
|
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
|
|
|
|
return;
|
|
|
|
|
2021-02-24 12:53:27 +00:00
|
|
|
if (!(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))) {
|
|
|
|
gd->arch.tlb_size = PGTABLE_SIZE;
|
|
|
|
gd->arch.tlb_addr = (unsigned long)&early_tlb;
|
|
|
|
}
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
|
2021-02-05 12:53:33 +00:00
|
|
|
/* enable MMU (default configuration) */
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
dcache_enable();
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:54:53 +00:00
|
|
|
/*
|
|
|
|
* Early system init
|
|
|
|
*/
|
2018-03-12 09:46:10 +00:00
|
|
|
int arch_cpu_init(void)
|
|
|
|
{
|
2018-05-17 12:50:46 +00:00
|
|
|
u32 boot_mode;
|
|
|
|
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
early_enable_caches();
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
/* early armv7 timer init: needed for polling */
|
|
|
|
timer_init();
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
|
2020-04-01 07:07:33 +00:00
|
|
|
#ifndef CONFIG_TFABOOT
|
2018-03-12 09:46:10 +00:00
|
|
|
security_init();
|
2019-02-27 16:01:12 +00:00
|
|
|
update_bootmode();
|
2019-02-12 10:44:39 +00:00
|
|
|
#endif
|
2019-10-30 13:38:30 +00:00
|
|
|
/* Reset Coprocessor state unless it wakes up from Standby power mode */
|
|
|
|
if (!(readl(PWR_MCUCR) & PWR_MCUCR_SBF)) {
|
|
|
|
writel(TAMP_COPRO_STATE_OFF, TAMP_COPRO_STATE);
|
|
|
|
writel(0, TAMP_COPRO_RSC_TBL_ADDRESS);
|
|
|
|
}
|
2018-03-12 09:46:10 +00:00
|
|
|
#endif
|
2018-05-17 12:50:46 +00:00
|
|
|
|
|
|
|
boot_mode = get_bootmode();
|
|
|
|
|
2021-02-25 12:37:01 +00:00
|
|
|
if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL) &&
|
|
|
|
(boot_mode & TAMP_BOOT_DEVICE_MASK) == BOOT_SERIAL_UART)
|
2018-05-17 12:50:46 +00:00
|
|
|
gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
|
|
|
|
#if defined(CONFIG_DEBUG_UART) && \
|
2020-04-01 07:07:33 +00:00
|
|
|
!defined(CONFIG_TFABOOT) && \
|
2018-05-17 12:50:46 +00:00
|
|
|
(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
|
|
|
|
else
|
|
|
|
debug_uart_init();
|
|
|
|
#endif
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:09:20 +00:00
|
|
|
void enable_caches(void)
|
|
|
|
{
|
2021-05-07 12:50:35 +00:00
|
|
|
/* parse device tree when data cache is still activated */
|
|
|
|
lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
|
|
|
|
|
arm: stm32mp: activate data cache in SPL and before relocation
Activate the data cache in SPL and in U-Boot before relocation.
In arch_cpu_init(), the function early_enable_caches() sets the early
TLB, early_tlb[] located .init section, and set cacheable:
- for SPL, all the SYSRAM
- for U-Boot, all the DDR
After relocation, the function enable_caches() (called by board_r)
reconfigures the MMU with new TLB location (reserved in
board_f.c::reserve_mmu) and re-enable the data cache.
This patch allows to reduce the execution time, particularly
- for the device tree parsing in U-Boot pre-reloc stage
(dm_extended_scan_fd =>dm_scan_fdt)
- in I2C timing computation in SPL (stm32_i2c_choose_solution())
For example, the result on STM32MP157C-DK2 board is:
1,6s gain for trusted boot chain with TF-A
2,2s gain for basic boot chain with SPL
For information, as TLB is added in .data section, the binary size
increased and the SPL load time by ROM code increased (30ms on DK2).
But early malloc can't be used for TLB because arch_cpu_init()
is executed before the early poll initialization done in spl_common_init()
called by spl_early_init() So it too late for this use case.
And if I initialize the MMU and the cache after this function it is
too late, as dm_init_and_scan and fdt parsing is also called in
spl_common_init().
And .BSS can be used in board_init_f(): only stack and global can use
before BSS init done in board_init_r().
So .data is the better solution without hardcoded location but if you
have size issue for SPL you can deactivate cache for SPL only
(with CONFIG_SPL_SYS_DCACHE_OFF).
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-04-30 14:30:20 +00:00
|
|
|
/* I-cache is already enabled in start.S: icache_enable() not needed */
|
|
|
|
|
|
|
|
/* deactivate the data cache, early enabled in arch_cpu_init() */
|
|
|
|
dcache_disable();
|
|
|
|
/*
|
|
|
|
* update MMU after relocation and enable the data cache
|
|
|
|
* warning: the TLB location udpated in board_f.c::reserve_mmu
|
|
|
|
*/
|
2018-03-19 18:09:20 +00:00
|
|
|
dcache_enable();
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:09:21 +00:00
|
|
|
static u32 read_idc(void)
|
|
|
|
{
|
2020-06-16 16:27:44 +00:00
|
|
|
/* DBGMCU access is controlled by BSEC_DENABLE.DBGSWENABLE */
|
|
|
|
if (bsec_dbgswenable()) {
|
|
|
|
setbits_le32(RCC_DBGCFGR, RCC_DBGCFGR_DBGCKEN);
|
2018-03-19 18:09:21 +00:00
|
|
|
|
2020-06-16 16:27:44 +00:00
|
|
|
return readl(DBGMCU_IDC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(STM32MP15x))
|
|
|
|
return CPU_DEV_STM32MP15; /* STM32MP15x and unknown revision */
|
|
|
|
else
|
|
|
|
return 0x0;
|
2018-03-19 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 08:24:48 +00:00
|
|
|
u32 get_cpu_dev(void)
|
|
|
|
{
|
|
|
|
return (read_idc() & DBGMCU_IDC_DEV_ID_MASK) >> DBGMCU_IDC_DEV_ID_SHIFT;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:09:21 +00:00
|
|
|
u32 get_cpu_rev(void)
|
|
|
|
{
|
|
|
|
return (read_idc() & DBGMCU_IDC_REV_ID_MASK) >> DBGMCU_IDC_REV_ID_SHIFT;
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:01:13 +00:00
|
|
|
static u32 get_otp(int index, int shift, int mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
u32 otp = 0;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(stm32mp_bsec),
|
2019-02-27 16:01:13 +00:00
|
|
|
&dev);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ret = misc_read(dev, STM32_BSEC_SHADOW(index),
|
|
|
|
&otp, sizeof(otp));
|
|
|
|
|
|
|
|
return (otp >> shift) & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Device Part Number (RPN) from OTP */
|
|
|
|
static u32 get_cpu_rpn(void)
|
|
|
|
{
|
|
|
|
return get_otp(BSEC_OTP_RPN, RPN_SHIFT, RPN_MASK);
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:09:21 +00:00
|
|
|
u32 get_cpu_type(void)
|
|
|
|
{
|
2020-03-18 08:24:48 +00:00
|
|
|
return (get_cpu_dev() << 16) | get_cpu_rpn();
|
2019-02-27 16:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Package options from OTP */
|
2019-07-05 15:20:13 +00:00
|
|
|
u32 get_cpu_package(void)
|
2019-02-27 16:01:13 +00:00
|
|
|
{
|
|
|
|
return get_otp(BSEC_OTP_PKG, PKG_SHIFT, PKG_MASK);
|
2018-03-19 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 12:15:09 +00:00
|
|
|
static const char * const soc_type[] = {
|
|
|
|
"????",
|
|
|
|
"151C", "151A", "151F", "151D",
|
|
|
|
"153C", "153A", "153F", "153D",
|
|
|
|
"157C", "157A", "157F", "157D"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const soc_pkg[] = { "??", "AD", "AC", "AB", "AA" };
|
|
|
|
static const char * const soc_rev[] = { "?", "A", "B", "Z" };
|
|
|
|
|
|
|
|
static void get_cpu_string_offsets(unsigned int *type, unsigned int *pkg,
|
|
|
|
unsigned int *rev)
|
2018-03-12 09:46:10 +00:00
|
|
|
{
|
2021-03-31 12:15:09 +00:00
|
|
|
u32 cpu_type = get_cpu_type();
|
|
|
|
u32 ct = cpu_type & ~(BIT(7) | BIT(0));
|
|
|
|
u32 cm = ((cpu_type & BIT(7)) >> 6) | (cpu_type & BIT(0));
|
|
|
|
u32 cp = get_cpu_package();
|
2018-03-19 18:09:21 +00:00
|
|
|
|
2021-03-31 12:15:09 +00:00
|
|
|
/* Bits 0 and 7 are the ACDF, 00:C 01:A 10:F 11:D */
|
|
|
|
switch (ct) {
|
|
|
|
case CPU_STM32MP151Cxx:
|
|
|
|
*type = cm + 1;
|
2020-02-26 10:26:43 +00:00
|
|
|
break;
|
2019-02-27 16:01:13 +00:00
|
|
|
case CPU_STM32MP153Cxx:
|
2021-03-31 12:15:09 +00:00
|
|
|
*type = cm + 5;
|
2020-02-26 10:26:43 +00:00
|
|
|
break;
|
2021-03-31 12:15:09 +00:00
|
|
|
case CPU_STM32MP157Cxx:
|
|
|
|
*type = cm + 9;
|
2019-02-27 16:01:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-03-31 12:15:09 +00:00
|
|
|
*type = 0;
|
2019-02-27 16:01:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Package */
|
2021-03-31 12:15:09 +00:00
|
|
|
switch (cp) {
|
2019-02-27 16:01:13 +00:00
|
|
|
case PKG_AA_LBGA448:
|
|
|
|
case PKG_AB_LBGA354:
|
|
|
|
case PKG_AC_TFBGA361:
|
|
|
|
case PKG_AD_TFBGA257:
|
2021-03-31 12:15:09 +00:00
|
|
|
*pkg = cp;
|
2018-03-19 18:09:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-03-31 12:15:09 +00:00
|
|
|
*pkg = 0;
|
2018-03-19 18:09:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:15:09 +00:00
|
|
|
/* Revision */
|
2018-03-19 18:09:21 +00:00
|
|
|
switch (get_cpu_rev()) {
|
|
|
|
case CPU_REVA:
|
2021-03-31 12:15:09 +00:00
|
|
|
*rev = 1;
|
2018-03-19 18:09:21 +00:00
|
|
|
break;
|
|
|
|
case CPU_REVB:
|
2021-03-31 12:15:09 +00:00
|
|
|
*rev = 2;
|
2018-03-19 18:09:21 +00:00
|
|
|
break;
|
2020-01-28 09:11:06 +00:00
|
|
|
case CPU_REVZ:
|
2021-03-31 12:15:09 +00:00
|
|
|
*rev = 3;
|
2020-01-28 09:11:06 +00:00
|
|
|
break;
|
2018-03-19 18:09:21 +00:00
|
|
|
default:
|
2021-03-31 12:15:09 +00:00
|
|
|
*rev = 0;
|
2018-03-19 18:09:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-03-31 12:15:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void get_soc_name(char name[SOC_NAME_SIZE])
|
|
|
|
{
|
|
|
|
unsigned int type, pkg, rev;
|
2018-03-19 18:09:21 +00:00
|
|
|
|
2021-03-31 12:15:09 +00:00
|
|
|
get_cpu_string_offsets(&type, &pkg, &rev);
|
|
|
|
|
|
|
|
snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s",
|
|
|
|
soc_type[type], soc_pkg[pkg], soc_rev[rev]);
|
2020-02-12 18:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO)
|
|
|
|
int print_cpuinfo(void)
|
|
|
|
{
|
|
|
|
char name[SOC_NAME_SIZE];
|
|
|
|
|
|
|
|
get_soc_name(name);
|
|
|
|
printf("CPU: %s\n", name);
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DISPLAY_CPUINFO */
|
|
|
|
|
2018-03-20 09:54:53 +00:00
|
|
|
static void setup_boot_mode(void)
|
|
|
|
{
|
2019-02-27 16:01:12 +00:00
|
|
|
const u32 serial_addr[] = {
|
|
|
|
STM32_USART1_BASE,
|
|
|
|
STM32_USART2_BASE,
|
|
|
|
STM32_USART3_BASE,
|
|
|
|
STM32_UART4_BASE,
|
|
|
|
STM32_UART5_BASE,
|
|
|
|
STM32_USART6_BASE,
|
|
|
|
STM32_UART7_BASE,
|
|
|
|
STM32_UART8_BASE
|
|
|
|
};
|
2021-07-06 15:19:45 +00:00
|
|
|
const u32 sdmmc_addr[] = {
|
|
|
|
STM32_SDMMC1_BASE,
|
|
|
|
STM32_SDMMC2_BASE,
|
|
|
|
STM32_SDMMC3_BASE
|
|
|
|
};
|
2018-03-20 09:54:53 +00:00
|
|
|
char cmd[60];
|
|
|
|
u32 boot_ctx = readl(TAMP_BOOT_CONTEXT);
|
|
|
|
u32 boot_mode =
|
|
|
|
(boot_ctx & TAMP_BOOT_MODE_MASK) >> TAMP_BOOT_MODE_SHIFT;
|
2019-06-21 13:26:39 +00:00
|
|
|
unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1;
|
2019-02-27 16:01:20 +00:00
|
|
|
u32 forced_mode = (boot_ctx & TAMP_BOOT_FORCED_MASK);
|
2019-02-27 16:01:12 +00:00
|
|
|
struct udevice *dev;
|
2018-03-20 09:54:53 +00:00
|
|
|
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d forced=%x\n",
|
|
|
|
__func__, boot_ctx, boot_mode, instance, forced_mode);
|
2018-03-20 09:54:53 +00:00
|
|
|
switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {
|
|
|
|
case BOOT_SERIAL_UART:
|
2019-02-27 16:01:12 +00:00
|
|
|
if (instance > ARRAY_SIZE(serial_addr))
|
|
|
|
break;
|
2021-02-25 12:37:03 +00:00
|
|
|
/* serial : search associated node in devicetree */
|
2019-02-27 16:01:12 +00:00
|
|
|
sprintf(cmd, "serial@%x", serial_addr[instance]);
|
2021-02-25 12:37:03 +00:00
|
|
|
if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev)) {
|
2021-02-25 12:37:02 +00:00
|
|
|
/* restore console on error */
|
|
|
|
if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL))
|
|
|
|
gd->flags &= ~(GD_FLG_SILENT |
|
|
|
|
GD_FLG_DISABLE_CONSOLE);
|
2021-04-06 07:27:39 +00:00
|
|
|
log_err("uart%d = %s not found in device tree!\n",
|
|
|
|
instance + 1, cmd);
|
2019-02-27 16:01:12 +00:00
|
|
|
break;
|
2021-02-25 12:37:02 +00:00
|
|
|
}
|
2021-02-25 12:37:03 +00:00
|
|
|
sprintf(cmd, "%d", dev_seq(dev));
|
2019-02-27 16:01:12 +00:00
|
|
|
env_set("boot_device", "serial");
|
2018-03-20 09:54:53 +00:00
|
|
|
env_set("boot_instance", cmd);
|
2019-02-27 16:01:12 +00:00
|
|
|
|
|
|
|
/* restore console on uart when not used */
|
2021-02-25 12:37:01 +00:00
|
|
|
if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL) && gd->cur_serial_dev != dev) {
|
2019-02-27 16:01:12 +00:00
|
|
|
gd->flags &= ~(GD_FLG_SILENT |
|
|
|
|
GD_FLG_DISABLE_CONSOLE);
|
2021-04-06 07:27:39 +00:00
|
|
|
log_info("serial boot with console enabled!\n");
|
2019-02-27 16:01:12 +00:00
|
|
|
}
|
2018-03-20 09:54:53 +00:00
|
|
|
break;
|
|
|
|
case BOOT_SERIAL_USB:
|
|
|
|
env_set("boot_device", "usb");
|
|
|
|
env_set("boot_instance", "0");
|
|
|
|
break;
|
|
|
|
case BOOT_FLASH_SD:
|
|
|
|
case BOOT_FLASH_EMMC:
|
2021-07-06 15:19:45 +00:00
|
|
|
if (instance > ARRAY_SIZE(sdmmc_addr))
|
|
|
|
break;
|
|
|
|
/* search associated sdmmc node in devicetree */
|
|
|
|
sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);
|
|
|
|
if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) {
|
|
|
|
printf("mmc%d = %s not found in device tree!\n",
|
|
|
|
instance, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprintf(cmd, "%d", dev_seq(dev));
|
2018-03-20 09:54:53 +00:00
|
|
|
env_set("boot_device", "mmc");
|
|
|
|
env_set("boot_instance", cmd);
|
|
|
|
break;
|
|
|
|
case BOOT_FLASH_NAND:
|
|
|
|
env_set("boot_device", "nand");
|
|
|
|
env_set("boot_instance", "0");
|
|
|
|
break;
|
2020-03-18 08:22:52 +00:00
|
|
|
case BOOT_FLASH_SPINAND:
|
|
|
|
env_set("boot_device", "spi-nand");
|
|
|
|
env_set("boot_instance", "0");
|
|
|
|
break;
|
2018-03-20 09:54:53 +00:00
|
|
|
case BOOT_FLASH_NOR:
|
|
|
|
env_set("boot_device", "nor");
|
|
|
|
env_set("boot_instance", "0");
|
|
|
|
break;
|
|
|
|
default:
|
2021-07-08 08:53:56 +00:00
|
|
|
env_set("boot_device", "invalid");
|
|
|
|
env_set("boot_instance", "");
|
|
|
|
log_err("unexpected boot mode = %x\n", boot_mode);
|
2018-03-20 09:54:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-27 16:01:20 +00:00
|
|
|
|
|
|
|
switch (forced_mode) {
|
|
|
|
case BOOT_FASTBOOT:
|
2021-04-06 07:27:39 +00:00
|
|
|
log_info("Enter fastboot!\n");
|
2019-02-27 16:01:20 +00:00
|
|
|
env_set("preboot", "env set preboot; fastboot 0");
|
|
|
|
break;
|
|
|
|
case BOOT_STM32PROG:
|
|
|
|
env_set("boot_device", "usb");
|
|
|
|
env_set("boot_instance", "0");
|
|
|
|
break;
|
|
|
|
case BOOT_UMS_MMC0:
|
|
|
|
case BOOT_UMS_MMC1:
|
|
|
|
case BOOT_UMS_MMC2:
|
2021-04-06 07:27:39 +00:00
|
|
|
log_info("Enter UMS!\n");
|
2019-02-27 16:01:20 +00:00
|
|
|
instance = forced_mode - BOOT_UMS_MMC0;
|
|
|
|
sprintf(cmd, "env set preboot; ums 0 mmc %d", instance);
|
|
|
|
env_set("preboot", cmd);
|
|
|
|
break;
|
|
|
|
case BOOT_RECOVERY:
|
|
|
|
env_set("preboot", "env set preboot; run altbootcmd");
|
|
|
|
break;
|
|
|
|
case BOOT_NORMAL:
|
|
|
|
break;
|
|
|
|
default:
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("unexpected forced boot mode = %x\n", forced_mode);
|
2019-02-27 16:01:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear TAMP for next reboot */
|
|
|
|
clrsetbits_le32(TAMP_BOOT_CONTEXT, TAMP_BOOT_FORCED_MASK, BOOT_NORMAL);
|
2018-03-20 09:54:53 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 13:24:07 +00:00
|
|
|
/*
|
|
|
|
* If there is no MAC address in the environment, then it will be initialized
|
|
|
|
* (silently) from the value in the OTP.
|
|
|
|
*/
|
2019-12-18 15:52:19 +00:00
|
|
|
__weak int setup_mac_address(void)
|
2018-05-17 13:24:07 +00:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_NET)
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
u32 otp[2];
|
|
|
|
uchar enetaddr[6];
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
/* MAC already in environment */
|
|
|
|
if (eth_env_get_enetaddr("ethaddr", enetaddr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(stm32mp_bsec),
|
2018-05-17 13:24:07 +00:00
|
|
|
&dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-02-27 16:01:29 +00:00
|
|
|
ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC),
|
2018-05-17 13:24:07 +00:00
|
|
|
otp, sizeof(otp));
|
2018-11-06 22:21:39 +00:00
|
|
|
if (ret < 0)
|
2018-05-17 13:24:07 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
enetaddr[i] = ((uint8_t *)&otp)[i];
|
|
|
|
|
|
|
|
if (!is_valid_ethaddr(enetaddr)) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_err("invalid MAC address in OTP %pM\n", enetaddr);
|
2018-05-17 13:24:07 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("OTP MAC address = %pM\n", enetaddr);
|
2020-04-07 14:07:46 +00:00
|
|
|
ret = eth_env_set_enetaddr("ethaddr", enetaddr);
|
|
|
|
if (ret)
|
2020-11-06 18:01:29 +00:00
|
|
|
log_err("Failed to set mac address %pM from OTP: %d\n", enetaddr, ret);
|
2018-05-17 13:24:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int setup_serial_number(void)
|
|
|
|
{
|
|
|
|
char serial_string[25];
|
|
|
|
u32 otp[3] = {0, 0, 0 };
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (env_get("serial#"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(stm32mp_bsec),
|
2018-05-17 13:24:07 +00:00
|
|
|
&dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-02-27 16:01:29 +00:00
|
|
|
ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
|
2018-05-17 13:24:07 +00:00
|
|
|
otp, sizeof(otp));
|
2018-11-06 22:21:39 +00:00
|
|
|
if (ret < 0)
|
2018-05-17 13:24:07 +00:00
|
|
|
return ret;
|
|
|
|
|
2019-02-27 16:01:25 +00:00
|
|
|
sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
|
2018-05-17 13:24:07 +00:00
|
|
|
env_set("serial#", serial_string);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:15:09 +00:00
|
|
|
static void setup_soc_type_pkg_rev(void)
|
|
|
|
{
|
|
|
|
unsigned int type, pkg, rev;
|
|
|
|
|
|
|
|
get_cpu_string_offsets(&type, &pkg, &rev);
|
|
|
|
|
|
|
|
env_set("soc_type", soc_type[type]);
|
|
|
|
env_set("soc_pkg", soc_pkg[pkg]);
|
|
|
|
env_set("soc_rev", soc_rev[rev]);
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:54:53 +00:00
|
|
|
int arch_misc_init(void)
|
|
|
|
{
|
|
|
|
setup_boot_mode();
|
2018-05-17 13:24:07 +00:00
|
|
|
setup_mac_address();
|
|
|
|
setup_serial_number();
|
2021-03-31 12:15:09 +00:00
|
|
|
setup_soc_type_pkg_rev();
|
2018-03-20 09:54:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|