关键词: U-boot, VersatilePB, ARM, Linux, Qemu, vexpress-a9
环境介绍:
- Win7 64 + Vmware 15 + ubuntu18.04 64
- u-boot 版本:u-boot-2012.04.01
- Linux kernel版本:linux-5.3.0
- busybox版本:1.32.0
- 交叉编译工具链:arm-linux-gnueabihf-
- qemu版本:2.11.1
概述:
目标:基于Qemu虚拟vexpress-a9单板,完整虚拟单板启动全过程,利用网络引导的方式启动Linux内核:uboot引导+加载linux内核+加载文件系统,最终进入命令行界面。具体方法是:开启Qemu的网络支持功能,启动u-boot,设置u-boot的环境变量,u-boot采用tftp的方式将uImage格式的Linux内核下载到内存地址0x60003000处进行引导,最后加载bosybox文件系统,显示命令行提示符。
命令:
sudo qemu-system-arm -M vexpress-a9 -m 512M -nographic -kernel u-boot -net nic -net tap -sd ~/a9rootfs.ext3
具体步骤:
需要加上sudo apt install ifupdown来开启ifupdowm,否则直接修改interface无效
sudo apt-get install uml-utilities bridge-utils
修改 /etc/network/interfaces 文件,最后需要重启计算机,使新的 /etc/network/interfaces 配置文件生效
#source /etc/network/interfaces.d/*
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet manual
auto tap0
iface tap0 inet manual
auto br0
iface br0 inet static
#之前上网时采用静态IP,所以这里依然使用此
address 192.168.0.111
# 将之前上网的ip地址分配给网桥。
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
bridge_ports ens33 tap0
# 为网桥添加两个接口,分别是enp3s0(之前默认的上网网口)和tap0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
dns-nameservers 114.114.114.114
使用qemu-ifup脚本,权限755 sudo chmod 755 qemu-ifup
#! /bin/sh
# Script to bring a network (tap) device for qemu up.
# The idea is to add the tap device to the same bridge
# as we have default routing to.
# in order to be able to find brctl
PATH=$PATH:/sbin:/usr/sbin
switch=br0
interface=ens33
if [ -n "$1" ]; then
switch_exit=`sudo ifconfig -a | grep $switch`
interface_switch=`sudo brctl show | grep $interface`
if [ "$switch_exit" = "" ] ; then
sudo brctl addbr $switch
fi
if [ "$interface_switch" = "" ] ; then
sudo ifconfig $interface 0.0.0.0 promisc up
sudo brctl addif $switch $interface
fi
sudo ifconfig $1 0.0.0.0 promisc up
sudo brctl addif $switch $1
sudo dhclient $switch
else
echo "Error: no interface specified"
exit
fi
使用qemu-ifdown脚本,权限755 sudo chmod 755 qemu-ifdown
#! /bin/sh
echo sudo brctl delif br0 $1
sudo brctl delif br0 $1
echo sudo tunctl -d $1
sudo tunctl -d $1
echo brctl show
brctl show
2、配置u-boot
修改单板配置文件:include/configs/ca9x4_ct_vxp.h
vim include/configs/ca9x4_ct_vxp.h
// netmask
#define CONFIG_IPADDR 192.168.0.119
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_SERVERIP 192.168.0.111
#修改启动命令为
/* Basic environment settings */
#define CONFIG_BOOTCOMMAND "run bootflash; tftp 0x60003000 uImage; tftp 0x60500000 dtb; setenv bootargs 'root