参考官方网站https://www.raspberrypi.org/documentation/linux/kernel/building.md
1.下载源代码及交叉编译工具
git clone --depth=1 https://github.com/raspberrypi/linux
git clone https://github.com/raspberrypi/tools
2.编译
cd linux/
kERNAL=kernel7
make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- bcm2709_defconfig
make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- zImage modules dtbs -j8
(可以把交叉编译工具路径添加到环境变量中)
3.oracle virtualbox虚拟机下识别SD卡
第一步:先运行virtualbox,但是不要运行虚拟系统,实机插入U盘,在虚拟机的设置按照如下图:
第二步 运行Ubuntu系统,在Terminal窗口,使用lsusb,或者lsblk命令找到SD卡。
sdb
sdb1
sdb2
4.更新镜像
Mount these first, adjusting the partition numbers for NOOBS cards:
mkdir mnt/fat32
mkdir mnt/ext4
sudo mount /dev/sdb1 mnt/fat32
sudo mount /dev/sdb2 mnt/ext4
Next, install the modules:
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt/ext4 modules_install
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to back up your old kernel:
sudo cp mnt/fat32/$KERNEL.img mnt/fat32/$KERNEL-backup.img
sudo scripts/mkknlimg arch/arm/boot/zImage mnt/fat32/$KERNEL.img
sudo cp arch/arm/boot/dts/*.dtb mnt/fat32/
sudo cp arch/arm/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
sudo cp arch/arm/boot/dts/overlays/README mnt/fat32/overlays/
sudo umount mnt/fat32
sudo umount mnt/ext4
Another option is to copy the kernel into the same place, but with a different filename - for instance, kernel-myconfig.img - rather than overwriting the kernel.img file. You can then edit the config.txt file to select the kernel that the Pi will boot into:
kernel=kernel-myconfig.img
This has the advantage of keeping your kernel separate from the kernel image managed by the system and any automatic update tools, and allowing you to easily revert to a stock kernel in the event that your kernel cannot boot.