实验依照《奔跑吧linux内核》第一版进行,感谢大佬们的创作。
1. 拉取kernel 4.0 code
wget -c https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.0.tar.gz
2. 拉取busybox code
wget -c https://busybox.net/downloads/busybox-1.24.0.tar.bz2
3. 解压 kernel 和 busybox
tar -xvf linux-4.0.tar.gz
tar -xvf busybox-1.24.0.tar.bz2
4. 编译busybox
cd busybox-1.24.0
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary (no shared libs)
make -j
make install
安装到 busybox-1.24.0 的 _install 目录下
cd _install/
mkdir etc
mkdir dev
mkdir mnt
mkdir -p etc/init.d/
cd etc/init.d/
touch rcS
在rcS中输入:
mkdi -p /proc
mkdi -p /tmp
mkdi -p /sys
mkdi -p /mnt
/bin/mount -a
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
chmod a+x rcS
cd ..
touch fstab
在 fstab中输入
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
debugfs /sys/kernel/debug debugfs defaults 0 0
touch inittab
在 inittab中输入
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
cd ../dev/
ls
sudo mknod console c 5 1
sudo mknod null c 1 3
5. 编译kernel
cd linux-4.0/
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make vexpress_defconfig
make menuconfig
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
(_install) Initramfs source file(s)
Kernel Features --->
Memory split (3G/1G user/kernel split) --->
Boot options --->
() Default kernel command string
make bzImage -j && make dtbs
include/linux/compiler-gcc.h:107:1: fatal error: linux/compiler-gcc7.h: 没有那个文件或目录
#include gcc_header(__GNUC__)
cd include/linux/
ln -s compiler-gcc5.h compiler-gcc7.h
make bzImage -j && make dtbs
6.
qemu-system-arm -M vexpress-a9 -smp 4 -m 1024M -kernel arch/arm/boot/zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8" -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic
可正常运行。
7.
DTC arch/arm/boot/dts/vexpress-v2p-ca5s.dtb
DTC arch/arm/boot/dts/vexpress-v2p-ca9.dtb
DTC arch/arm/boot/dts/vexpress-v2p-ca15-tc1.dtb
DTC arch/arm/boot/dts/vexpress-v2p-ca15_a7.dtb