内核源码可以看做是源码树,通过Kconfig .config Makefile 三个文件来控制内核哪些模块被编译,编译什么架构等。
一下是经过网上查找的资料自己的理解。
- Kconfig 是内核模块节点的位置标记,相当于树节点,有位置域,数据域。位置域确定的该节点位于源码树的位置,这样有利于make menuconfig等可视化工具来管理模块,可以说make menuconfig 是根据Kconfig 来展现出来的树形结构,数据域对应的就是定义相应的变量,会生成CONFIG_MY_RADIUS=y,最后生成的就是#define CONFIG_MY_RADIUS 这样的宏,内核在编译会根据这个宏来进行编译。内核源码树上的每个节点都有自己的Kconfig文件,也就是从顶层目录到递归子目录都有这个文件。Kconfig有自己的语法规则可参考https://www.cnblogs.com/taomaomao/archive/2012/01/05/2312816.html
- .config文件是内核配置完成后生成的文件,makefile会根据.config来进行编译
这是内核kernel/linux/fs目录下的Kconfig文件节选,
menu "File systems"
# Use unaligned word dcache accesses
config DCACHE_WORD_ACCESS
bool
if BLOCK
source "fs/ext2/Kconfig"
source "fs/ext4/Kconfig"
source "fs/jbd2/Kconfig"
config FS_DAX
bool "Direct Access (DAX) support"
depends on MMU
depends on !(ARM || MIPS || SPARC)
help
Direct Access (DAX) can be used on memory-backed block devices.
If the block device supports DAX and the filesystem supports DAX,
then you can avoid using the pagecache to buffer I/Os. Turning
on this option will compile in support for DAX; you will need to
mount the filesystem using the -o dax option.
If you do not have a block device that is capable of using this,
or if unsure, say N. Saying Y will increase the size of the kernel
by about 5kB.
注意menu "File systems"和config FS_DAX和bool "Direct Access (DAX) support"
这个三个在make menuconfig中是这样展现
这就根据menuconfig是根据Kconfig来生成可视化字符配置程序,并且可以在这里配置该选项,bool类型如果选中,会在.config文件中生成CONFIG_FX_DAX=y,最后会生成宏定义。
对于我们公司平台,在编译任何模块都会首先在build目录下下生成.config文件,如下
我们公司是通过这个来生成.config文件,
.config文件节选:
makefile根据.config文件进行编译生成了.h文件,内核包含该文件开始对内核进行编译.
.h文件目录: ./build/mips64-xlp/kernel/include/generated/autoconf.h:115:#define CONFIG_MIPS 1