树莓派 qemu模拟启动,构建arm环境;RASPBERRY PI ON QEMU

最近需要涉及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

镜像下载:https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/raspios_armhf/images/raspios_armhf-2021-05-28/

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

通过折腾,我的感悟是:与其折腾,不如买个树莓派省时省事;

原文地址:https://www.cnblogs.com/xuyaowen/p/qemu-arm.html