基于Qemu虚拟vexpress-a9开发板,实现完整系统启动(uboot+kernel+rootfs)

关键词: 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=/dev/mmcblk0 console=ttyAMA0'; bootm 0x60003000 - 0x60500000"

说明:
这里我把ipaddr等设置为了192.168.0.119,这个网址设置要跟br0的网址(192.168.0.111)在同一个网段

3、配置Linux Kernel
要用u-boot引导,需要把Kernel编译成uImage格式:(LOADADDR和uboot的启动加载位置一致)
make uImage LOADADDR=0x60003000
编译生成的uImage在 ~/linux-4.9.218/arch/arm/boot下,将uImage拷贝到/tftpboot目录下

测试结果:

book@100ask:~/sss/u-boot-2012.04.01$ sudo qemu-system-arm -M vexpress-a9 -m 512M -nographic -kernel u-boot -net nic -net tap -sd ~/a9rootfs.ext3 
[sudo] password for book: 
device tap0 is already a member of a bridge; can't enslave it to bridge br0.
cmp: EOF on /tmp/tmp.3EuLhKWRJw which is empty
WARNING: Image format was not specified for '/home/book/a9rootfs.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.
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument


U-Boot 2012.04.01 (Jul 08 2020 - 16:42:35)

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 
Wrong Image Format for bootm command
ERROR: can't get kernel image!
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 192.168.0.111; our IP address is 192.168.0.119
Filename 'uImage'.
Load address: 0x60003000
Loading: #################################################################
     #################################################################
     #################################################################
     ###############################################
done
Bytes transferred = 3552440 (3634b8 hex)
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device
TFTP from server 192.168.0.111; our IP address is 192.168.0.119
Filename 'dtb'.
Load address: 0x60500000
Loading: ##
done
Bytes transferred = 14708 (3974 hex)
## Booting kernel from Legacy Image at 60003000 ...
   Image Name:   Linux-4.9.218
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3552376 Bytes = 3.4 MiB
   Load Address: 60003000
   Entry Point:  60003000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 60500000
   Booting using the fdt blob at 0x60500000
   XIP Kernel Image ... OK
OK
   Loading Device Tree to 7feea000, end 7fef0973 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.9.218 (book@100ask) (gcc version 6.2.1 20161016 (Linaro GCC 6.2-2016.11) ) #1 SMP Tue Jul 7 19:16:33 CST 2020
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 12 pages/cpu s19148 r8192 d21812 u49152
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/mmcblk0 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: 15016(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: 510948K/524288K available (5120K kernel code, 170K rwdata, 1208K rodata, 1024K init, 150K bss, 13340K 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 - 0x8092a980   ( 171 kB)
       .bss : 0x8092c000 - 0x80951bf0   ( 151 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... 91.44MHz.
Calibrating delay loop... 434.99 BogoMIPS (lpj=2174976)
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: Spectre v2: using BPIALL workaround
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 (434.99 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)
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
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
mmcblk0: mmc0:4567 QEMU! 64.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 2020-07-09 02:58:11 UTC (1594263491)
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) readonly on device 179:0.
Freeing unused kernel memory: 1024K
random: crng init done

Please press Enter to activate this console. 
/ # 
 

主机环境:Ubuntu 18.04虚拟机,目标机器:QEMU模拟vexpress-a9

工具链设置为:
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
export PATH=$PATH:/home/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin
 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值