= STUFF
* Peruse ''runqemu'', clarify how it creates command for ''qemuriscv64''.
= Links
== OE-Core layer
* [[https://git.openembedded.org/openembedded-core/tree/|OE-Core]]
* [[https://git.openembedded.org/openembedded-core/tree/scripts|scripts/]]
* [[https://git.openembedded.org/openembedded-core/tree/scripts/runqemu|runqemu]]
* [[https://git.openembedded.org/openembedded-core/tree/meta|meta/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/classes|classes/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/classes/qemu.bbclass|qemu.bbclass]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/classes/qemuboot.bbclass|qemuboot.bbclass]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/|conf/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine|machine/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/qemuriscv64.conf|qemuriscv64.conf]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/|include/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/qemu.inc|qemu.inc]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/riscv/|riscv/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/riscv/qemuriscv.inc|qemuriscv64.inc]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/riscv/tune-riscv.inc|tune-riscv.inc]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/conf/machine/include/riscv/arch-riscv.inc|arch-riscv.inc]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/|recipes-bsp/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/opensbi/|opensbi/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/opensbi/opensbi_1.0.bb|opensbi_1.0.bb]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/opensbi/opensbi-payloads.inc|opensbi-payloads.inc]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/u-boot|u-boot/]]
* [[https://git.openembedded.org/openembedded-core/tree/meta/recipes-bsp/u-boot/u-boot-common.inc|u-boot-common.inc]]
* [[https://cgit.openembedded.org/openembedded-core/tree/meta/recipes-bsp/u-boot/u-boot.inc|u-boot.inc]]
* [[https://cgit.openembedded.org/openembedded-core/tree/meta/recipes-bsp/u-boot/u-boot_2022.01.bb|u-boot_2022.01.bb]]
== meta-riscv layer [abbreviated, unnecessary for QEMU]
* [[https://github.com/riscv/meta-riscv|meta-riscv/]]
* [[https://github.com/riscv/meta-riscv/tree/master/conf|conf/]]
* [[https://github.com/riscv/meta-riscv/blob/master/conf/layer.conf|layer.conf]]
* [[https://github.com/riscv/meta-riscv/tree/master/conf/machine|machine/]]
* [[https://github.com/riscv/meta-riscv/tree/master/recipes-bsp/u-boot|U-Boot stuff]]
* [[https://github.com/riscv/meta-riscv/tree/master/recipes-kernel/|recipes-kernel/]]
* [[https://github.com/riscv/meta-riscv/tree/master/recipes-kernel/linux|linux/]]
== GitHub riscv-software-src
* [[https://github.com/riscv-software-src|Main Page]]
* [[https://github.com/riscv-software-src/opensbi|opensbi]]
== Resources
* [[https://riscv.org/|https://riscv.org]]
* [[https://elinux.org/images/2/28/Linux-riscv.pdf|The Future of Linux on RISC-V (ELC 2021)]]
* [[https://www.youtube.com/watch?v=D4OSR9GhfC8|Build RISCV based IOT Systems using Yocto Project - Khem Raj]]
* [[https://duckduckgo.com/?q=opensbi+boot+flow&t=brave&ia=web|Online search, "OpenSBI boot flow"]]
= Building for qemuriscv64
== qemuriscv64
Note that, for the QEMU build, there is no need for the ''meta-riscv'' layer, just ''openembedded-core''.
$ MACHINE=qemuriscv64 bitbake core-image-full-cmdline
$ runqemu nographic
== qemuriscv.sh
To invoke your own script, remove ''-device bochs-display'' added by ''runqemu''.
$ sudo qemu-system-riscv64 \
-device virtio-net-device,netdev=net0,mac=52:54:00:12:34:02 \
-netdev tap,id=net0,ifname=tap0,script=no,downscript=no \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-pci,rng=rng0 \
-drive id=disk0,file=/home/rpjday/oe/builds/oe_qemuriscv64/tmp/deploy/images/qemuriscv64/core-image-minimal-qemuriscv64.ext4,if=none,format=raw \
-device virtio-blk-device,drive=disk0 \
-device virtio-mouse-pci \
-device virtio-keyboard-pci \
-machine virt \
-smp 4 \
-m 256 \
-serial mon:stdio \
-serial null \
-nographic \
-bios /home/rpjday/oe/builds/oe_qemuriscv64/tmp/deploy/images/qemuriscv64/fw_jump.elf \
-kernel /home/rpjday/oe/builds/oe_qemuriscv64/tmp/deploy/images/qemuriscv64/Image-qemuriscv64.bin \
-append 'root=/dev/vda rw mem=256M ip=192.168.7.2::192.168.7.1:255.255.255.0::eth0:off:8.8.8.8 console=ttyS0 console=hvc0 earlycon=sbi '
Why create a kernel containing-payload if you don't use it? Also, appears that the serial console is ''ttyS0'', and you can drop the ''console=hvc0 earlycon=sbi'' stuff, still works.
== tmp/deploy/images/qemuriscv64
Note which generated artifacts are used in the call to QEMU:
-rw-r--r--. 2 rpjday rpjday 4526 Feb 26 13:21 core-image-full-cmdline.env
-rw-r--r--. 2 rpjday rpjday 1682 Feb 26 13:21 core-image-full-cmdline-qemuriscv64-20220226161907.qemuboot.conf
-rw-r--r--. 2 rpjday rpjday 184259584 Feb 26 14:02 core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.ext4
-rw-r--r--. 2 rpjday rpjday 14723 Feb 26 13:21 core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.manifest
-rw-r--r--. 2 rpjday rpjday 43832694 Feb 26 13:21 core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.tar.bz2
-rw-r--r--. 2 rpjday rpjday 136642560 Feb 26 13:21 core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.wic.qcow2
-rw-r--r--. 2 rpjday rpjday 189565 Feb 26 13:21 core-image-full-cmdline-qemuriscv64-20220226161907.testdata.json
lrwxrwxrwx. 2 rpjday rpjday 62 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.ext4 -> core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.ext4
lrwxrwxrwx. 2 rpjday rpjday 66 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.manifest -> core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.manifest
lrwxrwxrwx. 2 rpjday rpjday 64 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.qemuboot.conf -> core-image-full-cmdline-qemuriscv64-20220226161907.qemuboot.conf
lrwxrwxrwx. 2 rpjday rpjday 65 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.tar.bz2 -> core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.tar.bz2
lrwxrwxrwx. 2 rpjday rpjday 64 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.testdata.json -> core-image-full-cmdline-qemuriscv64-20220226161907.testdata.json
lrwxrwxrwx. 2 rpjday rpjday 67 Feb 26 13:21 core-image-full-cmdline-qemuriscv64.wic.qcow2 -> core-image-full-cmdline-qemuriscv64-20220226161907.rootfs.wic.qcow2
-rwxr-xr-x. 2 rpjday rpjday 96496 Feb 26 13:17 fw_dynamic.bin
-rwxr-xr-x. 2 rpjday rpjday 938520 Feb 26 13:17 fw_dynamic.elf
-rwxr-xr-x. 2 rpjday rpjday 96496 Feb 26 13:17 fw_jump.bin
-rwxr-xr-x. 2 rpjday rpjday 938104 Feb 26 13:17 fw_jump.elf
-rwxr-xr-x. 2 rpjday rpjday 24799752 Feb 26 13:17 fw_payload.bin
-rwxr-xr-x. 2 rpjday rpjday 23640912 Feb 26 13:17 fw_payload.elf
lrwxrwxrwx. 2 rpjday rpjday 75 Feb 26 13:15 Image -> Image--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
-rw-r--r--. 2 rpjday rpjday 22702592 Feb 26 13:15 Image--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
lrwxrwxrwx. 2 rpjday rpjday 75 Feb 26 13:15 Image-qemuriscv64.bin -> Image--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
-rw-r--r--. 2 rpjday rpjday 2647632 Feb 26 13:16 modules--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.tgz
lrwxrwxrwx. 2 rpjday rpjday 77 Feb 26 13:16 modules-qemuriscv64.tgz -> modules--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.tgz
lrwxrwxrwx. 2 rpjday rpjday 33 Feb 26 13:19 u-boot.bin -> u-boot-qemuriscv64-2022.01-r0.bin
lrwxrwxrwx. 2 rpjday rpjday 33 Feb 26 13:19 u-boot.elf -> u-boot-qemuriscv64-2022.01-r0.elf
lrwxrwxrwx. 2 rpjday rpjday 41 Feb 26 13:19 u-boot-initial-env -> u-boot-initial-env-qemuriscv64-2022.01-r0
lrwxrwxrwx. 2 rpjday rpjday 41 Feb 26 13:19 u-boot-initial-env-qemuriscv64 -> u-boot-initial-env-qemuriscv64-2022.01-r0
-rw-r--r--. 2 rpjday rpjday 4155 Feb 26 13:19 u-boot-initial-env-qemuriscv64-2022.01-r0
-rw-r--r--. 2 rpjday rpjday 616024 Feb 26 13:19 u-boot-qemuriscv64-2022.01-r0.bin
-rw-r--r--. 2 rpjday rpjday 5967056 Feb 26 13:19 u-boot-qemuriscv64-2022.01-r0.elf
lrwxrwxrwx. 2 rpjday rpjday 33 Feb 26 13:19 u-boot-qemuriscv64.bin -> u-boot-qemuriscv64-2022.01-r0.bin
lrwxrwxrwx. 2 rpjday rpjday 33 Feb 26 13:19 u-boot-qemuriscv64.elf -> u-boot-qemuriscv64-2022.01-r0.elf
lrwxrwxrwx. 2 rpjday rpjday 76 Feb 26 13:15 uImage -> uImage--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
-rw-r--r--. 2 rpjday rpjday 6720345 Feb 26 13:15 uImage--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
lrwxrwxrwx. 2 rpjday rpjday 76 Feb 26 13:15 uImage-qemuriscv64.bin -> uImage--5.15.22+git0+2d38a472b2_7f685244af-r0-qemuriscv64-20220226161907.bin
= The RISC-V kernel
== linux-yocto_5.15.bb
Snippets:
KBRANCH:qemuriscv64 ?= "v5.15/standard/base"
SRCREV_machine:qemuriscv64 ?= "7f685244afb3acd13e94968312580b63d7296705"
SRC_URI = "git://git.yoctoproject.org/linux-yocto.git;name=machine;branch=${KBRANCH}; \
git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-5.15;destsuffix=${KMETA}"
# Functionality flags
KERNEL_EXTRA_FEATURES ?= "features/netfilter/netfilter.scc"
KERNEL_FEATURES:append = " ${KERNEL_EXTRA_FEATURES}"
KERNEL_FEATURES:append:qemuall=" cfg/virtio.scc features/drm-bochs/drm-bochs.scc"
== Generated RISC-V image/boot/ artifacts
-rw-r--r--. 1 rpjday rpjday 87068 Feb 26 12:10 config-5.15.22-yocto-standard
-rw-r--r--. 1 rpjday rpjday 22702592 Feb 26 12:10 Image-5.15.22-yocto-standard
-rw-r--r--. 1 rpjday rpjday 515147 Feb 26 12:10 Module.symvers-5.15.22-yocto-standard
-rw-r--r--. 1 rpjday rpjday 3984643 Feb 26 12:10 System.map-5.15.22-yocto-standard
-rw-r--r--. 1 rpjday rpjday 6720345 Feb 26 12:10 uImage-5.15.22-yocto-standard
-rw-r--r--. 1 rpjday rpjday 19733600 Feb 26 12:10 vmlinux-5.15.22-yocto-standard
== Selected snippets from kernel-meta/
=== arch/riscv/
==== riscv.scc
if [ "$KARCH" = "riscv" ]; then
kconf hardware riscv.cfg
include cfg/timer/hz_100.scc
fi
==== riscv.cfg
CONFIG_RISCV=y
CONFIG_RISCV_ISA_C=y
CONFIG_RISCV_ISA_A=y
CONFIG_RISCV_TIMER=y
CONFIG_MMU=y
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y [not set in .config?]
=== bsp/qemuriscv64/
==== qemuriscv64.cfg
CONFIG_ARCH_RV64I=y
CONFIG_64BIT=y
#
# Platform type
#
CONFIG_MAXPHYSMEM_128GB=y
CONFIG_SMP=y
CONFIG_NR_CPUS=8
CONFIG_TUNE_GENERIC=y
#
# Bus support
#
CONFIG_PCI=y
CONFIG_PCI_ECAM=y
CONFIG_PCI_HOST_COMMON=y
CONFIG_PCI_HOST_GENERIC=y
CONFIG_PCIEPORTBUS=y
#
# Serial drivers
#
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
#
# Non-8250 serial port support
#
CONFIG_VIRTIO_CONSOLE=y
#
# IRQ chip support
#
CONFIG_SIFIVE_PLIC=y
==== qemuriscv64.scc
kconf hardware qemuriscv64.cfg
# Graphics support
include features/drm-bochs/drm-bochs.scc
==== qemuriscv64-standard.scc
define KMACHINE qemuriscv64
define KTYPE standard
define KARCH riscv64
include ktypes/standard/standard.scc
include cfg/virtio.scc
include qemuriscv64.scc
== On the running QEMU session
root@qemuriscv64:/proc# gunzip -c /proc/config.gz | grep RISC
CONFIG_RISCV=y
CONFIG_RISCV_SBI=y
CONFIG_RISCV_ERRATA_ALTERNATIVE=y
CONFIG_RISCV_ISA_C=y
CONFIG_RISCV_BASE_PMU=y
CONFIG_RISCV_SBI_V01=y
# CONFIG_SERIAL_EARLYCON_RISCV_SBI is not set
# CONFIG_HVC_RISCV_SBI is not set
CONFIG_RISCV_TIMER=y
CONFIG_RISCV_INTC=y
= opensbi
== qemuriscv.inc variables
EXTRA_IMAGEDEPENDS += "opensbi"
RISCV_SBI_PLAT ?= "generic"
RISCV_SBI_PAYLOAD ?= "${KERNEL_IMAGETYPE}-${MACHINE}.bin"
UBOOT_ENTRYPOINT:riscv32 = "0x80400000"
UBOOT_ENTRYPOINT:riscv64 = "0x80200000"
== opensbi-payloads.inc
def riscv_get_extra_oemake_image(d):
sbi_payload = d.getVar('RISCV_SBI_PAYLOAD')
deploy_dir = d.getVar('DEPLOY_DIR_IMAGE')
if sbi_payload is None:
return ""
return "FW_PAYLOAD_PATH=" + deploy_dir + "/" + sbi_payload
def riscv_get_extra_oemake_fdt(d):
sbi_fdt = d.getVar('RISCV_SBI_FDT')
deploy_dir = d.getVar('DEPLOY_DIR_IMAGE')
if sbi_fdt is None:
return ""
return "FW_FDT_PATH=" + deploy_dir + "/" + sbi_fdt
def riscv_get_do_compile_depends(d):
sbi_payload = d.getVar('RISCV_SBI_PAYLOAD') or ""
sbi_fdt = d.getVar('RISCV_SBI_FDT') or ""
if sbi_payload == "" and sbi_fdt == "":
return ""
if sbi_fdt != "" and 'u-boot.bin' in sbi_payload:
return "virtual/kernel:do_deploy virtual/bootloader:do_deploy"
if 'linux' in sbi_payload or 'Image' in sbi_payload:
return "virtual/kernel:do_deploy"
if 'u-boot.bin' in sbi_payload:
return "virtual/bootloader:do_deploy"
if sbi_fdt != "":
return "virtual/kernel:do_deploy"
return ""
== opensbi_1.0.bb [master branch]
require opensbi-payloads.inc
inherit autotools-brokensep deploy
SRCREV = "ce4c0188d96b2c20c2e08d24646a5e517fe15a4b"
SRC_URI = "git://github.com/riscv/opensbi.git;branch=master;protocol=https \
"
S = "${WORKDIR}/git"
EXTRA_OEMAKE += "PLATFORM=${RISCV_SBI_PLAT} I=${D} FW_PIC=n CLANG_TARGET= "
# If RISCV_SBI_PAYLOAD is set then include it as a payload
EXTRA_OEMAKE:append = " ${@riscv_get_extra_oemake_image(d)}"
EXTRA_OEMAKE:append = " ${@riscv_get_extra_oemake_fdt(d)}"
# Required if specifying a custom payload
do_compile[depends] += "${@riscv_get_do_compile_depends(d)}"
do_install:append() {
# In the future these might be required as a dependency for other packages.
# At the moment just delete them to avoid warnings
rm -r ${D}/include
rm -r ${D}/lib*
rm -r ${D}/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/payloads
}
do_deploy () {
install -m 755 ${D}/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_payload.* ${DEPLOYDIR}/
install -m 755 ${D}/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_jump.* ${DEPLOYDIR}/
install -m 755 ${D}/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_dynamic.* ${DEPLOYDIR}/
}
addtask deploy before do_build after do_install
FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_jump.*"
FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_payload.*"
FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_dynamic.*"
COMPATIBLE_HOST = "(riscv64|riscv32).*"
INHIBIT_PACKAGE_STRIP = "1"
SECURITY_CFLAGS = ""
== bitbake -e opensbi
# $RISCV_SBI_PAYLOAD
# set? /home/rpjday/oe/dist/layers/openembedded-core/meta/conf/machine/include/riscv/qemuriscv.inc:23
# "${KERNEL_IMAGETYPE}-${MACHINE}.bin"
RISCV_SBI_PAYLOAD="Image-qemuriscv64.bin"
#
# $RISCV_SBI_PLAT
# set? /home/rpjday/oe/dist/layers/openembedded-core/meta/conf/machine/include/riscv/qemuriscv.inc:22
# "generic"
RISCV_SBI_PLAT="generic"
== git/build/platform/generic/firmware
With (default) kernel payload:
-rwxr-xr-x. 1 rpjday rpjday 96496 Feb 27 05:28 fw_dynamic.bin
-rwxr-xr-x. 1 rpjday rpjday 938520 Feb 27 05:28 fw_dynamic.elf
-rwxr-xr-x. 1 rpjday rpjday 96496 Feb 27 05:28 fw_jump.bin
-rwxr-xr-x. 1 rpjday rpjday 938104 Feb 27 05:28 fw_jump.elf
-rwxr-xr-x. 1 rpjday rpjday 24799752 Feb 27 05:28 fw_payload.bin
-rwxr-xr-x. 1 rpjday rpjday 23640912 Feb 27 05:28 fw_payload.elf
With ''u-boot.bin'' payload (note much smaller payload files):
-rwxr-xr-x. 2 rpjday rpjday 96496 Mar 1 06:10 fw_dynamic.bin
-rwxr-xr-x. 2 rpjday rpjday 938520 Mar 1 06:10 fw_dynamic.elf
-rwxr-xr-x. 2 rpjday rpjday 96496 Mar 1 06:10 fw_jump.bin
-rwxr-xr-x. 2 rpjday rpjday 938104 Mar 1 06:10 fw_jump.elf
-rwxr-xr-x. 2 rpjday rpjday 2713192 Mar 1 06:10 fw_payload.bin
-rwxr-xr-x. 2 rpjday rpjday 1554336 Mar 1 06:10 fw_payload.elf
== log.do_compile
make -j 8
PLATFORM=generic
I=/home/rpjday/oe/builds/oe_qemuriscv64/tmp-glibc/work/riscv64-oe-linux/opensbi/1.0-r0/image
FW_PIC=n CLANG_TARGET=
FW_PAYLOAD_PATH=.../qemuriscv64/Image-qemuriscv64.bin
== git/platform/generic/config.mk
# Compiler flags
platform-cppflags-y =
platform-cflags-y =
platform-asflags-y =
platform-ldflags-y =
# Command for platform specific "make run"
platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
-nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
# Blobs to build
FW_TEXT_START=0x80000000
FW_DYNAMIC=y
FW_JUMP=y
ifeq ($(PLATFORM_RISCV_XLEN), 32)
# This needs to be 4MB aligned for 32-bit system
FW_JUMP_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x400000)))
else
# This needs to be 2MB aligned for 64-bit system
FW_JUMP_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x200000)))
endif
FW_JUMP_FDT_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x2200000)))
FW_PAYLOAD=y
ifeq ($(PLATFORM_RISCV_XLEN), 32)
# This needs to be 4MB aligned for 32-bit system
FW_PAYLOAD_OFFSET=0x400000
else
# This needs to be 2MB aligned for 64-bit system
FW_PAYLOAD_OFFSET=0x200000
endif
FW_PAYLOAD_FDT_ADDR=$(FW_JUMP_FDT_ADDR)