- 編譯內(nèi)核: vmlinuz、zImage鹏往、dtb
- 編譯qemu: qemu-system-arm
- 根文件系統(tǒng)
vmlinuz: 原始內(nèi)核文件, 用于gdb調(diào)試
zImage: 壓縮后的內(nèi)核影響
dtb: 編譯后的設(shè)備樹文件
內(nèi)核vmlinuz、zImage骇塘、dtb
交叉編譯工具鏈
sudo apt-get install gcc-arm-linux-gnueabihf
32位編譯內(nèi)核
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make vexpress_defconfig
make menuconfig
64位編譯內(nèi)核
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make defconfig
make menuconfig
路徑
32位Image
arch/arm/boot/zImage
arch/arm/boot/dts/*.dtb
64位Image
arch/arm/boot/Image
arch/arm/boot/dts/arm/vexpress-v2f-1xv7-ca53x2.dtb
Qemu
編譯qemu-5.2.0
mkdir build
cd build
../configure
make
32啟動(dòng)
./qemu-system-arm
-M vexpress-a9 \
-m 512M \
-dtb vexpress/vexpress-v2p-ca9.dtb \
-kernel vexpress/zImage \
-nographic \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" \
-sd vexpress.ext3
~/qemu-system-elf64/qemu-system-aarch64 \
-machine virt,virtualization=true,gic-version=3 \
-nographic \
-m size=1024M \
-cpu cortex-a57 \
-smp 2 \
-kernel Image \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd ../vexpress-a9.ext3
常用啟動(dòng)參數(shù)
-m 512M 內(nèi)存大小
-display none
-s shorthand for -gdb tcp::1234
-S freeze CPU at startup (use 'c' to start execution)
Linux/Multiboot boot specific:
-kernel bzImage use 'bzImage' as kernel image
-append cmdline use 'cmdline' as kernel command line
-initrd file use 'file' as initial ram disk
-dtb file use 'file' as device tree image
gdb 調(diào)試
sudo apt install gdb-multiarch
64位busybox
[*] Build static binary (no shared libs) (aarch64-linux-gnu-) Cross compiler prefix
制作根文件系統(tǒng)
#!/bin/bash
sudo rm -rf rootfs
sudo rm -rf tmpfs
sudo rm -f a9rootfs.ext3
sudo mkdir rootfs
sudo cp busybox/_install/* rootfs/ -raf
sudo mkdir -p rootfs/proc/
sudo mkdir -p rootfs/sys/
sudo mkdir -p rootfs/tmp/
sudo mkdir -p rootfs/root/
sudo mkdir -p rootfs/var/
sudo mkdir -p rootfs/mnt/
sudo cp etc rootfs/ -arf
sudo cp -arf /usr/arm-linux-gnueabi/lib rootfs/
sudo rm rootfs/lib/*.a
sudo arm-linux-gnueabi-strip rootfs/lib/*
sudo mkdir -p rootfs/dev/
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
sudo mknod rootfs/dev/console c 5 1
sudo mknod rootfs/dev/null c 1 3
sudo dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
sudo mkfs.ext3 a9rootfs.ext3
sudo mkdir -p tmpfs
sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop
sudo cp -r rootfs/* tmpfs/
sudo umount tmpfs
jffs2 文件系統(tǒng)
sudo apt install mtd-utils
busybox 編譯
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make defconfig
make menuconfig
# 勾選 Busybox Setting-> Build Options-> [*] Build static binary (no shared libs) 或者 搜索 CONFIG_STATIC
make -j4
make install
$cd busybox-1.18.5/_install
$mkdir -p etc/init.d
$cd etc/init.d
$cat > rcS <<EOF
#!/bin/sh
>mkdir /proc /sys
>mount -t proc proc /proc
>mount -t sysfs sysfs /sys
>mdev -s
EOF
$chmod +x rcS
$cd busybox-1.18.5/_install
$find . | cpio -o -H newc | gzip > $HOME/versatile-busybox