如何在QEMU上模拟Raspberry Pi 2?

问题描述 投票:11回答:3

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

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

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

linux raspberry-pi emulation raspberry-pi2 qemu
3个回答
5
投票

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

有关在https://github.com/0xabu/qemu/wiki结束时启动Raspbian的简要说明


11
投票

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

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


5
投票

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

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: 下载图像并解压缩: wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27-raspbian-jessie.zip unzip 2016-05-27-raspbian-jessie.zip 挂载分区的第二个图像。最简单的方法是: 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 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所述 摘要: 像我们为-M raspi2所做的那样挂载图像,但使用第二个分区而不是第一个分区: sudo mount /dev/loop0p2 /mnt/rpi 编辑图像: # 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 mentions rootdelay=1解决了这个问题,我必须尝试一下。

QEMU上的bztsrc/raspi3-tutorial RPI3裸机

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

© www.soinside.com 2019 - 2024. All rights reserved.