diff options
author | 2023-10-10 14:33:42 +0000 | |
---|---|---|
committer | 2023-10-10 14:33:42 +0000 | |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/u-boot/board/emulation | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/u-boot/board/emulation')
22 files changed, 1049 insertions, 0 deletions
diff --git a/roms/u-boot/board/emulation/Kconfig b/roms/u-boot/board/emulation/Kconfig new file mode 100644 index 000000000..f821458fa --- /dev/null +++ b/roms/u-boot/board/emulation/Kconfig @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> + +if VENDOR_EMULATION + +choice + prompt "Mainboard model" + +config TARGET_QEMU_X86 + bool "QEMU x86" + help + This is the QEMU emulated x86 board. U-Boot supports running + as a coreboot payload as well as bare boot without coreboot. + There are two types of x86 boards supported by QEMU which are + supported by U-Boot. They are via QEMU '-M pc', an i440FX/PIIX + chipset platform and '-M q35', a Q35/ICH9 chipset platform. + +config TARGET_QEMU_X86_64 + bool "QEMU x86 64-bit" + help + This is the QEMU emulated x86 64-bit board. With this config + U-Boot is built as a 64-bit binary. This allows testing while + this feature is being completed. + +endchoice + +source "board/emulation/qemu-x86/Kconfig" + +endif diff --git a/roms/u-boot/board/emulation/common/Kconfig b/roms/u-boot/board/emulation/common/Kconfig new file mode 100644 index 000000000..4c15c8bcb --- /dev/null +++ b/roms/u-boot/board/emulation/common/Kconfig @@ -0,0 +1,15 @@ +config MTDPARTS_NOR0 + string "mtd boot partition for nor0" + default "64m(u-boot)" if TARGET_QEMU_ARM_64BIT && !TFABOOT + depends on SYS_MTDPARTS_RUNTIME + help + This define the partition of nor0 used to build mtparts dynamically + for boot from nor0. + +config MTDPARTS_NOR1 + string "mtd u-boot env partition for nor1" + default "64m(u-boot-env)" if TARGET_QEMU_ARM_64BIT && !TFABOOT + depends on SYS_MTDPARTS_RUNTIME + help + This define the partition of nor1 used to build mtparts dynamically + for the u-boot env stored on nor1. diff --git a/roms/u-boot/board/emulation/common/Makefile b/roms/u-boot/board/emulation/common/Makefile new file mode 100644 index 000000000..7ed447a69 --- /dev/null +++ b/roms/u-boot/board/emulation/common/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += qemu_mtdparts.o +obj-$(CONFIG_SET_DFU_ALT_INFO) += qemu_dfu.o +obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) += qemu_capsule.o diff --git a/roms/u-boot/board/emulation/common/qemu_capsule.c b/roms/u-boot/board/emulation/common/qemu_capsule.c new file mode 100644 index 000000000..6b8a87022 --- /dev/null +++ b/roms/u-boot/board/emulation/common/qemu_capsule.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Linaro Limited + */ + +#include <common.h> +#include <efi_api.h> +#include <efi_loader.h> +#include <env.h> +#include <fdtdec.h> +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR; + +int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len) +{ + const void *fdt_blob = gd->fdt_blob; + const void *blob; + const char *cnode_name = "capsule-key"; + const char *snode_name = "signature"; + int sig_node; + int len; + + sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name); + if (sig_node < 0) { + EFI_PRINT("Unable to get signature node offset\n"); + return -FDT_ERR_NOTFOUND; + } + + blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len); + + if (!blob || len < 0) { + EFI_PRINT("Unable to get capsule-key value\n"); + *pkey = NULL; + *pkey_len = 0; + return -FDT_ERR_NOTFOUND; + } + + *pkey = (void *)blob; + *pkey_len = len; + + return 0; +} diff --git a/roms/u-boot/board/emulation/common/qemu_dfu.c b/roms/u-boot/board/emulation/common/qemu_dfu.c new file mode 100644 index 000000000..62234a764 --- /dev/null +++ b/roms/u-boot/board/emulation/common/qemu_dfu.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Linaro Limited + */ + +#include <common.h> +#include <dfu.h> +#include <env.h> +#include <memalign.h> +#include <mtd.h> + +#define DFU_ALT_BUF_LEN SZ_1K + +static void board_get_alt_info(struct mtd_info *mtd, char *buf) +{ + struct mtd_info *part; + bool first = true; + const char *name; + int len, partnum = 0; + + name = mtd->name; + len = strlen(buf); + + if (buf[0] != '\0') + len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&"); + len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, + "mtd %s=", name); + + list_for_each_entry(part, &mtd->partitions, node) { + partnum++; + if (!first) + len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";"); + first = false; + + len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, + "%s part %d", + part->name, partnum); + } +} + +void set_dfu_alt_info(char *interface, char *devstr) +{ + struct mtd_info *mtd; + + ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); + + if (env_get("dfu_alt_info")) + return; + + memset(buf, 0, sizeof(buf)); + + /* + * Currently dfu_alt_info is needed on Qemu ARM64 for + * capsule updates + */ + if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) && + IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) { + /* probe all MTD devices */ + mtd_probe_devices(); + + mtd = get_mtd_device_nm("nor0"); + if (!IS_ERR_OR_NULL(mtd)) + board_get_alt_info(mtd, buf); + } + + env_set("dfu_alt_info", buf); + printf("dfu_alt_info set\n"); +} diff --git a/roms/u-boot/board/emulation/common/qemu_mtdparts.c b/roms/u-boot/board/emulation/common/qemu_mtdparts.c new file mode 100644 index 000000000..60212e97a --- /dev/null +++ b/roms/u-boot/board/emulation/common/qemu_mtdparts.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Linaro Limited + */ + +#include <common.h> +#include <dm.h> +#include <mtd.h> + +#include <linux/string.h> + +#define MTDPARTS_LEN 256 +#define MTDIDS_LEN 128 + +static void board_get_mtdparts(const char *dev, const char *partition, + char *mtdids, char *mtdparts) +{ + /* mtdids: "<dev>=<dev>, ...." */ + if (mtdids[0] != '\0') + strcat(mtdids, ","); + strcat(mtdids, dev); + strcat(mtdids, "="); + strcat(mtdids, dev); + + /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */ + if (mtdparts[0] != '\0') + strncat(mtdparts, ";", MTDPARTS_LEN); + else + strcat(mtdparts, "mtdparts="); + + strncat(mtdparts, dev, MTDPARTS_LEN); + strncat(mtdparts, ":", MTDPARTS_LEN); + strncat(mtdparts, partition, MTDPARTS_LEN); +} + +void board_mtdparts_default(const char **mtdids, const char **mtdparts) +{ + struct mtd_info *mtd; + struct udevice *dev; + const char *mtd_partition; + static char parts[3 * MTDPARTS_LEN + 1]; + static char ids[MTDIDS_LEN + 1]; + static bool mtd_initialized; + + if (mtd_initialized) { + *mtdids = ids; + *mtdparts = parts; + return; + } + + memset(parts, 0, sizeof(parts)); + memset(ids, 0, sizeof(ids)); + + /* Currently mtdparts is needed on Qemu ARM64 for capsule updates */ + if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) && + IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) { + /* probe all MTD devices */ + for (uclass_first_device(UCLASS_MTD, &dev); dev; + uclass_next_device(&dev)) { + debug("mtd device = %s\n", dev->name); + } + + mtd = get_mtd_device_nm("nor0"); + if (!IS_ERR_OR_NULL(mtd)) { + mtd_partition = CONFIG_MTDPARTS_NOR0; + board_get_mtdparts("nor0", mtd_partition, ids, parts); + put_mtd_device(mtd); + } + + mtd = get_mtd_device_nm("nor1"); + if (!IS_ERR_OR_NULL(mtd)) { + mtd_partition = CONFIG_MTDPARTS_NOR1; + board_get_mtdparts("nor1", mtd_partition, ids, parts); + put_mtd_device(mtd); + } + } + + mtd_initialized = true; + *mtdids = ids; + *mtdparts = parts; + debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts); +} diff --git a/roms/u-boot/board/emulation/qemu-arm/Kconfig b/roms/u-boot/board/emulation/qemu-arm/Kconfig new file mode 100644 index 000000000..95dbefa78 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-arm/Kconfig @@ -0,0 +1,23 @@ +if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT + +config SYS_TEXT_BASE + default 0x00000000 + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + select CMD_QFW + select QFW_MMIO + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK + +endif + +if TARGET_QEMU_ARM_64BIT && !TFABOOT +config BOARD_SPECIFIC_OPTIONS + imply SYS_MTDPARTS_RUNTIME + imply SET_DFU_ALT_INFO + +source "board/emulation/common/Kconfig" +endif diff --git a/roms/u-boot/board/emulation/qemu-arm/MAINTAINERS b/roms/u-boot/board/emulation/qemu-arm/MAINTAINERS new file mode 100644 index 000000000..e757ffc64 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-arm/MAINTAINERS @@ -0,0 +1,7 @@ +QEMU ARM 'VIRT' BOARD +M: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi> +S: Maintained +F: board/emulation/qemu-arm/ +F: include/configs/qemu-arm.h +F: configs/qemu_arm_defconfig +F: configs/qemu_arm64_defconfig diff --git a/roms/u-boot/board/emulation/qemu-arm/Makefile b/roms/u-boot/board/emulation/qemu-arm/Makefile new file mode 100644 index 000000000..a22d1237f --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-arm/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += qemu-arm.o diff --git a/roms/u-boot/board/emulation/qemu-arm/qemu-arm.c b/roms/u-boot/board/emulation/qemu-arm/qemu-arm.c new file mode 100644 index 000000000..aa68bef46 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-arm/qemu-arm.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2017 Tuomas Tynkkynen + */ + +#include <common.h> +#include <cpu_func.h> +#include <dm.h> +#include <fdtdec.h> +#include <init.h> +#include <log.h> +#include <virtio_types.h> +#include <virtio.h> + +#ifdef CONFIG_ARM64 +#include <asm/armv8/mmu.h> + +static struct mm_region qemu_arm64_mem_map[] = { + { + /* Flash */ + .virt = 0x00000000UL, + .phys = 0x00000000UL, + .size = 0x08000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE + }, { + /* Lowmem peripherals */ + .virt = 0x08000000UL, + .phys = 0x08000000UL, + .size = 0x38000000, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + /* RAM */ + .virt = 0x40000000UL, + .phys = 0x40000000UL, + .size = 255UL * SZ_1G, + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE + }, { + /* Highmem PCI-E ECAM memory area */ + .virt = 0x4010000000ULL, + .phys = 0x4010000000ULL, + .size = 0x10000000, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + /* Highmem PCI-E MMIO memory area */ + .virt = 0x8000000000ULL, + .phys = 0x8000000000ULL, + .size = 0x8000000000ULL, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + /* List terminator */ + 0, + } +}; + +struct mm_region *mem_map = qemu_arm64_mem_map; +#endif + +int board_init(void) +{ + return 0; +} + +int board_late_init(void) +{ + /* + * Make sure virtio bus is enumerated so that peripherals + * on the virtio bus can be discovered by their drivers + */ + virtio_init(); + + return 0; +} + +int dram_init(void) +{ + if (fdtdec_setup_mem_size_base() != 0) + return -EINVAL; + + return 0; +} + +int dram_init_banksize(void) +{ + fdtdec_setup_memory_banksize(); + + return 0; +} + +void *board_fdt_blob_setup(void) +{ + /* QEMU loads a generated DTB for us at the start of RAM. */ + return (void *)CONFIG_SYS_SDRAM_BASE; +} + +void enable_caches(void) +{ + icache_enable(); + dcache_enable(); +} + +#if defined(CONFIG_EFI_RNG_PROTOCOL) +#include <efi_loader.h> +#include <efi_rng.h> + +#include <dm/device-internal.h> + +efi_status_t platform_get_rng_device(struct udevice **dev) +{ + int ret; + efi_status_t status = EFI_DEVICE_ERROR; + struct udevice *bus, *devp; + + for (uclass_first_device(UCLASS_VIRTIO, &bus); bus; + uclass_next_device(&bus)) { + for (device_find_first_child(bus, &devp); devp; + device_find_next_child(&devp)) { + if (device_get_uclass_id(devp) == UCLASS_RNG) { + *dev = devp; + status = EFI_SUCCESS; + break; + } + } + } + + if (status != EFI_SUCCESS) { + debug("No rng device found\n"); + return EFI_DEVICE_ERROR; + } + + if (*dev) { + ret = device_probe(*dev); + if (ret) + return EFI_DEVICE_ERROR; + } else { + debug("Couldn't get child device\n"); + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} +#endif /* CONFIG_EFI_RNG_PROTOCOL */ + +#ifdef CONFIG_ARM64 +#define __W "w" +#else +#define __W +#endif + +u8 flash_read8(void *addr) +{ + u8 ret; + + asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr)); + return ret; +} + +u16 flash_read16(void *addr) +{ + u16 ret; + + asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr)); + return ret; +} + +u32 flash_read32(void *addr) +{ + u32 ret; + + asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr)); + return ret; +} + +void flash_write8(u8 value, void *addr) +{ + asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value)); +} + +void flash_write16(u16 value, void *addr) +{ + asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value)); +} + +void flash_write32(u32 value, void *addr) +{ + asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value)); +} diff --git a/roms/u-boot/board/emulation/qemu-ppce500/Kconfig b/roms/u-boot/board/emulation/qemu-ppce500/Kconfig new file mode 100644 index 000000000..1c5aa18aa --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-ppce500/Kconfig @@ -0,0 +1,18 @@ +if TARGET_QEMU_PPCE500 + +config SYS_BOARD + default "qemu-ppce500" + +config SYS_VENDOR + default "emulation" + +config SYS_CONFIG_NAME + default "qemu-ppce500" + +config PLATFORM_BUS_MAP_ADDR + hex + default 0xf0000000 + help + The QEMU platform bus base mapped address in the virtual memory space. + +endif diff --git a/roms/u-boot/board/emulation/qemu-ppce500/MAINTAINERS b/roms/u-boot/board/emulation/qemu-ppce500/MAINTAINERS new file mode 100644 index 000000000..7317983d6 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-ppce500/MAINTAINERS @@ -0,0 +1,7 @@ +QEMU-PPCE500 BOARD +M: Alexander Graf <agraf@csgraf.de> +M: Bin Meng <bmeng.cn@gmail.com> +S: Maintained +F: board/emulation/qemu-ppce500/ +F: include/configs/qemu-ppce500.h +F: configs/qemu-ppce500_defconfig diff --git a/roms/u-boot/board/emulation/qemu-ppce500/Makefile b/roms/u-boot/board/emulation/qemu-ppce500/Makefile new file mode 100644 index 000000000..817d06d84 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-ppce500/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2007 Freescale Semiconductor, Inc. +# (C) Copyright 2001-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. + +obj-y += qemu-ppce500.o diff --git a/roms/u-boot/board/emulation/qemu-ppce500/qemu-ppce500.c b/roms/u-boot/board/emulation/qemu-ppce500/qemu-ppce500.c new file mode 100644 index 000000000..924cc02c4 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-ppce500/qemu-ppce500.c @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2007,2009-2014 Freescale Semiconductor, Inc. + * Copyright (C) 2021, Bin Meng <bmeng.cn@gmail.com> + */ + +#include <common.h> +#include <command.h> +#include <cpu_func.h> +#include <dm.h> +#include <env.h> +#include <init.h> +#include <log.h> +#include <net.h> +#include <pci.h> +#include <time.h> +#include <dm/simple_bus.h> +#include <dm/uclass-internal.h> +#include <asm/global_data.h> +#include <asm/processor.h> +#include <asm/mmu.h> +#include <asm/fsl_pci.h> +#include <asm/io.h> +#include <linux/libfdt.h> +#include <fdt_support.h> +#include <netdev.h> +#include <fdtdec.h> +#include <errno.h> +#include <malloc.h> +#include <virtio_types.h> +#include <virtio.h> + +DECLARE_GLOBAL_DATA_PTR; + +static void *get_fdt_virt(void) +{ + if (gd->flags & GD_FLG_RELOC) + return (void *)gd->fdt_blob; + else + return (void *)CONFIG_SYS_TMPVIRT; +} + +static uint64_t get_fdt_phys(void) +{ + return (uint64_t)(uintptr_t)gd->fdt_blob; +} + +static void map_fdt_as(int esel) +{ + u32 mas0, mas1, mas2, mas3, mas7; + uint64_t fdt_phys = get_fdt_phys(); + unsigned long fdt_phys_tlb = fdt_phys & ~0xffffful; + unsigned long fdt_virt_tlb = (ulong)get_fdt_virt() & ~0xffffful; + + mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(esel); + mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_1M); + mas2 = FSL_BOOKE_MAS2(fdt_virt_tlb, 0); + mas3 = FSL_BOOKE_MAS3(fdt_phys_tlb, 0, MAS3_SW|MAS3_SR); + mas7 = FSL_BOOKE_MAS7(fdt_phys_tlb); + + write_tlb(mas0, mas1, mas2, mas3, mas7); +} + +uint64_t get_phys_ccsrbar_addr_early(void) +{ + void *fdt = get_fdt_virt(); + uint64_t r; + int size, node; + u32 naddr; + const fdt32_t *prop; + + /* + * To be able to read the FDT we need to create a temporary TLB + * map for it. + */ + map_fdt_as(10); + node = fdt_path_offset(fdt, "/soc"); + naddr = fdt_address_cells(fdt, node); + prop = fdt_getprop(fdt, node, "ranges", &size); + r = fdt_translate_address(fdt, node, prop + naddr); + disable_tlb(10); + + return r; +} + +int checkboard(void) +{ + return 0; +} + +static int pci_map_region(phys_addr_t paddr, phys_size_t size, ulong *pmap_addr) +{ + ulong map_addr; + + if (!pmap_addr) + return 0; + + map_addr = *pmap_addr; + + /* Align map_addr */ + map_addr += size - 1; + map_addr &= ~(size - 1); + + if (map_addr + size >= CONFIG_SYS_PCI_MAP_END) + return -1; + + /* Map virtual memory for range */ + assert(!tlb_map_range(map_addr, paddr, size, TLB_MAP_IO)); + *pmap_addr = map_addr + size; + + return 0; +} + +static void platform_bus_map_region(ulong map_addr, phys_addr_t paddr, + phys_size_t size) +{ + /* Align map_addr */ + map_addr += size - 1; + map_addr &= ~(size - 1); + + /* Map virtual memory for range */ + assert(!tlb_map_range(map_addr, paddr, size, TLB_MAP_IO)); +} + +int misc_init_r(void) +{ + struct udevice *dev; + struct pci_region *io; + struct pci_region *mem; + struct pci_region *pre; + ulong map_addr; + int ret; + + /* Ensure PCI is probed */ + uclass_first_device(UCLASS_PCI, &dev); + + pci_get_regions(dev, &io, &mem, &pre); + + /* Start MMIO and PIO range maps above RAM */ + map_addr = CONFIG_SYS_PCI_MAP_START; + + /* Map MMIO range */ + ret = pci_map_region(mem->phys_start, mem->size, &map_addr); + if (ret) + return ret; + + /* Map PIO range */ + ret = pci_map_region(io->phys_start, io->size, &map_addr); + if (ret) + return ret; + + /* + * Make sure virtio bus is enumerated so that peripherals + * on the virtio bus can be discovered by their drivers. + */ + virtio_init(); + + /* + * U-Boot is relocated to RAM already, let's delete the temporary FDT + * virtual-physical mapping that was used in the pre-relocation phase. + */ + disable_tlb(find_tlb_idx((void *)CONFIG_SYS_TMPVIRT, 1)); + + /* + * Detect the presence of the platform bus node, and + * create a virtual memory mapping for it. + */ + for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev); + dev; + ret = uclass_find_next_device(&dev)) { + if (device_is_compatible(dev, "qemu,platform")) { + struct simple_bus_plat *plat = dev_get_uclass_plat(dev); + + platform_bus_map_region(CONFIG_PLATFORM_BUS_MAP_ADDR, + plat->target, plat->size); + break; + } + } + + return 0; +} + +int last_stage_init(void) +{ + void *fdt = get_fdt_virt(); + int len = 0; + const uint64_t *prop; + int chosen; + + chosen = fdt_path_offset(fdt, "/chosen"); + if (chosen < 0) { + printf("Couldn't find /chosen node in fdt\n"); + return -EIO; + } + + /* -kernel boot */ + prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len); + if (prop && (len >= 8)) + env_set_hex("qemu_kernel_addr", *prop); + + return 0; +} + +static uint64_t get_linear_ram_size(void) +{ + void *fdt = get_fdt_virt(); + const void *prop; + int memory; + int len; + + memory = fdt_path_offset(fdt, "/memory"); + prop = fdt_getprop(fdt, memory, "reg", &len); + + if (prop && len >= 16) + return *(uint64_t *)(prop+8); + + panic("Couldn't determine RAM size"); +} + +phys_size_t fsl_ddr_sdram_size(void) +{ + return get_linear_ram_size(); +} + +void init_tlbs(void) +{ + phys_size_t ram_size; + + /* + * Create a temporary AS=1 map for the fdt + * + * We use ESEL=0 here to overwrite the previous AS=0 map for ourselves + * which was only 4k big. This way we don't have to clear any other maps. + */ + map_fdt_as(0); + + /* Fetch RAM size from the fdt */ + ram_size = get_linear_ram_size(); + + /* And remove our fdt map again */ + disable_tlb(0); + + /* Create an internal map of manually created TLB maps */ + init_used_tlb_cams(); + + /* Create a dynamic AS=0 CCSRBAR mapping */ + assert(!tlb_map_range(CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS, + 1024 * 1024, TLB_MAP_IO)); + + /* Create a RAM map that spans all accessible RAM */ + setup_ddr_tlbs(ram_size >> 20); + + /* Create a map for the TLB */ + assert(!tlb_map_range((ulong)get_fdt_virt(), get_fdt_phys(), + 1024 * 1024, TLB_MAP_RAM)); +} + +static uint32_t get_cpu_freq(void) +{ + void *fdt = get_fdt_virt(); + int cpus_node = fdt_path_offset(fdt, "/cpus"); + int cpu_node = fdt_first_subnode(fdt, cpus_node); + const char *prop = "clock-frequency"; + return fdt_getprop_u32_default_node(fdt, cpu_node, 0, prop, 0); +} + +void get_sys_info(sys_info_t *sys_info) +{ + int freq = get_cpu_freq(); + + memset(sys_info, 0, sizeof(sys_info_t)); + sys_info->freq_systembus = freq; + sys_info->freq_ddrbus = freq; + sys_info->freq_processor[0] = freq; +} + +int get_clocks(void) +{ + sys_info_t sys_info; + + get_sys_info(&sys_info); + + gd->cpu_clk = sys_info.freq_processor[0]; + gd->bus_clk = sys_info.freq_systembus; + gd->mem_clk = sys_info.freq_ddrbus; + gd->arch.lbc_clk = sys_info.freq_ddrbus; + + return 0; +} + +unsigned long get_tbclk(void) +{ + void *fdt = get_fdt_virt(); + int cpus_node = fdt_path_offset(fdt, "/cpus"); + int cpu_node = fdt_first_subnode(fdt, cpus_node); + const char *prop = "timebase-frequency"; + return fdt_getprop_u32_default_node(fdt, cpu_node, 0, prop, 0); +} + +/******************************************** + * get_bus_freq + * return system bus freq in Hz + *********************************************/ +ulong get_bus_freq(ulong dummy) +{ + sys_info_t sys_info; + get_sys_info(&sys_info); + return sys_info.freq_systembus; +} + +/* + * Return the number of cores on this SOC. + */ +int cpu_numcores(void) +{ + /* + * The QEMU u-boot target only needs to drive the first core, + * spinning and device tree nodes get driven by QEMU itself + */ + return 1; +} + +/* + * Return a 32-bit mask indicating which cores are present on this SOC. + */ +u32 cpu_mask(void) +{ + return (1 << cpu_numcores()) - 1; +} + +/** + * Return the virtual address of FDT that was passed by QEMU + * + * @return virtual address of FDT received from QEMU in r3 register + */ +void *board_fdt_blob_setup(void) +{ + return get_fdt_virt(); +} + +/* See CONFIG_SYS_NS16550_CLK in arch/powerpc/include/asm/config.h */ +int get_serial_clock(void) +{ + return get_bus_freq(0); +} diff --git a/roms/u-boot/board/emulation/qemu-riscv/Kconfig b/roms/u-boot/board/emulation/qemu-riscv/Kconfig new file mode 100644 index 000000000..0818048ba --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-riscv/Kconfig @@ -0,0 +1,68 @@ +if TARGET_QEMU_VIRT + +config SYS_BOARD + default "qemu-riscv" + +config SYS_VENDOR + default "emulation" + +config SYS_CPU + default "generic" + +config SYS_CONFIG_NAME + default "qemu-riscv" + +config SYS_TEXT_BASE + default 0x81200000 if SPL + default 0x80000000 if !RISCV_SMODE + default 0x80200000 if RISCV_SMODE && ARCH_RV64I + default 0x80400000 if RISCV_SMODE && ARCH_RV32I + +config SPL_TEXT_BASE + default 0x80000000 + +config SPL_OPENSBI_LOAD_ADDR + hex + default 0x81000000 + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + select GENERIC_RISCV + select SUPPORT_SPL + imply AHCI + imply SMP + imply BOARD_LATE_INIT + imply PCI_INIT_R + imply SPL_RAM_SUPPORT + imply SPL_RAM_DEVICE + imply CMD_PCI + imply CMD_POWEROFF + imply CMD_SCSI + imply CMD_PING + imply CMD_EXT2 + imply CMD_EXT4 + imply CMD_FAT + imply CMD_FS_GENERIC + imply DOS_PARTITION + imply ISO_PARTITION + imply EFI_PARTITION + imply SCSI_AHCI + imply AHCI_PCI + imply E1000 + imply NVME + imply PCI + imply DM_PCI + imply PCIE_ECAM_GENERIC + imply SCSI + imply DM_SCSI + imply SYS_NS16550 + imply SIFIVE_SERIAL + imply SYSRESET + imply SYSRESET_CMD_POWEROFF + imply SYSRESET_SYSCON + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK + +endif diff --git a/roms/u-boot/board/emulation/qemu-riscv/MAINTAINERS b/roms/u-boot/board/emulation/qemu-riscv/MAINTAINERS new file mode 100644 index 000000000..78969ed6b --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-riscv/MAINTAINERS @@ -0,0 +1,11 @@ +QEMU RISC-V 'VIRT' BOARD +M: Bin Meng <bmeng.cn@gmail.com> +S: Maintained +F: board/emulation/qemu-riscv/ +F: include/configs/qemu-riscv.h +F: configs/qemu-riscv32_defconfig +F: configs/qemu-riscv32_smode_defconfig +F: configs/qemu-riscv32_spl_defconfig +F: configs/qemu-riscv64_defconfig +F: configs/qemu-riscv64_smode_defconfig +F: configs/qemu-riscv64_spl_defconfig diff --git a/roms/u-boot/board/emulation/qemu-riscv/Makefile b/roms/u-boot/board/emulation/qemu-riscv/Makefile new file mode 100644 index 000000000..3f29b90a4 --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-riscv/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> + +obj-y += qemu-riscv.o diff --git a/roms/u-boot/board/emulation/qemu-riscv/qemu-riscv.c b/roms/u-boot/board/emulation/qemu-riscv/qemu-riscv.c new file mode 100644 index 000000000..dcfd3f20b --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-riscv/qemu-riscv.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> + */ + +#include <common.h> +#include <dm.h> +#include <env.h> +#include <fdtdec.h> +#include <image.h> +#include <log.h> +#include <spl.h> +#include <init.h> +#include <virtio_types.h> +#include <virtio.h> + +int board_init(void) +{ + /* + * Make sure virtio bus is enumerated so that peripherals + * on the virtio bus can be discovered by their drivers + */ + virtio_init(); + + return 0; +} + +int board_late_init(void) +{ + ulong kernel_start; + ofnode chosen_node; + int ret; + + chosen_node = ofnode_path("/chosen"); + if (!ofnode_valid(chosen_node)) { + debug("No chosen node found, can't get kernel start address\n"); + return 0; + } + +#ifdef CONFIG_ARCH_RV64I + ret = ofnode_read_u64(chosen_node, "riscv,kernel-start", + (u64 *)&kernel_start); +#else + ret = ofnode_read_u32(chosen_node, "riscv,kernel-start", + (u32 *)&kernel_start); +#endif + if (ret) { + debug("Can't find kernel start address in device tree\n"); + return 0; + } + + env_set_hex("kernel_start", kernel_start); + + return 0; +} + +#ifdef CONFIG_SPL +u32 spl_boot_device(void) +{ + /* RISC-V QEMU only supports RAM as SPL boot device */ + return BOOT_DEVICE_RAM; +} +#endif + +#ifdef CONFIG_SPL_LOAD_FIT +int board_fit_config_name_match(const char *name) +{ + /* boot using first FIT config */ + return 0; +} +#endif diff --git a/roms/u-boot/board/emulation/qemu-x86/Kconfig b/roms/u-boot/board/emulation/qemu-x86/Kconfig new file mode 100644 index 000000000..9bb8a726e --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-x86/Kconfig @@ -0,0 +1,29 @@ +if TARGET_QEMU_X86 || TARGET_QEMU_X86_64 + +config SYS_BOARD + default "qemu-x86" + +config SYS_VENDOR + default "emulation" + +config SYS_SOC + default "qemu" + +config SYS_CONFIG_NAME + default "qemu-x86" + +config SYS_TEXT_BASE + default 0xfff00000 if !SUPPORT_SPL + default 0x01110000 if SUPPORT_SPL + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + select X86_RESET_VECTOR + select QEMU + select QFW_PIO + select BOARD_ROMSIZE_KB_1024 + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK + +endif diff --git a/roms/u-boot/board/emulation/qemu-x86/MAINTAINERS b/roms/u-boot/board/emulation/qemu-x86/MAINTAINERS new file mode 100644 index 000000000..9a99d38ca --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-x86/MAINTAINERS @@ -0,0 +1,13 @@ +QEMU X86 BOARD +M: Bin Meng <bmeng.cn@gmail.com> +S: Maintained +F: board/emulation/qemu-x86/ +F: include/configs/qemu-x86.h +F: configs/qemu-x86_defconfig + +QEMU X86 64-bit BOARD +M: Bin Meng <bmeng.cn@gmail.com> +S: Maintained +F: board/emulation/qemu-x86/ +F: include/configs/qemu-x86.h +F: configs/qemu-x86_64_defconfig diff --git a/roms/u-boot/board/emulation/qemu-x86/Makefile b/roms/u-boot/board/emulation/qemu-x86/Makefile new file mode 100644 index 000000000..ff4aaa51c --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-x86/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> + +obj-y += qemu-x86.o diff --git a/roms/u-boot/board/emulation/qemu-x86/qemu-x86.c b/roms/u-boot/board/emulation/qemu-x86/qemu-x86.c new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/roms/u-boot/board/emulation/qemu-x86/qemu-x86.c |