gpt4 book ai didi

linux - 如何在 QEMU 上模拟 Raspberry Pi 2?

转载 作者:IT王子 更新时间:2023-10-28 23:57:55 26 4
gpt4 key购买 nike

前段时间我在 this article 之后模拟了 Raspberry Pi , 但这种方法有几个问题:

  1. 速度很慢。
  2. 显示解决方案限于 800x600。
  3. 你不能模拟超过 256mb 的内存。

此外,Qemu 中没有针对新 Broadcom BCM2836 或任何其他基于 arm7 的 cpu 的仿真。 .但是,有几个原因可以说明为什么模拟 Raspberry Pi 会很有趣。因此,我对任何提示都感兴趣,这些提示可以将我推向正确的方向,以便使用 Qemu 或 Linux 下的任何其他仿真软件获得工作的 Raspberry Pi 2 仿真。

最佳答案

Ubuntu 16.04、QEMU 2.9.0 -M raspi2、Raspbian 2016-05-27、 Vanilla 内核

enter image description here

  1. 从源代码编译 QEMU 2.9.0:

    sudo apt-get build-dep qemu-system-arm
    git clone --recursive git://git.qemu-project.org/qemu.git
    cd qemu
    git checkout v2.9.0
    ./configure
    make `nproc`
  2. 下载镜像并从中提取内核和dts:

    1. 下载图片并解压:

      wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27-raspbian-jessie.zip
      unzip 2016-05-27-raspbian-jessie.zip
    2. 挂载分区的第二个镜像。最简单的方法是:

      sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img

      这仅适用于 Ubuntu 16.04 上的最新 losetup,其他方法位于:https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576

      这会打印一个循环设备,例如:

      /dev/loop0

      我们这样做:

      sudo mkdir /mnt/rpi
      sudo mount /dev/loop0p1 /mnt/rpi
      cp /mnt/rpi/kernel7.img .
      cp /mnt/rpi/bcm2709-rpi-2-b.dtb .
      sudo umount /mnt/rpi
      sudo losetup -d /dev/loop0
  3. 运行:

    ./arm-softmmu/qemu-system-arm \
    -M raspi2 \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2" \
    -cpu arm1176 \
    -dtb bcm2709-rpi-2-b.dtb \
    -sd 2016-05-27-raspbian-jessie.img \
    -kernel kernel7.img \
    -m 1G \
    -smp 4 \
    -serial stdio \
    ;

然后您可以在主机终端上显示的终端上登录。

当前限制:

  • -M raspi2是QEMU 2.6.0加入的,而Ubuntu 16.04只有QEMU 2.5.0,所以我们要从源码编译QEMU。但这并不难。
  • GUI 显示但不响应鼠标/键盘,已在 SDL 和 VNC 上测试。但是 CLI 却工作得很好。因此,您不妨暂时使用具有 go GUI 的 Lite 图像。
  • 没有网络

Ubuntu 16.04、QEMU 2.5.0、Raspbian 2016-05-27、修改内核

此方法使用 Ubuntu 16.04 的 QEMU 2.5.0 上的 -M versatilepb

缺点是您必须下载修改后的内核(参见 https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel ),并修改镜像,因此它不太能代表真实系统。

  1. 下载:https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/36ede073f4ccb64f60200ede36c231afe9502070/kernel-qemu-4.4.12-jessie

    我们选择 4.4.12,因为这是 Raspbian 镜像中的内核版本。

    生成该内核 blob 的过程在存储库中有描述:https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools

    为什么需要这个额外的内核镜像:https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel

  2. 按照以下位置修改 Raspbian 镜像:https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c

    总结:

    1. 像我们为 -M raspi2 一样安装镜像,但使用第二个分区而不是第一个分区:

      sudo mount /dev/loop0p2 /mnt/rpi
    2. 编辑图片:

      # Comment out the line present there with #
      sudo vim /mnt/rpi/etc/ld.so.preload
      # Comment out the lines of type: "/dev/mmcblk*"
      sudo vim /mnt/rpi/etc/fstab
  3. 运行:

    sudo apt-get install qemu-system-arm
    qemu-system-arm \
    -kernel kernel-qemu-4.4.12-jessie \
    -cpu arm1176 \
    -m 256 \
    -M versatilepb \
    -no-reboot \
    -serial stdio \
    -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
    -hda 2016-05-27-raspbian-jessie.img

[失败] Ubuntu 17.04、QEMU 2.8.0 -M raspi2、Raspbian 2016-05-27、 Vanilla 内核

在这个较新的 Ubuntu 上,QEMU 2.8.0 是默认的,因此我们不需要为 -M raspi2 从源代码编译 QEMU。但是,2.8.0 在出现以下消息后在启动时挂起:

Console: switching to colour frame buffer device 100x30

这表明 -M raspi2 仍然不稳定。

[失败] Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2017-08-16, Vanilla 内核

在这个较新的图像上,使用与 2016-05-27 相同的方法,内核在启动时出现 panic :

Please append a correct "root=" boot option; here are the available partitions:
...
[ 4.138114] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

待办事项:sschoof mentions rootdelay=1 解决了这个问题,我必须尝试一下。

bztsrc/raspi3-tutorial QEMU 上的 RPI3 裸机

https://github.com/bztsrc/raspi3-tutorial是一组很好的例子,只适用于 QEMU,超快速入门:https://raspberrypi.stackexchange.com/questions/34733/how-to-do-qemu-emulation-for-bare-metal-raspberry-pi-images/85135#85135

关于linux - 如何在 QEMU 上模拟 Raspberry Pi 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28880833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com