1.下载内核
https://www.kernel.org/
2.上传服务器,解压
tar -xvf linux-4.9.310
3.编辑Makefile,设置交叉编译工具链
#ARCH ?= $(SUBARCH)
ARCH ?= arm
#CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:“%”=%)
CROSS_COMPILE ?= arm-linux-gnueabihf-
4.编译默认配置,配置在arch/arm/configs/目录下
make exynos_defconfig
5.设置菜单配置
make menuconfig
5.1执行命令报错 scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h
这是没有安装用户界面显示的库
在 Debian/Ubuntu 环境下安装 ncurses 库
sudo apt-get install libncurses5-dev libncursesw5-dev
在 CentOS/RHEL 环境下安装 ncurses 库
sudo yum install ncurses-devel
6.编译内核
make uImage
6.1 出现如下报错
This is incompatible with uImages
Specify LOADADDR on the commandline to build an uImage
arch/arm/boot/Makefile:79: recipe for target ‘arch/arm/boot/uImage’ failed
重新执行命令:LOADADDR=0x40000000 make uImage
6.2出现如下报错
"mkimage" command not found - U-Boot images will not be built
arch/arm/boot/Makefile:79: recipe for target ‘arch/arm/boot/uImage’ failed
执行命令:sudo apt-get install uboot-mkimage
但却提示”现在没有可用的软件包 uboot-mkimage,过时了,用u-boot-tools替代
执行命令:sudo apt-get install u-boot-tools
重新执行编译命令:LOADADDR=0x40000000 make uImage
6.3出现如下错误
xxx: fatal error: Python.h: No such file or directory
是python版本与操作系统版本不一致(python32位,操作系统64位)
执行如下命令,查看python版本
python -V
apt-get install python3-dev (我这是python3,python版本号-dev)
重新执行编译命令:LOADADDR=0x40000000 make uImage
7.编译成功,如下
Image Name: Linux-4.9.310
Created: Sat Apr 16 18:46:18 2022
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4640656 Bytes = 4531.89 KiB = 4.43 MiB
Load Address: 40000000
Entry Point: 40000000
Kernel: arch/arm/boot/uImage is ready
8.编译设备树
make dtbs