Some time ago I emulated the Raspberry Pi following this article, but this approach has several problems:
前段时间我在本文后仿效了Raspberry Pi,但这种方法有几个问题:
- It is very slow.
- 这很慢。
- The display solution is limited to 800x600.
- 显示解决方案限制为800x600。
- You cannot emulate more than 256mb ram.
- 你不能模仿超过256mb ram。
Furthermore there is no emulation for the new Broadcom BCM2836 or any other arm7 based cpu in Qemu. However, there are several reasons, why it would be interesting to emulate the Raspberry Pi. So I am interested in any hints that push me in the right direction to get a working Raspberry Pi 2 emulation using Qemu or any other emulation software under Linux.
此外,在Qemu中没有新的Broadcom BCM2836或任何其他基于arm7的CPU的仿真。但是,有几个原因,为什么模仿Raspberry Pi会很有趣。因此,我感兴趣的任何提示都可以帮助我在正确的方向上使用Qemu或Linux下的任何其他仿真软件来获得可用的Raspberry Pi 2仿真。
3 个解决方案
#1
5
If you're comfortable building qemu, you can find support for pi2 system emulation here: https://github.com/0xabu/qemu. It's not particularly speedy, and the device emulations are incomplete, but you can resize the RAM and framebuffer.
如果你很乐意构建qemu,你可以在这里找到对pi2系统仿真的支持:https://github.com/0xabu/qemu。它不是特别快速,并且设备仿真不完整,但您可以调整RAM和帧缓冲区的大小。
There are brief instructions for booting Raspbian at the end of https://github.com/0xabu/qemu/wiki
在https://github.com/0xabu/qemu/wiki末尾有关于启动Raspbian的简要说明
#2
11
If you want to run a Raspberry Pi 2 build bot or something similar you should take a look at running Qemu in user/static mode. I tried this using Linux in a virtual machine, it's quite fast compared to Qemu system emulation. Unfortunately it only emulates the CPU so you won't be able to test games or Wayland/Weston.
如果你想运行Raspberry Pi 2 build bot或类似的东西,你应该看一下在用户/静态模式下运行Qemu。我在虚拟机中使用Linux尝试了这个,与Qemu系统仿真相比,速度非常快。不幸的是,它只能模拟CPU,因此您将无法测试游戏或Wayland / Weston。
I was able to build a kernel for my Pi 2 in roughly a hour using this method.
我使用这种方法在大约一个小时内为我的Pi 2构建了一个内核。
#3
2
Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel
Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2016-05-27,香草内核
-
Compile QEMU 2.9.0 from source:
从源代码编译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`
-
Download image and extract the kernel and dts from it:
下载图像并从中提取内核和dts:
-
Download the image and unzip it:
下载图像并解压缩:
wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27-raspbian-jessie.zip unzip 2016-05-27-raspbian-jessie.zip
-
Mount the second image of the partition. The easiest way is:
挂载分区的第二个图像。最简单的方法是:
sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
This only works with latest
losetup
on Ubuntu 16.04, other methods at: https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576这仅适用于Ubuntu 16.04上的最新版本,其他方法适用于:https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576
This prints a loop device, e.g.:
这打印一个循环设备,例如:
/dev/loop0
so we do:
所以我们这样做:
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
-
-
Run:
跑:
./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 \ ;
You can then login on the terminal that shows on your host terminal.
然后,您可以登录主机终端上显示的终端。
Current limitations:
目前的限制:
-
-M raspi2
was added in QEMU 2.6.0, and Ubuntu 16.04 only has QEMU 2.5.0, so we have to compile QEMU from source. But this is not hard. - -M raspi2在QEMU 2.6.0中添加,而Ubuntu 16.04只有QEMU 2.5.0,因此我们必须从源代码编译QEMU。但这并不难。
- the GUI shows but is not responding to the mouse / keyboard, tested on both SDL and VNC. But CLI works perfectly however. So you might as well use the Lite image which has go GUI for now.
- GUI显示但没有响应鼠标/键盘,在SDL和VNC上都进行了测试。但是CLI工作得很好。所以你不妨使用现在已经使用GUI的Lite图像。
- no networking
- 没有网络
Ubuntu 16.04, QEMU 2.5.0, Raspbian 2016-05-27, modified kernel
Ubuntu 16.04,QEMU 2.5.0,Raspbian 2016-05-27,修改内核
This method uses -M versatilepb
which is present on the QEMU 2.5.0 of Ubuntu 16.04.
此方法使用-M versatilepb,它存在于Ubuntu 16.04的QEMU 2.5.0上。
The downside is that you have to download a modified kernel (see https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel), and modify the image, so it is less representative of the real system.
缺点是您必须下载修改后的内核(请参阅https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel),并修改图像,因此它是不太代表真实的系统。
-
下载:https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/36ede073f4ccb64f60200ede36c231afe9502070/kernel-qemu-4.4.12-jessie
We pick
4.4.12
since that is the kernel version in the Raspbian image.我们选择4.4.12,因为这是Raspbian图像中的内核版本。
The process to generate that kernel blob is described at in the repository at: https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools
生成该内核blob的过程在以下位置的存储库中进行了描述:https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools
Why this extra kernel image is needed: https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel
为什么需要这个额外的内核映像:https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel
-
Modify the Raspbian image as mentioned at: https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c
修改Raspbian图像,如下所述:https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c
Summary:
概要:
-
Mount the image just as we did for the
-M raspi2
, but use the second partition instead of the first:正如我们对-M raspi2所做的那样挂载图像,但是使用第二个分区而不是第一个分区:
sudo mount /dev/loop0p2 /mnt/rpi
-
Edit the image:
编辑图像:
# 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
-
-
Run:
跑:
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
[failed] Ubuntu 17.04, QEMU 2.8.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel
[失败] Ubuntu 17.04,QEMU 2.8.0 -M raspi2,Raspbian 2016-05-27,香草内核
On this newer Ubuntu, QEMU 2.8.0 is the default, so we don't need to compile QEMU from source for -M raspi2
. However, 2.8.0 hangs on boot after the message:
在这个较新的Ubuntu上,QEMU 2.8.0是默认的,因此我们不需要从源代码为-M raspi2编译QEMU。但是,消息后,2.8.0在启动时挂起:
Console: switching to colour frame buffer device 100x30
This goes to show how unstable -M raspi2
still is.
这表明不稳定的-M raspi2仍然存在。
[failed] Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2017-08-16, vanilla kernel
[失败] Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2017-08-16,香草内核
On this newer image, using the same method for 2016-05-27, the kernel panics at boot with:
在这个较新的图像上,使用相同的方法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)
bztsrc/raspi3-tutorial
RPI3 bare metal on QEMU
在QEMU上使用bztsrc / raspi3-tutorial RPI3裸机
https://github.com/bztsrc/raspi3-tutorial is a good set of examples that just work on QEMU, ultraquick getting started at: https://raspberrypi.stackexchange.com/questions/34733/how-to-do-qemu-emulation-for-bare-metal-raspberry-pi-images/85135#85135
https://github.com/bztsrc/raspi3-tutorial是一套很好的例子,只适用于QEMU,来自的快速入门:https://raspberrypi.stackexchange.com/questions/34733/how-to-do- QEMU仿真换裸机-覆盆子-PI-图像/ 85135#85135
#1
5
If you're comfortable building qemu, you can find support for pi2 system emulation here: https://github.com/0xabu/qemu. It's not particularly speedy, and the device emulations are incomplete, but you can resize the RAM and framebuffer.
如果你很乐意构建qemu,你可以在这里找到对pi2系统仿真的支持:https://github.com/0xabu/qemu。它不是特别快速,并且设备仿真不完整,但您可以调整RAM和帧缓冲区的大小。
There are brief instructions for booting Raspbian at the end of https://github.com/0xabu/qemu/wiki
在https://github.com/0xabu/qemu/wiki末尾有关于启动Raspbian的简要说明
#2
11
If you want to run a Raspberry Pi 2 build bot or something similar you should take a look at running Qemu in user/static mode. I tried this using Linux in a virtual machine, it's quite fast compared to Qemu system emulation. Unfortunately it only emulates the CPU so you won't be able to test games or Wayland/Weston.
如果你想运行Raspberry Pi 2 build bot或类似的东西,你应该看一下在用户/静态模式下运行Qemu。我在虚拟机中使用Linux尝试了这个,与Qemu系统仿真相比,速度非常快。不幸的是,它只能模拟CPU,因此您将无法测试游戏或Wayland / Weston。
I was able to build a kernel for my Pi 2 in roughly a hour using this method.
我使用这种方法在大约一个小时内为我的Pi 2构建了一个内核。
#3
2
Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel
Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2016-05-27,香草内核
-
Compile QEMU 2.9.0 from source:
从源代码编译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`
-
Download image and extract the kernel and dts from it:
下载图像并从中提取内核和dts:
-
Download the image and unzip it:
下载图像并解压缩:
wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27-raspbian-jessie.zip unzip 2016-05-27-raspbian-jessie.zip
-
Mount the second image of the partition. The easiest way is:
挂载分区的第二个图像。最简单的方法是:
sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
This only works with latest
losetup
on Ubuntu 16.04, other methods at: https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576这仅适用于Ubuntu 16.04上的最新版本,其他方法适用于:https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576
This prints a loop device, e.g.:
这打印一个循环设备,例如:
/dev/loop0
so we do:
所以我们这样做:
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
-
-
Run:
跑:
./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 \ ;
You can then login on the terminal that shows on your host terminal.
然后,您可以登录主机终端上显示的终端。
Current limitations:
目前的限制:
-
-M raspi2
was added in QEMU 2.6.0, and Ubuntu 16.04 only has QEMU 2.5.0, so we have to compile QEMU from source. But this is not hard. - -M raspi2在QEMU 2.6.0中添加,而Ubuntu 16.04只有QEMU 2.5.0,因此我们必须从源代码编译QEMU。但这并不难。
- the GUI shows but is not responding to the mouse / keyboard, tested on both SDL and VNC. But CLI works perfectly however. So you might as well use the Lite image which has go GUI for now.
- GUI显示但没有响应鼠标/键盘,在SDL和VNC上都进行了测试。但是CLI工作得很好。所以你不妨使用现在已经使用GUI的Lite图像。
- no networking
- 没有网络
Ubuntu 16.04, QEMU 2.5.0, Raspbian 2016-05-27, modified kernel
Ubuntu 16.04,QEMU 2.5.0,Raspbian 2016-05-27,修改内核
This method uses -M versatilepb
which is present on the QEMU 2.5.0 of Ubuntu 16.04.
此方法使用-M versatilepb,它存在于Ubuntu 16.04的QEMU 2.5.0上。
The downside is that you have to download a modified kernel (see https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel), and modify the image, so it is less representative of the real system.
缺点是您必须下载修改后的内核(请参阅https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel),并修改图像,因此它是不太代表真实的系统。
-
下载:https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/36ede073f4ccb64f60200ede36c231afe9502070/kernel-qemu-4.4.12-jessie
We pick
4.4.12
since that is the kernel version in the Raspbian image.我们选择4.4.12,因为这是Raspbian图像中的内核版本。
The process to generate that kernel blob is described at in the repository at: https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools
生成该内核blob的过程在以下位置的存储库中进行了描述:https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools
Why this extra kernel image is needed: https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel
为什么需要这个额外的内核映像:https://raspberrypi.stackexchange.com/questions/47124/emulating-with-qemu-why-the-extra-kernel
-
Modify the Raspbian image as mentioned at: https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c
修改Raspbian图像,如下所述:https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c
Summary:
概要:
-
Mount the image just as we did for the
-M raspi2
, but use the second partition instead of the first:正如我们对-M raspi2所做的那样挂载图像,但是使用第二个分区而不是第一个分区:
sudo mount /dev/loop0p2 /mnt/rpi
-
Edit the image:
编辑图像:
# 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
-
-
Run:
跑:
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
[failed] Ubuntu 17.04, QEMU 2.8.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel
[失败] Ubuntu 17.04,QEMU 2.8.0 -M raspi2,Raspbian 2016-05-27,香草内核
On this newer Ubuntu, QEMU 2.8.0 is the default, so we don't need to compile QEMU from source for -M raspi2
. However, 2.8.0 hangs on boot after the message:
在这个较新的Ubuntu上,QEMU 2.8.0是默认的,因此我们不需要从源代码为-M raspi2编译QEMU。但是,消息后,2.8.0在启动时挂起:
Console: switching to colour frame buffer device 100x30
This goes to show how unstable -M raspi2
still is.
这表明不稳定的-M raspi2仍然存在。
[failed] Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2017-08-16, vanilla kernel
[失败] Ubuntu 16.04,QEMU 2.9.0 -M raspi2,Raspbian 2017-08-16,香草内核
On this newer image, using the same method for 2016-05-27, the kernel panics at boot with:
在这个较新的图像上,使用相同的方法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)
bztsrc/raspi3-tutorial
RPI3 bare metal on QEMU
在QEMU上使用bztsrc / raspi3-tutorial RPI3裸机
https://github.com/bztsrc/raspi3-tutorial is a good set of examples that just work on QEMU, ultraquick getting started at: https://raspberrypi.stackexchange.com/questions/34733/how-to-do-qemu-emulation-for-bare-metal-raspberry-pi-images/85135#85135
https://github.com/bztsrc/raspi3-tutorial是一套很好的例子,只适用于QEMU,来自的快速入门:https://raspberrypi.stackexchange.com/questions/34733/how-to-do- QEMU仿真换裸机-覆盆子-PI-图像/ 85135#85135