最近需要涉及arm平台汇编,为了方便学习,使用qemu进行模拟一下;
教程:https://azeria-labs.com/emulate-raspberry-pi-with-qemu/
镜像下载: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
修改镜像文件:(详情请参考上述链接,此处只是方便我个人记忆)
代码语言:javascript复制root@os-lab-vm /h/o/D/rasp# fdisk -l 2021-05-07-raspios-buster-armhf.img
Disk 2021-05-07-raspios-buster-armhf.img: 3.7 GiB, 3980394496 bytes, 7774208 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf4481065
Device Boot Start End Sectors Size Id Type
2021-05-07-raspios-buster-armhf.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
2021-05-07-raspios-buster-armhf.img2 532480 7774207 7241728 3.5G 83 Linux
532480 * 512 = 272629760:
代码语言:javascript复制$ sudo mkdir /mnt/raspbian
$ sudo mount -v -o offset=272629760 -t ext4 2021-05-07-raspios-buster-armhf.img /mnt/raspbian
$ sudo vim /mnt/raspbian/etc/ld.so.preload
Comment out every entry in that file with ‘#’, save and exit with Ctrl-x » Y.
$ sudo vim /mnt/raspbian/etc/fstab
IF you see anything with mmcblk0 in fstab, then:
Replace the first entry containing /dev/mmcblk0p1 with /dev/sda1
Replace the second entry containing /dev/mmcblk0p2 with /dev/sda2, save and exit.
$ sudo umount /mnt/raspbian
运行:(最新的kernel 5 没运行成功使用的 4)
代码语言:javascript复制qemu-system-arm -kernel kernel-qemu-4.19.50-buster -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2021-05-07-raspios-buster-armhf.img -no-reboot -dtb versatile-pb.dtb
运行效果:(成功运行,我的目的是想启动图形界面的,但是图形界面启动不了)
通过折腾,我的感悟是:与其折腾,不如买个树莓派省时省事。出坑了