用Qemu搭建aarch32学习环境
Posted 摩斯电码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用Qemu搭建aarch32学习环境相关的知识,希望对你有一定的参考价值。
作者信息
作者: 彭东林
邮箱: pengdonglin137@163.com
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的命令:
1 #!/bin/bash 2 cross_compile=/home/pengdonglin/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi- 3 #make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 vexpress_defconfig 4 make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 menuconfig 5 make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 zImage -j4 6 make CROSS_COMPILE=$cross_compile ARCH=arm O=./out_aarch32 dtbs -j4
编译之前可以对kernel进行一下配置
1 Kernel Features ---> 2 Memory split (3G/1G user/kernel split) ---> 3 [*] High Memory Support 4 Device Drivers ---> 5 [*] Block devices ---> 6 <*> RAM block device support 7 (8192) Default RAM disk size (kbytes)
这里我们给ramdisk设置的默认大小是8MB,不能比后面我们实际生成的ramdisk.img的size小。
这样就有了我们下面要用到的内核镜像zImage。
4、制作根文件系统
登录https://busybox.net/downloads/下载要用的busybox版本,这里我下的是busybox-1.24.2
要设置的不多:
执行make menuconfig,配置下面几项:
1 Build Options ---> 2 [*] Build BusyBox as a static binary (no shared libs) 3 (/home/pengdonglin/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-) Cross Compiler prefix
然后执行make && make install命令
下面制作启动用的ramdisk,我把这个过程写成了脚本,如下:
1 #!/bin/bash 2 sudo rm -rf rootfs 3 sudo rm -rf tmpfs 4 sudo rm -rf ramdisk* 5 sudo mkdir rootfs 6 sudo cp ../busybox-1.24.2/_install/* rootfs/ -raf 7 sudo mkdir -p rootfs/proc/ 8 sudo mkdir -p rootfs/sys/ 9 sudo mkdir -p rootfs/tmp/ 10 sudo mkdir -p rootfs/root/ 11 sudo mkdir -p rootfs/var/ 12 sudo mkdir -p rootfs/mnt/ 13 sudo cp etc rootfs/ -arf 14 sudo cp -arf ../arm-2014.05/arm-none-linux-gnueabi/libc/lib rootfs/ 15 sudo rm -rf rootfs/lib/*.a 16 sudo ../arm-2014.05/bin/arm-none-linux-gnueabi-strip rootfs/lib/* 17 sudo mkdir -p rootfs/dev/ 18 sudo mknod rootfs/dev/tty1 c 4 1 19 sudo mknod rootfs/dev/tty2 c 4 2 20 sudo mknod rootfs/dev/tty3 c 4 3 21 sudo mknod rootfs/dev/tty4 c 4 4 22 sudo mknod rootfs/dev/console c 5 1 23 sudo mknod rootfs/dev/null c 1 3 24 sudo dd if=/dev/zero of=ramdisk bs=1M count=8 25 sudo mkfs.ext4 -F ramdisk 26 sudo mkdir -p tmpfs 27 sudo mount -t ext4 ramdisk ./tmpfs/ -o loop 28 sudo cp -raf rootfs/* tmpfs/ 29 sudo umount tmpfs 30 sudo gzip --best -c ramdisk > ramdisk.gz 31 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、测试
支持网络的启方法:
1 sudo qemu-system-arm \\ 2 -M vexpress-a9 \\ 3 -m 1024M \\ 4 -smp 2 \\ 5 -kernel ./linux-4.10/out_aarch32/arch/arm/boot/zImage \\ 6 -nographic \\ 7 -append "root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel" \\ 8 -initrd ./rootfs/ramdisk.img \\ 9 -dtb ./linux-4.10/out_aarch32/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \\ 10 -net nic,vlan=0 -net tap,vlan=0,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 8000.eada212d369f no eth0 tap0 Booting Linux on physical CPU 0x0 Linux version 4.10.0 (pengdonglin@pengdonglin-dell) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29) ) #9 SMP Sat Feb 25 18:51:59 CST 2017 CPU: ARMv7 Processor [410fc090] revision 0 (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 0 totalpages: 262144 free_area_init_node: node 0, pgdat c092af80, node_mem_map ef7fa000 Normal zone: 1536 pages used for memmap Normal zone: 0 pages reserved Normal zone: 196608 pages, LIFO batch:31 HighMem zone: 65536 pages, LIFO batch:15 percpu: Embedded 13 pages/cpu @ef7b9000 s23424 r8192 d21632 u53248 pcpu-alloc: s23424 r8192 d21632 u53248 alloc=13*4096 pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 Built 1 zonelists in Zone order, mobility grouping on. Total pages: 260608 Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel log_buf_len individual max cpu contribution: 4096 bytes log_buf_len total cpu_extra contributions: 12288 bytes log_buf_len min size: 16384 bytes log_buf_len: 32768 bytes early log buf free: 14860(90%) PID hash table entries: 4096 (order: 2, 16384 bytes) Dentry cache hash table entries: 131072 (order: 7, 524288 bytes) Inode-cache hash table entries: 65536 (order: 6, 262144 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 ( 4 kB) fixmap : 0xffc00000 - 0xfff00000 (3072 kB) vmalloc : 0xf0800000 - 0xff800000 ( 240 MB) lowmem : 0xc0000000 - 0xf0000000 ( 768 MB) pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB) modules : 0xbf000000 - 0xbfe00000 ( 14 MB) .text : 0xc0008000 - 0xc0600000 (6112 kB) .init : 0xc0800000 - 0xc0900000 (1024 kB) .data : 0xc0900000 - 0xc092bb80 ( 175 kB) .bss : 0xc092d000 - 0xc0959448 ( 178 kB) SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1 Hierarchical RCU implementation. Build-time adjustment of leaf fanout to 32. RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4. RCU: Adjusting geometry for rcu_fanout_leaf=32, nr_cpu_ids=4 NR_IRQS:16 nr_irqs:16 16 L2C: platform modifies aux control register: 0x02020000 -> 0x02420000 L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000 L2C-310 enabling early BRESP for Cortex-A9 L2C-310 full line of zeros enabled for Cortex-A9 L2C-310 dynamic clock gating disabled, standby mode disabled L2C-310 cache controller enabled, 8 ways, 128 kB L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001 smp_twd: clock not found -2 sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns Failed to initialize \'/smb@04000000/motherboard/iofpga@7,00000000/timer@12000\': -22 Console: colour dummy device 80x30 Calibrating local timer... 95.23MHz. Calibrating delay loop... 746.70 BogoMIPS (lpj=3733504) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 2048 (order: 1, 8192 bytes) Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes) CPU: Testing write buffer coherency: ok CPU0: thread -1, cpu 0, socket 0, mpidr 80000000 Setting up static identity map for 0x60100000 - 0x60100058 smp: Bringing up secondary CPUs ... CPU1: thread -1, cpu 1, socket 0, mpidr 80000001 CPU2: failed to boot: -38 CPU3: failed to boot: -38 smp: Brought up 1 node, 2 CPUs SMP: Total of 2 processors activated (1487.66 BogoMIPS). CPU: All CPU(s) started in SVC mode. devtmpfs: initialized VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0 clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns futex hash table entries: 1024 (order: 4, 65536 bytes) NET: Registered protocol family 16 DMA: preallocated 256 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 (-19) for /memory-controller@100e0000 OF: amba_device_add() failed (-19) for /memory-controller@100e1000 OF: amba_device_add() failed (-19) for /watchdog@100e5000 irq: type mismatch, failed to map hwirq-75 for /interrupt-controller@1e001000! 10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 38, base_baud = 0) is a PL011 rev1 console [ttyAMA0] enabled 1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 39, base_baud = 0) is a PL011 rev1 1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 40, base_baud = 0) is a PL011 rev1 1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 41, base_baud = 0) is a PL011 rev1 OF: amba_device_add() failed (-19) for /smb@04000000/motherboard/iofpga@7,00000000/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 2 TCP established hash table entries: 8192 (order: 3, 32768 bytes) TCP bind hash table entries: 8192 (order: 4, 65536 bytes) TCP: Hash tables configured (established 8192 bind 8192) UDP hash table entries: 512 (order: 2, 16384 bytes) UDP-Lite hash table entries: 512 (order: 2, 16384 bytes) NET: Registered protocol family 1 RPC: Registered named UNIX socket transport module. RPC: Registered udp transport module. RPC: Registered tcp transport module. RPC: Registered tcp NFSv4.1 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, 1 counters available workingset: timestamp_bits=30 max_order=18 bucket_order=0 squashfs: version 4.0 (2009/01/31) Phillip Lougher jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc. 9p: Installing v9fs 9p2000 file system support bounce: pool size: 64 pages io scheduler noop registered (default) clcd-pl11x 10020000.clcd: PL111 designer 41 rev2 at 0x10020000 clcd-pl11x 10020000.clcd: /clcd@10020000 hardware, 1024x768@59 display Console: switching to colour frame buffer device 128x48 clcd-pl11x 1001f000.clcd: PL111 designer 41 rev2 at 0x1001f000 clcd-pl11x 1001f000.clcd: /smb@04000000/motherboard/iofpga@7,00000000/clcd@1f000 hardware, 640x480@59 display brd: module loaded 40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031 Using buffer write method erase region 0: offset=0x0,size=0x80000,blocks=128 40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031 Using buffer write method erase region 0: offset=0x0,size=0x80000,blocks=128 Concatenating MTD devices: (0): "40000000.flash" (1): "40000000.flash" into device "40000000.flash" libphy: Fixed MDIO Bus: probed libphy: smsc911x-mdio: probed smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56 isp1760 4f000000.usb: bus width: 32, oc: digital isp1760 4f000000.usb: NXP ISP1760 USB Host Controller isp1760 4f000000.usb: new USB bus registered, assigned bus number 1 isp1760 4f000000.usb: Scratch test failed. isp1760 4f000000.usb: can\'t setup: -19 isp1760 4f000000.usb: USB bus 1 deregistered usbcore: registered new interface driver usb-storage mousedev: PS/2 mouse device common for all mice rtc-pl031 10017000.rtc: rtc core: registered pl031 as rtc0 mmci-pl18x 10005000.mmci: Got CD GPIO mmci-pl18x 10005000.mmci: Got WP GPIO mmci-pl18x 10005000.mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 34,35 (pio) ledtrig-cpu: registered to indicate activity on CPUs usbcore: registered new interface driver usbhid usbhid: USB HID core driver input: AT Raw Set 2 keyboard as /devices/platform/smb@04000000/smb@04000000:motherboard/smb@04000000:motherboard:iofpga@7,00000000/10006000.kmi/serio0/input/input0 aaci-pl041 10004000.aaci: ARM AC\'97 Interface PL041 rev0 at 0x10004000, irq 33 aaci-pl041 10004000.aaci: FIFO 512 entries oprofile: using arm/armv7-ca9 NET: Registered protocol family 17 9pnet: Installing 9P2000 support Registering SWP/SWPB emulation handler rtc-pl031 10017000.rtc: setting system clock to 2017-02-25 10:57:49 UTC (1488020269) ALSA device list: #0: ARM AC\'97 Interface PL041 rev0 at 0x10004000, irq 33 input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@04000000/smb@04000000:motherboard/smb@04000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2 RAMDISK: gzip image found at block 0 EXT4-fs (ram0): mounted filesystem with ordered data mode. Opts: (null) VFS: Mounted root (ext4 filesystem) on device 1:0. Freeing unused kernel memory: 1024K Generic PHY 4e000000.etherne:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=4e000000.etherne:01, irq=-1) smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xf1420000, IRQ: 31 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
完。
以上是关于用Qemu搭建aarch32学习环境的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu18.04使用qemu搭建ARM64架构虚拟机(方法一)