使用 QEMU 模拟 Raspberry Pi 4?

问题描述 投票:0回答:5

我想使用 QEMU 模拟 Raspberry Pi 4,但我找不到 RPi4 的任何图像。我需要一个 QEMU 可以模拟 Cortex-A72 的内核。

raspberry-pi arm qemu raspberry-pi4
5个回答
6
投票

QEMU 目前没有树莓派 4 的型号(只有 0、1ap、2b、3ap 和 3b)。如果 QEMU 支持的其他机器类型对您来说足够好,您可以为该机器类型构建一个内核并使用它。 (例如,对于很多人来说,他们真正想要的是“启动 64 位 Linux 用户空间”,并且不需要它与 Raspberry Pi 板硬件完全匹配;对于这些人来说,“虚拟”板通常是一个不错的选择。)

无论你做什么,你都需要确保你要求 QEMU 模拟的机器类型与你为其构建内核的机器类型相匹配——如果你尝试在不支持的板上启动内核,它将无法启动工作。


6
投票

我只是在x86 ubuntu笔记本上启动raspios bullseye,它可以显示桌面,可以登录。但是速度很慢。

qemu-system-aarch64 -M virt,highmem=off -smp 8 -m 2G -cpu cortex-a72 -kernel linux-stable/arch/arm64/boot/Image -append root=PARTUUID=d97f5830-02 rw console=ttyAMA0 -serial telnet:localhost:4321,server,nowait -monitor telnet:localhost:4322,server,nowait -device VGA,id=vga1 -device secondary-vga,id=vga2 -object iothread,id=io1 -device virtio-blk-pci,drive=disk0,iothread=io1 -drive data/images/2022-01-28-raspios-bullseye-arm64.img

我按照本指南构建内核映像。

https://github.com/anholt/linux/wiki/Raspberry-Pi-development-environment#building-the-Kernel

当然,由于 raspios 是在 x86 笔记本电脑上模拟的,所以速度肯定很慢。所以,如果你可以在arm64主机上虚拟化它,你就可以使用像kvm、hvf等加速器

    qemu-system-aarch64 \
      -M virt,highmem=off,accel=hvf \
      -cpu host \
      -m 1G \
      -smp 4 \
      -kernel $KERNEL_IMAGE_PATH -append "root=/dev/vda2 rw console=ttyAMA0" \
      -netdev user,id=n1,ipv6=off,hostfwd=tcp::5555-:22 -device e1000,netdev=n1 \
      -hda data/images/2022-01-28-raspios-bullseye-arm64.img \
      -serial telnet:localhost:4321,server,nowait \
      -monitor telnet:localhost:4322,server,nowait \
      -device VGA,id=vga2 \
      -drive file=data/images/2021-10-30-raspios-bullseye-armhf.img,if=virtio

3
投票

如果需要的话,这里有一个补丁。 您可以使用raspi4b2g编译qemu (补丁不是我提供的)

https://github.com/0xMirasio/qemu-patch-raspberry4.git


0
投票

或者尝试以下分支(2019),它可能是也可能不是等同于已经提到的补丁: https://gitlab.com/philmd/qemu/-/tree/raspi4_wip


0
投票

我已经在

https://github.com/U007D/qemu
发布了
qemu
存储库的一个分支,其中 -machine raspi4b 经过了冒烟测试。感谢 Sergey Kambalin 和他的补丁集的工作。

tl;dr 构建说明:

  • 安装
    qemu
    prereqs 并克隆上面的
    qemu
    存储库
  • cd qemu && mkdir build && cd build
  • ../configure --disable-werror
    --disable-werror
    是必需的(至少在 macOS 上),因为从 XCode 15 开始,链接器选项发生了更改,这会针对先前有效的参数发出警告。在其他平台上可能不需要。构建在其他方面是干净的。
  • make
    (在测试阶段编译后,此编译仍然会失败(测试失败记录在上面链接的补丁线程中)
  • ./qemu-system-<your_host_architecture> -machine help
    将显示
    raspi4b
    作为支持的机器之一。
  • 享受吧!
© www.soinside.com 2019 - 2024. All rights reserved.