树梅派kernel的编译与patch

根据官方文档 https://www.raspberrypi.org/documentation/linux/kernel/building.md

步骤如下(这里只说交叉编译,因为在配置高的机器上编译效率高):

1) 下载 kernel 的 source 

$ git clone --depth=1 https://github.com/raspberrypi/linux

如何知道kernel 的当前版本,两个方法

a) make  kernelversion

b) head Makefile 


2) 配置kernel 

RASPBERRY PI 1 (OR COMPUTE MODULE) DEFAULT BUILD CONFIGURATION

$ cd linux
$ KERNEL=kernel
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-  bcmrpi_defconfig

RASPBERRY PI 2 DEFAULT BUILD CONFIGURATION

$ cd linux
$ KERNEL=kernel7
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

这时候,生成.config文件

如何你不满意可以用 make ARCH=arm menuconfig 继续改


3) 安装toolchain

 git clone https://github.com/raspberrypi/tools

把工具路径设置到$PATH 

export PATH=$PATH:~/rapi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

4) 开始编译

make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs


5)  打 rt 补丁 (把rapi 改为实时控制系统)

官方文档 https://www.raspberrypi.org/documentation/linux/kernel/patching.md

我的步骤:

a) 看 kernel 版本 (4.1.12)

$ head Makefile -n 4
VERSION = 4
PATCHLEVEL = 1
SUBLEVEL = 12
EXTRAVERSION =


下载rt补丁(可先在浏览器https://www.kernel.org/pub/linux/kernel/projects/rt/中浏览 )

wget https://www.kernel.org/pub/linux/kernel/projects/rt/4.1/patch-4.1.10-rt11.patch.gz  


解开gz文件,patch kernel 文件

gunzip patch-4.1.10-rt11.patch.gz 

cat patch-4.1.10-rt11.patch  | patch -p1


而后重新编译kernel

make -j3 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs

你可能感兴趣的:(raspberry)