[U-Boot] [PATCH v2 0/4] ARM: Extend qemu_arm to support ARM64

Changes in v2: - Remove references to setting ARCH from the documentation - Add Reviewed-by to the other 3 batches
Hi,
This series extends qemu_arm to have support for ARM64 as well. Adding test.py support for it gets us the first test.py job for an ARM64 board on Travis-CI.
The corresponding changes in the uboot-test-hook repository have already been merged but for reference they were in:
https://github.com/swarren/uboot-test-hooks/pull/15
Tuomas Tynkkynen (4): ARM: qemu-arm: Add support for AArch64 ARM: Document AArch64 version of qemu-arm Travis-CI: Download ARM64 version of GRUB as well Travis-CI: Add job for running test.py on qemu_arm64
.travis.yml | 8 +++++ arch/arm/Kconfig | 2 -- arch/arm/mach-qemu/Kconfig | 11 +++++++ board/emulation/qemu-arm/MAINTAINERS | 1 + board/emulation/qemu-arm/qemu-arm.c | 35 ++++++++++++++++++++++ .../{qemu_arm_defconfig => qemu_arm64_defconfig} | 1 + configs/qemu_arm_defconfig | 1 + doc/README.qemu-arm | 21 +++++++++---- 8 files changed, 73 insertions(+), 7 deletions(-) copy configs/{qemu_arm_defconfig => qemu_arm64_defconfig} (94%)

This adds support for '-machine virt' on AArch64. This is rather simple: we just add TARGET_QEMU_ARM_xxBIT to select a few different Kconfig symbols, provide the ARMv8 memory map from the board file and add a new defconfig based on the 32-bit defconfig.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com --- v2: No change (except added Reviewed-by) --- arch/arm/Kconfig | 2 -- arch/arm/mach-qemu/Kconfig | 11 +++++++ board/emulation/qemu-arm/MAINTAINERS | 1 + board/emulation/qemu-arm/qemu-arm.c | 35 ++++++++++++++++++++++ .../{qemu_arm_defconfig => qemu_arm64_defconfig} | 1 + configs/qemu_arm_defconfig | 1 + 6 files changed, 49 insertions(+), 2 deletions(-) copy configs/{qemu_arm_defconfig => qemu_arm64_defconfig} (94%)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index f2c35e32c6..ee27f07285 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -642,8 +642,6 @@ config ARCH_MX5
config ARCH_QEMU bool "QEMU Virtual Platform" - select CPU_V7 - select ARCH_SUPPORT_PSCI select DM select DM_SERIAL select OF_CONTROL diff --git a/arch/arm/mach-qemu/Kconfig b/arch/arm/mach-qemu/Kconfig index 3500b56cb0..133163aecf 100644 --- a/arch/arm/mach-qemu/Kconfig +++ b/arch/arm/mach-qemu/Kconfig @@ -10,3 +10,14 @@ config SYS_CONFIG_NAME default "qemu-arm"
endif + +config TARGET_QEMU_ARM_32BIT + bool "Support qemu_arm" + depends on ARCH_QEMU + select CPU_V7 + select ARCH_SUPPORT_PSCI + +config TARGET_QEMU_ARM_64BIT + bool "Support qemu_arm64" + depends on ARCH_QEMU + select ARM64 diff --git a/board/emulation/qemu-arm/MAINTAINERS b/board/emulation/qemu-arm/MAINTAINERS index a803061ff4..e757ffc64f 100644 --- a/board/emulation/qemu-arm/MAINTAINERS +++ b/board/emulation/qemu-arm/MAINTAINERS @@ -4,3 +4,4 @@ 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/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c index e29ba4630f..1bc7edcfb7 100644 --- a/board/emulation/qemu-arm/qemu-arm.c +++ b/board/emulation/qemu-arm/qemu-arm.c @@ -6,6 +6,41 @@ #include <common.h> #include <fdtdec.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 + }, { + /* 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 = 0xc0000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE + }, { + /* List terminator */ + 0, + } +}; + +struct mm_region *mem_map = qemu_arm64_mem_map; +#endif + int board_init(void) { return 0; diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm64_defconfig similarity index 94% copy from configs/qemu_arm_defconfig copy to configs/qemu_arm64_defconfig index 3cd4d45433..4309bd25eb 100644 --- a/configs/qemu_arm_defconfig +++ b/configs/qemu_arm64_defconfig @@ -1,6 +1,7 @@ CONFIG_ARM=y CONFIG_ARM_SMCCC=y CONFIG_ARCH_QEMU=y +CONFIG_TARGET_QEMU_ARM_64BIT=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y # CONFIG_DISPLAY_CPUINFO is not set diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig index 3cd4d45433..db61b12869 100644 --- a/configs/qemu_arm_defconfig +++ b/configs/qemu_arm_defconfig @@ -1,6 +1,7 @@ CONFIG_ARM=y CONFIG_ARM_SMCCC=y CONFIG_ARCH_QEMU=y +CONFIG_TARGET_QEMU_ARM_32BIT=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y # CONFIG_DISPLAY_CPUINFO is not set

On Thu, Jan 11, 2018 at 04:11:23PM +0200, Tuomas Tynkkynen wrote:
This adds support for '-machine virt' on AArch64. This is rather simple: we just add TARGET_QEMU_ARM_xxBIT to select a few different Kconfig symbols, provide the ARMv8 memory map from the board file and add a new defconfig based on the 32-bit defconfig.
While nvme is in the defconfig it seems only ahci works with distroboot automatically.
Booting off nvme requires manually running
=> nvme scan => setenv devtype nvme => run scan_dev_for_boot_part
Having it work automatically requires something like the below
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index 5c469a23fa..305e102cb8 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -195,6 +195,31 @@ BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_SCSI #endif
+#ifdef CONFIG_NVME +#define BOOTENV_RUN_NVME_INIT "run nvme_init; " +#define BOOTENV_SET_NVME_NEED_INIT "setenv nvme_need_init; " +#define BOOTENV_SHARED_NVME \ + "nvme_init=" \ + "if ${nvme_need_init}; then " \ + "setenv nvme_need_init false; " \ + "nvme scan; " \ + "fi\0" \ + \ + "nvme_boot=" \ + BOOTENV_RUN_NVME_INIT \ + BOOTENV_SHARED_BLKDEV_BODY(nvme) +#define BOOTENV_DEV_NVME BOOTENV_DEV_BLKDEV +#define BOOTENV_DEV_NAME_NVME BOOTENV_DEV_NAME_BLKDEV +#else +#define BOOTENV_RUN_NVME_INIT +#define BOOTENV_SET_NVME_NEED_INIT +#define BOOTENV_SHARED_NVME +#define BOOTENV_DEV_NVME \ + BOOT_TARGET_DEVICES_references_NVME_without_CONFIG_NVME +#define BOOTENV_DEV_NAME_NVME \ + BOOT_TARGET_DEVICES_references_NVME_without_CONFIG_NVME +#endif + #ifdef CONFIG_IDE #define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide) #define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV @@ -324,6 +349,7 @@ #define BOOTENV \ BOOTENV_SHARED_HOST \ BOOTENV_SHARED_MMC \ + BOOTENV_SHARED_NVME \ BOOTENV_SHARED_PCI \ BOOTENV_SHARED_USB \ BOOTENV_SHARED_SATA \ @@ -390,6 +416,7 @@ BOOT_TARGET_DEVICES(BOOTENV_DEV) \ \ "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \ + BOOTENV_SET_NVME_NEED_INIT \ "for target in ${boot_targets}; do " \ "run bootcmd_${target}; " \ "done\0" diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h index c8852cef34..8c65babb77 100644 --- a/include/configs/qemu-arm.h +++ b/include/configs/qemu-arm.h @@ -38,7 +38,8 @@ #include <config_distro_defaults.h>
#define BOOT_TARGET_DEVICES(func) \ - func(SCSI, scsi, 0) + func(SCSI, scsi, 0) \ + func(NVME, nvme, 0)
#include <config_distro_bootcmd.h>

Hi Jonathan,
On 01/13/2018 09:08 AM, Jonathan Gray wrote:
On Thu, Jan 11, 2018 at 04:11:23PM +0200, Tuomas Tynkkynen wrote:
This adds support for '-machine virt' on AArch64. This is rather simple: we just add TARGET_QEMU_ARM_xxBIT to select a few different Kconfig symbols, provide the ARMv8 memory map from the board file and add a new defconfig based on the 32-bit defconfig.
While nvme is in the defconfig it seems only ahci works with distroboot automatically.
Booting off nvme requires manually running
=> nvme scan => setenv devtype nvme => run scan_dev_for_boot_part
Having it work automatically requires something like the below
Yeah. You should probably send that as a formal patch (or two I guess; one for config_distro_bootcmd.h; one for qemu-arm.h).
FWIW, I have a mostly-working virtio stack for U-Boot which probably would be the best disk interface for booting Linux. Still needs a lot of cleanup, hopefully one day it will be ready...

On Sat, Jan 13, 2018 at 02:45:32PM +0200, Tuomas Tynkkynen wrote:
Hi Jonathan,
On 01/13/2018 09:08 AM, Jonathan Gray wrote:
On Thu, Jan 11, 2018 at 04:11:23PM +0200, Tuomas Tynkkynen wrote:
This adds support for '-machine virt' on AArch64. This is rather simple: we just add TARGET_QEMU_ARM_xxBIT to select a few different Kconfig symbols, provide the ARMv8 memory map from the board file and add a new defconfig based on the 32-bit defconfig.
While nvme is in the defconfig it seems only ahci works with distroboot automatically.
Booting off nvme requires manually running
=> nvme scan => setenv devtype nvme => run scan_dev_for_boot_part
Having it work automatically requires something like the below
Yeah. You should probably send that as a formal patch (or two I guess; one for config_distro_bootcmd.h; one for qemu-arm.h).
FWIW, I have a mostly-working virtio stack for U-Boot which probably would be the best disk interface for booting Linux. Still needs a lot of cleanup, hopefully one day it will be ready...
That would be great. I'm interested in running OpenBSD not Linux and ahci cant't map the interrupt with qemu (does on pci ecam + ahci on an overdrive 1000), and nvme turns out to hang when mounting the root filesystem.
Would be nice to be able to replace using edk2 ovmf for booting off virtio storage.

On Thu, Jan 11, 2018 at 04:11:23PM +0200, Tuomas Tynkkynen wrote:
This adds support for '-machine virt' on AArch64. This is rather simple: we just add TARGET_QEMU_ARM_xxBIT to select a few different Kconfig symbols, provide the ARMv8 memory map from the board file and add a new defconfig based on the 32-bit defconfig.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

It's mostly obvious, except that QEMU is annoying and requires an explicit '-cpu cortex-a57' (or some other 64-bit core) to actually run in 64-bit mode.
While at it, remove the references to setting the ARCH environment variable; that is not used in U-Boot.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi --- v2: Drop ARCH=arm as it turns out not to be needed in U-Boot. --- doc/README.qemu-arm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/doc/README.qemu-arm b/doc/README.qemu-arm index 2895e3b97f..aee789447a 100644 --- a/doc/README.qemu-arm +++ b/doc/README.qemu-arm @@ -4,11 +4,12 @@ # SPDX-License-Identifier: GPL-2.0+ #
-U-Boot on QEMU's 'virt' machine on ARM -====================================== +U-Boot on QEMU's 'virt' machine on ARM & AArch64 +================================================
QEMU for ARM supports a special 'virt' machine designed for emulation and virtualization purposes. This document describes how to run U-Boot under it. +Both 32-bit ARM and AArch64 are supported.
The 'virt' platform provides the following as the basic functionality:
@@ -17,7 +18,7 @@ The 'virt' platform provides the following as the basic functionality: - A generated device tree blob placed at the start of RAM - A freely configurable amount of RAM, described by the DTB - A PL011 serial port, discoverable via the DTB - - An ARMv7 architected timer + - An ARMv7/ARMv8 architected timer - PSCI for rebooting the system - A generic ECAM-based PCI host controller, discoverable via the DTB
@@ -25,19 +26,29 @@ Additionally, a number of optional peripherals can be added to the PCI bus.
Building U-Boot --------------- -Set the CROSS_COMPILE and ARCH=arm environment variables as usual, and run: +Set the CROSS_COMPILE environment variable as usual, and run:
+- For ARM: make qemu_arm_defconfig make
+- For AArch64: + make qemu_arm64_defconfig + make + Running U-Boot -------------- The minimal QEMU command line to get U-Boot up and running is:
+- For ARM: qemu-system-arm -machine virt,highmem=off -bios u-boot.bin
+- For AArch64: + qemu-system-aarch64 -machine virt,highmem=off -cpu cortex-a57 -bios u-boot.bin + The 'highmem=off' parameter to the 'virt' machine is required for PCI to work -in U-Boot. +in U-Boot. Also, for some odd reason qemu-system-aarch64 needs to be explicitly +told to use a 64-bit CPU or it will boot in 32-bit mode.
Additional peripherals that have been tested to work in both U-Boot and Linux can be enabled with the following command line parameters:

On Thu, Jan 11, 2018 at 04:11:24PM +0200, Tuomas Tynkkynen wrote:
It's mostly obvious, except that QEMU is annoying and requires an explicit '-cpu cortex-a57' (or some other 64-bit core) to actually run in 64-bit mode.
While at it, remove the references to setting the ARCH environment variable; that is not used in U-Boot.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi
Reviewed-by: Tom Rini trini@konsulko.com

On Thu, Jan 11, 2018 at 04:11:24PM +0200, Tuomas Tynkkynen wrote:
It's mostly obvious, except that QEMU is annoying and requires an explicit '-cpu cortex-a57' (or some other 64-bit core) to actually run in 64-bit mode.
While at it, remove the references to setting the ARCH environment variable; that is not used in U-Boot.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

For preparation of adding AArch64 test.py jobs.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com --- v2: No change (except added Reviewed-by) --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/.travis.yml b/.travis.yml index 8a220ccc42..65c6e52046 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,8 @@ install: - grub-mkimage -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - mkdir ~/grub2-arm - ( cd ~/grub2-arm; wget -O - http://download.opensuse.org/ports/armv7hl/distribution/leap/42.2/repo/oss/s... | rpm2cpio | cpio -di ) + - mkdir ~/grub2-arm64 + - ( cd ~/grub2-arm64; wget -O - http://download.opensuse.org/ports/aarch64/distribution/leap/42.2/repo/oss/s... | rpm2cpio | cpio -di )
env: global: @@ -109,6 +111,7 @@ script: - export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/.bm-work/${TEST_PY_BD}; cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/; cp ~/grub2-arm/usr/lib/grub2/arm-efi/grub.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm.efi; + cp ~/grub2-arm64/usr/lib/grub2/arm64-efi/grub.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm64.efi; if [[ "${TEST_PY_BD}" != "" ]]; then ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}"

On Thu, Jan 11, 2018 at 04:11:25PM +0200, Tuomas Tynkkynen wrote:
For preparation of adding AArch64 test.py jobs.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

The corresponding changes in the uboot-test-hooks repo are:
https://github.com/swarren/uboot-test-hooks/pull/15
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com --- v2: No change (except added Reviewed-by) --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/.travis.yml b/.travis.yml index 65c6e52046..75e0d98ed7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -315,6 +315,11 @@ matrix: TEST_PY_TEST_SPEC="not sleep" QEMU_TARGET="arm-softmmu" BUILDMAN="^qemu_arm$" + - env: + - TEST_PY_BD="qemu_arm64" + TEST_PY_TEST_SPEC="not sleep" + QEMU_TARGET="aarch64-softmmu" + BUILDMAN="^qemu_arm64$" - env: - TEST_PY_BD="qemu_mips" TEST_PY_TEST_SPEC="not sleep"

On Thu, Jan 11, 2018 at 04:11:26PM +0200, Tuomas Tynkkynen wrote:
The corresponding changes in the uboot-test-hooks repo are:
https://github.com/swarren/uboot-test-hooks/pull/15
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (3)
-
Jonathan Gray
-
Tom Rini
-
Tuomas Tynkkynen