Raspberry Pi 3 --- Kernel Building and Run in A New Version Kernal
ABSTRACT
There are two main methods for building the kernel. You can build locally on a Raspberry Pi which will take a long time; or you can cross-compile, which is much quicker.There is an introduction about cross-compilation as follows.
You need ubuntu as your development environment.So you can install VMWare on Windows and install ubuntu on VMWare.
This link is the introduction from the official website : https://www.raspberrypi.org/documentation/linux/kernel/building.md
CROSS COMPILING:
Download the cross compiling tools.
$ mkdir raspberry //make a folder for use
$ cd ./raspberry
$ git clone https://github.com/raspberrypi/tools // make a folder named "tools" in the "raspberry"
Add the following directory "/home/god/Desktop/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin" to your $PATH in the .bashrc as a environment variable.For the 32-bit host systems,the directory is "/home/god/Desktop/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin".If you put the path to your account rather than "root",you had better execute the following in your account.Otherwise you will be reminded that command not found.
$ sudo apt-get install gcc-arm-linux-gnueabihf //if execute it, you can use this gcc-linaro-arm-linux-gnueabihf version,not the version downloaded from "https://github.com/raspberrypi/tools".
GET SOURCE:
Enter the folder named "raspberry" ,then download the source:
$ git clone --depth=1 https://github.com/raspberrypi/linux //make a folder named "linux" in the "raspberry"
The paramenter "--depth=1" means only downloading the lastest version
BUILD SOURCE:
$ cd ./linux
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig //bcm2709_defconfig作为一个输入参数给makefile,然后通过标准路径“arch/arm/configs/”得到bcm2709_defconfig这个文件,进而把一些参数复制给.config文件,
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs //generate zImage,modules and dtbs
To speed up compilation on multiprocessor systems, and get some improvement on single processor ones, use -j n
where n is number of processors * 1.5. Alternatively, feel free to experiment and see what works!
INSTALL ON THE SD CARD:
Having built the kernel you need to copy it onto your raspberry pi and install modules.This is the best done directly using an sd card reader.
Use lsblk before and after plugging in your sd card to identify which one is.
$ lsblk
$ mkdir /mnt/fat32
$ mkdir /mnt/ext4
$ mount /dev/sdc1 /mnt/fat32 //for example sdc1 is the FAT(boot) partition
$ mount /dev/sdc2 /mnt/ext4 //for example sdc2 is the ext3 filesystem(root) partition
execute the orders before enter the folder of "linux"
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ext4 modules_install //install the modules into the "lib/modules/XXXX" folder
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to back up your old kernel:
$ KERNEL=kernel7 //for Pi2 or 3, the kernel file is "kernel7.img" but for Pi 1,the kernel file is "kernel.img".So use "$KERNEL" to replace "kernel7"
$ cp /mnt/fat32/$KERNEL.img /mnt/fat32/$KERNEL-backup.img
$ scripts/mkknlimg arch/arm/boot/zImage /mnt/fat32/$KERNEL.img //zImage is a Compressed kernel image,need transfer to .img
$ cp arch/arm/boot/dts/*.dtb /mnt/fat32/
$ cp arch/arm/boot/dts/overlays/*.dtb* /mnt/fat32/overlays/
$ cp arch/arm/boot/dts/overlays/README /mnt/fat32/overlays/
$ umount /mnt/fat32
$ umount /mnt/ext4
FINALLY
plug the SD card into Pi and boot it.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)