This is an old revision of the document!
= 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]] == meta-riscv layer [abbreviated] * [[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/firmware|firmware/]] * [[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''. <code> $ MACHINE=qemuriscv64 bitbake core-image-full-cmdline $ runqemu nographic </code> == qemuriscv.sh To invoke your own script, remove ''-device bochs-display'' added by ''runqemu''. <code> $ 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 ' </code> Why create a kernel containing-payload if you don't use it? == tmp/deploy/images/qemuriscv64 Note which generated artifacts are used in the call to QEMU: <code> -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 </code> = The RISC-V kernel == linux-yocto_5.15.bb Carefully selected snippets: <code> 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}" </code> == Generated image/boot/ artifacts <code> -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 </code> == Selected snippets from kernel-meta/ === arch/riscv/ ==== riscv.scc <code> if [ "$KARCH" = "riscv" ]; then kconf hardware riscv.cfg include cfg/timer/hz_100.scc fi </code> ==== riscv.cfg <code> 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?] </code> === bsp/qemuriscv64/ ==== qemuriscv64.cfg <code> 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 </code> ==== qemuriscv64.scc <code> kconf hardware qemuriscv64.cfg # Graphics support include features/drm-bochs/drm-bochs.scc </code> ==== qemuriscv64-standard.scc <code> define KMACHINE qemuriscv64 define KTYPE standard define KARCH riscv64 include ktypes/standard/standard.scc include cfg/virtio.scc include qemuriscv64.scc </code> = opensbi == qemuriscv.inc variables <code> EXTRA_IMAGEDEPENDS += "opensbi" RISCV_SBI_PLAT ?= "generic" RISCV_SBI_PAYLOAD ?= "${KERNEL_IMAGETYPE}-${MACHINE}.bin" </code> == opensbi-payloads.inc <code> 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 "" </code> == opensbi_1.0.bb [master branch] <code> 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.*" </code> == bitbake -e opensbi <code> # $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" </code> == git/build/platform/generic/firmware <code> -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 </code> == log.do_compile <code> 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 </code> == git/platform/generic/config.mk <code> # 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) </code>