Centos7 build qemu simulator to simulate arm-vexpress-a9 development board
-
reference:
Finishing: Hanshui Sitian https://www.cnblogs.com/phldylj/p/8299326.html
Release: 2018-01-16 23:06
Original: Using Qemu to simulate vexpress-a9 by Morse code https://www. cnblogs.com/pengdonglin137/p/5023342.html -
Reprint instructions:
Refer to the above information, successfully built in CentOS7, thank you for sharing in advance such as Morse code. Some pits were filled in during the construction, hoping to be helpful to the visitors, the following is the construction notes.
1. Download and installation of cross compiler
-
1. Download address: http://blog.csdn.net/dldw8816/article/details/46004167
Compilation tool chain of linaro.org ( https://releases.linaro.org/components/toolchain/binaries/ )
-
linaro.org, arm-linux-gnueabi, 6.3.1-2017.05
- gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabi.tar.xz — 27-Feb-2018 00:35 97.8M (OK)
- gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar.xz — 26-Feb-2018 23:50 77.0M
- runtime-gcc-linaro-6.3.1-2017.05-arm-linux-gnueabi.tar.xz — 28-Jan-2018 18:33 6.2M
- sysroot-glibc-linaro-2.23-2017.05-arm-linux-gnueabi.tar.xz — 27-Feb-2018 00:35 38.4M
-
linaro.org , arm-eabi (bare-metal, bare desk), 6.3-2017.05
ARM official compilation tool chain
- arm.com , arm-eabi (AArch32 bare-metal target, bare metal), 8.2-2019.01
- AArch32 target with soft float (arm-linux-gnueabi)
-
-
2. Then unzip
# tar jxvf arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 tar xvf gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabi.tar.xz
-
3. Add environment variables, assuming that the directory where the compressed package is located is /home, and the directory after decompression is arm-linux-gnueabi-6.
vim /etc/profile # 在最下面添加 export PATH=$PATH:/home/arm-linux-gnueabi-6/bin # 然后更新 source /etc/profile
-
4. Test whether the installation is successful
arm-linux-gnueabi-gcc -v
2. Installation of qemu
-
reference:
-
Official website: https://download.qemu.org/
-
step:
# 下载源代码 wget https://download.qemu.org/qemu-3.1.0.tar.xz tar xvf qemu-3.1.0.tar.xz # 新建编译目标路径 mkdir build # 编译 cd qemu-3.1.0 ./configure --target-list=arm-softmmu --audio-drv-list= --prefix=/root/qemu/build # 配置qemu,支持模拟arm架构下的全部单板 # ./configure --prefix=/root/xxx/build make -j8 make install # 说明: $./configure --enable-kvm --enable-debug --enable-vnc --enable-werror --target-list=arm-softmmu --audio-drv-list= # configure脚本用于生成Makefile,其选项可以用./configure --help查看。这里使用到的选项含义如下: # --enable-kvm:编译KVM模块,使QEMU可以利用KVM来访问硬件提供的虚拟化服务。 # --enable-vnc:启用VNC。 # --enalbe-werror:编译时,将所有的警告当作错误处理。 # --target-list:选择目标机器的架构。默认是将所有的架构都编译,但为了更快的完成编译,指定需要的架构即可。
3. uboot installation
Reference: http://blog.csdn.net/aggresss/article/details/54945726
-
1), source file download: http://ftp.denx.de/pub/u-boot/
wget http://ftp.denx.de/pub/u-boot/u-boot-2018.09.tar.bz2
-
2), unzip the source file
tar jvxf u-boot-2018.01.tar.bz2 -C xxxx (xxx为需要解压的目录)
-
3). Enter the U-Boot source file directory, and then execute:
# export CROSS_COMPILE=arm-none-eabi- export ARCH=arm export CROSS_COMPILE=arm-linux-gnueabi- # 要求bison等 yum install bison flex # 编译 make vexpress_ca9x4_defconfig make # 或执行如下2个步骤 # make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_ca9x4_defconfig # make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm
After the compilation is complete, if the u-boot file is generated in the directory, the compilation is successful.
-
4) Write the script run.sh in the U-Boot source code directory
qemu-system-arm -M vexpress-a9 -nographic -m 512M -kernel u-boot
Then chmod +x run.sh increases file execution permissions.
-
5), finally execute ./run.sh, you can see that the bootloader is started, but there is no image file
smc911x: MAC 52:54:00:12:34:56 Wrong Image Format for bootm command ERROR: can't get kernel image! =>
Press Ctrl+a, X to exit
4. Compile the kernel
-
Reference blog post: http://blog.csdn.net/aggresss/article/details/54946438
-
Official download address: https://www.kernel.org/pub/linux/kernel/
-
Tsinghua University Mirror: https://mirrors.tuna.tsinghua.edu.cn/kernel
- linux-3.18.135.tar.xz — 78MB 2019-02-07 00:47 (very fast)
-
Git clone
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
-
Download
wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v3.x/linux-3.18.135.tar.xz
-
1), find the configuration file vexpress_defconfig that needs to compile the kernel from arch/arm/configs and copy it to the root directory of the source code
-
2), execute the command
# export CROSS_COMPILE=arm-none-eabi- # export ARCH=arm make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig # 生成vexpress开发板的config文件 make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm zImage make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm modules make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm dtbs
-
3). Generate zImage file in arch/arm/boot directory after compiling, it means compiling successfully.
- test
qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -nographic -append "console=ttyAMA0"
- Which tty should be filled in the console= parameter in the kernel startup parameters?
- Reference: https://blog.csdn.net/qingtian12138/article/details/53609526
- Solution: Because the serial port driver types of different boards are different, the names of the created tty devices are of course also different. What is the tty device name of the vexpress board? In fact, this value can be found from the generated .config file CONFIG_CONSOLE macro.
- test
-
4), about the kernel version
- Reference: https://www.cnblogs.com/mfmdaoyou/p/6934098.html
- Explanation: It is found that the code of the 3.18 version number and later version number on the main line cannot be executed using this construction method. The root cause of the problem has not yet been identified. Suppose the reader wants to build successfully at high speed. It is recommended to use the kernel of version 3.16 to build.
-
5) When I compile the 3.1.16 kernel with arm-none-eabi- version 5.4, the following error is reported
include/linux/compiler-gcc.h:106:30: fatal error: linux/compiler-gcc6.h: No such file or directory #include gcc_header(__GNUC__)
- You can download the corresponding version of the cross-compilation tool on Linaro's official website (https://releases.linaro.org/components/toolchain/binaries/) to solve this problem.
# 原因是因为我使用的交叉编译工具链版本太高(6.2.1版本)导致,先在内核代码根目录下搜索compiler-gcc* ./include/linux/compiler-gcc3.h ./include/linux/compiler-gcc5.h ./include/linux/compiler-gcc.h ./include/linux/compiler-gcc4.h # 支持的版本有3、4、5,在Linaro官网上下载5版本的交叉编译工具链即可解决问题。
- The author also reported the above problems when compiling 3.1.16 with gcc-linaro-6.3.1 version of arm-linux-gnueabi, and compiling version 3.18.135 did not report the above problems.
- You can download the corresponding version of the cross-compilation tool on Linaro's official website (https://releases.linaro.org/components/toolchain/binaries/) to solve this problem.
5. Compile busybox
-
1), download busybox from https://busybox.net/downloads/
-
2), enter the Busybox source file directory and execute make menuconfig, if an error is reported, yum list ncurses , and then install the listed things
Busybox Setting -> Build options -> Build Busybox as a static binary (no shared libs) # 选中 静态编译。 -> Cross Compiler prefix # 交叉编译器配置(arm-linux-gnueabi-,可make命令带入) -> Installation options -> BusyBox installation prefix # 默认目标位置(若不指定,需手动移到rootfs;若已有rootfs,可指定rootfs位置<推荐,自动完成>)
Note : If you do not select "Build Busybox as a static binary (no shared libs)", when you start qemu, it will report a "kernel panic" error!
-
3), compile
make distclean # 清除原有配置 make menuconfig # 配置命令选项 make CROSS_COMPILE=arm-linux-gnueabi- make CROSS_COMPILE=arm-linux-gnueabi- install # 在_install 目录下生成编译文件: bin sbin linuxrc usr 等
-
4), the problem
- When compiling busybox with arm-none-eabi-, an error of curses.h not found is reported
# make menuconfig HOSTCC scripts/basic/fixdep HOSTCC scripts/basic/split-include HOSTCC scripts/basic/docproc HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/kxgettext.o HOSTCC scripts/kconfig/mconf.o HOSTCC scripts/kconfig/zconf.tab.o HOSTLD scripts/kconfig/mconf HOSTCC scripts/kconfig/lxdialog/checklist.o In file included from scripts/kconfig/lxdialog/checklist.c:24:0: scripts/kconfig/lxdialog/dialog.h:31:20: 致命错误:curses.h:没有那个文件或目录 #include CURSES_LOC
- solve:
- Method: When compiling the application, it is not suitable to use the compiler of **arm-none-eabi- version, but the compiler of arm-linux-gnueabi-** version
- Reference: Differences among ARM cross compilers GNUEABI, NONE-EABI, ARM-EABI, GNUEABIHF, etc. (http://www.veryarm.com/296.html)
6. Make the root file system
-
1), create a blank file, 32M
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
-
2), format
mkfs.ext3 a9rootfs.ext3
-
3), create a root file system directory
mkdir rootfs
-
4) Copy the files under busybox
cp busybox/busybox-1.26.2/_install/* -r rootfs/
-
5), copy the lib of the cross compiler
mkdir rootfs/lib/ cp -P /xxx/arm-linux-gnueabi/lib/* rootfs/lib/
-
6), create terminal equipment
mkdir rootfs/dev/ mknod rootfs/dev/tty1 c 4 1 mknod rootfs/dev/tty2 c 4 2 mknod rootfs/dev/tty3 c 4 3 mknod rootfs/dev/tty4 c 4 4 mknod rootfs/dev/console c 5 1 mknod rootfs/dev/null c 1 3
-
7), create the necessary directories
mkdir -p rootfs/proc/ mkdir -p rootfs/sys/ mkdir -p rootfs/tmp/ mkdir -p rootfs/root/ mkdir -p rootfs/var/ mkdir -p rootfs/mnt/
-
8), create a temporary directory and map with blank files, the purpose is to copy the root file system into it
mkdir tmpfs mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop cp -r rootfs/* tmpfs/ umount tmpfs
-
0), the script of the above steps,
create a directory, copy the zImage, vexpress-v2p-ca9.dtb, _install directories under one directory# 打开脚本文件 vim mkrootfs.sh # 粘贴如下内容 rm -rf rootfs rm -rf tmpfs rm -f a9rootfs.ext3 mkdir rootfs cp ../busybox/busybox-1.26.2/_install/* rootfs/ -raf # 与你的busybox的目录有关 mkdir -p rootfs/proc/ mkdir -p rootfs/sys/ mkdir -p rootfs/tmp/ mkdir -p rootfs/root/ mkdir -p rootfs/var/ mkdir -p rootfs/mnt/ cp -arf ~/xxx/arm-linux-gnueabi-6/lib/lib rootfs/ # 与你的arm-linux-gnueabi-的目录有关 rm rootfs/lib/*.a arm-linux-gnueabi-strip rootfs/lib/* mkdir -p rootfs/dev/ mknod rootfs/dev/tty1 c 4 1 mknod rootfs/dev/tty2 c 4 2 mknod rootfs/dev/tty3 c 4 3 mknod rootfs/dev/tty4 c 4 4 mknod rootfs/dev/console c 5 1 mknod rootfs/dev/null c 1 3 dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32 mkfs.ext3 a9rootfs.ext3 mkdir -p tmpfs mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop cp -r rootfs/* tmpfs/ umount tmpfs
7, start
# 拷贝kernel文件到a9rootfs.ext3所在目录,以便执行
cp -r ../kernel/linux-3.18.135/arch/arm/boot/ .
# 执行
qemu-system-arm -nographic -sd a9rootfs.ext3 -M vexpress-a9 -m 512M -kernel zImage -dtb ./dts/vexpress-v2p-ca9.dtb -append "init=/linuxrc root=/dev/mmcblk0 rw rootwait earlyprintk console=ttyAMA0"
qemu-system-arm -serial stdio -sd a9rootfs.ext3 -M vexpress-a9 -m 512M -kernel zImage -dtb ./dts/vexpress-v2p-ca9.dtb -append "init=/linuxrc root=/dev/mmcblk0 rw rootwait earlyprintk console=ttyAMA0"
8. Attention
- 1). Before compiling the above, please make sure export ARCH=arm; export CROSS_COMPILE=arm-linux-gnueabi-
- 2). If an error is reported, it is generally not included in some libraries, Baidu or Google
9. Problem
- 1)、audio: Could not init `oss’ audio driver
- Solution: [Summary of sound card simulation method in virtual machine under QEMU ( https://blog.csdn.net/hubbybob1/article/details/77199567 )] ( https://blog.csdn.net/hubbybob1/article/details/ 77199567 )