作者信息
作者: 彭东林
QQ: 405728433
软件平台
主机: Ubuntu14.04 64位版本
模拟器:Qemu-2.8.0
Linux内核版本: Linux-4.10
Busybox版本:busybox-1.24.2
工具链: arm-none-linux-gnueabi-gcc (gcc version 4.8.3 20140320)
具备的功能
模拟一个vexpress 双核或者单核的环境,采用NFS跟Host共享一些文件,为了简单起见,根文件系统使用的是ramdisk格式。
正文
1、编译Qemu模拟器
请参考博文用qemu搭建aarch64学习环境
2、下载工具链
登录这个网址:http://www.veryarm.com/arm-none-linux-gnueabi-gcc
我们这里使用的是最新的Linux解压版:
3、下载编译最新的Linux内核
登录https://www.kernel.org/, 下载最新的Linux版本,目前最新的是Linux-4.10。
下面是编译下面要用的kernel的命令:
#!/bin/bash
cross_compile=/home/pengdonglin/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-
#make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 vexpress_defconfig
make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 menuconfig
make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 zImage -j4
make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 dtbs -j4
编译之前可以对kernel进行一下配置
Kernel Features --->
Memory split (3G/1G user/kernel split) --->
[*] High Memory Support
Device Drivers --->
[*] Block devices --->
<*> RAM block device support
() Default RAM disk size (kbytes)
这里我们给ramdisk设置的默认大小是8MB,不能比后面我们实际生成的ramdisk.img的size小。
这样就有了我们下面要用到的内核镜像zImage。
4、制作根文件系统
登录https://busybox.net/downloads/下载要用的busybox版本,这里我下的是busybox-1.24.2
要设置的不多:
执行make menuconfig,配置下面几项:
Build Options --->
[*] Build BusyBox as a static binary (no shared libs)
(/home/pengdonglin/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-) Cross Compiler prefix
然后执行make && make install命令
下面制作启动用的ramdisk,我把这个过程写成了脚本,如下:
#!/bin/bash
sudo rm -rf rootfs
sudo rm -rf tmpfs
sudo rm -rf ramdisk*
sudo mkdir rootfs
sudo cp ../busybox-1.24./_install/* rootfs/ -raf
sudo mkdir -p rootfs/proc/
sudo mkdir -p rootfs/sys/
sudo mkdir -p rootfs/tmp/
sudo mkdir -p rootfs/root/
sudo mkdir -p rootfs/var/
sudo mkdir -p rootfs/mnt/
sudo cp etc rootfs/ -arf
sudo cp -arf ../arm-2014.05/arm-none-linux-gnueabi/libc/lib rootfs/
sudo rm -rf rootfs/lib/*.a
sudo ../arm-2014.05/bin/arm-none-linux-gnueabi-strip rootfs/lib/*
sudo mkdir -p rootfs/dev/
sudo mknod rootfs/dev/tty1 c 4 1
sudo mknod rootfs/dev/tty2 c 4 2
sudo mknod rootfs/dev/tty3 c 4 3
sudo mknod rootfs/dev/tty4 c 4 4
sudo mknod rootfs/dev/console c 5 1
sudo mknod rootfs/dev/null c 1 3
sudo dd if=/dev/zero of=ramdisk bs=1M count=8
sudo mkfs.ext4 -F ramdisk
sudo mkdir -p tmpfs
sudo mount -t ext4 ramdisk ./tmpfs/ -o loop
sudo cp -raf rootfs/* tmpfs/
sudo umount tmpfs
sudo gzip --best -c ramdisk > ramdisk.gz
sudo mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img
制作ramdisk用到的文件到这里下载。
5、Qemu支持网络
请参考博客:
用Qemu模拟vexpress-a9 --- 配置 qemu 的网络功能
用Qemu模拟vexpress-a9 (三)--- 实现用u-boot引导Linux内核
6、测试
支持网络的启方法:
sudo qemu-system-arm \
-M vexpress-a9 \
-m 1024M \
-smp \
-kernel ./linux-4.10/out_aarch32/arch/arm/boot/zImage \
-nographic \
-append "root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel" \
-initrd ./rootfs/ramdisk.img \
-dtb ./linux-4.10/out_aarch32/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-net nic,vlan= -net tap,vlan=,ifname=tap0
mount -t nfs -o nolock 192.168.1.6:/nfsroot /mnt
下面是启动信息:
$./run.sh
sudo tunctl -u root -t tap0
TUNSETIFF: Device or resource busy
sudo ifconfig tap0 0.0.0.0 promisc up
sudo brctl addif br0 tap0
brctl show
bridge name bridge id STP enabled interfaces
br0 .eada212d369f no eth0
tap0
Booting Linux on physical CPU 0x0
Linux version 4.10. (pengdonglin@pengdonglin-dell) (gcc version 4.8. (prerelease) (Sourcery CodeBench Lite 2014.05-) ) # SMP Sat Feb :: CST
CPU: ARMv7 Processor [410fc090] revision (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt:Machine model: V2P-CA9
debug: ignoring loglevel setting.
Memory policy: Data cache writealloc
On node totalpages:
free_area_init_node: node , pgdat c092af80, node_mem_map ef7fa000
Normal zone: pages used for memmap
Normal zone: pages reserved
Normal zone: pages, LIFO batch:
HighMem zone: pages, LIFO batch:
percpu: Embedded pages/cpu @ef7b9000 s23424 r8192 d21632 u53248
pcpu-alloc: s23424 r8192 d21632 u53248 alloc=*
pcpu-alloc: [] [] [] []
Built zonelists in Zone order, mobility grouping on. Total pages:
Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel
log_buf_len individual max cpu contribution: bytes
log_buf_len total cpu_extra contributions: bytes
log_buf_len min size: bytes
log_buf_len: bytes
early log buf free: (%)
PID hash table entries: (order: , bytes)
Dentry cache hash table entries: (order: , bytes)
Inode-cache hash table entries: (order: , bytes)
Memory: 1028136K/1048576K available (5120K kernel code, 174K rwdata, 1224K rodata, 1024K init, 177K bss, 20440K reserved, 0K cma-reserved, 262144K highmem)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( kB)
fixmap : 0xffc00000 - 0xfff00000 ( kB)
vmalloc : 0xf0800000 - 0xff800000 ( MB)
lowmem : 0xc0000000 - 0xf0000000 ( MB)
pkmap : 0xbfe00000 - 0xc0000000 ( MB)
modules : 0xbf000000 - 0xbfe00000 ( MB)
.text : 0xc0008000 - 0xc0600000 ( kB)
.init : 0xc0800000 - 0xc0900000 ( kB)
.data : 0xc0900000 - 0xc092bb80 ( kB)
.bss : 0xc092d000 - 0xc0959448 ( kB)
SLUB: HWalign=, Order=-, MinObjects=, CPUs=, Nodes=
Hierarchical RCU implementation.
Build-time adjustment of leaf fanout to .
RCU restricting CPUs from NR_CPUS= to nr_cpu_ids=.
RCU: Adjusting geometry for rcu_fanout_leaf=, nr_cpu_ids=
NR_IRQS: nr_irqs:
L2C: platform modifies aux control register: 0x02020000 -> 0x02420000
L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000
L2C- enabling early BRESP for Cortex-A9
L2C- full line of zeros enabled for Cortex-A9
L2C- dynamic clock gating disabled, standby mode disabled
L2C- cache controller enabled, ways, kB
L2C-: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001
smp_twd: clock not found -
sched_clock: bits at 24MHz, resolution 41ns, wraps every 89478484971ns
clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: ns
Failed to initialize '/smb@04000000/motherboard/iofpga@7,00000000/timer@12000': -
Console: colour dummy device 80x30
Calibrating local timer... .23MHz.
Calibrating delay loop... 746.70 BogoMIPS (lpj=)
pid_max: default: minimum:
Mount-cache hash table entries: (order: , bytes)
Mountpoint-cache hash table entries: (order: , bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -, cpu , socket , mpidr
Setting up static identity map for 0x60100000 - 0x60100058
smp: Bringing up secondary CPUs ...
CPU1: thread -, cpu , socket , mpidr
CPU2: failed to boot: -
CPU3: failed to boot: -
smp: Brought up node, CPUs
SMP: Total of processors activated (1487.66 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.: implementor architecture part variant rev
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: ns
futex hash table entries: (order: , bytes)
NET: Registered protocol family
DMA: preallocated KiB pool for atomic coherent allocations
cpuidle: using governor ladder
hw-breakpoint: debug architecture 0x4 unsupported.
Serial: AMBA PL011 UART driver
OF: amba_device_add() failed (-) for /memory-controller@100e0000
OF: amba_device_add() failed (-) for /memory-controller@100e1000
OF: amba_device_add() failed (-) for /watchdog@100e5000
irq: type mismatch, failed to map hwirq- for /interrupt-controller@1e001000!
.uart: ttyAMA0 at MMIO 0x10009000 (irq = , base_baud = ) is a PL011 rev1
console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = , base_baud = ) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = , base_baud = ) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = , base_baud = ) is a PL011 rev1
OF: amba_device_add() failed (-) for /smb@/motherboard/iofpga@,/wdt@0f000
SCSI subsystem initialized
libata version 3.00 loaded.
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm,sp804
NET: Registered protocol family
TCP established hash table entries: (order: , bytes)
TCP bind hash table entries: (order: , bytes)
TCP: Hash tables configured (established bind )
UDP hash table entries: (order: , bytes)
UDP-Lite hash table entries: (order: , bytes)
NET: Registered protocol family
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4. backchannel transport module.
Trying to unpack rootfs image as initramfs...
rootfs image is not initramfs (no cpio magic); looks like an initrd
Freeing initrd memory: 2528K
hw perfevents: enabled with armv7_cortex_a9 PMU driver, counters available
workingset: timestamp_bits= max_order= bucket_order=
squashfs: version 4.0 (//) Phillip Lougher
jffs2: version 2.2. (NAND) © - Red Hat, Inc.
9p: Installing v9fs 9p2000 file system support
bounce: pool size: pages
io scheduler noop registered (default)
clcd-pl11x .clcd: PL111 designer rev2 at 0x10020000
clcd-pl11x .clcd: /clcd@ hardware, 1024x768@ display
Console: switching to colour frame buffer device 128x48
clcd-pl11x 1001f000.clcd: PL111 designer rev2 at 0x1001f000
clcd-pl11x 1001f000.clcd: /smb@/motherboard/iofpga@,/clcd@1f000 hardware, 640x480@ display
brd: module loaded
.flash: Found x16 devices at 0x0 in -bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
erase region : offset=0x0,size=0x80000,blocks=
.flash: Found x16 devices at 0x0 in -bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
erase region : offset=0x0,size=0x80000,blocks=
Concatenating MTD devices:
(): "40000000.flash"
(): "40000000.flash"
into device "40000000.flash"
libphy: Fixed MDIO Bus: probed
libphy: smsc911x-mdio: probed
smsc911x 4e000000.ethernet eth0: MAC Address: :::::
isp1760 4f000000.usb: bus width: , oc: digital
isp1760 4f000000.usb: NXP ISP1760 USB Host Controller
isp1760 4f000000.usb: new USB bus registered, assigned bus number
isp1760 4f000000.usb: Scratch test failed.
isp1760 4f000000.usb: can't setup: -19
isp1760 4f000000.usb: USB bus deregistered
usbcore: registered new interface driver usb-storage
mousedev: PS/ mouse device common for all mice
rtc-pl031 .rtc: rtc core: registered pl031 as rtc0
mmci-pl18x .mmci: Got CD GPIO
mmci-pl18x .mmci: Got WP GPIO
mmci-pl18x .mmci: mmc0: PL181 manf rev0 at 0x10005000 irq , (pio)
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
input: AT Raw Set keyboard as /devices/platform/smb@/smb@:motherboard/smb@:motherboard:iofpga@,/.kmi/serio0/input/input0
aaci-pl041 .aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 33
aaci-pl041 .aaci: FIFO entries
oprofile: using arm/armv7-ca9
NET: Registered protocol family
9pnet: Installing 9P2000 support
Registering SWP/SWPB emulation handler
rtc-pl031 .rtc: setting system clock to -- :: UTC ()
ALSA device list:
#: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 33
input: ImExPS/ Generic Explorer Mouse as /devices/platform/smb@/smb@:motherboard/smb@:motherboard:iofpga@,/.kmi/serio1/input/input2
RAMDISK: gzip image found at block
EXT4-fs (ram0): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device :.
Freeing unused kernel memory: 1024K
Generic PHY 4e000000.etherne:: attached PHY driver [Generic PHY] (mii_bus:phy_addr=4e000000.etherne:, irq=-)
smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xf1420000, IRQ:
Please press Enter to activate this console.
[root@vexpress ]#
[root@vexpress ]#
[root@vexpress ]# mount -t nfs -o nolock 192.168.1.6:/nfsroot /mnt
[root@vexpress ]# cd /mnt
[root@vexpress mnt]# ls
a.out interrupt_gpm4_0.ko passwd
dmesg.log interrupt_xeint14_15.ko shadow3
fdt interrupt_xeint26_29.ko trace
完。