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>
|
|
|
|
#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>
|
2023-01-12 17:58:41 +00:00
|
|
|
#include <spl.h>
|
2018-03-12 09:46:10 +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
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
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)) {
|
2022-05-20 16:24:46 +00:00
|
|
|
/* STM32_SYSRAM_BASE exist only when SPL is supported */
|
|
|
|
#ifdef CONFIG_SPL
|
2021-02-05 12:53:33 +00:00
|
|
|
start = ALIGN_DOWN(STM32_SYSRAM_BASE, MMU_SECTION_SIZE);
|
|
|
|
size = ALIGN(STM32_SYSRAM_SIZE, MMU_SECTION_SIZE);
|
2022-05-20 16:24:46 +00:00
|
|
|
#endif
|
2021-02-05 12:53:33 +00:00
|
|
|
} 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)
|
|
|
|
{
|
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();
|
|
|
|
|
2022-05-20 16:24:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* weak function for SOC specific initialization */
|
|
|
|
__weak void stm32mp_cpu_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int mach_cpu_init(void)
|
|
|
|
{
|
|
|
|
u32 boot_mode;
|
|
|
|
|
|
|
|
stm32mp_cpu_init();
|
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;
|
2021-10-11 07:52:51 +00:00
|
|
|
else if (IS_ENABLED(CONFIG_DEBUG_UART) && IS_ENABLED(CONFIG_SPL_BUILD))
|
2018-05-17 12:50:46 +00:00
|
|
|
debug_uart_init();
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-11 07:52:51 +00:00
|
|
|
/* used when CONFIG_DISPLAY_CPUINFO is activated */
|
2020-02-12 18:37:43 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
2022-05-20 16:24:47 +00:00
|
|
|
u32 otp[3];
|
2018-05-17 13:24:07 +00:00
|
|
|
uchar enetaddr[6];
|
|
|
|
struct udevice *dev;
|
2022-05-20 16:24:47 +00:00
|
|
|
int nb_eth, nb_otp, index;
|
2018-05-17 13:24:07 +00:00
|
|
|
|
2021-10-11 07:52:51 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_NET))
|
|
|
|
return 0;
|
|
|
|
|
2022-05-20 16:24:47 +00:00
|
|
|
nb_eth = get_eth_nb();
|
|
|
|
|
|
|
|
/* 6 bytes for each MAC addr and 4 bytes for each OTP */
|
|
|
|
nb_otp = DIV_ROUND_UP(6 * nb_eth, 4);
|
2018-05-17 13:24:07 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-05-20 16:24:47 +00:00
|
|
|
ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp);
|
2018-11-06 22:21:39 +00:00
|
|
|
if (ret < 0)
|
2018-05-17 13:24:07 +00:00
|
|
|
return ret;
|
|
|
|
|
2022-05-20 16:24:47 +00:00
|
|
|
for (index = 0; index < nb_eth; index++) {
|
|
|
|
/* MAC already in environment */
|
|
|
|
if (eth_env_get_enetaddr_by_index("eth", index, enetaddr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
enetaddr[i] = ((uint8_t *)&otp)[i + 6 * index];
|
2018-05-17 13:24:07 +00:00
|
|
|
|
2022-05-20 16:24:47 +00:00
|
|
|
if (!is_valid_ethaddr(enetaddr)) {
|
|
|
|
log_err("invalid MAC address %d in OTP %pM\n",
|
|
|
|
index, enetaddr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
log_debug("OTP MAC address %d = %pM\n", index, enetaddr);
|
|
|
|
ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr);
|
|
|
|
if (ret) {
|
|
|
|
log_err("Failed to set mac address %pM from OTP: %d\n",
|
|
|
|
enetaddr, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2018-05-17 13:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:24:42 +00:00
|
|
|
__weak void stm32mp_misc_init(void)
|
2021-03-31 12:15:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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();
|
2022-05-20 16:24:42 +00:00
|
|
|
stm32mp_misc_init();
|
2018-03-20 09:54:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-01-12 17:58:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Without forcing the ".data" section, this would get saved in ".bss". BSS
|
|
|
|
* will be cleared soon after, so it's not suitable.
|
|
|
|
*/
|
|
|
|
static uintptr_t rom_api_table __section(".data");
|
|
|
|
static uintptr_t nt_fw_dtb __section(".data");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ROM gives us the API location in r0 when starting. This is only available
|
|
|
|
* during SPL, as there isn't (yet) a mechanism to pass this on to u-boot. Save
|
|
|
|
* the FDT address provided by TF-A in r2 at boot time. This function is called
|
|
|
|
* from start.S
|
|
|
|
*/
|
|
|
|
void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
|
|
|
|
unsigned long r3)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_STM32_ECDSA_VERIFY))
|
|
|
|
rom_api_table = r0;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_TFABOOT))
|
|
|
|
nt_fw_dtb = r2;
|
|
|
|
|
|
|
|
save_boot_params_ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t get_stm32mp_rom_api_table(void)
|
|
|
|
{
|
|
|
|
return rom_api_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t get_stm32mp_bl2_dtb(void)
|
|
|
|
{
|
|
|
|
return nt_fw_dtb;
|
|
|
|
}
|
2023-01-12 17:58:41 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
|
|
|
|
{
|
|
|
|
typedef void __noreturn (*image_entry_stm32_t)(u32 romapi);
|
|
|
|
uintptr_t romapi = get_stm32mp_rom_api_table();
|
|
|
|
|
|
|
|
image_entry_stm32_t image_entry =
|
|
|
|
(image_entry_stm32_t)spl_image->entry_point;
|
|
|
|
|
|
|
|
printf("image entry point: 0x%lx\n", spl_image->entry_point);
|
|
|
|
image_entry(romapi);
|
|
|
|
}
|
|
|
|
#endif
|