qemu系统-vexpress v9

qemu启动实践。环境:ubuntu 16.04 64 bit,使用SecureCRT软件连接。

安装交叉编译器

到下载配套交叉编译器。按说明解压。

1
2
3
$ arm-unknown-linux-gnueabihf-gcc -v
...
gcc version 6.3.0 (crosstool-NG crosstool-ng-1.23.0)

qemu

参考《qemu使用笔记》安装qemu软件。
设置qemu网络:

1
2
3
$ sudo tunctl -t tap0 -u `whoami`
$ sudo brctl addif br0 tap0
$ sudo ifconfig tap0 up

u-boot

下载源码

编译

1
2
3
4
$ export ARCH=arm
$ export CROSS_COMPILE=arm-unknown-linux-gnueabihf-
$ make vexpress_ca9x4_defconfig
$ make -j4

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
$ qemu-system-arm \
-M vexpress-a9 \
-nographic \
-m 512M \
-kernel u-boot

带网络:
# qemu-system-arm \
-M vexpress-a9 \
-nographic \
-net nic -net tap,ifname=tap0 \
-m 512M \
-kernel u-boot

输出信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument


U-Boot 2018.03-g4f45366 (Apr 15 2019 - 15:49:53 +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
=>

内核

下载配套内核

配置内核

1
2
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm menuconfig
1
2
3
4
5
System Type -->
[ ] Enable the L2x0 outer cache controller // 将*去掉,否则QEMU起不来
Kernel Features -->
[*] Use the ARM EABI to compile the kernel
确保该选项被选择

其它配置:

编译内核

1
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm

TODO:编译设备树:make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm dtbs
得到内核镜像为:arch/arm/boot/zImage,设备树文件为:arch/arm/boot/dts/vexpress-v2p-ca9.dtb

启动内核

进入arch/arm/boot/目录:

1
cd arch/arm/boot/

启动:

1
2
3
4
5
6
7
8
9
qemu-system-arm -M vexpress-a9 -nographic -m 512M \
-kernel ./zImage \
-dtb ./dts/vexpress-v2p-ca9.dtb \
-append "ignore_loglevel log_buf_len=10M print_fatal_signals=1 LOGLEVEL=8 earlyprintk=vga,keep sched_debug console=ttyAMA0"
或:
qemu-system-arm -M vexpress-a9 -nographic -m 512M \
-kernel ./zImage \
-dtb ./dts/vexpress-v2p-ca9.dtb \
-append "earlyprintk=vga log_buf_len=15M console=ttyAMA0,115200n8"

注:

  • 需要指定dtb,否则无法启动。
  • 启动参数需要添加console=ttyAMA0,否则不会打印启动信息。log_buf_len指定启动信息大小,过小会不显示最初的信息。
  • qemu选项-nographic需要保留,否则会提示Could not initialize SDL(No available video device)
  • 此时,内核可启动,但无法挂载rootfs,最终失败。这是正常情况。

busybox

下载源码

配置

生成默认配置:

1
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm defconfig

自定义配置:

1
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm menuconfig

将busybox编译为静态库版本:

1
2
Settings  ---> 
[*] Build static binary (no shared libs)

除此外,其它默认即可。原则上,删除不使用的工具(如Mail工具、打印工具),添加需要的工具(中文支持)。
中文支持:

1
2
3
4
5
6
7
8
Settings  ---> 
[*] Support Unicode // 默认已选
[ ] Check $LC_ALL, $LC_CTYPE and $LANG environment variables
(63) Character code to substitute unprintable characters with
(195102) Range of supported Unicode characters // 由原来的767改为195102,中文的Unicode最大为0x2FA1D(196101)
[ ] Allow zero-width Unicode characters on output
[*] Allow wide Unicode characters on output // 默认未选择,需要按空格中选中
[ ] Bidirectional character-aware line input

编译

1
make CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm install

根文件系统

主要包括:busybox生成的二进制文件、库文件(静态库、动态为、链接器)、设备文件、启动脚本。

库文件

拷贝交叉编译器的库:
位于(交叉编译器路径)/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot目录的libusr/lib。注意,lib目录有链接脚本:ld-2.25.so,它连接到同目录下的文件ld-linux-armhf.so.3。因此,拷贝时要使用cp -a进行。

启动:

1
2
3
4
5
6
7
8
9
10
11
12
13
qemu-system-arm -M vexpress-a9 -nographic -m 512M \
-kernel ./zImage \
-dtb ./dts/vexpress-v2p-ca9.dtb \
-append "earlyprintk=vga log_buf_len=15M root=/dev/mmcblk0 console=ttyAMA0,115200n8" \
-sd rootfs.img

带网络的:要用root权限执行:
qemu-system-arm -M vexpress-a9 -nographic -m 512M \
-kernel ./zImage \
-dtb ./dts/vexpress-v2p-ca9.dtb \
-append "earlyprintk=vga log_buf_len=15M root=/dev/mmcblk0 console=ttyAMA0,115200n8" \
-sd rootfs.img \
-net nic,macaddr=6c:61:74:65:6c:65 -net tap,ifname=tap0

在uboot中启动内核

安装mkimage工具:sudo apt-get install u-boot-tools
编译内核:

1
make uImage LOADADDR=0x60003000 CROSS_COMPILE=arm-unknown-linux-gnueabihf- ARCH=arm

启动uboot:

1
2
3
4
5
6
7
8
9
# qemu-system-arm \
-M vexpress-a9 \
-nographic \
-net nic,macaddr=6c:61:74:65:6c:65 -net tap,ifname=tap0 \
-m 512M \
-kernel u-boot \
-sd rootfs.img

注:macaddr为手动指定mac地址,也可不指定。

uboot中输入:

1
2
3
4
5
6
7
8
9
setenv ipaddr 192.168.28.130
setenv serverip 192.168.28.131
setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0'
tftp 0x60003000 uImage
tftp 0x61000000 vexpress-v2p-ca9.dtb
bootm 0x60003000 - 0x61000000

另:
=> iminfo # 检查下载的uImage格式

可正常启动

配套实验资源

本文已整理好配套的实验资源,直接下载使用即可。

注:busybox源码编译的二进制已整合到rootfs中。

外一篇:xilinx预编译

下载地址:

文件名:

1
$ 2016.2-zed-release.tar.xz

解压:

1
$ tar xf 2016.2-zed-release.tar.xz

启动:

1
2
3
4
$ qemu-system-aarch64 \
-M arm-generic-fdt-7series -machine xilinx-zynq-a9 \
-serial /dev/null -serial mon:stdio -display none \
-kernel ./zed/uImage -dtb ./zed/devicetree.dtb --initrd ./zed/uramdisk.image.gz

参考资料:

李迟

  • 本文作者:李迟
  • 版权声明:原创文章,版权归署名作者,转载建议注明出处(当然不注明亦可)。
  • 本文链接:/ellp/ellp-qemu-start.html