最新版的 Linux 核心資訊在 kernel.org 中可以看到,目前為止第三版最新的核心版本為 linux-3.18.44,我們以此版本作為「虛擬 ARM」版的開機核心。我們所使用的「虛擬 ARM」版為 vexpress-a9,qemu 所支援的虛擬 ARM 資訊可以執行底下指令來觀看:
$ qemu-system-arm -machine help
Supported machines are:
akita Sharp SL-C1000 (Akita) PDA (PXA270)
borzoi Sharp SL-C3100 (Borzoi) PDA (PXA270)
canon-a1100 Canon PowerShot A1100 IS
cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
collie Sharp SL-5500 (Collie) PDA (SA-1110)
connex Gumstix Connex (PXA255)
cubieboard cubietech cubieboard
highbank Calxeda Highbank (ECX-1000)
imx25-pdk ARM i.MX25 PDK board (ARM926)
integratorcp ARM Integrator/CP (ARM926EJ-S)
kzm ARM KZM Emulation Baseboard (ARM1136)
lm3s6965evb Stellaris LM3S6965EVB
lm3s811evb Stellaris LM3S811EVB
mainstone Mainstone II (PXA27x)
midway Calxeda Midway (ECX-2000)
musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
netduino2 Netduino 2 Machine
none empty machine
nuri Samsung NURI board (Exynos4210)
palmetto-bmc OpenPOWER Palmetto BMC
raspi2 Raspberry Pi 2
realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
sabrelite Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)
smdkc210 Samsung SMDKC210 board (Exynos4210)
spitz Sharp SL-C3000 (Spitz) PDA (PXA270)
sx1 Siemens SX1 (OMAP310) V2
sx1-v1 Siemens SX1 (OMAP310) V1
terrier Sharp SL-C3200 (Terrier) PDA (PXA270)
tosa Sharp SL-6000 (Tosa) PDA (PXA255)
verdex Gumstix Verdex (PXA270)
versatileab ARM Versatile/AB (ARM926EJ-S)
versatilepb ARM Versatile/PB (ARM926EJ-S)
vexpress-a15 ARM Versatile Express for Cortex-A15
vexpress-a9 ARM Versatile Express for Cortex-A9
virt-2.6 QEMU 2.6 ARM Virtual Machine
virt QEMU 2.7 ARM Virtual Machine (alias of virt-2.7)
virt-2.7 QEMU 2.7 ARM Virtual Machine
xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
z2 Zipit Z2 (PXA27x)
其中有一行如下:
vexpress-a9 ARM Versatile Express for Cortex-A9
這是我們要玩的虛擬 ARM 開發板,請把 linux 核心放在 /usr/src/ 目錄下,其完整路徑為
/usr/src/linux-3.18.44.tar.xz
=======================底下流程請全部以一般使用者來執行========================
接下來在本地端要解開 linux 原始碼,並準備編譯。請在 ~/qemu_image/arm2 目錄新增 kernel 目錄
~/qemu_image/arm2 $ mkdir kernel
~/qemu_image/arm2 $ cd kernel
~/qemu_image/arm2/kernel $ tar xfva linux-3.18.44.tar.xz
~/qemu_image/arm2/kernel $ cd linux-3.18.44
~/qemu_image/arm2/kernel/linux-3.18.44 $ makerpi vexpress_defconfig
~/qemu_image/arm2/kernel/linux-3.18.44 $ makerpi menuconfig
此時會進入核心設定選單,請選擇
General setup --->
Kernel compression mode (XZ) --->
System Type --->
[ ] Enable the L2x0 outer cache controller
請把原有的 * 取消,否則開機會有問題
完全上述設定後離開設定畫面,然後執行:
~/qemu_image/arm2/kernel/linux-3.18.44 $ makerpi uImage LOADADDR=0x60000000 -j 8
作完之後其訊息如下:
..
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-3.18.44
Created: Mon Oct 31 11:22:50 2016
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2437760 Bytes = 2380.62 kB = 2.32 MB
Load Address: 60000000
Entry Point: 60000000
Image arch/arm/boot/uImage is ready
接著可以用 qemu 來試開機,請執行:
~/qemu_image/arm2 $ qemu-system-arm -M vexpress-a9 -m 256 -nographic -kernel
./kernel/linux-3.18.44/arch/arm/boot/zImage
此時會進入核心開機畫面,但是因為我們還沒有給這個核心 rootfs 的緣故,因此開機開到一半會出現底下錯誤:
VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
1f00 131072 mtdblock0 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.18.44 #2
[<80014824>] (unwind_backtrace) from [<800116d0>] (show_stack+0x10/0x14)
[<800116d0>] (show_stack) from [<80477c64>] (dump_stack+0x98/0xac)
[<80477c64>] (dump_stack) from [<80475b10>] (panic+0x9c/0x200)
[<80475b10>] (panic) from [<805ec228>] (mount_block_root+0x1d0/0x260)
[<805ec228>] (mount_block_root) from [<805ec3c0>] (mount_root+0x108/0x110)
[<805ec3c0>] (mount_root) from [<805ec520>] (prepare_namespace+0x158/0x19c)
[<805ec520>] (prepare_namespace) from [<805ebeb4>] (kernel_init_freeable+0x244/0x254)
[<805ebeb4>] (kernel_init_freeable) from [<80473f60>] (kernel_init+0x8/0xe8)
[<80473f60>] (kernel_init) from [<8000e500>] (ret_from_fork+0x14/0x34)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
這是正常的,請按 Ctrl+a 然後再按 x 即可離開 qemu 模擬畫面,之後我們將會為此虛擬 ARM 主機加上 rootfs 及 bootloader 使其可以開機。