Linux 内核编译

1、工具链

2、 内核源码

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth=1

3、内核配置

3.1、使用deconfig

armhf

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sunxi_defconfig

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig

3.2、手动配置

armhf

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make menuconfig

4、内核编译

4.1、zImage/ Image

armhf

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

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 Image

编译结束后,应该在arch/arm/boot(armhf)中生成zImage,或者在arch/arm64/boot(arm64)中生成Image

4.2、设备树

armhf

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

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 dtbs

现在,您应该在arch/arm/boot/dts(armhf)或arch/arm64/boot/dts(arm64)中有一个与你的设备匹配的设备树二进制文件(.dtb)

4.3、模块

armhf

ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j4 modules
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=<any-path-you-like> make modules modules_install

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 modules
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=<any-path-you-like> make modules modules_install
After the build succeeds, you can find the modules in the supplied INSTALL_MOD_PATH directory.

4.4、头文件

armhf

ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- INSTALL_HDR_PATH=<any-path-you-like> make headers_install

arm64

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_HDR_PATH=<any-path-you-like> make headers_install

将INSTALL_HDR_PATH更改为你想要将头文件安装到的路径,例如,/usr or <some_prefix>/usr

参考:

posted @ 2021-03-15 23:53  红豆の布丁  阅读(87)  评论(0编辑  收藏  举报