mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-24 08:01:21 +02:00
Rockchip BROM writes a boot source id at CFG_IRAM_BASE + 0x10, this id indicates from what storage media TPL/SPL was loaded from. SPL uses this id to determine what device "same-as-spl" represent when determining from where FIT should be loaded. This works as long as the boot_devices array contain a matching id <-> node path entry. However, SPL typically load a small part of TF-A into SRAM and on RK3399 this overwrites the CFG_IRAM_BASE + 0x10 addr used for boot source id. For affected devices the u-boot,spl-boot-device would not be set when booting from SPI flash and the flash@0 node was not explicitly listed in the u-boot,spl-boot-order prop. Here boot source id is 3 before FIT images is loaded, and 0 after: U-Boot SPL 2024.04-rc4 (Mar 15 2024 - 17:26:19 +0000) board_spl_was_booted_from: brom_bootdevice_id 3 maps to '/spi@ff1d0000/flash@0' Trying to boot from SPI ## Checking hash(es) for config config-1 ... OK ## Checking hash(es) for Image atf-1 ... sha256+ OK ## Checking hash(es) for Image u-boot ... sha256+ OK ## Checking hash(es) for Image fdt-1 ... sha256+ OK ## Checking hash(es) for Image atf-2 ... sha256+ OK ## Checking hash(es) for Image atf-3 ... sha256+ OK board_spl_was_booted_from: failed to resolve brom_bootdevice_id 0 spl_decode_boot_device: could not find udevice for /mmc@fe330000 spl_decode_boot_device: could not find udevice for /mmc@fe320000 spl_perform_fixups: could not map boot_device to ofpath: -19 Use a static brom_bootsource_id_cache to save the boot source id after an initial read from SRAM to fix this, this allow spl_perform_fixups() to resolve correct boot source path for "same-as-spl" after SPL have loaded TF-A related FIT images into memory. With this the spl-boot-device prop can correctly be resolved to the SPI flash node in the control FDT: => fdt addr ${fdtcontroladdr} Working FDT set to f1ee6710 => fdt list /chosen chosen { u-boot,spl-boot-device = "/spi@ff1d0000/flash@0"; stdout-path = "serial2:1500000n8"; u-boot,spl-boot-order = "same-as-spl", "/mmc@fe330000", "/mmc@fe320000"; }; Fixes: d57e16c7e712 ("rockchip: find U-boot proper boot device by inverting the logic that sets it") Signed-off-by: Jonas Karlman <jonas@kwiboo.se> Reviewed-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Dragan Simic <dsimic@manjaro.org>
164 lines
3.7 KiB
C
164 lines
3.7 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* (C) Copyright 2019 Rockchip Electronics Co., Ltd
|
|
*/
|
|
|
|
#include <cpu_func.h>
|
|
#include <debug_uart.h>
|
|
#include <dm.h>
|
|
#include <hang.h>
|
|
#include <image.h>
|
|
#include <init.h>
|
|
#include <log.h>
|
|
#include <ram.h>
|
|
#include <spl.h>
|
|
#include <asm/arch-rockchip/bootrom.h>
|
|
#include <asm/global_data.h>
|
|
#include <asm/io.h>
|
|
#include <linux/bitops.h>
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
int board_return_to_bootrom(struct spl_image_info *spl_image,
|
|
struct spl_boot_device *bootdev)
|
|
{
|
|
back_to_bootrom(BROM_BOOT_NEXTSTAGE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
__weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
|
|
};
|
|
|
|
const char *board_spl_was_booted_from(void)
|
|
{
|
|
static u32 brom_bootsource_id_cache = BROM_BOOTSOURCE_UNKNOWN;
|
|
u32 bootdevice_brom_id;
|
|
const char *bootdevice_ofpath = NULL;
|
|
|
|
if (brom_bootsource_id_cache != BROM_BOOTSOURCE_UNKNOWN)
|
|
bootdevice_brom_id = brom_bootsource_id_cache;
|
|
else
|
|
bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
|
|
|
|
if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
|
|
bootdevice_ofpath = boot_devices[bootdevice_brom_id];
|
|
|
|
if (bootdevice_ofpath) {
|
|
brom_bootsource_id_cache = bootdevice_brom_id;
|
|
debug("%s: brom_bootdevice_id %x maps to '%s'\n",
|
|
__func__, bootdevice_brom_id, bootdevice_ofpath);
|
|
} else {
|
|
debug("%s: failed to resolve brom_bootdevice_id %x\n",
|
|
__func__, bootdevice_brom_id);
|
|
}
|
|
|
|
return bootdevice_ofpath;
|
|
}
|
|
|
|
u32 spl_boot_device(void)
|
|
{
|
|
u32 boot_device = BOOT_DEVICE_MMC1;
|
|
|
|
#if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
|
|
defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
|
|
defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
|
|
defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) || \
|
|
defined(CONFIG_TARGET_CHROMEBOOK_BOB) || \
|
|
defined(CONFIG_TARGET_CHROMEBOOK_KEVIN)
|
|
return BOOT_DEVICE_SPI;
|
|
#endif
|
|
if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
|
|
return BOOT_DEVICE_BOOTROM;
|
|
|
|
return boot_device;
|
|
}
|
|
|
|
u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
|
|
{
|
|
return MMCSD_MODE_RAW;
|
|
}
|
|
|
|
#define TIMER_LOAD_COUNT_L 0x00
|
|
#define TIMER_LOAD_COUNT_H 0x04
|
|
#define TIMER_CONTROL_REG 0x10
|
|
#define TIMER_EN 0x1
|
|
#define TIMER_FMODE BIT(0)
|
|
#define TIMER_RMODE BIT(1)
|
|
|
|
__weak void rockchip_stimer_init(void)
|
|
{
|
|
#if defined(CONFIG_ROCKCHIP_STIMER_BASE)
|
|
/* If Timer already enabled, don't re-init it */
|
|
u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
|
|
|
|
if (reg & TIMER_EN)
|
|
return;
|
|
#ifndef CONFIG_ARM64
|
|
asm volatile("mcr p15, 0, %0, c14, c0, 0"
|
|
: : "r"(CONFIG_COUNTER_FREQUENCY));
|
|
#endif
|
|
writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
|
|
writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
|
|
writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
|
|
writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
|
|
TIMER_CONTROL_REG);
|
|
#endif
|
|
}
|
|
|
|
__weak int board_early_init_f(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
__weak int arch_cpu_init(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void board_init_f(ulong dummy)
|
|
{
|
|
int ret;
|
|
|
|
board_early_init_f();
|
|
|
|
ret = spl_early_init();
|
|
if (ret) {
|
|
printf("spl_early_init() failed: %d\n", ret);
|
|
hang();
|
|
}
|
|
arch_cpu_init();
|
|
|
|
rockchip_stimer_init();
|
|
|
|
#ifdef CONFIG_SYS_ARCH_TIMER
|
|
/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
|
|
timer_init();
|
|
#endif
|
|
#if !defined(CONFIG_TPL) || defined(CONFIG_SPL_RAM)
|
|
debug("\nspl:init dram\n");
|
|
ret = dram_init();
|
|
if (ret) {
|
|
printf("DRAM init failed: %d\n", ret);
|
|
return;
|
|
}
|
|
gd->ram_top = gd->ram_base + get_effective_memsize();
|
|
gd->ram_top = board_get_usable_ram_top(gd->ram_size);
|
|
|
|
if (IS_ENABLED(CONFIG_ARM64) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
|
|
gd->relocaddr = gd->ram_top;
|
|
arch_reserve_mmu();
|
|
enable_caches();
|
|
}
|
|
#endif
|
|
preloader_console_init();
|
|
}
|
|
|
|
void spl_board_prepare_for_boot(void)
|
|
{
|
|
if (!IS_ENABLED(CONFIG_ARM64) || CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
|
|
return;
|
|
|
|
cleanup_before_linux();
|
|
}
|