qemu-system-arm 命令用法
qemu-system-arm -M vexpress-a9 -m 512M -kernel ./uImage -dtb ./vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
-M 指定开发板
-m 指定内存
-kernel 指定镜像
-nographic 不使用图形化
root@vm:~/tftpboot# ifconfig
br0 Link encap:Ethernet HWaddr 00:0c:29:17:3d:ea
inet addr:192.168.199.238 Bcast:192.168.199.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe17:3dea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3550 errors:0 dropped:0 overruns:0 frame:0
TX packets:2540 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:267188 (267.1 KB) TX bytes:3633841 (3.6 MB)
U-boot编译
http://ftp.denx.de/pub/u-boot/
u-boot-2017.05.tar.bz2
Makefile: CROSS_COMPILE=arm-linux-gnueabi-
config.mk : ARCH=arm
u-boot-2017.05# vim include/configs/vexpress_common.h #支持tftp启动
/* Basic environment settings */
/*#define CONFIG_BOOTCOMMAND \
"run distro_bootcmd; " \
"run bootflash; "*/
#define CONFIG_BOOTCOMMAND \
"tftp 0x60003000 uImage;tftp 0x60500000 vexpress-v2p-ca9.dtb;\
setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0';\
bootm 0x60003000 - 0x60500000;"
#define CONFIG_IPADDR 192.168.199.239
#define CONFIG_NETMASK 255.255.2555.0
#define CONFIG_SERVERIP 192.168.199.238
#define BOOT_TARGET_DEVICES(func) \
func(MMC, mmc, 1) \
func(MMC, mmc, 0) \
func(PXE, pxe, na) \
func(DHCP, dhcp, na)
u-boot-2017.05# vim include/configs/vexpress_common.h #支持nfs启动
/* Basic environment settings */
/*#define CONFIG_BOOTCOMMAND \
"run distro_bootcmd; " \
"run bootflash; "*/
#define CONFIG_BOOTCOMMAND \
"tftp 0x60003000 uImage;tftp 0x60500000 vexpress-v2p-ca9.dtb;\
setenv bootargs 'root=/dev/nfs rw \
nfsroot=192.168.199.238:/root/qemu/rootfs init=/linuxrc \
ip=192.168.199.239 console=ttyAMA0';\
bootm 0x60003000 - 0x60500000;"
#define CONFIG_IPADDR 192.168.199.239
#define CONFIG_NETMASK 255.255.2555.0
#define CONFIG_SERVERIP 192.168.199.238
make vexpress_ca9x4_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
qemu-system-arm -M vexpress-a9 -m 512M -nographic -kernel u-boot
qemu-system-arm 启动u-boot
qemu-system-arm -M vexpress-a9 -m 512M -nographic -kernel u-boot
Linux内核编译
https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/
linux-4.4.76.tar.xz
cd linux-4.4.76
修改Makefile
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make vexpress_defconfig
make zImage -j4
arch/arm/boot/zImage
make LOADADDR=0x60003000 uImage -j4
make modules
make dtbs
qemu-system-arm 启动内核
qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
killall qemu-system-arm
补充:内核支持NFS文件系统
make menuconfig
File systems —>
[*] Network File Systems —>
<*> NFS client support
<*> NFS client support for NFS version 2
<*> NFS client support for NFS version 3
[ ] NFS client support for the NFSv3 ACL protocol extension
< > NFS client support for NFS version 4
[ ] Provide swap over NFS support
[*] Root file system on NFS
busybox 编译
https://busybox.net/downloads/
busybox-1.27.0.tar.bz2
cd busybox-1.27.0
修改 Makefile
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make defconfig
apt install libncurses5-dev libncursesw5-dev
make menuconfig
Busybox Settings —>
— Build Options
[*] Build BusyBox as a static binary (no shared libs)
make -j4
make install
在当前目录下生成 _install
制作根文件系统
mkdir rootfs
mkdir rootfs/lib
cp -r busybox-1.27.0/_install/* rootfs
cp -p /usr/arm-linux-gnueabi/lib/* rootfs/lib
mkdir -p rootfs/dev/
cd rootfs/dev/
mknod -m 666 tty1 c 4 1
mknod -m 666 tty2 c 4 2
mknod -m 666 tty3 c 4 3
mknod -m 666 tty4 c 4 4
mknod -m 666 console c 5 1
mknod -m 666 null c 1 3
制作SD卡文件系统镜像
生成镜像
dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
生成 rootfs.ext3
格式化为exts文件系统
mkfs.ext3 rootfs.ext3
文件拷贝到文件系统镜像中
mount -t ext3 rootfs.ext3 /mnt/ -o loop
cp -rp rootfs/* /mnt
umount /mnt
** 启动镜像和文件系统**
qemu-system-arm -M vexpress-a9 -m 512M -kernel linux-4.4.76/arch/arm/boot/zImage -dtb linux-4.4.76/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd rootfs.ext3
** 在图形界面下启动镜像和文件系统**
qemu-system-arm -M vexpress-a9 -m 512M -kernel linux-4.4.76/arch/arm/boot/zImage -dtb linux-4.4.76/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -append "root=/dev/mmcblk0 rw console=tty0" -sd rootfs.ext3
cp linux-4.4.76/arch/arm/boot/dts/vexpress-v2p-ca9.dtb ~/tftpboot
cp linux-4.4.76/arch/arm/boot/uImage ~/tftpboot
cp u-boot-2017.05/u-boot ~/tftpboot
tftp 启动系统
cd ~/tftpboot
qemu-system-arm -M vexpress-a9 -kernel u-boot -nographic -m 512M -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 -sd /root/qemu/rootfs.ext3
killall qemu-system-arm
nfs启动系统
qemu-system-arm -M vexpress-a9 -kernel u-boot -nographic -m 512M -net nic,vlan=0 -net tap,vlan=0,ifname=tap0