Yet another generic QEMU VIRT machine. QEMU placed FDT in memory before launching U-Boot, so we can just obtian FDT here.
Signed-off-by: Jiaxun Yang <jiaxun.y...@flygoat.com> --- arch/loongarch/Kconfig | 5 ++ arch/loongarch/dts/qemu-loongarch64.dts | 9 +++ board/emulation/qemu-loongarch/Kconfig | 68 ++++++++++++++++++ board/emulation/qemu-loongarch/MAINTAINERS | 7 ++ board/emulation/qemu-loongarch/Makefile | 6 ++ board/emulation/qemu-loongarch/qemu-loongarch.c | 84 +++++++++++++++++++++++ board/emulation/qemu-loongarch/qemu-loongarch.env | 6 ++ configs/qemu-loongarch64_defconfig | 36 ++++++++++ include/configs/qemu-loongarch.h | 13 ++++ 9 files changed, 234 insertions(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 5254afb2cd05..6cf7ad9b3a4f 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -7,9 +7,14 @@ config SYS_ARCH choice prompt "Target select" +config TARGET_QEMU_LOONGARCH_VIRT + bool "Support QEMU Virt Board" + select BOARD_LATE_INIT + endchoice # board-specific options below +source "board/emulation/qemu-loongarch/Kconfig" # platform-specific options below source "arch/loongarch/cpu/generic/Kconfig" diff --git a/arch/loongarch/dts/qemu-loongarch64.dts b/arch/loongarch/dts/qemu-loongarch64.dts new file mode 100644 index 000000000000..39d303798fcb --- /dev/null +++ b/arch/loongarch/dts/qemu-loongarch64.dts @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 Jiaxun Yang <jiaxun.y...@flygoat.com> + */ + +/dts-v1/; + +/ { +}; diff --git a/board/emulation/qemu-loongarch/Kconfig b/board/emulation/qemu-loongarch/Kconfig new file mode 100644 index 000000000000..188cd6967bfd --- /dev/null +++ b/board/emulation/qemu-loongarch/Kconfig @@ -0,0 +1,68 @@ +if TARGET_QEMU_LOONGARCH_VIRT + +config SYS_BOARD + default "qemu-loongarch" + +config SYS_VENDOR + default "emulation" + +config SYS_CPU + default "generic" + +config SYS_CONFIG_NAME + default "qemu-loongarch" + +config TEXT_BASE + default 0x1c000000 + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + select GENERIC_LOONGARCH + imply AHCI + imply BOARD_LATE_INIT + imply PCI_INIT_R + 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 PCI + imply NVME_PCI + imply PCIE_ECAM_GENERIC + imply DM_RNG + imply DM_RTC + imply QFW + imply QFW_MMIO + imply SCSI + imply SYS_NS16550 + imply SYSRESET + imply SYSRESET_CMD_POWEROFF + imply SYSRESET_SYSCON + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK + imply MTD_NOR_FLASH + imply CFI_FLASH + imply OF_HAS_PRIOR_STAGE + imply VIDEO + imply VIDEO_BOCHS + imply SYS_WHITE_ON_BLACK + imply USB + imply USB_XHCI_HCD + imply USB_XHCI_PCI + imply USB_KEYBOARD + imply CMD_USB + imply UFS + imply UFS_PCI + +endif diff --git a/board/emulation/qemu-loongarch/MAINTAINERS b/board/emulation/qemu-loongarch/MAINTAINERS new file mode 100644 index 000000000000..0ecd8201fb96 --- /dev/null +++ b/board/emulation/qemu-loongarch/MAINTAINERS @@ -0,0 +1,7 @@ +QEMU LOONGARCH 'VIRT' BOARD +M: Jiaxun Yang <jiaxun.y...@flygoat.com> +S: Maintained +F: board/emulation/qemu-loongarch/ +F: board/emulation/common/ +F: include/configs/qemu-loongarch.h +F: configs/qemu-loongarch64_defconfig diff --git a/board/emulation/qemu-loongarch/Makefile b/board/emulation/qemu-loongarch/Makefile new file mode 100644 index 000000000000..a928b90780e9 --- /dev/null +++ b/board/emulation/qemu-loongarch/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2024 Jiaxun yang <jiaxun.y...@flygoat.com> +# + +obj-y += qemu-loongarch.o diff --git a/board/emulation/qemu-loongarch/qemu-loongarch.c b/board/emulation/qemu-loongarch/qemu-loongarch.c new file mode 100644 index 000000000000..5cedd2c7479e --- /dev/null +++ b/board/emulation/qemu-loongarch/qemu-loongarch.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 Jiaxun Yang <jiaxun.y...@flygoat.com> + */ + +#include <dm.h> +#include <dm/ofnode.h> +#include <env.h> +#include <fdtdec.h> +#include <image.h> +#include <lmb.h> +#include <log.h> +#include <spl.h> +#include <init.h> +#include <usb.h> +#include <virtio_types.h> +#include <virtio.h> + +DECLARE_GLOBAL_DATA_PTR; + +#if IS_ENABLED(CONFIG_MTD_NOR_FLASH) +int is_flash_available(void) +{ + if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"), + ofnode_null())) + return 1; + + return 0; +} +#endif + +phys_addr_t board_get_usable_ram_top(phys_size_t total_size) +{ + /* Limit RAM used by U-Boot to the DDR low region */ + if (gd->ram_top > 0x10000000) + return 0x10000000; + + return gd->ram_top; +} + +int board_init(void) +{ + return 0; +} + +#define addr_alloc(lmb, size) lmb_alloc(lmb, size, SZ_64K) + +int board_late_init(void) +{ + struct lmb lmb; + u32 status = 0; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + + status |= env_set_hex("kernel_addr_r", addr_alloc(&lmb, SZ_128M)); + status |= env_set_hex("ramdisk_addr_r", addr_alloc(&lmb, SZ_128M)); + status |= env_set_hex("kernel_comp_addr_r", addr_alloc(&lmb, SZ_64M)); + status |= env_set_hex("kernel_comp_size", SZ_64M); + status |= env_set_hex("scriptaddr", addr_alloc(&lmb, SZ_4M)); + status |= env_set_hex("pxefile_addr_r", addr_alloc(&lmb, SZ_4M)); + status |= env_set_hex("fdt_addr_r", addr_alloc(&lmb, SZ_2M)); + + if (status) + log_warning("late_init: Failed to set run time variables\n"); + + /* start usb so that usb keyboard can be used as input device */ + if (CONFIG_IS_ENABLED(USB_KEYBOARD)) + usb_init(); + + /* + * Make sure virtio bus is enumerated so that peripherals + * on the virtio bus can be discovered by their drivers + */ + virtio_init(); + + return 0; +} + +void *board_fdt_blob_setup(int *err) +{ + *err = 0; + /* Stored the DTB address there during our init */ + return (void *)(ulong)0x100000; +} diff --git a/board/emulation/qemu-loongarch/qemu-loongarch.env b/board/emulation/qemu-loongarch/qemu-loongarch.env new file mode 100644 index 000000000000..2d130510607d --- /dev/null +++ b/board/emulation/qemu-loongarch/qemu-loongarch.env @@ -0,0 +1,6 @@ + +stdin=serial,usbkbd +stdout=serial,vidconsole +stderr=serial,vidconsole + +boot_targets=qfw usb scsi virtio nvme dhcp diff --git a/configs/qemu-loongarch64_defconfig b/configs/qemu-loongarch64_defconfig new file mode 100644 index 000000000000..d7f9c4338486 --- /dev/null +++ b/configs/qemu-loongarch64_defconfig @@ -0,0 +1,36 @@ +CONFIG_LOONGARCH=y +CONFIG_SYS_MALLOC_LEN=0x800000 +CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_NR_DRAM_BANKS=8 +CONFIG_ENV_SIZE=0x20000 +CONFIG_DEFAULT_DEVICE_TREE="qemu-loongarch64" +CONFIG_DM_RESET=y +CONFIG_SYS_LOAD_ADDR=0x02000000 +CONFIG_SHOW_REGS=y +# CONFIG_OF_BOARD_FIXUP is not set +CONFIG_SYS_PCI_64BIT=y +CONFIG_FIT=y +CONFIG_BOOTSTD_FULL=y +CONFIG_SYS_BOOTM_LEN=0x4000000 +CONFIG_USE_BOOTARGS=y +CONFIG_BOOTARGS_SUBST=y +CONFIG_DISPLAY_CPUINFO=y +CONFIG_DISPLAY_BOARDINFO=y +# CONFIG_CMD_MII is not set +CONFIG_CMD_2048=y +CONFIG_CMD_RTC=y +CONFIG_CMD_TIME=y +CONFIG_CMD_SYSBOOT=y +CONFIG_CMD_QFW=y +CONFIG_PARTITION_TYPE_GUID=y +CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_BLKMAP=y +CONFIG_EFI_MEDIA=y +CONFIG_DM_MMC=y +CONFIG_DM_MTD=y +CONFIG_FLASH_SHOW_PROGRESS=0 +CONFIG_SYS_MAX_FLASH_BANKS=2 +CONFIG_PCI_REGION_MULTI_ENTRY=y +CONFIG_DM_REBOOT_MODE=y +CONFIG_RESET_SYSCON=y +CONFIG_HEXDUMP=y diff --git a/include/configs/qemu-loongarch.h b/include/configs/qemu-loongarch.h new file mode 100644 index 000000000000..c1af4fee83ff --- /dev/null +++ b/include/configs/qemu-loongarch.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2024 Jiaxun Yang <jiaxun.y...@flygoat.com> + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +/* Those values are chosen by LoongArchQemuPkg */ +#define CFG_SYS_INIT_RAM_ADDR 0x10000 +#define CFG_SYS_INIT_RAM_SIZE 0x10000 + +#endif -- 2.43.0