主机环境:Ubuntu16.04
交叉编译工具:arm-linux-gnueabihf-
qemu版本:2.5.0
一、安装软件包
sudo apt-get install qemu
sudo apt-get install arm-linux-gnueabihf
二、编译uboot
1.下载uboot
2.安装编译依赖库
$ sudo apt-get install bison
$ sudo apt-get install flex
3.编译
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- vexpress_ca9x4_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4
4.执行仿真u-boot
$ qemu-system-arm -M vexpress-a9 -m 256 -kernel u-boot -nographic
三、编译kernel
1.下载kernel
https://mirrors.tuna.tsinghua.edu.cn/kernel/v4.x/linux-4.4.302.tar.xz
2.执行编译
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- vexpress_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4
3.执行仿真kernel
$ qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -nographic
-M vexpress-a9 模拟vexpress-a9单板,你能够使用-M ?參数来获取该qemu版本号支持的全部单板
-m 512M 单板执行物理内存512M
-kernel arch/arm/boot/zImage 告诉qemu单板执行内核镜像路径
-dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb 告诉qemu单板的设备树(必须加入)
-nographic 不使用图形化界面,仅仅使用串口
四、编译busybox,制作rootfs
1.下载busybox
2.配置
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
编译选择使用glibc动态库,因为静态库可能会出现一些未知的问题
$ make menuconfig
Settings --->
Build Options --->
[ ] Build static binary (no shared libs)
默认的安装目录是./_install,如果需要指定安装目录,可以在下边修改:
Settings --->
Installation Options ("make install" behavior)
(./_install) Destination path for 'make install'
3.编译
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
4.安装
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install
提示下边信息,表示安装成功:
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
安装完成之后,生成的目标文件默认在./_install目录,这个目标文件目录就是下边要制作根文件系统需要用到的工具:
$ ls _install/
bin linuxrc sbin usr
或者直接使用CONFIG_PREFIX指定安装目录:
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CONFIG_PREFIX=/.../rootfs/ install
五、生成最小根文件系统
1.添加glibc库
在根文件系统中添加加载器和动态库:
$ mkdir rootfs/lib
$ cp /usr/arm-linux-gnueabi/lib/* rootfs/lib/ -rfp
2.创建设备文件
$ mkdir rootfs/dev
$ cd rootfs/dev
$ mknod -m 666 console c 5 1
$ mknod -m 666 null c 1 3
3.制作SD卡文件系统镜像
1.生成一个空的SD卡镜像
$ dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
2.格式化为exts文件系统
$ mkfs.ext3 rootfs.ext3
3.将rootfs烧写到SD卡
$ sudo mount -t ext3 rootfs.ext3 /mnt -o loop
$ sudo cp -rf rootfs/* /mnt/
$ sudo umount /mnt
在开发过程中,如果需要修改SD卡中的内容,可以将SD卡的镜像rootfs.ext3挂载到/mnt目录下,直接操作/mnt来修改;
$ sudo mount -t ext3 rootfs.ext3 /mnt -o loop