View previous topic :: View next topic |
Author |
Message |
brendlefly62 Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/3917469165880438e1c4a2.jpg)
Joined: 19 Dec 2009 Posts: 158
|
Posted: Sat Feb 08, 2025 7:29 pm Post subject: Gentoo raspi4b image on qemu |
|
|
Hi! I created an image of a working raspberry pi 4 b system running gentoo, and I want to boot it as a vm on qemu-system-aarch64. I don't have it working yet and could use help with qemu basics. [/b]
I do have a raspi3b qemu vm running, using the "raspi3b" machine available in qemu, passing keyboard through to the vm as a usb-host, using the following script. Code: | qemu-system-aarch64 \
-M raspi3b \
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 console=tty1 \
coherent_pool=1M 8250.nr_uarts=0 \
snd_bcm2835.enable_headphones=0 snd_bcm2835.enable_headphones=1 \
snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=720 bcm2708_fb.fbheight=480 \
bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3f000000 \
vc_mem.mem_size=0x3f600000 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 \
rootfstype=ext4 rootdelay=1 elevator=deadline fsck.repair=yes verbosity=2 \
net.ifnames=0" \
-dtb bcm2710-rpi-3-b-plus.dtb \
-drive if=sd,file=raspi36402-6.6.13.img,format=raw \
-kernel kernel8.img-6.11.1 \
-m 1G -smp 4 \
-serial stdio \
-device usb-net,netdev=net0 -netdev user,id=net0 \
-device usb-host,hostbus=1,hostaddr=15 \
&
|
I could not replicate that success with a raspi4b image and the "raspi4b" machine in qemu (available only on ~arm64 qemu). My "raspi4b" machine boots nicely in a graphical qemu window like the raspi3b, but I can find no combination of settings to get a keyboard working with it. Here is my non-working script for that -- Code: | qemu-system-aarch64 \
-M raspi4b \
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 console=tty1 \
coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_headphones=0 \
snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 \
bcm2708_fb.fbwidth=720 bcm2708_fb.fbheight=480 \
bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3f000000 \
vc_mem.mem_size=0x3f600000 dwc_otg.lpm_enable=0 \
root=/dev/mmcblk1p2 rootfstype=ext4 rootdelay=1 elevator=deadline fsck.repair=yes \
verbosity=2 net.ifnames=0" \
-dtb bcm2711-rpi-4-b.dtb \
-drive if=sd,file=raspi464q1.img,format=raw \
-kernel kernel8.img-6.12.9 \
-m 2G -smp 4 \
-serial stdio \
-device usb-net,netdev=net0 -netdev user,id=net0 \
-device usb-host,hostbus=1,hostaddr=15 \
& | Here is a link to a png image screenshot of the qemu window --
https://paste.gentoo.zip/GVTtlHKL
This raspi4b does not work. It boots nicely all the way to a login prompt, but the keyboard does not work so I cannot log in... and it seems the keyboard is the only thing that doesn't work. A pointer to any obvious error would be really helpful.
So, I also tried using the "virt" machine in qemu as shown below, using efi and grub. This seems promising, but I'm not quite there yet. With the following script, I can chroot into my image (raspi464q1.img) after having qemu boot from a recent minimal iso (install-arm64-minimal-20250126T230320Z.iso). Code: | #!/bin/bash
qemu-system-aarch64 -nographic \
-machine virt,gic-version=max \
-m 2048M \
-cpu max \
-smp 4 \
-bios /usr/share/qemu/edk2-aarch64-code.fd \
-netdev user,id=vnet,hostfwd=:127.0.0.1:5555-:22,net=192.168.122.0/24,host=192.168.122.145 \
-device virtio-net-pci,netdev=vnet \
-drive file=raspi464q1.img,if=none,id=hd0,format=raw \
-device virtio-blk-device,drive=hd0 \
-name "Gentoo arm64 VM raspi464q1" \
-device virtio-rng-pci \
-drive file=install-arm64-minimal-20250126T230320Z.iso,if=none,id=hd1,format=raw \
-device virtio-blk-device,drive=hd1 |
The chroot works fine, taking over the terminal window of the host workstation on which I launch the qemu session. I have run emerge --sync and installed grub from inside the chroot. <-- I believe that is necessary because the original raspi4 system from which this image came does not use grub -- it just boots as a raspi normally would - from data in /boot/confit.txt and /boot/cmdline.txt
However, when I comment out the last two lines of the script above, and run it again, It doesn't work. At first, I do get a nice grub menu htat matches the configuration I build with grub-mkconfig, and it says it's loading Linux, but then I just get three lines from the EFI boot service -- Code: | Loading Linux kernel8.img-6.12.9-v8-rpi4-2711-joetoo ...
EFI stub: Booting Linux Kernel...
EFI stub: Generating empty DTB
EFI stub: Exiting boot services... | It goes no further...
I've reviewed several other posts including these --
https://wiki.gentoo.org/wiki/QEMU/Linux_guest
https://forums.gentoo.org/viewtopic-p-8824260.html?sid=e23e1b3728c9c9e0588f6f4202c42aae
Any pointers would be helpful -- that could help me learn why the keyboard doesn't work in my "raspi4b" machine or about why the efi/grub "virt" machine doesn't boot properly.[b] |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
gentoo_ram Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 25 Oct 2007 Posts: 517 Location: San Diego, California USA
|
Posted: Mon Feb 10, 2025 5:38 am Post subject: |
|
|
Something doesn't sound right. There is no EFI or GRUB on a real Raspberry Pi. Is there a way to make the VM not have those features? Also RPi's contain a bootloader that probably inintializes a lot of hardware, reads the stuff in /boot/config.txt and /boot/cmdline.txt, and loads the kernel to the appropriate address. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
brendlefly62 Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/3917469165880438e1c4a2.jpg)
Joined: 19 Dec 2009 Posts: 158
|
Posted: Mon Feb 10, 2025 5:08 pm Post subject: |
|
|
Hi, gentoo_ram. Thanks for responding to my help request. Yes, it's my preference to do this w/o EFI. My primary method of using qemu to emulate rpi boards has been to employ the machine types available in qemu for some raspi boards, but the "raspi4b" machine type is only available in a version of qemu not yet considered stable, and it "didn't work" for me - so I have also tried to use the "virt" machine type and specify appropriate rpi cpus to make a "poor man's raspi4" emulation platform.
Note: even with my preferred method, qemu does not use raspi's boodloader, firmware, or any of the files normally in the boot fs on a physical raspi... When using "-M raspi3b" in the vm that "works" (see OP), I provide a copy of the kernel, dtb, (and maybe initramfs) on the host, external to the vm's "image" file, and I specify each of these in the qemu-system-aarch64 (or qemu-system-arm) command line (see original post)
Since it "didn't work" for me with "-M raspi4b", I tried a different (EFI) method with "-M virt" which allows me to boot my gentoo install-arm64- iso file on the "virt" platform with cortex-a72 cpus and attch my raspi image (built with dd from an actual working raspi4 sd card) as an additional disk (vdb). The iso file contains a grub boot loader, kernel, and initramfs, so I don't have to provide them externally. This method also does not use an actual raspi device tree - qemu/EFI build a device tree for the virt platform "on the fly." This way, I can chroot into my image and run it just fine... -- but I haven't been able to make it bootable by qemu like the iso image... |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|