繁体   English   中英

如何在QEMU上模拟Raspberry Pi 2?

[英]How to emulate the Raspberry Pi 2 on QEMU?

前段时间我在本文后仿效了Raspberry Pi,但这种方法有几个问题:

  1. 这很慢。
  2. 显示解决方案限制为800x600。
  3. 你无法模仿超过256mb的ram。

此外,在Qemu中没有新的Broadcom BCM2836或任何其他基于arm7的CPU的仿真。 但是,有几个原因,为什么模仿Raspberry Pi会很有趣。 因此,我感兴趣的任何提示都可以帮助我在正确的方向上使用Qemu或Linux下的任何其他仿真软件来获得可用的Raspberry Pi 2仿真。

如果你想运行Raspberry Pi 2 build bot或类似的东西,你应该看看在用户/静态模式下运行Qemu 我在虚拟机中使用Linux尝试了这一点,与Qemu系统仿真相比,速度非常快。 不幸的是,它只能模拟CPU,因此您将无法测试游戏或Wayland / Weston。

我使用这种方法在大约一个小时内为我的Pi 2构建了一个内核。

如果你很乐意构建qemu,你可以在这里找到对pi2系统仿真的支持: https//github.com/0xabu/qemu 它不是特别快速,并且设备仿真不完整,但您可以调整RAM和帧缓冲区的大小。

https://github.com/0xabu/qemu/wiki末尾有关于启动Raspbian的简要说明

Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2016-05-27,香草内核

在此输入图像描述

  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 

      这仅与最新作品losetup在Ubuntu 16.04,其他方法在: 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 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工作得很好。 所以你不妨使用现在已经使用GUI的Lite图像。
  • 没有网络

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

此方法使用-M versatilepb ,它存在于Ubuntu 16.04的QEMU 2.5.0上。

缺点是您必须下载修改后的内核(请参阅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,香草内核

在这个较新的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,香草内核

在这个较新的图像上,使用相同的方法2016-05-27,内核在启动时发生恐慌:

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)

TODO: sschoof提到 rootdelay=1解决了这个问题,我必须尝试一下。

在QEMU上使用bztsrc/raspi3-tutorial RPI3裸机

https://github.com/bztsrc/raspi3-tutorial是一套很好的例子,可以在QEMU上工作,超级快速入门: https ://raspberrypi.stackexchange.com/questions/34733/how-to-do- QEMU仿真换裸机-覆盆子-PI-图像/ 85135#85135

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM