u-boot/board/armltd/vexpress64/vexpress64.c

228 lines
5 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2013
* David Feng <fenghua@phytium.com.cn>
* Sharma Bhupesh <bhupesh.sharma@freescale.com>
*/
#include <common.h>
#include <cpu_func.h>
#include <dm.h>
#include <init.h>
#include <malloc.h>
#include <errno.h>
#include <net.h>
#include <netdev.h>
#include <asm/global_data.h>
#include <asm/io.h>
#include <linux/compiler.h>
#include <linux/sizes.h>
#include <dm/platform_data/serial_pl01x.h>
#include "pcie.h"
#include <asm/armv8/mmu.h>
#ifdef CONFIG_VIRTIO_NET
#include <virtio_types.h>
#include <virtio.h>
#endif
DECLARE_GLOBAL_DATA_PTR;
static const struct pl01x_serial_plat serial_plat = {
.base = V2M_UART0,
.type = TYPE_PL011,
.clock = CFG_PL011_CLOCK,
};
U_BOOT_DRVINFO(vexpress_serials) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
static struct mm_region vexpress64_mem_map[] = {
{
.virt = V2M_PA_BASE,
.phys = V2M_PA_BASE,
.size = SZ_2G,
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
PTE_BLOCK_NON_SHARE |
PTE_BLOCK_PXN | PTE_BLOCK_UXN
}, {
.virt = V2M_DRAM_BASE,
.phys = V2M_DRAM_BASE,
.size = SZ_2G,
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_INNER_SHARE
}, {
/*
* DRAM beyond 2 GiB is located high. Let's map just some
* of it, although U-Boot won't realistically use it, and
* the actual available amount might be smaller on the model.
*/
.virt = 0x880000000UL, /* 32 + 2 GiB */
.phys = 0x880000000UL,
.size = 6UL * SZ_1G,
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_INNER_SHARE
}, {
/* List terminator */
0,
}
};
struct mm_region *mem_map = vexpress64_mem_map;
/* This function gets replaced by platforms supporting PCIe.
* The replacement function, eg. on Juno, initialises the PCIe bus.
*/
__weak void vexpress64_pcie_init(void)
{
}
int board_init(void)
{
vexpress64_pcie_init();
#ifdef CONFIG_VIRTIO_NET
virtio_init();
#endif
return 0;
}
int dram_init(void)
{
return fdtdec_setup_mem_size_base();
}
int dram_init_banksize(void)
{
return fdtdec_setup_memory_banksize();
}
/* Assigned in lowlevel_init.S
* Push the variable into the .data section so that it
* does not get cleared later.
*/
vexpress64: also consider DTB pointer in x1 Commit c0fce929564f("vexpress64: fvp: enable OF_CONTROL") added code to consider a potential DTB address being passed in the x0 register, or revert to the built-in DTB otherwise. The former case was used when using the boot-wrapper, to which we sell U-Boot as a Linux kernel. The latter was meant for TF-A, for which we couldn't find an easy way to use the DTB it uses itself. We have some quirk to filter for a valid DTB, as TF-A happens to pass a pointer to some special devicetree blob in x0 as well. Now the TF-A case is broken, when enabling proper emulation of secure memory (-C bp.secure_memory=1). TF-A carves out some memory at the top of the first DRAM bank for its own purposes, and configures the TrustZone DRAM controller to make this region secure-only. U-Boot will then hang when it tries to relocate itself exactly to the end of DRAM. TF-A announces this by carving out that region of the /memory node, in the DT it passes on to BL33 in x1, but we miss that so far. Instead of repeating this carveout in our DT copy, let's try to look for a DTB at the address x1 points to as well. This will let U-Boot pick up the DTB provided by TF-A, which has the correct carveout in place, avoiding the hang. While we are at it, make the detection more robust: the length test (is the DT larger than 256 bytes?) is too fragile, in fact the TF-A port for a new FVP model already exceeds this. So we test x1 first, consider 0 an invalid address, and also require a /memory node to detect a valid DTB. And for the records: Some asking around revealed what is really going on with TF-A and that ominous DTB pointer in x0: TF-A expects EDK-2 as its non-secure payload (BL33), and there apparently was some long-standing ad-hoc boot protocol defined just between the two: x0 would carry the MPIDR register value of the boot CPU, and the hardware DTB address would be stored in x1. Now the MPIDR of CPU 0 is typically 0, plus bit 31 set, which is defined as RES1 in the ARMv7 and ARMv8 architectures. This gives 0x80000000, which is the same value as the address of the beginning of DRAM (2GB). And coincidentally TF-A put some DTB structure exactly there, for its own purposes (passing it between stages). So U-Boot was trying to use this DTB, which requires the quirk to check for its validity. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Tested-by: Peter Hoyes <peter.hoyes@arm.com>
2022-09-21 17:09:46 +00:00
unsigned long __section(".data") prior_stage_fdt_address[2];
#ifdef CONFIG_OF_BOARD
#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
#define JUNO_FLASH_SEC_SIZE (256 * 1024)
static phys_addr_t find_dtb_in_nor_flash(const char *partname)
{
phys_addr_t sector = CFG_SYS_FLASH_BASE;
int i;
for (i = 0;
i < CONFIG_SYS_MAX_FLASH_SECT;
i++, sector += JUNO_FLASH_SEC_SIZE) {
int len = strlen(partname) + 1;
int offs;
phys_addr_t imginfo;
u32 reg;
reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x04);
/* This makes up the string "HSLFTOOF" flash footer */
if (reg != 0x464F4F54U)
continue;
reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x08);
if (reg != 0x464C5348U)
continue;
for (offs = 0; offs < 32; offs += 4, len -= 4) {
reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x30 + offs);
if (strncmp(partname + offs, (char *)&reg,
len > 4 ? 4 : len))
break;
if (len > 4)
continue;
reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x10);
imginfo = sector + JUNO_FLASH_SEC_SIZE - 0x30 - reg;
reg = readl(imginfo + 0x54);
return CFG_SYS_FLASH_BASE +
reg * JUNO_FLASH_SEC_SIZE;
}
}
printf("No DTB found\n");
return ~0;
}
#endif
vexpress64: also consider DTB pointer in x1 Commit c0fce929564f("vexpress64: fvp: enable OF_CONTROL") added code to consider a potential DTB address being passed in the x0 register, or revert to the built-in DTB otherwise. The former case was used when using the boot-wrapper, to which we sell U-Boot as a Linux kernel. The latter was meant for TF-A, for which we couldn't find an easy way to use the DTB it uses itself. We have some quirk to filter for a valid DTB, as TF-A happens to pass a pointer to some special devicetree blob in x0 as well. Now the TF-A case is broken, when enabling proper emulation of secure memory (-C bp.secure_memory=1). TF-A carves out some memory at the top of the first DRAM bank for its own purposes, and configures the TrustZone DRAM controller to make this region secure-only. U-Boot will then hang when it tries to relocate itself exactly to the end of DRAM. TF-A announces this by carving out that region of the /memory node, in the DT it passes on to BL33 in x1, but we miss that so far. Instead of repeating this carveout in our DT copy, let's try to look for a DTB at the address x1 points to as well. This will let U-Boot pick up the DTB provided by TF-A, which has the correct carveout in place, avoiding the hang. While we are at it, make the detection more robust: the length test (is the DT larger than 256 bytes?) is too fragile, in fact the TF-A port for a new FVP model already exceeds this. So we test x1 first, consider 0 an invalid address, and also require a /memory node to detect a valid DTB. And for the records: Some asking around revealed what is really going on with TF-A and that ominous DTB pointer in x0: TF-A expects EDK-2 as its non-secure payload (BL33), and there apparently was some long-standing ad-hoc boot protocol defined just between the two: x0 would carry the MPIDR register value of the boot CPU, and the hardware DTB address would be stored in x1. Now the MPIDR of CPU 0 is typically 0, plus bit 31 set, which is defined as RES1 in the ARMv7 and ARMv8 architectures. This gives 0x80000000, which is the same value as the address of the beginning of DRAM (2GB). And coincidentally TF-A put some DTB structure exactly there, for its own purposes (passing it between stages). So U-Boot was trying to use this DTB, which requires the quirk to check for its validity. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Tested-by: Peter Hoyes <peter.hoyes@arm.com>
2022-09-21 17:09:46 +00:00
/*
* Filter for a valid DTB, as TF-A happens to provide a pointer to some
* data structure using the DTB format, which we cannot use.
* The address of the DTB cannot be 0, in fact this is the reserved value
* for x1 in the kernel boot protocol.
* And while the nt_fw_config.dtb used by TF-A is a valid DTB structure, it
* does not contain the typical nodes and properties, which we test for by
* probing for the mandatory /memory node.
*/
static bool is_valid_dtb(uintptr_t dtb_ptr)
{
if (dtb_ptr == 0 || fdt_magic(dtb_ptr) != FDT_MAGIC)
return false;
return fdt_subnode_offset((void *)dtb_ptr, 0, "memory") >= 0;
}
void *board_fdt_blob_setup(int *err)
{
#ifdef CONFIG_TARGET_VEXPRESS64_JUNO
phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART);
*err = 0;
if (fdt_rom_addr == ~0UL) {
*err = -ENXIO;
return NULL;
}
return (void *)fdt_rom_addr;
#endif
#ifdef VEXPRESS_FDT_ADDR
if (fdt_magic(VEXPRESS_FDT_ADDR) == FDT_MAGIC) {
*err = 0;
return (void *)VEXPRESS_FDT_ADDR;
}
#endif
vexpress64: also consider DTB pointer in x1 Commit c0fce929564f("vexpress64: fvp: enable OF_CONTROL") added code to consider a potential DTB address being passed in the x0 register, or revert to the built-in DTB otherwise. The former case was used when using the boot-wrapper, to which we sell U-Boot as a Linux kernel. The latter was meant for TF-A, for which we couldn't find an easy way to use the DTB it uses itself. We have some quirk to filter for a valid DTB, as TF-A happens to pass a pointer to some special devicetree blob in x0 as well. Now the TF-A case is broken, when enabling proper emulation of secure memory (-C bp.secure_memory=1). TF-A carves out some memory at the top of the first DRAM bank for its own purposes, and configures the TrustZone DRAM controller to make this region secure-only. U-Boot will then hang when it tries to relocate itself exactly to the end of DRAM. TF-A announces this by carving out that region of the /memory node, in the DT it passes on to BL33 in x1, but we miss that so far. Instead of repeating this carveout in our DT copy, let's try to look for a DTB at the address x1 points to as well. This will let U-Boot pick up the DTB provided by TF-A, which has the correct carveout in place, avoiding the hang. While we are at it, make the detection more robust: the length test (is the DT larger than 256 bytes?) is too fragile, in fact the TF-A port for a new FVP model already exceeds this. So we test x1 first, consider 0 an invalid address, and also require a /memory node to detect a valid DTB. And for the records: Some asking around revealed what is really going on with TF-A and that ominous DTB pointer in x0: TF-A expects EDK-2 as its non-secure payload (BL33), and there apparently was some long-standing ad-hoc boot protocol defined just between the two: x0 would carry the MPIDR register value of the boot CPU, and the hardware DTB address would be stored in x1. Now the MPIDR of CPU 0 is typically 0, plus bit 31 set, which is defined as RES1 in the ARMv7 and ARMv8 architectures. This gives 0x80000000, which is the same value as the address of the beginning of DRAM (2GB). And coincidentally TF-A put some DTB structure exactly there, for its own purposes (passing it between stages). So U-Boot was trying to use this DTB, which requires the quirk to check for its validity. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Tested-by: Peter Hoyes <peter.hoyes@arm.com>
2022-09-21 17:09:46 +00:00
if (is_valid_dtb(prior_stage_fdt_address[1])) {
*err = 0;
return (void *)prior_stage_fdt_address[1];
} else if (is_valid_dtb(prior_stage_fdt_address[0])) {
*err = 0;
vexpress64: also consider DTB pointer in x1 Commit c0fce929564f("vexpress64: fvp: enable OF_CONTROL") added code to consider a potential DTB address being passed in the x0 register, or revert to the built-in DTB otherwise. The former case was used when using the boot-wrapper, to which we sell U-Boot as a Linux kernel. The latter was meant for TF-A, for which we couldn't find an easy way to use the DTB it uses itself. We have some quirk to filter for a valid DTB, as TF-A happens to pass a pointer to some special devicetree blob in x0 as well. Now the TF-A case is broken, when enabling proper emulation of secure memory (-C bp.secure_memory=1). TF-A carves out some memory at the top of the first DRAM bank for its own purposes, and configures the TrustZone DRAM controller to make this region secure-only. U-Boot will then hang when it tries to relocate itself exactly to the end of DRAM. TF-A announces this by carving out that region of the /memory node, in the DT it passes on to BL33 in x1, but we miss that so far. Instead of repeating this carveout in our DT copy, let's try to look for a DTB at the address x1 points to as well. This will let U-Boot pick up the DTB provided by TF-A, which has the correct carveout in place, avoiding the hang. While we are at it, make the detection more robust: the length test (is the DT larger than 256 bytes?) is too fragile, in fact the TF-A port for a new FVP model already exceeds this. So we test x1 first, consider 0 an invalid address, and also require a /memory node to detect a valid DTB. And for the records: Some asking around revealed what is really going on with TF-A and that ominous DTB pointer in x0: TF-A expects EDK-2 as its non-secure payload (BL33), and there apparently was some long-standing ad-hoc boot protocol defined just between the two: x0 would carry the MPIDR register value of the boot CPU, and the hardware DTB address would be stored in x1. Now the MPIDR of CPU 0 is typically 0, plus bit 31 set, which is defined as RES1 in the ARMv7 and ARMv8 architectures. This gives 0x80000000, which is the same value as the address of the beginning of DRAM (2GB). And coincidentally TF-A put some DTB structure exactly there, for its own purposes (passing it between stages). So U-Boot was trying to use this DTB, which requires the quirk to check for its validity. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Tested-by: Peter Hoyes <peter.hoyes@arm.com>
2022-09-21 17:09:46 +00:00
return (void *)prior_stage_fdt_address[0];
}
if (fdt_magic(gd->fdt_blob) == FDT_MAGIC) {
*err = 0;
return (void *)gd->fdt_blob;
}
*err = -ENXIO;
return NULL;
}
#endif
/* Actual reset is done via PSCI. */
void reset_cpu(void)
{
}
/*
* Board specific ethernet initialization routine.
*/
int board_eth_init(struct bd_info *bis)
{
int rc = 0;
#ifndef CONFIG_DM_ETH
#ifdef CONFIG_SMC911X
rc = smc911x_initialize(0, CFG_SMC911X_BASE);
#endif
#endif
return rc;
}