1.5.2 QEMU实验平台
QEMU模拟了vexpress Cortex-A9SMP四核处理器开发板,板上集成了Flash、SD、I2C、LCD等。ARM公司的Versatile Express系列开发平台提供了超快的环境,用于为下一代片上系统设计方案建立原型,比如Cortex-A9Quad Core。
在http://www.arm.com/zh/products/tools/development-boards/versatile-express/index.php上可以发现更多关于Versatile Express系列开发平台的细节。
本书配套虚拟机映像中已经安装好了工具链,包含arm-linux-gnueabihf-gcc和arm-linux-gnueabi-gcc两个版本。
Linux内核在/home/baohua/develop/linux目录中,在该目录下面,包含内核编译脚本:
export ARCH=arm export CROSS_COMPILE=arm-linux-gnueabi- make LDDD3_vexpress_defconfig make zImage -j8 make modules -j8 make dtbs cp arch/arm/boot/zImage extra/ cp arch/arm/boot/dts/*ca9.dtb extra/ cp .config extra/
由此可见,我们用的默认内核配置文件是LDDD3_vexpress_defconfig。上述脚本也会自动将编译好的zImage和dtbs复制到extra目录中。
extra目录下的vexpress.img是一张虚拟的SD卡,将作为根文件系统的存放介质。它能以loop的形式被挂载(mount),譬如在/home/baohua/develop/linux目录下运行。
sudo mount -o loop,offset=$((2048*512)) extra/vexpress.img extra/img
可以把vexpress.img的根文件系统分区挂载到extra/img,这样我们可以在目标板的根文件系统中放置我们喜欢的内容。
/home/baohua/develop/linux目录下面有个编译模块的脚本module.sh,它会自动编译内核模块并安装到vexpress.img中,其内容如下:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules sudo mount -o loop,offset=$((2048*512)) extra/vexpress.img extra/img sudo make ARCH=arm modules_install INSTALL_MOD_PATH=extra/img sudo umount extra/img
运行extra下面的run-nolcd.sh可以启动一个不含LCD的ARM Linux。run-nolcd.sh的内容为qemu-system-arm-nographic-sd vexpress.img-M vexpress-a9-m 512M-kernel zImage-dtb vexpress-v2p-ca9.dtb-smp 4-append"init=/linuxrc root=/dev/mmcblk0p1rw rootwait earlyprintk console=ttyAMA0"2>/dev/null,运行结果为:
baohua@baohua-VirtualBox:~/develop/linux/extra$ ./run-nolcd.sh Uncompressing Linux... done, booting the kernel. Booting Linux on physical CPU 0x0 Initializing cgroup subsys cpuset Linux version 3.16.0+ (baohua@baohua-VirtualBox) (gcc version 4.7.3 (Ubuntu/ Linaro 4.7.3-12ubuntu1) ) #3 SMP Mon Dec 1 16:53:04 CST 2014 CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c53c7d CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache Machine model: V2P-CA9 bootconsole [earlycon0] enabled Memory policy: Data cache writealloc PERCPU: Embedded 7 pages/cpu @9fbcd000 s7232 r8192 d13248 u32768 Built 1 zonelists in Zone order, mobility grouping on. Total pages: 130048 Kernel command line: init=/linuxrc root=/dev/mmcblk0p1 rw rootwait earlyprintk console=ttyAMA0 PID 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: 513088K/524288K available (4583K kernel code, 188K rwdata, 1292K rodata, 247K init, 149K bss, 11200K 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 - 0x805c502c (5877 kB) .init : 0x805c6000 - 0x80603c40 ( 248 kB) .data : 0x80604000 - 0x80633100 ( 189 kB) .bss : 0x80633108 - 0x806588a8 ( 150 kB) SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1 Hierarchical RCU implementation. RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4. RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4 NR_IRQS:16 nr_irqs:16 16 L2C: platform modifies aux control register: 0x02020000 -> 0x02420000 L2C: device tree omits to specify unified cache 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 178956969942ns Console: colour dummy device 80x30…
运行extra下面的run-lcd.sh可以启动一个含LCD的ARM Linux,运行结果如图1.11所示。
图1.11 含LCD的ARM Linux
除了QEMU模拟的ARM电路板以外,本书配套的Ubuntu中还包含一些直接可以在Ubuntu上运行的案例,譬如/home/baohua/develop/training/kernel中就包含了globalfifo、globalmem等,这些目录的源代码都包含了Makefile,在其中直接make,生成的.ko可以直接在Ubuntu上运行。