本次PC系统:Ubuntu16.04
目标系统:以Versatile Express-A9开发板为例搭建环境
一.Qemu编译安装
1.Qemu源码下载:wget http://wiki.qemu-project.org/download/qemu-2.7.0.tar.bz2
2.安装所需要的软件包(参考两文章):
sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0-0
sudo apt-get install libglib2.0-dev
sudo apt-get install autoconf
sudo apt-get install flex bison
sudo apt-get install libtool
3.解压Qemu安装包
sudo tar -jxvf qemu-2.7.0.tar.bz2
4.进入Qemu包
cd qemu-2.7.0
5.编译安装
./configure --target-list=arm-softmmu --audio-drv-list=
make
make install
注:最初原文此处用的是2.0的安装包,但是在编译的时候总会出现如下错误:
fatal error: linux/compiler-gcc5.h: No such file or directory
此错误是因为2.0版本的Qemu并不支持Gcc5.h,起初仍找了很多方法去修改这种错误,例如下载Gcc或者从别的地方
找Gcc补进来,但并没有什么用。而用Qemu2.7安装包便不会出现这些问题。
最终结果:
二.Linux内核编译
1.安装交叉编译工具
sudo apt-get install gcc-arm-linux-gnueabi
2.内核下载
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.8.tar.xz
解压: tar -xvf linux-4.8.tar.xz
注:此处不用原文的3.16版本,是因为我们的下载交叉编译器指令默认直接下载最新版的交叉编译器,
但是3.16并不支持最新版的交叉编译器,在之后的make中会反复出现error,所以此处换用4.8版本的
Linux内核,换用之后一路风顺,不会出现问题。
若有朋友有兴趣想要编译3.16版本的内核,可以降低交叉编译器的版本,使用4.7版本的交叉编译器,由于降低版本
的话后面的环境变量的设置都要改动,有点麻烦,所以这里我就不展示出来。
3.配置编译
-配置内核
make menuconfig:
在kernel hacking下的选项中选中(实用空格键,星号*代表选选中)compile the kernel with debug info
注意【记得提前安装libncurses5-dev】,或者其他编译内核需要的依赖包
│ │ [*] 64-bit kernel │ │
│ │ General setup —> │ │
│ │ [*] Enable loadable module support —> │ │
│ │ -*- Enable the block layer —> │ │
│ │ Processor type and features —> │ │
│ │ Power management and ACPI options —> │ │
│ │ Bus options (PCI etc.) —> │ │
│ │ Executable file formats / Emulations —> │ │
│ │ [*] Networking support —> │ │
│ │ Device Drivers —> │ │
│ │ Firmware Drivers —> │ │
│ │ File systems —> │ │
│ │ Kernel hacking —> │ │
│ │ Security options —> │ │
│ │ -*- Cryptographic API —> │ │
│ │ [*] Virtualization —> │ │
│ │ Library routines —> │ │
按K键选中Kernel hacking之后按enter键进入子选项,按K键选移动到 Kernel debugging选项并按空格键选中为星号*(如下)
│ │
[*] Magic SysRq key │ │
│ │ (0x1) Enable magic SysRq key functions by default │ │
│ │ [*] Enable magic SysRq key over serial │ │
│ │ [*] Kernel debugging │ │
│ │ Memory Debugging —> │ │
│ │ [ ] Code coverage for fuzzing │ │
│ │ [ ] Debug shared IRQ handlers │ │
│ │ Debug Lockups and Hangs —>
进入kernel debuging 选中compile the kernel with debug info选项
保存退出
export CROSS_COMPILE=arm-linux-gnueabi-
export ARCH=arm
make vexpress_defconfig
make -j2
完全之后便在arch/arm/boot/目录中生成了zImage:
三.根文件的制作
(1)busybox的下载
wget http://www.busybox.net/downloads/busybox-1.25.0.tar.bz2 --no-check-certificate
解压:tar -jxvf busybox-1.20.2.tar.bz2
(2)配置编译
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make CROSS_COMPILE=arm-linux-gnueabi- install
(3)开始制作根目录
1.创建必要的目录
mkdir rootfs
cd rootfs
mkdir rootfs /lib
mkdir rootfs /dev
2.拷贝busybox编译生产的目录和文件,编译器自带的lib
sudo cp busybox-1.25.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
3.创建4个tty终端设备
sudo mknod rootfs/dev/tty1 c 4 1
sudo mknod rootfs/dev/tty2 c 4 2
sudo mknod rootfs/dev/tty3 c 4 3
sudo mknod rootfs/dev/tty4 c 4 4
4.生成32M大小的镜像,并拷文件系统树到镜像文件中
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
mkfs.ext3 a9rootfs.ext3
mkdir tmpfs
mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop
cp -r rootfs/* tmpfs/
sudo umount tmpfs
运行虚拟机
在终端输入指令:qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/chris/Desktop/linux-
4.8/arch/arm/boot/zImage -dtb /home/chris/Desktop/linux-4.8/arch/arm/boot/dts/vexpress-
v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3