如何使用qemu模拟器qemu 加载内核cpio独立生成

相关内容推荐
about echojb.com爱脚本网(www.echojb.com)为你提供软件编程和硬件技术方面资料,信息,方法,是你完成项目及工作的好帮手。没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长![Copy]如何使用qemu执行交叉环境下的内核镜像文件
编辑:www.fx114.net
本篇文章主要介绍了"[Copy]如何使用qemu执行交叉环境下的内核镜像文件 ",主要涉及到[Copy]如何使用qemu执行交叉环境下的内核镜像文件 方面的内容,对于[Copy]如何使用qemu执行交叉环境下的内核镜像文件 感兴趣的同学可以参考一下。
&&This command sets a predefined configuration, used in compilation, that is capable of building a kernel targeted to run inside the VersatilePB board. I wanted to tweak it a little bit, so I ran:1make ARCH=arm menuconfigI removed module support (for simplicity) and enabled EABI support as a binary format (allowing also old ABI). This is necessary to run software compiled with the CodeSourcery toolchain. I exited the menu and saved the configuration, then I ran:1make ARCH=arm CROSS_COMPILE=arm-none-eabi- all[edit] If using the GNU/Linux toolchain, the command that must be used is, instead:1make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- all[/edit]This will start the building of the kernel using the correct ARM the build will create, among other binaries, a compressed kernel in a file called&zImage&located in “arch/arm/boot“. This image can be run in QEMU using the following command (assuming that you are in the “arch/arm/boot” directory):1qemu-system-arm -M versatilepb -m 128M -kernel zImageQEMU will execute the Linux image: the kernel will display many boot messages and then it will complain that it didn’t find a root filesystem. Let’s then create the simplest filesystem we can do: it consists of a single “Hello World” executable, that can be built using the&.1#include &stdio.h&2&3void&main() {4&&printf("Hello World!\n");5&&while(1);6}Note: an infinite loop is introduced because when Linux executes the first program in the root filesystem, it expects that the program does not exit.Having the GNU/Linux ARM toolchain installed (be aware that it is different from the bare EABI toolchain) I ran:1arm-none-linux-gnueabi-gcc -static&&& test.c&& -o testThis creates an executable ELF program for ARM, statically linked (all the libraries that it needs are linked together in a single binary). We can now create a simple filesystem using the&cpio&tool as follows:1echo test | cpio -o --format=newc & rootfsThe&cpio&tool takes a list of files an the&newc&format is the format of theinitramfs&filesystem, that the Linux kernel recognizes. The&rootfs&file in our case is a binary image of a filesystem containing a single file, that is the test ELF program. QEMU can pass the filesystem binary image to the kernel using the&initrd& the kernel must also know that the root filesystem will be located in RAM (because that’s where QEMU writes the&initrd&binary) and that the program to launch is our&test&executable, so the command line becomes:1qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs -append "root=/dev/ram rdinit=/test"&
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:Yocto tips (20): Yocto中qemu模拟器的使用,以zynq Cortex-A9为例
在以前的文章《使用Buildroot与Qemu学习ARM linux IIC驱动》中,写到过使用qemu来模拟使用ARM ,那个时候借助的是buildroot,这次我们使用Yocto来做同样的事情。
使用Qemu的好处在于,当我们在开发Userspace的程序时,可以在没有硬件的情况下完成测试。
同时不像以前一样我们需要自己去编译qemu,这次我们使用Yocto编译出来的native qemu来模拟。省去了我们手动编译可能出现的问题。
这里的选择指的是,我们在local.conf中指定MACHINE变量的值。我将其分成两种:
1. 默认的qemuarm
以前我一直使用这个,但是这个模拟的是一个ARM9的处理器,各种外设功能不足,我们希望可以模拟一个更高ARM架构的SoC。
2. Xilinx的zynq-9:xilinx-zynq-a9
在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
Zipit Z2 (PXA27x)
Gumstix Connex (PXA255)
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
Marvell 88w8618 / MusicPal (ARM926EJ-S)
Mainstone II (PXA27x)
Terrier PDA (PXA270)
Nokia N810 tablet aka. RX-44 (OMAP2420)
xilinx-zynq-a9
Xilinx Zynq Platform Baseboard for Cortex-A9
Samsung NURI board (Exynos4210)
realview-eb-mpcore
ARM RealView Emulation Baseboard (ARM11MPCore)
Gumstix Verdex (PXA270)
Spitz PDA (PXA270)
canon-a1100
Canon PowerShot A1100 IS
Akita PDA (PXA270)
Samsung SMDKC210 board (Exynos4210)
integratorcp
ARM Integrator/CP (ARM926EJ-S)
Siemens SX1 (OMAP310) V1
ARM KZM Emulation Baseboard (ARM1136)
Calxeda Highbank (ECX-1000)
Nokia N800 tablet aka. RX-34 (OMAP2420)
Collie PDA (SA-1110)
realview-pb-a8
ARM RealView Platform Baseboard for Cortex-A8
vexpress-a15
ARM Versatile Express for Cortex-A15
empty machine
Palm Tungsten|E aka. Cheetah PDA (OMAP310)
Tosa PDA (PXA255)
Calxeda Midway (ECX-2000)
ARM Virtual Machine
Borzoi PDA (PXA270)
针对这个板子在Yocto中的模拟,官方也有一个网页:,我们可以参考这个网页,但是根据这个网页做其实是行不通的。下面我主要说明一下需要更改和注意的地方。
构建与使用步骤
先根据官方的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
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
同时还需要配置output的initrd type为cpio:
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-35.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-35.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-system-arm: Unsupported NIC model: virtio
对此,有多种处理方法,最为简单的是我们直接使用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
可以看到支持的是cadence_gem,因此我们需要更改成这个。
runqemu的更改
runqemu的脚本位于:
中,在里面我们可以看到其指定了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&
QEMU_NETWORK_CMD=&-net nic,model=virtio $QEMU_TAP_CMD&
然后再次运行,就可以工作了,可以看到其部分log如下:
$ 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-35.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-35.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 @eefd r 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: 48576K 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:
: 0xffff0000 - 0xffff1000
: 0xffc00000 - 0xfff00000
vmalloc : 0xf0000000 - 0xff000000
: 0xc0000000 - 0xef800000
: 0xbfe00000 - 0xc0000000
modules : 0xbf000000 - 0xbfe00000
.text : 0xc0008000 - 0xc05c28f4
.init : 0xc05c3000 - 0xc05fa000
.data : 0xc05fa000 - 0xc06349e0
.bss : 0xc06349e0 - 0xc0666470
0.000000] Preemptible hierarchical RCU implementation.
RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
输入Ctrl + A C,并输入q回车即可,Ctrl+C是无法退出的。
runqemu的其他工具
所有的工具有:
runqemu-addptable2image
runqemu-export-rootfs
runqemu-extract-sdk &
runqemu-gen-tapdevs
runqemu-ifdown
runqemu-ifup
runqemu-internal
可以看到主要涉及到TAP功能的up down与create,与nfsroot相关的两个工具。}

我要回帖

更多关于 cemu模拟器加载塞尔达 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信