你的位置:首页 > 操作系统

[操作系统]用Qemu模拟vexpress


 

 

环境介绍

Win7 64 + Vmware 11 + ubuntu12.04 32

u-boot 版本:u-boot-2015-04

Linux kernel版本:linux-3.16.y

busybox版本:1_24_stable

交叉编译工具链:arm-linux-gnueabi-

qemu版本:stable-2.4

 

概述

这里我采用的方法是,利用网络引导的方式启动Linux内核。具体方式如下:

开启Qemu的网络支持功能,启动u-boot,设置u-boot的环境变量,u-boot采用tftp的方式将uImage格式的Linux内核下载到内存地址0x60003000处,为什么是0x60000000起始的地址,参考文件u-boot的配置文件 include/configs/vexpress_common.h。如果用Qemu直接启动Kernel,是通过-append parameter 的方式给kernel传参的,现在是通过u-boot,那么需要通过u-boot的环境变量bootargs,可以设置为如下值 setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0 console=tty0'。 然后设置u-boot环境变量bootcmd,如下: setenv bootcmd 'tftp 0x60003000 uImage; bootm 0x60003000'.

具体步骤

1、启动Qemu的网络支持

这个请参考博客:http://www.cnblogs.com/pengdonglin137/p/5023340.html

 

2、配置u-boot

主要是修改include/configs/vexpress_common.h

diff --git a/include/configs/vexpress_common.h b/include/configs/vexpress_common.hindex 0c1da01..9fa7d9e 100644--- a/include/configs/vexpress_common.h+++ b/include/configs/vexpress_common.h@@ -48,6 +48,11 @@ #define CONFIG_SYS_TEXT_BASE  0x80800000 #endif +/* netmask */+#define CONFIG_IPADDR  192.168.11.5+#define CONFIG_NETMASK 255.255.255.0+#define CONFIG_SERVERIP 192.168.11.20+ /* * Physical addresses, offset from V2M_PA_CS0-3 */@@ -202,7 +207,9 @@ #define CONFIG_SYS_INIT_SP_ADDR        CONFIG_SYS_GBL_DATA_OFFSET /* Basic environment settings */-#define CONFIG_BOOTCOMMAND       "run bootflash;"+/* #define CONFIG_BOOTCOMMAND     "run bootflash;" */+#define CONFIG_BOOTCOMMAND       "tftp 0x60003000 uImage; setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0'; bootm 0x60003000+

 

说明:

这里我把ipaddr等设置为了192.168.11.x网段,这个需要跟br0的网址一致,br0的地址在/etc/qemu-ifuo中修改:

#!/bin/shecho sudo tunctl -u $(id -un) -t $1sudo tunctl -u $(id -un) -t $1echo sudo ifconfig $1 0.0.0.0 promisc upsudo ifconfig $1 0.0.0.0 promisc upecho sudo brctl addif br0 $1sudo brctl addif br0 $1echo brctl showbrctl showsudo ifconfig br0 192.168.11.20


然后重新编译u-boot代码

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j2

 

测试:

qemu-system-arm -M vexpress-a9 \   -kernel u-boot \   -nographic \   -m 512M \   -net nic,vlan=0 -net tap,vlan=0,ifname=tap0


运行:

U-Boot 2015.07-rc3-00092-gf3edfd3-dirty (Dec 05 2015 - 22:00:46 -0800)DRAM: 512 MiBWARNING: Caches not enabledFlash: 128 MiBMMC:  MMC: 0*** Warning - bad CRC, using default environmentIn:  serialOut:  serialErr:  serialNet:  smc911x-0Warning: smc911x-0 using MAC address from net deviceHit any key to stop autoboot: 0 VExpress# ping 192.168.11.20smc911x: MAC 52:54:00:12:34:56smc911x: detected LAN9118 controllersmc911x: phy initializedsmc911x: MAC 52:54:00:12:34:56Using smc911x-0 devicesmc911x: MAC 52:54:00:12:34:56host 192.168.11.20 is alive

 

2、配置Linux Kernel

因为要用u-boot引导,所以需要把Kernel编译成uImage格式。

执行如下命令:

make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm O=./out_vexpress_3_16 uImage -j2

编译时会报错:

make[1]: Entering directory `/root/tq2440_work/kernel/linux-stable/out_vexpress_3_16' CHK   include/config/kernel.release GEN   ./Makefile CHK   include/generated/uapi/linux/version.h Using .. as source for kernel CHK   include/generated/utsrelease.hmake[2]: `include/generated/mach-types.h' is up to date. CALL  ../scripts/checksyscalls.sh CHK   include/generated/compile.h CHK   kernel/config_data.h Kernel: arch/arm/boot/Image is ready Kernel: arch/arm/boot/zImage is readymultiple (or no) load addresses: This is incompatible with uImagesSpecify LOADADDR on the commandline to build an uImagemake[2]: *** [arch/arm/boot/uImage] Error 1make[1]: *** [uImage] Error 2make: *** [sub-make] Error 2

这里需要我们制定LOADADDR的值,即uImage的加载地址,根据u-boot,我们可以将其设置为0x60003000.

修改后的命令如下:

make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm O=./out_vexpress_3_16 LOADADDR=0x60003000 uImage -j2

编译信息:

make[1]: Entering directory `/root/tq2440_work/kernel/linux-stable/out_vexpress_3_16' CHK   include/config/kernel.release GEN   ./Makefile CHK   include/generated/uapi/linux/version.h Using .. as source for kernel CHK   include/generated/utsrelease.hmake[2]: `include/generated/mach-types.h' is up to date. CALL  ../scripts/checksyscalls.sh CHK   include/generated/compile.h CHK   kernel/config_data.h Kernel: arch/arm/boot/Image is ready Kernel: arch/arm/boot/zImage is ready UIMAGE arch/arm/boot/uImageImage Name:  Linux-3.16.7Created:   Sat Dec 5 23:10:41 2015Image Type:  ARM Linux Kernel Image (uncompressed)Data Size:  3326696 Bytes = 3248.73 kB = 3.17 MBLoad Address: 0x60003000Entry Point: 0x60003000 Image arch/arm/boot/uImage is ready

 

编译生成的uImage在 linux-stable/out_vexpress_3_16/arch/arm/boot下,然后将uImage拷贝到/tftpboot目录下,关于tftp服务器的配置请参考:
http://files.cnblogs.com/files/pengdonglin137/ubuntu-12.04%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.pdf

 

3、测试

执行如下命令:

qemu-system-arm -M vexpress-a9 \   -kernel /root/tq2440_work/u-boot/u-boot/u-boot \   -nographic \   -m 512M \   -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \   -sd /root/tq2440_work/busybox_study/a9rootfs.ext3

 

启动信息:

sudo tunctl -u root -t tap0sudo ifconfig tap0 0.0.0.0 promisc upsudo brctl addif br0 tap0brctl showbridge name  bridge id    STP enabled  interfacesbr0    8000.000c290bd2f3  no    eth0              tap0U-Boot 2015.07-rc3-00092-gf3edfd3-dirty (Dec 05 2015 - 23:20:40 -0800)DRAM: 512 MiBWARNING: Caches not enabledFlash: 128 MiBMMC:  MMC: 0*** Warning - bad CRC, using default environmentIn:  serialOut:  serialErr:  serialNet:  smc911x-0Warning: smc911x-0 using MAC address from net deviceHit any key to stop autoboot: 0 smc911x: MAC 52:54:00:12:34:56smc911x: detected LAN9118 controllersmc911x: phy initializedsmc911x: MAC 52:54:00:12:34:56Using smc911x-0 deviceTFTP from server 192.168.11.20; our IP address is 192.168.11.5Filename 'uImage'.Load address: 0x60003000Loading: #################################################################   #################################################################   #################################################################   ################################   796.9 KiB/sdoneBytes transferred = 3326760 (32c328 hex)smc911x: MAC 52:54:00:12:34:56## Booting kernel from Legacy Image at 60003000 ...  Image Name:  Linux-3.16.7  Image Type:  ARM Linux Kernel Image (uncompressed)  Data Size:  3326696 Bytes = 3.2 MiB  Load Address: 60003000  Entry Point: 60003000  Verifying Checksum ... OK  Loading Kernel Image ... OKStarting kernel ...Booting Linux on physical CPU 0x0Initializing cgroup subsys cpusetLinux version 3.16.7 (root@ubuntu) (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1) ) #5 SMP Sat Dec 5 21:17:17 PST 2015CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c53c7dCPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cacheMachine: ARM-Versatile ExpressMemory policy: Data cache writebackCPU: All CPU(s) started in SVC mode.sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956969942nsPERCPU: Embedded 7 pages/cpu @9fbed000 s7552 r8192 d12928 u32768Built 1 zonelists in Zone order, mobility grouping on. Total pages: 130048Kernel command line: root=/dev/mmcblk0 console=ttyAMA0PID hash table entries: 2048 (order: 1, 8192 bytes)Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)Memory: 513272K/524288K available (4563K kernel code, 190K rwdata, 1292K rodata, 239K init, 149K bss, 11016K reserved)Virtual kernel memory layout:  vector : 0xffff0000 - 0xffff1000  (  4 kB)  fixmap : 0xffc00000 - 0xffe00000  (2048 kB)  vmalloc : 0xa0800000 - 0xff000000  (1512 MB)  lowmem : 0x80000000 - 0xa0000000  ( 512 MB)  modules : 0x7f000000 - 0x80000000  ( 16 MB)   .text : 0x80008000 - 0x805c01b0  (5857 kB)   .init : 0x805c1000 - 0x805fcd80  ( 240 kB)   .data : 0x805fe000 - 0x8062dba0  ( 191 kB)    .bss : 0x8062dba8 - 0x8065336c  ( 150 kB)SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1Hierarchical RCU implementation.  RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1NR_IRQS:16 nr_irqs:16 16GIC CPU mask not found - kernel will fail to boot.GIC CPU mask not found - kernel will fail to boot.smp_twd: clock not found -2Console: colour dummy device 80x30Calibrating local timer... 88.21MHz.Calibrating delay loop... 310.68 BogoMIPS (lpj=1553408)pid_max: default: 32768 minimum: 301Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)CPU: Testing write buffer coherency: okmissing device node for CPU 0CPU0: thread -1, cpu 0, socket 0, mpidr 80000000Setting up static identity map for 0x604546d0 - 0x60454728Brought up 1 CPUsSMP: Total of 1 processors activated.CPU: All CPU(s) started in SVC mode.devtmpfs: initializedVFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0regulator-dummy: no parametersNET: Registered protocol family 16DMA: preallocated 256 KiB pool for atomic coherent allocationscpuidle: using governor laddercpuidle: using governor menuhw-breakpoint: debug architecture 0x4 unsupported.Serial: AMBA PL011 UART drivermb:uart0: ttyAMA0 at MMIO 0x10009000 (irq = 37, base_baud = 0) is a PL011 rev1console [ttyAMA0] enabledmb:uart1: ttyAMA1 at MMIO 0x1000a000 (irq = 38, base_baud = 0) is a PL011 rev1mb:uart2: ttyAMA2 at MMIO 0x1000b000 (irq = 39, base_baud = 0) is a PL011 rev1mb:uart3: ttyAMA3 at MMIO 0x1000c000 (irq = 40, base_baud = 0) is a PL011 rev1fixed-dummy: no parametersSCSI subsystem initializedusbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbAdvanced Linux Sound Architecture Driver Initialized.Switched to clocksource v2m-timer1NET: Registered protocol family 2TCP established hash table entries: 4096 (order: 2, 16384 bytes)TCP bind hash table entries: 4096 (order: 3, 32768 bytes)TCP: Hash tables configured (established 4096 bind 4096)TCP: reno registeredUDP hash table entries: 256 (order: 1, 8192 bytes)UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)NET: Registered protocol family 1RPC: Registered named UNIX socket transport module.RPC: Registered udp transport module.RPC: Registered tcp transport module.RPC: Registered tcp NFSv4.1 backchannel transport module.CPU PMU: probing PMU on CPU 0hw perfevents: enabled with ARMv7 Cortex-A9 PMU driver, 1 counters availablefutex hash table entries: 256 (order: 2, 16384 bytes)squashfs: version 4.0 (2009/01/31) Phillip Lougherjffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.9p: Installing v9fs 9p2000 file system supportmsgmni has been set to 1002io scheduler noop registered (default)clcd-pl11x ct:clcd: PL111 rev2 at 0x10020000clcd-pl11x ct:clcd: CT-CA9X4 hardware, XVGA displayConsole: switching to colour frame buffer device 128x48physmap platform flash device: 04000000 at 40000000physmap-flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000Intel/Sharp Extended Query Table at 0x0031Using buffer write methodphysmap platform flash device: 04000000 at 44000000physmap-flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000Intel/Sharp Extended Query Table at 0x0031Using buffer write methodConcatenating MTD devices:(0): "physmap-flash"(1): "physmap-flash"into device "physmap-flash"libphy: smsc911x-mdio: probedsmsc911x smsc911x eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=smsc911x-fffffff:01, irq=-1)smsc911x smsc911x eth0: MAC Address: 52:54:00:12:34:56isp1760 isp1760: NXP ISP1760 USB Host Controllerisp1760 isp1760: new USB bus registered, assigned bus number 1isp1760 isp1760: Scratch test failed.isp1760 isp1760: can't setup: -19isp1760 isp1760: USB bus 1 deregisteredisp1760: Failed to register the HCD deviceusbcore: registered new interface driver usb-storagemousedev: PS/2 mouse device common for all micertc-pl031 mb:rtc: rtc core: registered pl031 as rtc0mmci-pl18x mb:mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 41,42 (pio)input: AT Raw Set 2 keyboard as /devices/mb:kmi0/serio0/input/input0ledtrig-cpu: registered to indicate activity on CPUsusbcore: registered new interface driver usbhidusbhid: USB HID core drivermmc0: host does not support reading read-only switch. assuming write-enable.mmc0: new SD card at address 4567mmcblk0: mmc0:4567 QEMU! 32.0 MiB mmcblk0: unknown partition tableaaci-pl041 mb:aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 43aaci-pl041 mb:aaci: FIFO 512 entriesoprofile: using arm/armv7-ca9TCP: cubic registeredNET: Registered protocol family 179pnet: Installing 9P2000 supportrtc-pl031 mb:rtc: setting system clock to 2015-12-06 07:22:11 UTC (1449386531)ALSA device list: #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 43input: ImExPS/2 Generic Explorer Mouse as /devices/mb:kmi1/serio1/input/input2kjournald starting. Commit interval 5 secondsEXT3-fs (mmcblk0): using internal journalEXT3-fs (mmcblk0): recovery completeEXT3-fs (mmcblk0): mounted filesystem with writeback data modeVFS: Mounted root (ext3 filesystem) on device 179:0.Freeing unused kernel memory: 236K (805c1000 - 805fc000)random: nonblocking pool is initializedmount: mounting none on /proc/bus/usb failed: No such file or directoryPlease press Enter to activate this console. [root@vexpress ]# [root@vexpress ]# [root@vexpress ]# [root@vexpress ]# [root@vexpress ]# [root@vexpress ]# lsbin     etc     linuxrc   mnt     root    sys     usrdev     lib     lost+found proc    sbin    tmp     var[root@vexpress ]# ifconfig lo    Link encap:Local Loopback      inet addr:127.0.0.1 Mask:255.0.0.0     UP LOOPBACK RUNNING MTU:65536 Metric:1     RX packets:0 errors:0 dropped:0 overruns:0 frame:0     TX packets:0 errors:0 dropped:0 overruns:0 carrier:0     collisions:0 txqueuelen:0      RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)[root@vexpress ]# ifconfig eth0 192.168.11.5smsc911x smsc911x eth0: SMSC911x/921x identified at 0xa0a40000, IRQ: 47[root@vexpress ]# ping 192.168.11.20PING 192.168.11.20 (192.168.11.20): 56 data bytes64 bytes from 192.168.11.20: seq=0 ttl=64 time=20.928 ms64 bytes from 192.168.11.20: seq=1 ttl=64 time=1.250 ms64 bytes from 192.168.11.20: seq=2 ttl=64 time=0.573 ms^C--- 192.168.11.20 ping statistics ---3 packets transmitted, 3 packets received, 0% packet lossround-trip min/avg/max = 0.573/7.583/20.928 ms[root@vexpress ]# 

 

可以在/etc/init.d/rcS中设置eth0的ip地址为 ifconfig eth0 192.168.11.5

 

4、开启图形界面

修改u-boot的bootargs环境变量为:

setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0 console=tty0';

执行命令:

qemu-system-arm -M vexpress-a9 \   -kernel /root/tq2440_work/u-boot/u-boot/u-boot \   -nographic \   -m 512M \   -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \   -sd /root/tq2440_work/busybox_study/a9rootfs.ext3


截图:

山西旅游必去景点排名山西旅游地图线路大全山西旅游多少钱山西旅游攻略大全山西旅游攻略自助游珠海武林源怎样?门票多少啊? 广州番禺有什么好玩的?广州番禺哪里好玩? 茂名天马山好玩吗? 江门河东名人山庄好玩吗? 深圳三门岛怎么去? 深圳到马尔代夫旅游要多少钱? 深圳三门岛在哪?怎么样? 深圳南澳万绿农庄有什么好玩的? 到香港旅游,去哪购物好? 香港买化妆品的地方有哪些?香港哪里买化妆品最好? 十一香港自由行,有哪些美食推荐? 去香港玩怎样省钱?去香港旅游省钱方法? 惠州象头山国家级自然保护区怎么样?好玩吗? 惠州水帘洞漂流要门票吗? 惠州北门公园怎么走?最佳旅游时间是什么时候? 惠州象头山国家级自然保护区有什么特色美食呢? MPC8323VRADDC Datasheet MPC8323VRADDC Datasheet MPC8323VRAFDC Datasheet MPC8323VRAFDC Datasheet MPC8323ZQADDC Datasheet MPC8323ZQADDC Datasheet 乌镇旅游地图 乌镇旅游地图 乌镇旅游地图 吐鲁番坎儿井 吐鲁番坎儿井 吐鲁番坎儿井 新山门 新山门 新山门