最近需要涉及arm平台匯編,為了方便學習,使用qemu進行模擬一下;
qemu下模擬樹莓派有兩種方法:
- Emuation using Qemu's native raspi2/3 machine (此處演示,需要使用github倉庫中提供的img和dtb文件)
- Emulation using pre-compiled versatilepb kernels (本博客展示)
教程:https://github.com/dhruvvyas90/qemu-rpi-kernel
Kernel文件:https://github.com/dhruvvyas90/qemu-rpi-kernel
下載文件:
kernel-qemu-5.4.51-buster
versatile-pb-buster-5.4.51.dtb
2021-05-07-raspios-buster-armhf.zip
tigervncviewer
運行命令:
qemu-system-arm \ -M versatilepb \ -cpu arm1176 \ -m 256 \ -drive "file=./2021-05-07-raspios-buster-armhf.img,if=none,index=0,media=disk,format=raw,id=disk0" \ -device "virtio-blk-pci,drive=disk0,disable-modern=on,disable-legacy=off" \ -net "user,hostfwd=tcp::5022-:22" \ -dtb versatile-pb-buster-5.4.51.dtb \ -kernel kernel-qemu-5.4.51-buster \ -append 'root=/dev/vda2 panic=1' \ -no-reboot
運行效果(使用vncviewer展示圖形界面):



使用Qemu native 模擬:(核心數和內存數更多,支持64位的arm8, 消耗資源過多)
sudo qemu-system-aarch64 -M raspi3 -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" -dtb bcm2710-rpi-3-b-plus.dtb -sd 2021-05-07-raspios-buster-armhf.img -kernel kernel8.img -m 1G -smp 4 -serial stdio -usb


通過折騰,我的感悟是:與其折騰,不如買個樹莓派省時省事;
