diff --git a/Chapter8_SOC_与_Linux/8.4_内核的配置和编译.md b/Chapter8_SOC_与_Linux/8.4_内核的配置和编译.md index 48f7a50..289be86 100644 --- a/Chapter8_SOC_与_Linux/8.4_内核的配置和编译.md +++ b/Chapter8_SOC_与_Linux/8.4_内核的配置和编译.md @@ -1,22 +1,21 @@ # 8.4 内核的配置和编译 +## 内核编译和配置的基本方法 + 获取 Linux 内核源码的途径有很多,可以直接从 下载,或者来自于 BSP 厂商提供的软件包。 -内核源码解压后,需要经过配置才能够编译。 +内核源码解压后,需要经过配置才能够编译,期间比较常用的命令如下: ```bash -# 生成 .config -make ARCH=arm yuzhen_iot_defconfig +# 加载 defconfig 生成 .config +make ARCH= # 进入内核配置页面 make menuconfig -``` - -![menuconfig 01](./imgs/8.4_内核的配置和编译/001.png) - -```bash # 指定 LOCALVERSION 并以 n 个进程进行编译。 make LOCALVERSION="" -j -# 编译独立内核模块并安装到指定目录下。 +# 编译内核模块 +make modules +# 将内核模块安装到指定目录下。 make modules_install INSTALL_MOD_PATH= # 生成设备树文件。 make dtbs @@ -26,20 +25,83 @@ make clean make distclean ``` -## i2som PanGuBoard +习惯上使用 menuconfig 来配置内核,其界面通常如下所示: + +![menuconfig 01](./imgs/8.4_内核的配置和编译/001.png) + +在该界面下,可使用方向键/Tab键进行导航,使用 Enter 键进行确认,使用空格键切换选项配置,有三种选项值,含义如下: + +* N:不将该功能编译进内核 +* Y:将该功能编译进内核 +* M:将该功能编译成内核模块 + +如果不清楚某个配置在哪个菜单下,则可以使用“/”键进行搜索,搜索到结果后直接按对应序号即可进入该菜单。 + +![menuconfig 02](./imgs/8.4_内核的配置和编译/002.png) + +还有一些隐藏配置,在 menuconfig 中无法进行配置,此时可在 .config 中直接修改,或修改对应的 defconfig 文件,而 .config 即为内核编译时所使用的最终配置,这是一个临时文件,任何修改配置或加载 defconfig 的行为都可能修改该文件,因此若需要将配置持久化,则必须修改对应的 defconfig 文件。可以通过 .config 生成 defconfig 文件,方法如下: ```bash +# 通过 .config 生成 ./defconfig +make ARCH= savedefconfig +``` + +### General setup + +通用配置菜单,包含了 swap 内存配置、各子系统配置、日志缓存大小等设置。 + +### Device Drivers + +各总线驱动和设备驱动的配置菜单,如 SPI、I2C、设备树、固件、USB、MMC/SD/SDIO、ADC、加速度计、DMA、DMABUF、以太网 PHY 芯片驱动等。 + +如果开发的驱动需要集成到内核,则应该将其配置添加到该菜单的子目录下。 + +### File systems + +文件系统配置菜单,调整内核所支持的文件系统类型,如:Ext4、NFS、VFAT、NTFS 等。 + +## i2som PanGuBoard 的内核编译 + +湃兔核的 PanGuBoard 是一款以 STM32MP157 SOC 为核心的开发板,下面以该开发板为例来演示内核的编译过程。在 [官方 Wiki](https://i2som.atlassian.net/wiki/spaces/PanGuBoard/overview?homepageId=389251083) 中可以获得该开发板的详细信息和资料,包括开发工具包和内核源码等。 + +```bash +# 安装开发工具链 chmod a+x i2som-image-weston-openstlinux-weston-pangu-x86_64-toolchain-2.6-snapshot.sh ./i2som-image-weston-openstlinux-weston-pangu-x86_64-toolchain-2.6-snapshot.sh +# 配置编译环境 source /opt/st/pangu/2.6-snapshot/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi +# 解压内核源码 tar -xvf linux-st-44c0cc69.tar.gz cd linux-st +# 加载 PanGuBoard 的内核配置 make i2som_panguboard_defconfig +# 编译内核镜像 make uImage LOADADDR=0xC2000040 -j +# 生成 DeviceTree make dtbs +# 生成内核模块 +make modules +# 将内核模块打包至 ./mods 目录下 +make modules_install INSTALL_MOD_PATH=./mods ``` +在源码根目录下将生成 vmlinux 内核镜像文件: + +![vmlinux](./imgs/8.4_内核的配置和编译/003.png) + +其他类型的内核镜像在 arch/arm/boot/ 目录下 + +![images](./imgs/8.4_内核的配置和编译/004.png) + +DTB 文件在 arch/arm/boot/dts 下生成: + +![DTB](./imgs/8.4_内核的配置和编译/005.png) + +内核模块在 mods 目录下: + +![modules](./imgs/8.4_内核的配置和编译/006.png) + ### 参考链接 * [配置开发环境](https://i2som.atlassian.net/wiki/spaces/PanGuBoard/pages/389251162) diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/001.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/001.png index d72b08e..73d01b6 100644 Binary files a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/001.png and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/001.png differ diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/002.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/002.png new file mode 100644 index 0000000..eb97c03 Binary files /dev/null and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/002.png differ diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/003.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/003.png new file mode 100644 index 0000000..85dc87e Binary files /dev/null and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/003.png differ diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/004.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/004.png new file mode 100644 index 0000000..714c0ce Binary files /dev/null and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/004.png differ diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/005.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/005.png new file mode 100644 index 0000000..646c6ec Binary files /dev/null and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/005.png differ diff --git a/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/006.png b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/006.png new file mode 100644 index 0000000..5cf6336 Binary files /dev/null and b/Chapter8_SOC_与_Linux/imgs/8.4_内核的配置和编译/006.png differ