2

I've built a yocto image for the raspberry pi model 3 and I'd like to run it in Qemu. The build process for the core-image-minimal runs fine and if I build it for the raspberry3-64 machine instead of the qemuarm and flash the image to the SD card I can boot to the console as intended.

build git:(dunfell) bitbake core-image-base   
WARNING: Host distribution "ubuntu-22.04" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
Loading cache: 100% |############################################| Time: 0:00:01
Loaded 3298 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "arm-poky-linux-gnueab"
MACHINE              = "qemux86-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.22"
TUNE_FEATURES        = "arm armv7ve vfp thumb neon callconvention-hard"
TARGET_FPU           = "hard"
meta                 
meta-poky            
meta-yocto-bsp       = "dunfell:6b8a307b7843af23d189d7ffcecf32c05afac850"
meta-oe              
meta-python          
meta-multimedia      
meta-networking      = "dunfell:e707e9b7cf5c62bff4fee029965a87b22dd4ccba"
meta-raspberrypi     = "dunfell:2081e1bb9a44025db7297bfd5d024977d42191ed"

Initialising tasks: 100% |#######################################| Time: 0:00:02
Checking sstate mirror object availability: 100% |###############| Time: 0:04:40
Sstate summary: Wanted 836 Found 7 Missed 829 Current 355 (0% match, 30% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 3162 tasks of which 1267 didn't need to be rerun and all succeeded.

Summary: There was 1 WARNING message shown.

But when I try to run this image in qemu, it doesn't seem to work...

➜  build git:(dunfell) runqemu core-image-base
runqemu - INFO - Running bitbake -e ...
runqemu - INFO - Continuing with the following parameters:
KERNEL: [/home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/deploy/images/qemuarm/bzImage]
MACHINE: [qemuarm]
FSTYPE: [ext4]
ROOTFS: [/home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/deploy/images/qemuarm/core-image-base-qemuarm.ext4]
CONFFILE: [/home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/deploy/images/qemuarm/core-image-base-qemuarm.qemuboot.conf]

runqemu - INFO - Setting up tap interface under sudo
[sudo] password for wtech: 
runqemu - INFO - Network configuration: ip=192.168.7.2::192.168.7.1:255.255.255.0
runqemu - INFO - Running /home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/qemu-system-arm -device virtio-net-device,netdev=net0,mac=52:54:00:12:34:02 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -drive id=disk0,file=/home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/deploy/images/qemuarm/core-image-base-qemuarm.ext4,if=none,format=raw -device virtio-blk-device,drive=disk0 -show-cursor -device VGA,edid=on -device qemu-xhci -device usb-tablet -device usb-kbd -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0  -machine virt,highmem=off -cpu cortex-a15 -m 256 -serial mon:vc -serial null -kernel /home/wtech/Workspace/rpi-yocto/poky-dunfell/build/tmp/deploy/images/qemuarm/zImage -append 'root=/dev/vda rw  mem=256M ip=192.168.7.2::192.168.7.1:255.255.255.0 console=ttyAMA0 '

No progress after that. I also tried to build for qemux86_64 but the outcome is the same. What do i have to change in order to be able to emulate the image using qemu so I don't have to flash the SD card for every change I do?

My host system is a virtualized (VirtualBox) Ubutu 22.04

Update: In case it adds any information, this is the output of ps -la when the runqemu hangs.

~ ps -la
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000    1097    1091  0  80   0 - 57920 do_pol tty2     00:00:00 gnome-session-b
0 S  1000    2338    1811  0  80   0 -  8634 do_wai pts/0    00:00:00 python3
2 R  1000    2399    2338 89  80   0 - 311794 -     pts/0    00:00:09 qemu-system-arm 
0 R  1000    2434    2081  0  80   0 -  5331 -      pts/1    00:00:00 ps

Update:

In case someone ever tries the same. I couldn't manage to run it with the yocto runqemu environment. What did work in the end was to manually install qemu-system-aarch64 and run the build with

qemu-system-aarch64 \
-M virt -cpu cortex-a57 \
-kernel tmp/deploy/images/qemuarm64/Image--5.4.228+gitAUTOINC+b00c12ce7a_2bd8ca7c09-r0-qemuarm64-20230208202924.bin \
-append "root=/dev/vda rw mem=512M earlyprintk console=ttyAMA0,115200" \
-drive id=disk0,file=tmp/deploy/images/qemuarm64/core-image-base-qemuarm64-20230215193657.rootfs.ext4,format=raw,if=none \
-smp 4 \ 
-device virtio-blk-device,drive=disk0 -device qemu-xhci \
-serial mon:vc -serial null \
-display sdl,gl=on \
-device virtio-rng-pci,rng=rng0 \
-object rng-random,filename=/dev/urandom,id=rng0
7

1 Answer 1

2

Yocto qemuarm Image is for ARM926EJ-S Versatile Board. runqemu will configure QEMU to emulate exactly that board. This is different from a Raspberry Pi, especially a 64-bit one.

Instead, just use QEMU directly. Check that qemu-system-arm -M ? lists raspi3b and then specify kernel, DT and SD directly. Googling I found this:

qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a72 \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
    -dtb bcm2710-rpi-3-b-plus.dtb \
    -sd disk.img \
    -kernel kernel8.img \
    -m 1G -smp 4 \
    -serial stdio \
    -usb -device usb-mouse -device usb-kbd \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22

I haven't found QEMU for embedded development terribly useful though. Either you have something well isolated that you could compile for your Linux setup locally or you have something hardware-specific that you'd rather want to test on actual HW and not on an incomplete emulation. For automated testing, it surely is nice though.

For the problem of slow iterations, consider booting from a shared medium, e.g. via the network or from a muxable SD-Card (e.g. https://www.linux-automation.com/en/products/usb-sd-mux.html which my employer sells).

6
  • Thanks, I'll give it a try. The main reason for me to initially work with qemu is the steep learning curve of yocto/bitbake itself. To test custom layers or kernel modules I thought it would be handier to just have the image emulated than always have to swap the SD card. I also thought about network booting with U-Boot, but that will be a future topic.
    – po.pe
    Commented Feb 13, 2023 at 9:49
  • @po.pe You can still build the image for qemuarm64 and test it with runqemu, just without the rpi-specific parts.
    – a3f
    Commented Feb 13, 2023 at 12:59
  • You mean I'd have to remove the meta-raspberrypi layer?
    – po.pe
    Commented Feb 13, 2023 at 13:05
  • No. Just ensure that when you add rpi-specific parts, it's only for your raspberry pi $MACHINE: docs.yoctoproject.org/…
    – a3f
    Commented Feb 13, 2023 at 13:07
  • But what is the reason that my qemu console doesn't come up? If the build is wrong, I'd expect an error in qemu but it seems like it doesn't start at all.
    – po.pe
    Commented Feb 13, 2023 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .