全志平台TWI子系统源码分析(4)TWI 编译规则讲解
前言
在前几篇文章中有一个点没讲清楚,那就是TWI的编译规则,为什么这些文件生效,需要补充说明一下。
一、Makefile文件
我们先分析Makefile文件,在kernel/linux-4.9/i2c/目录下
#
# Makefile for the i2c core.
#
obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
obj-$(CONFIG_I2C) += i2c-core.o
obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o
obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
obj-$(CONFIG_I2C_MUX) += i2c-mux.o
obj-y += algos/ busses/ muxes/
obj-$(CONFIG_I2C_STUB) += i2c-stub.o
obj-$(CONFIG_I2C_SLAVE_EEPROM) += i2c-slave-eeprom.o
ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG
CFLAGS_i2c-core.o := -Wno-deprecated-declarations
这些宏控我们可以在Device Drivers > I2C support中配置,勾选上对应的项,比如I2c device interface,这个选项对应的是宏CONFIG_I2C_CHARDEV。
保存后会在kernel/linux-4.9/.config文件中生效宏,这样编译的时候就可以生成.o文件了。
#
# I2C support
#
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
# CONFIG_I2C_COMPAT is not set
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y
有人会问,这个宏CONFIG_I2C_CHARDEV和I2C device interface是怎么联系起来的呢?通过键入“/”,然后输入我们想要查找的宏,我们就可以找到对应的选项。
Prompt对应的就是我们要勾选的项,这样就关联了我们的宏控。另外CONFIG_I2C=y是这个选项生效的前提。
二、Kconfig文件
在对应的Kconfig文件中,则详细定义了每个宏的意义。例如I2C_CHARDEV
config I2C_CHARDEV
tristate "I2C device interface"
help
Say Y here to use i2c-* device files, usually found in the /dev
directory on your system. They make it possible to have user-space
programs use the I2C bus. Information on how to do this is
contained in the file <file:Documentation/i2c/dev-interface>.
This support is also available as a module. If so, the module
will be called i2c-dev.
i2c-sunxi.c的宏控并不在这里,因为在下一级目录。所以我们可以在Kconfig文件中找到
source drivers/i2c/busses/Kconfig
在drivers/i2c/busses/Kconfig文件中,我们找到了CONFIG_I2C_SUNXI宏。
config I2C_SUNXI
tristate "SUNXI I2C controller"
depends on ARCH_SUNXI
default y if MACH_SUNXI
help
If you say yes to this option, support will be included for the
I2C interface from Allwinner Technology SUNXI platform.
This driver can also be built as a module. If so, the module
will be called i2c-sunxi.
三、.config文件
生成的.config文件其实是一个临时文件,当我们在kernel/linux-4.9中make distclean后,.config文件将会被清空,那么这个文件是由哪个文件生成来的呢?在
kernel\linux-4.9\arch\arm64\configs目录下的defconfig文件,不同项目对应的defconfig文件是不一样的,这个根据具体项目来定,好的习惯就是.config文件确认后,及时的和defconfig文件进行同步。
总结
本文对TWI的编译规则进行了讲解,对于其他模块其实也是适用的,大多都是相同的原理,如果有些文件没有编译到,那么请仔细排查一下是否按照上述规则进行了宏控制。通过上述解释,我们在学习过程中就可以举一反三了。