riscv: qemu: Boot a kernel passed with -kernel
cover riscv: qemu: Boot a kernel passed with -kernel
When U-Boot runs from pflash on the QEMU RISC-V virt machine, QEMU passes -kernel, -initrd and -append through fw_cfg and leaves booting them to the firmware. U-Boot ignores them today: QFW is only enabled with ACPI, and distro boot has no qfw target.
This series brings the RISC-V QEMU targets in line with the Arm ones:
1. Enable CMD_QFW (and so QFW_MMIO) by default, and keep SPL_BLOBLIST off in the SPL defconfigs, which would otherwise fail to link.
2. Stop disabling initrd relocation, which checkpatch would reject in the .env file of the next patch.
3. Switch from distro boot to standard boot, with the environment in qemu-riscv.env and qfw first in boot_targets.
4. Document booting through fw_cfg.
Tested with QEMU v11.1.2 and the Debian trixie riscv64 netboot kernel and initrd (Linux 6.12):
- qemu-riscv64_smode built for pflash, run with -kernel, -initrd and -append and no input: U-Boot boots the kernel through qfw, the kernel gets the command line and unpacks the initrd.
- qemu-riscv64_smode with a GPT disk holding an extlinux.conf on
virtio-blk: standard boot boots it with the extlinux method, as distro boot did before the series.
- qemu-riscv64, qemu-riscv64_smode_acpi and qemu-riscv64_spl boot to the prompt with the new boot_targets and bootcmd.
- qemu-riscv64_smode and qemu-riscv64_spl build at every patch.
I could not build the riscv32 targets here: my toolchain lacks the rv32 libgcc and fails to link them with or without this series.
Hung-Chun Tseng (4):
cmd: Enable qfw by default on QEMU RISC-V
riscv: qemu: Do not disable initrd relocation
riscv: qemu: Switch to standard boot
doc: qemu-riscv: Describe booting a kernel through fw_cfg
board/emulation/qemu-riscv/qemu-riscv.env | 15 +++++++++++++ cmd/Kconfig | 2 +- configs/qemu-riscv32_defconfig | 2 +- configs/qemu-riscv32_smode_defconfig | 2 +- configs/qemu-riscv32_spl_defconfig | 3 ++- configs/qemu-riscv64_defconfig | 2 +- configs/qemu-riscv64_smode_defconfig | 2 +- configs/qemu-riscv64_spl_defconfig | 3 ++- doc/board/emulation/qemu-riscv.rst | 12 ++++++++++ include/configs/qemu-riscv.h | 27 ----------------------- 10 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 board/emulation/qemu-riscv/qemu-riscv.env
Signature · 1 line
2.43.0
PATCH 1/4 cmd: Enable qfw by default on QEMU RISC-V
The QEMU RISC-V virt machine has an fw_cfg device, and when U-Boot runs from pflash, QEMU passes the files given with -kernel, -initrd and -append through it rather than loading the kernel itself. QFW is only enabled with ACPI today, though, so these files cannot be loaded.
Enable CMD_QFW by default on TARGET_QEMU_VIRT, as on the Arm and x86 QEMU targets. The existing "select QFW_MMIO if QFW" in the board Kconfig then picks the MMIO transport.
QFW brings in QFW_SMBIOS, which selects BLOBLIST, and SPL_BLOBLIST defaults to y with a fixed address that the RISC-V SPL configs do not set. As SPL does not need a bloblist here, disable SPL_BLOBLIST in the two SPL defconfigs.
--- cmd/Kconfig | 2 +- configs/qemu-riscv32_spl_defconfig | 1 + configs/qemu-riscv64_spl_defconfig | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
cmd/Kconfig +1 -1
@@ -2599,7 +2599,7 @@ config CMD_QFW bool "qfw" select QFW default y if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT || \ - TARGET_QEMU_X86 || TARGET_QEMU_X86_64 + TARGET_QEMU_VIRT || TARGET_QEMU_X86 || TARGET_QEMU_X86_64 help This provides access to the QEMU firmware interface. The main feature is to allow easy loading of files passed to qemu-system
configs/qemu-riscv32_spl_defconfig +1 -0
@@ -17,6 +17,7 @@ CONFIG_DISTRO_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set +# CONFIG_SPL_BLOBLIST is not set CONFIG_SPL_MAX_SIZE=0x100000 CONFIG_SPL_SYS_MALLOC=y # CONFIG_CMD_MII is not set
configs/qemu-riscv64_spl_defconfig +1 -0
@@ -16,6 +16,7 @@ CONFIG_DISTRO_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set +# CONFIG_SPL_BLOBLIST is not set CONFIG_SPL_MAX_SIZE=0x100000 CONFIG_SPL_SYS_MALLOC=y # CONFIG_CMD_MII is not set
Signature · 1 line
2.43.0
PATCH 2/4 riscv: qemu: Do not disable initrd relocation
In reply to Hung-Chun TsengSetting initrd_high to all ones tells U-Boot not to copy the initrd at all, so it stays wherever it was loaded and the user has to make sure it does not overlap anything else. checkpatch rejects new settings like this, which the next patch would otherwise add when moving the environment into a .env file.
Nothing on the QEMU virt machine needs the initrd to stay in place, so drop the setting and let U-Boot copy the initrd as usual.
--- include/configs/qemu-riscv.h | 1 - 1 file changed, 1 deletion(-)
include/configs/qemu-riscv.h +0 -1
@@ -32,7 +32,6 @@#define CFG_EXTRA_ENV_SETTINGS \ CFG_STD_DEVICES_SETTINGS \ - "initrd_high=0xffffffffffffffff\0" \ "kernel_addr_r=0x84000000\0" \ "kernel_comp_addr_r=0x88000000\0" \ "kernel_comp_size=0x4000000\0" \
Signature · 1 line
2.43.0
PATCH 3/4 riscv: qemu: Switch to standard boot
In reply to Hung-Chun TsengReplace distro boot with standard boot, as the QEMU Arm targets did. Move the environment from CFG_EXTRA_ENV_SETTINGS into qemu-riscv.env, keeping the same addresses, and replace BOOT_TARGET_DEVICES with a boot_targets variable that lists qfw first, then the devices distro boot scanned.
With distro boot, a kernel passed with -kernel is never tried, as distro_bootcmd has no qfw target. With this change, booting U-Boot from pflash with -kernel, -initrd and -append boots that kernel directly.
The sysboot command is no longer enabled, as the extlinux boot method replaces it; this matches the QEMU Arm targets.
--- board/emulation/qemu-riscv/qemu-riscv.env | 15 +++++++++++++ configs/qemu-riscv32_defconfig | 2 +- configs/qemu-riscv32_smode_defconfig | 2 +- configs/qemu-riscv32_spl_defconfig | 2 +- configs/qemu-riscv64_defconfig | 2 +- configs/qemu-riscv64_smode_defconfig | 2 +- configs/qemu-riscv64_spl_defconfig | 2 +- include/configs/qemu-riscv.h | 26 ----------------------- 8 files changed, 21 insertions(+), 32 deletions(-) create mode 100644 board/emulation/qemu-riscv/qemu-riscv.env
board/emulation/qemu-riscv/qemu-riscv.env new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* environment for qemu-riscv32 and qemu-riscv64 */ + +stdin=serial,usbkbd +stdout=serial,vidconsole +stderr=serial,vidconsole +kernel_addr_r=0x84000000 +kernel_comp_addr_r=0x88000000 +kernel_comp_size=0x4000000 +fdt_addr_r=0x8c000000 +scriptaddr=0x8c100000 +pxefile_addr_r=0x8c200000 +ramdisk_addr_r=0x8c300000 +boot_targets=qfw nvme virtio scsi dhcp
configs/qemu-riscv32_defconfig +1 -1
@@ -7,7 +7,7 @@ CONFIG_SYS_MONITOR_LEN=786432 CONFIG_SYS_LOAD_ADDR=0x80200000 CONFIG_TARGET_QEMU_VIRT=y CONFIG_FIT=y -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set
configs/qemu-riscv32_smode_defconfig +1 -1
@@ -8,7 +8,7 @@ CONFIG_SYS_LOAD_ADDR=0x80200000 CONFIG_TARGET_QEMU_VIRT=y CONFIG_RISCV_SMODE=y CONFIG_FIT=y -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set
configs/qemu-riscv32_spl_defconfig +1 -1
@@ -13,7 +13,7 @@ CONFIG_RISCV_SMODE=y # CONFIG_OF_BOARD_FIXUP is not set CONFIG_FIT=y CONFIG_SPL_LOAD_FIT_ADDRESS=0x80200000 -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set
configs/qemu-riscv64_defconfig +1 -1
@@ -7,7 +7,7 @@ CONFIG_SYS_LOAD_ADDR=0x80200000 CONFIG_TARGET_QEMU_VIRT=y CONFIG_ARCH_RV64I=y CONFIG_FIT=y -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set
configs/qemu-riscv64_smode_defconfig +1 -1
@@ -8,7 +8,7 @@ CONFIG_TARGET_QEMU_VIRT=y CONFIG_ARCH_RV64I=y CONFIG_RISCV_SMODE=y CONFIG_FIT=y -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_USE_PREBOOT=y CONFIG_PREBOOT="setenv fdt_addr ${fdtcontroladdr}; fdt addr ${fdtcontroladdr};" CONFIG_DISPLAY_CPUINFO=y
configs/qemu-riscv64_spl_defconfig +1 -1
@@ -12,7 +12,7 @@ CONFIG_ARCH_RV64I=y CONFIG_RISCV_SMODE=y CONFIG_FIT=y CONFIG_SPL_LOAD_FIT_ADDRESS=0x80200000 -CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTSTD_DEFAULTS=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y # CONFIG_BOARD_INIT is not set
include/configs/qemu-riscv.h +0 -26
@@ -15,30 +15,4 @@#define RISCV_MMODE_TIMER_FREQ 1000000#define RISCV_SMODE_TIMER_FREQ 1000000 -/* Environment options */ - -#define CFG_STD_DEVICES_SETTINGS "stdin=serial,usbkbd\0" \ - "stdout=serial,vidconsole\0" \ - "stderr=serial,vidconsole\0" - -#define BOOT_TARGET_DEVICES (func) \ - func(NVME, nvme, 0) \ - func(VIRTIO, virtio, 0) \ - func(VIRTIO, virtio, 1) \ - func(SCSI, scsi, 0) \ - func(DHCP, dhcp, na) - -#include <config_distro_bootcmd.h> - -#define CFG_EXTRA_ENV_SETTINGS \ - CFG_STD_DEVICES_SETTINGS \ - "kernel_addr_r=0x84000000\0" \ - "kernel_comp_addr_r=0x88000000\0" \ - "kernel_comp_size=0x4000000\0" \ - "fdt_addr_r=0x8c000000\0" \ - "scriptaddr=0x8c100000\0" \ - "pxefile_addr_r=0x8c200000\0" \ - "ramdisk_addr_r=0x8c300000\0" \ - BOOTENV -#endif /* __CONFIG_H */
Signature · 1 line
2.43.0
PATCH 4/4 doc: qemu-riscv: Describe booting a kernel through fw_cfg
In reply to Hung-Chun TsengExplain that QEMU passes -kernel, -initrd and -append through fw_cfg when U-Boot runs from flash, and that the qfw boot method boots them.
--- doc/board/emulation/qemu-riscv.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
doc/board/emulation/qemu-riscv.rst +12 -0
@@ -205,6 +205,18 @@ Invoke QEMU with: qemu-system-riscv64 -M virt -nographic \ -drive if=pflash,format=raw,unit=0,file=u-boot.bin,readonly=off +When U-Boot runs from flash, QEMU passes the files given with ``-kernel``, +``-initrd`` and ``-append`` to it through the fw_cfg interface instead of +loading the kernel itself. The QEMU firmware boot method (see +:doc:`../../develop/bootstd/qfw`) picks them up, and since ``qfw`` comes +first in ``boot_targets``, the kernel is booted without further input: + +.. code-block:: bash + + qemu-system-riscv64 -M virt -nographic -m 1G \ + -drive if=pflash,format=raw,unit=0,file=u-boot.bin,readonly=on \ + -kernel Image -initrd initrd.gz -append "console=ttyS0" + Debug UART ----------
Signature · 1 line
2.43.0
Hi Leo, Bin,
Gentle ping on this series. It still applies cleanly to the current main. Please let me know if anything should change.
Thanks,
Hung-Chun
Quoted 18 lines · Hung-Chun Tseng
When U-Boot runs from pflash on the QEMU RISC-V virt machine, QEMU passes -kernel, -initrd and -append through
fw_cfgand leaves booting them to the firmware. U-Boot ignores them today: QFW is only enabled with ACPI, and distro boot has no qfw target.This series brings the RISC-V QEMU targets in line with the Arm ones:
1. Enable
CMD_QFW(and soQFW_MMIO) by default, and keepSPL_BLOBLISToff in the SPL defconfigs, which would otherwise fail to link.
2. Stop disabling initrd relocation, which checkpatch would reject in the .env file of the next patch.
3. Switch from distro boot to standard boot, with the environment in qemu-riscv.env and qfw first inboot_targets.
4. Document booting throughfw_cfg.Tested with QEMU v11.1.2 and the Debian trixie riscv64 netboot kernel and initrd (Linux 6.12):
Quoted 9 lines
- qemu-riscv64_smode built for pflash, run with -kernel, -initrd and -append and no input: U-Boot boots the kernel through qfw, the kernel gets the command line and unpacks the initrd.
- qemu-riscv64_smode with a GPT disk holding an extlinux.conf on
virtio-blk: standard boot boots it with the extlinux method, as distro boot did before the series.
- qemu-riscv64, qemu-riscv64_smode_acpi and qemu-riscv64_spl boot to the prompt with the newboot_targetsand bootcmd.
- qemu-riscv64_smode and qemu-riscv64_spl build at every patch.
For the whole series,