基于QEMU搭建完整的虚拟ARM开发环境(uboot+linux+rootfs)

主机环境:ubuntu 16.04虚拟机,目标机器:QEMU模拟vexpress-a9。
------------------------------------------------
一、准备工作
安装qemu, 交叉编译工具等略过。


konga@ubuntu:~/work/vexpress/uboot$ qemu-system-arm -M ? 
Supported machines are:
……
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
……

准备一个单独的目录vexpress, uboot, linux和busybox源码并解压,创建镜像文件目录image

konga@ubuntu:~/work/vexpress$ ls 
busybox-1.27.1.tar.bz2  linux-4.9.39.tar.xz  u-boot-2017.07.tar.bz2

konga@ubuntu:~/work/vexpress$ tar xjf busybox-1.27.1.tar.bz2  
konga@ubuntu:~/work/vexpress$ mv busybox-1.27.1 busybox
konga@ubuntu:~/work/vexpress$ tar xJf linux-4.9.39.tar.xz 
konga@ubuntu:~/work/vexpress$ rm linux-4.9.39.tar.xz 
konga@ubuntu:~/work/vexpress$ mv linux-4.9.39/ linux
konga@ubuntu:~/work/vexpress$ tar xjf u-boot-2017.07.tar.bz2  
konga@ubuntu:~/work/vexpress$ rm u-boot-2017.07.tar.bz2 
konga@ubuntu:~/work/vexpress$ mv u-boot-2017.07/ uboot
konga@ubuntu:~/work/vexpress$ rm busybox-1.27.1.tar.bz2 


konga@ubuntu:~/work/vexpress$ mkdir image

konga@ubuntu:~/work/vexpress$ ls
busybox  image  linux  uboot


------------------------------------------------
二、编译运行uboot

创建mkuboot.sh脚本并添加执行权限,进行编译
konga@ubuntu:~/work/vexpress/uboot$ ls configs/vexpress_* 
configs/vexpress_aemv8a_dram_defconfig  configs/vexpress_aemv8a_semi_defconfig  configs/vexpress_ca5x2_defconfig
configs/vexpress_aemv8a_juno_defconfig  configs/vexpress_ca15_tc2_defconfig     configs/vexpress_ca9x4_defconfig

konga@ubuntu:~/work/vexpress/uboot$ cat mkuboot.sh 
	export ARCH=arm
	export CROSS_COMPILE=arm-linux-gnueabi-
	make  vexpress_ca9x4_defconfig
	make V=1
konga@ubuntu:~/work/vexpress/uboot$ chmod +x mkuboot.sh 
konga@ubuntu:~/work/vexpress/uboot$ ./mkuboot.sh

编译完成后在当前目录有u-boot文件,用下面命令可以跑起来
konga@ubuntu:~/work/vexpress/uboot$ qemu-system-arm -M vexpress-a9 -m 512 -nographic  -kernel u-boot
audio: Could not init `oss' audio driver

U-Boot 2017.07 (Mar 17 2018 - 20:09:31 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment
In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 
=> 

此时的uboot没有网络支持,无法通过tftp下载内核镜像,将其复制到image目录
konga@ubuntu:~/work/vexpress/uboot$  cp u-boot ../image/
konga@ubuntu:~/work/vexpress/uboot$  echo "cp u-boot ../image/"  >> mkuboot.sh

把uboot目录下的mkimage命令所在目录加到PATH环境变量(略过)
konga@ubuntu:~/work/vexpress/uboot$ find . -name mkimage
./tools/mkimage

------------------------------------------------------
三、编译linux并运行

konga@ubuntu:~/work/vexpress/linux$ ls arch/arm/configs/ve* 
arch/arm/configs/versatile_defconfig  arch/arm/configs/vexpress_defconfig

创建mklinux.sh脚本赋权限并执行
konga@ubuntu:~/work/vexpress/linux$ cat mklinux.sh 
	export ARCH=arm
	export CROSS_COMPILE=arm-linux-gnueabi-
	make vexpress_defconfig
	make -j4
	make uImage LOADADDR=0x60000000
	make dtbs

	cp -f arch/arm/boot/uImage  ../image/
	cp -f arch/arm/boot/dts/vexpress-v2p-ca9.dtb  ../image/device.dtb
konga@ubuntu:~/work/vexpress/linux$ ./mklinux.sh

编译完成后可用直接单独跑下内核:
konga@ubuntu:~/work/vexpress/linux$ qemu-system-arm -M vexpress-a9 -m 512 -kernel arch/arm/boot/zImage -nographic -append "console=ttyAMA0" -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb

audio: Could not init `oss' audio driver
Booting Linux on physical CPU 0x0
Linux version 4.9.39 (konga@ubuntu) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Sat Mar 17 20:31:19 CST 2018
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
Memory policy: Data cache writeback
……
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
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?)
1f01           32768 mtdblock1  (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 4.9.39 #1
Hardware name: ARM-Versatile Express
[<8010e5c8>] (unwind_backtrace) from [<8010b028>] (show_stack+0x10/0x14)
[<8010b028>] (show_stack) from [<80356200>] (dump_stack+0x84/0x98)
[<80356200>] (dump_stack) from [<801a8d38>] (panic+0xdc/0x248)
[<801a8d38>] (panic) from [<808012ac>] (mount_block_root+0x1c8/0x2a0)
[<808012ac>] (mount_block_root) from [<808014a8>] (mount_root+0x124/0x12c)
[<808014a8>] (mount_root) from [<80801600>] (prepare_namespace+0x150/0x198)
[<80801600>] (prepare_namespace) from [<80800eb4>] (kernel_init_freeable+0x250/0x260)
[<80800eb4>] (kernel_init_freeable) from [<805d276c>] (kernel_init+0x8/0x114)
[<805d276c>] (kernel_init) from [<80107578>] (ret_from_fork+0x14/0x3c)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)


目前没有根文件系统,上面报错是正常的。


---------------------------------------------
四、配置tftp

konga@ubuntu:~/work/vexpress/linux$ sudo apt-get install tftp-hpa tftpd-hpa


修改tftp配置文件:
konga@ubuntu:/etc/default$ cat tftpd-hpa 
	# /etc/default/tftpd-hpa


	TFTP_USERNAME="tftp"
	TFTP_DIRECTORY="/home/konga/work/vexpress/image"
	TFTP_ADDRESS=":69"
	TFTP_OPTIONS="--secure"
重启tftp服务
konga@ubuntu:/etc/default$  sudo service tftpd-hpa restart


确保可以正常下载image目录的文件,必要时可能要增加image目录的权限
konga@ubuntu:~$ ls work/vexpress/image/
device.dtb  u-boot  uImage
konga@ubuntu:~$ tftp localhost
tftp> get uImage
tftp> quit
konga@ubuntu:~$ ls 
bin  Desktop  docs  uImage  work


-----------------------------------------------------
五、配置TUN/TAP虚拟网络

konga@ubuntu:~/work/vexpress/linux$ sudo apt-get install bridge-utils uml-utilities 

检查是否有/dev/net/tun 设备文件,无则自行配置安装。

创建脚本并放在自己的bin目录(ens38为虚拟网卡接口,网段为10.8.8.0,VMWare中的"仅主机模式"):
konga@ubuntu:~/bin$ cat tuntap.sh 
#!/bin/bash
if test -z $1 ; then
	echo need a arg: down/up
	exit
fi 

if [ "up" = $1 ] ; then

	brctl addbr br0

	ifconfig ens38 down
	brctl addif br0 ens38

	#关闭生成树协议
	brctl stp br0 off

	ifconfig br0 10.8.8.3 netmask 255.255.255.0 promisc up
	ifconfig ens38 10.8.8.2 netmask 255.255.255.0 promisc up

	tunctl -t tap0 -u konga
	ifconfig tap0 10.8.8.4 netmask 255.255.255.0 promisc up
	brctl addif br0 tap0
else
    	ifconfig tap0 down
	brctl delif br0 tap0

	ifconfig ens38 down
	brctl delif br0 ens38

	ifconfig br0 down
	brctl delbr br0

        ifconfig ens38 10.8.8.2 netmask 255.255.255.0
fi
为了方便执行,在~/.bashrc加入两行:
alias ttup='sudo ~/bin/tuntap.sh up'
alias ttdown='sudo ~/bin/tuntap.sh down'

konga@ubuntu:~/bin$  source ~/.bashrc


-----------------------------------------
六、用uboot下载内核并执行

konga@ubuntu:~/work/vexpress/image$ ls
device.dtb  u-boot  uImage

konga@ubuntu:~/work/vexpress/image$ ttup 
Set 'tap0' persistent and owned by uid 1000

带网络执行uboot,进入命令行:
konga@ubuntu:~/work/vexpress/image$ qemu-system-arm -M vexpress-a9 -m 512 -nographic  -net nic -net tap,ifname=tap0,script=no -kernel u-boot
audio: Could not init `oss' audio driver


U-Boot 2017.07 (Mar 17 2018 - 20:17:48 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 

=> ping 10.8.8.2
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
smc911x: MAC 52:54:00:12:34:56
host 10.8.8.2 is alive

=> ping 10.8.8.3
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
smc911x: MAC 52:54:00:12:34:56
host 10.8.8.3 is alive

=> ping 10.8.8.4
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
smc911x: MAC 52:54:00:12:34:56
host 10.8.8.4 is alive

设置环境变量,自己IP,tftp服务器:
=> setenv ipaddr 10.8.8.100; setenv netmask 255.255.255.0; setenv serverip 10.8.8.3;

下载内核镜像、设备树并启动内核(如果没有加载设备树,会卡在 Starting kernel...这一步):
=> tftp 0x60000000 uImage; tftp 0x70000000 device.dtb; fdt addr 0x70000000; bootm 0x60000000 - 0x70000000

smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 10.8.8.3; our IP address is 10.8.8.100
Filename 'uImage'.
Load address: 0x60000000
Loading: #################################################################
#################################################################
#################################################################
############################################
5.1 MiB/s
done
Bytes transferred = 3500592 (356a30 hex)
smc911x: MAC 52:54:00:12:34:56
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 10.8.8.3; our IP address is 10.8.8.100
Filename 'device.dtb'.
Load address: 0x70000000
Loading: ##
50.8 KiB/s
done
Bytes transferred = 14708 (3974 hex)
smc911x: MAC 52:54:00:12:34:56
## Booting kernel from Legacy Image at 60000000 ...
   Image Name:   Linux-4.9.39
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3500528 Bytes = 3.3 MiB
   Load Address: 60000000
   Entry Point:  60000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 70000000
   Booting using the fdt blob at 0x70000000
   Loading Kernel Image ... OK
   Loading Device Tree to 7fed4000, end 7feda973 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.9.39 (konga@ubuntu) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Sat Mar 17 20:31:19 CST 2018
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
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 13 pages/cpu @9ffba000 s23372 r8192 d21684 u53248
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttyAMA0
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: 15012(91%)
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: 510936K/524288K available (5120K kernel code, 168K rwdata, 1196K rodata, 1024K init, 158K bss, 13352K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x80008000 - 0x80600000   (6112 kB)
      .init : 0x80800000 - 0x80900000   (1024 kB)
      .data : 0x80900000 - 0x8092a380   ( 169 kB)
       .bss : 0x8092c000 - 0x80953bb8   ( 159 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
GIC CPU mask not found - kernel will fail to boot.
GIC CPU mask not found - kernel will fail to boot.
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... 93.12MHz.
Calibrating delay loop... 892.92 BogoMIPS (lpj=4464640)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x60100000 - 0x60100058
Brought up 1 CPUs
SMP: Total of 1 processors activated (892.92 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
10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 35, base_baud = 0) is a PL011 rev1
console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 36, base_baud = 0) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 37, base_baud = 0) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 38, 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
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: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 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.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 1 counters available
workingset: timestamp_bits=30 max_order=17 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
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
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
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
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 31,32 (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 30
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 2018-03-17 13:05:13 UTC (1521291913)
ALSA device list:
  #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 30
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
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?)
1f01           32768 mtdblock1  (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 4.9.39 #1
Hardware name: ARM-Versatile Express
[<8010e5c8>] (unwind_backtrace) from [<8010b028>] (show_stack+0x10/0x14)
[<8010b028>] (show_stack) from [<80356200>] (dump_stack+0x84/0x98)
[<80356200>] (dump_stack) from [<801a8d38>] (panic+0xdc/0x248)
[<801a8d38>] (panic) from [<808012ac>] (mount_block_root+0x1c8/0x2a0)
[<808012ac>] (mount_block_root) from [<808014a8>] (mount_root+0x124/0x12c)
[<808014a8>] (mount_root) from [<80801600>] (prepare_namespace+0x150/0x198)
[<80801600>] (prepare_namespace) from [<80800eb4>] (kernel_init_freeable+0x250/0x260)


内核报错,还是因为没有根文件系统。


------------------------------------
七、制作根文件系统
创建脚本并执行:
konga@ubuntu:~/work/vexpress/busybox$ cat mkbusybox.sh
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install

	dd if=/dev/zero of=sdcard.ext3 bs=1M count=32
	mkfs.ext3 sdcard.ext3
	sudo rm -fr rootfs
	mkdir rootfs
	sudo mount -t ext3 -o loop sdcard.ext3  rootfs/
	cd rootfs;
	sudo mkdir lib proc sys dev etc etc/init.d
	sudo cp -r ../_install/* .
	sudo cp -P /usr/arm-linux-gnueabi/lib/*  lib/

	sudo touch etc/init.d/rcS ;
	sudo chmod 0777 etc/init.d/rcS;
	sudo echo "#!/bin/sh" >> etc/init.d/rcS
	sudo echo "mount -t proc none /proc" >> etc/init.d/rcS
	sudo echo "mount -t sysfs none /sys" >> etc/init.d/rcS
	sudo echo "/sbin/mdev -s" >> etc/init.d/rcS
	sudo chmod 0755 etc/init.d/rcS;

	cd ..;
	sudo umount rootfs/
	cp sdcard.ext3 ../image/

konga@ubuntu:~/work/vexpress/busybox$ bash -x mkbusybox.sh
编译制作根文件系统完成。

----------------------------------------------
八、完整运行

konga@ubuntu:~/work/vexpress/image$ ls
device.dtb  sdcard.ext3  u-boot  uImage

konga@ubuntu:~/work/vexpress/image$ qemu-system-arm -M vexpress-a9 -m 512 -nographic -net nic -net tap,ifname=tap0,script=no -sd sdcard.ext3 -kernel u-boot

WARNING: Image format was not specified for 'sdcard.ext3' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
audio: Could not init `oss' audio driver

U-Boot 2017.07 (Mar 17 2018 - 20:17:48 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 
=>

=> setenv ipaddr 10.8.8.100; setenv netmask 255.255.255.0; setenv serverip 10.8.8.3; setenv bootargs "console=ttyAMA0 root=/dev/mmcblk0 init=/linuxrc rw rootwait"

=> tftp 0x60000000 uImage; tftp 0x70000000 device.dtb; fdt addr 0x70000000; bootm 0x60000000 - 0x70000000 
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 10.8.8.3; our IP address is 10.8.8.100
Filename 'uImage'.
Load address: 0x60000000
Loading: #################################################################
#################################################################
#################################################################
############################################
8.5 MiB/s
done
Bytes transferred = 3500592 (356a30 hex)
smc911x: MAC 52:54:00:12:34:56
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 10.8.8.3; our IP address is 10.8.8.100
Filename 'device.dtb'.
Load address: 0x70000000
Loading: ##
2.3 MiB/s
done
Bytes transferred = 14708 (3974 hex)
smc911x: MAC 52:54:00:12:34:56
## Booting kernel from Legacy Image at 60000000 ...
   Image Name:   Linux-4.9.39
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3500528 Bytes = 3.3 MiB
   Load Address: 60000000
   Entry Point:  60000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 70000000
   Booting using the fdt blob at 0x70000000
   Loading Kernel Image ... OK
   Loading Device Tree to 7fed4000, end 7feda973 ... OK


Starting kernel ...


Booting Linux on physical CPU 0x0
Linux version 4.9.39 (konga@ubuntu) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Sat Mar 17 20:31:19 CST 2018
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
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 13 pages/cpu @9ffba000 s23372 r8192 d21684 u53248
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttyAMA0 root=/dev/mmcblk0 init=/linuxrc rw rootwait
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: 14968(91%)
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: 510936K/524288K available (5120K kernel code, 168K rwdata, 1196K rodata, 1024K init, 158K bss, 13352K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x80008000 - 0x80600000   (6112 kB)
      .init : 0x80800000 - 0x80900000   (1024 kB)
      .data : 0x80900000 - 0x8092a380   ( 169 kB)
       .bss : 0x8092c000 - 0x80953bb8   ( 159 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
GIC CPU mask not found - kernel will fail to boot.
GIC CPU mask not found - kernel will fail to boot.
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... 83.92MHz.
Calibrating delay loop... 666.41 BogoMIPS (lpj=3332096)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x60100000 - 0x60100058
Brought up 1 CPUs
SMP: Total of 1 processors activated (666.41 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
10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 35, base_baud = 0) is a PL011 rev1
console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 36, base_baud = 0) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 37, base_baud = 0) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 38, 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
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: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 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.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 1 counters available
workingset: timestamp_bits=30 max_order=17 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
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
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
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
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 31,32 (pio)
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
mmc0: new SD card at address 4567
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
mmcblk0: mmc0:4567 QEMU! 32.0 MiB 
aaci-pl041 10004000.aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 30
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 2018-03-17 14:03:43 UTC (1521295423)
ALSA device list:
  #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 30
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
EXT4-fs (mmcblk0): mounting ext3 file system using the ext4 subsystem
random: fast init done
EXT4-fs (mmcblk0): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext3 filesystem) on device 179:0.
Freeing unused kernel memory: 1024K (80800000 - 80900000)
random: crng init done


Please press Enter to activate this console. 
/ #
/ # uname -a 
Linux (none) 4.9.39 #1 SMP Sat Mar 17 20:31:19 CST 2018 armv7l GNU/Linux


/ # cat /proc/cpuinfo 
processor : 0
model name : ARMv7 Processor rev 0 (v7l)
BogoMIPS : 666.41
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc09
CPU revision : 0


Hardware : ARM-Versatile Express
Revision : 0000
Serial : 0000000000000000
/ #

猜你喜欢

转载自blog.csdn.net/konga/article/details/79595119