在以前的文章《使用Buildroot与Qemu学习ARM linux IIC驱动》中,写到过使用qemu来模拟使用ARM Linux,那个时候借助的是buildroot,这次我们使用Yocto来做同样的事情。
使用Qemu的好处在于,当我们在开发Userspace的程序时,可以在没有硬件的情况下完成测试。
同时不像以前一样我们需要自己去编译qemu,这次我们使用Yocto编译出来的native qemu来模拟。省去了我们手动编译可能出现的问题。
这里的选择指的是,我们在local.conf中指定MACHINE变量的值。我将其分成两种:
以前我一直使用这个,但是这个模拟的是一个ARM9的处理器,各种外设功能不足,我们希望可以模拟一个更高ARM架构的SoC。
在Qemu的模拟中,据个人有限经验对不同的板子的模拟情况的了解,zynq在Qemu中有较好的支持。同时xilinx对此也有不少的文档,同时xilinx的一些板子的支持属于Qemu默认的测试与支持Machine,因此选择Xilinx的板子来模拟比较合适。
同时,我们关注的是ARM相关,因此使用Cortex-A9比较好,对此,我们选择xilinx-zynq-a9。
在我们的Host PC中如果安装了qemu-system-arm,那么我们可以看到其支持的板子里面是有这个板子的:
qemu-system-arm -M ?
Supported machines are:
versatileab ARM Versatile/AB (ARM926EJ-S)
versatilepb ARM Versatile/PB (ARM926EJ-S)
lm3s811evb Stellaris LM3S811EVB
z2 Zipit Z2 (PXA27x)
connex Gumstix Connex (PXA255)
sx1 Siemens SX1 (OMAP310) V2
realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
cubieboard cubietech cubieboard
vexpress-a9 ARM Versatile Express for Cortex-A9
lm3s6965evb Stellaris LM3S6965EVB
realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
mainstone Mainstone II (PXA27x)
terrier Terrier PDA (PXA270)
n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
nuri Samsung NURI board (Exynos4210)
realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
verdex Gumstix Verdex (PXA270)
spitz Spitz PDA (PXA270)
canon-a1100 Canon PowerShot A1100 IS
akita Akita PDA (PXA270)
smdkc210 Samsung SMDKC210 board (Exynos4210)
integratorcp ARM Integrator/CP (ARM926EJ-S)
sx1-v1 Siemens SX1 (OMAP310) V1
kzm ARM KZM Emulation Baseboard (ARM1136)
highbank Calxeda Highbank (ECX-1000)
n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
collie Collie PDA (SA-1110)
realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
vexpress-a15 ARM Versatile Express for Cortex-A15
none empty machine
cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
tosa Tosa PDA (PXA255)
midway Calxeda Midway (ECX-2000)
virt ARM Virtual Machine
borzoi Borzoi PDA (PXA270)
先根据官方的step1到step6来编译出需要的image。需要注意的是我们这里使用单核的A9,因此machine应该为qemuzynq,即在local.conf中应该为:
# This sets the default machine to be qemux86 if no other machine is selected:
MACHINE ??= "qemuzynq"
这个machine的定义位于其layer中的config中:
$ ls ../meta-xilinx/conf/machine/ -l
total 52
drwxrwxr-x 11 hexiongjun hexiongjun 4096 May 16 10:38 boards
-rw-rw-r-- 1 hexiongjun hexiongjun 593 May 16 10:38 ep108-zynqmp.conf
drwxrwxr-x 3 hexiongjun hexiongjun 4096 May 16 10:38 include
-rw-rw-r-- 1 hexiongjun hexiongjun 1049 May 16 10:38 kc705-trd-microblazeel.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 623 May 16 10:38 microzed-zynq7.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 804 May 16 10:38 picozed-zynq7.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 564 May 16 10:16 qemumicroblaze.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 512 May 16 10:16 qemumicroblaze-s3adsp1800.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 496 May 16 10:38 qemuzynq.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 1059 May 16 10:38 zc702-zynq7.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 1008 May 16 10:38 zc706-zynq7.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 847 May 16 10:38 zedboard-zynq7.conf
-rw-rw-r-- 1 hexiongjun hexiongjun 627 May 16 10:38 zybo-zynq7.conf
IMAGE_FSTYPES = "jffs2 tar.bz2 cpio"
否则我们在后面的qemu中指定initrd的时候无法指定。
至此,我们就准备好了所有的材料。
直接使用runqemu即可:
$ runqemu qemuzynq
Continuing with the following parameters:
KERNEL: [/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage]
ROOTFS: [/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/core-image-minimal-qemuzynq-20160516035635.rootfs.cpio]
FSTYPE: [cpio]
Setting up tap interface under sudo
Acquiring lockfile for tap0...
Running qemu-system-arm...
/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-arm -kernel /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage -net nic,model=virtio -net tap,vlan=0,ifname=tap0,script=no,downscript=no -M xilinx-zynq-a9 -serial null -serial mon:stdio -dtb /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage-qemuzynq.dtb -initrd /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/core-image-minimal-qemuzynq-20160516035635.rootfs.cpio -no-reboot -m 1024 --append "earlyprintk root=/dev/ram rw ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=1024M "
qemu-system-arm: Unsupported NIC model: virtio
Set 'tap0' nonpersistent
Releasing lockfile of preconfigured tap device 'tap0'
对此,有多种处理方法,最为简单的是我们直接使用qemu至此的 NIC model即可,因此先查询一下:
$ /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-arm -M xilinx-zynq-a9 -net nic,model=?
qemu: Supported NIC models: cadence_gem
runqemu的脚本位于:
poky/scripts/runqemu-internal中,在里面我们可以看到其指定了NIC model,因此我们将其改成cadence_gem即可:
KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0"
QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
if [ "$VHOST_ACTIVE" = "yes" ]; then
QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on"
else
QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD"
fi
$ runqemu qemuzynq
Continuing with the following parameters:
KERNEL: [/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage]
ROOTFS: [/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/core-image-minimal-qemuzynq-20160516035635.rootfs.cpio]
FSTYPE: [cpio]
Setting up tap interface under sudo
Acquiring lockfile for tap0...
Running qemu-system-arm...
/home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-arm -kernel /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage -net nic,model=cadence_gem -net tap,vlan=0,ifname=tap0,script=no,downscript=no -M xilinx-zynq-a9 -serial null -serial mon:stdio -dtb /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/uImage-qemuzynq.dtb -initrd /home/hexiongjun/EmbProj/am335X_Yocto/qemuzynq/tmp/deploy/images/qemuzynq/core-image-minimal-qemuzynq-20160516035635.rootfs.cpio -no-reboot -m 1024 --append "earlyprintk root=/dev/ram rw ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=1024M "
Warning: nic cadence_gem.1 has no peer
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 3.19.0-xilinx (hexiongjun@hexiongjun-9020) (gcc version 5.2.0 (GCC) ) #1 SMP PREEMPT Mon May 16 11:54:40 CST 2016
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[ 0.000000] Machine model: xilinx-zynq-a9
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] CPU: All CPU(s) started in SVC mode.
[ 0.000000] PERCPU: Embedded 9 pages/cpu @eefd8000 s8128 r8192 d20544 u36864
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 260624
[ 0.000000] Kernel command line: earlyprintk root=/dev/ram rw ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=1024M
[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] Memory: 1028324K/1048576K available (4457K kernel code, 234K rwdata, 1408K rodata, 220K init, 198K bss, 20252K reserved, 0K cma-reserved, 270336K highmem)
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[ 0.000000] vmalloc : 0xf0000000 - 0xff000000 ( 240 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xef800000 ( 760 MB)
[ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
[ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
[ 0.000000] .text : 0xc0008000 - 0xc05c28f4 (5867 kB)
[ 0.000000] .init : 0xc05c3000 - 0xc05fa000 ( 220 kB)
[ 0.000000] .data : 0xc05fa000 - 0xc06349e0 ( 235 kB)
[ 0.000000] .bss : 0xc06349e0 - 0xc0666470 ( 199 kB)
[ 0.000000] Preemptible hierarchical RCU implementation.
[ 0.000000] RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
输入Ctrl + A C,并输入q回车即可,Ctrl+C是无法退出的。
所有的工具有:
$ runqemu
runqemu runqemu-addptable2image runqemu-export-rootfs runqemu-extract-sdk
runqemu-gen-tapdevs runqemu-ifdown runqemu-ifup runqemu-internal
参考
http://www.wiki.xilinx.com/QEMU
http://zedboard.org/content/qemu-deep-dive-0
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg00755.html