Kconfig实例解析

注:本文基于u-boot.2016.03。

1、 设备驱动菜单配置

root/drivers/Kconfig

menu "Device Drivers" #菜单项(开始),这个名字会在图形界面的最上面显示
source "drivers/core/Kconfig" #把下级目录的kconfig文件给包含进来,会在原地展开
# types of drivers sorted in alphabetical order #注示,表明这些菜单是按字母排序的
source "drivers/adc/Kconfig"
source "drivers/block/Kconfig"
source "drivers/clk/Kconfig"
source "drivers/cpu/Kconfig"
source "drivers/crypto/Kconfig"
source "drivers/demo/Kconfig"
source "drivers/dfu/Kconfig"
source "drivers/dma/Kconfig"
source "drivers/gpio/Kconfig"
source "drivers/hwmon/Kconfig"
source "drivers/i2c/Kconfig"
source "drivers/input/Kconfig"
source "drivers/led/Kconfig"
source "drivers/misc/Kconfig"
source "drivers/mmc/Kconfig"
source "drivers/mtd/Kconfig"
source "drivers/net/Kconfig"
source "drivers/pci/Kconfig"
source "drivers/pcmcia/Kconfig"
source "drivers/pinctrl/Kconfig"
source "drivers/power/Kconfig"
source "drivers/pwm/Kconfig"
source "drivers/ram/Kconfig"
source "drivers/remoteproc/Kconfig"
source "drivers/rtc/Kconfig"
source "drivers/serial/Kconfig"
source "drivers/sound/Kconfig"
source "drivers/spi/Kconfig"
source "drivers/thermal/Kconfig"
source "drivers/timer/Kconfig"
source "drivers/tpm/Kconfig"
source "drivers/usb/Kconfig"
source "drivers/video/Kconfig"
source "drivers/watchdog/Kconfig"
config PHYS_TO_BUS #配置项     会自动在这个名称的前面加上“CONFIG_”
	bool "Custom physical to bus address mapping"#用户可见的提示信息,bool表示,可以选择编进内核或不编译,只能选中或不选中。
	help#帮助信息,这个信息可以在界面的底部选择并展开
	  Some SoCs use a different address map for CPU physical addresses and
	  peripheral DMA master accesses. If yours does, select this option in
	  your platform's Kconfig, and implement the appropriate mapping
	  functions in your platform's support code.

endmenu #菜单(结束)

u-boot.2016.03 ,make menuconfig的设备驱动配置界面。
在这里插入图片描述

在这里插入图片描述

2、Kconfig 配置类型语法

Tristate:

表示该项是否编进内核、编成模块。显示为< > , 假如选择编译成内核模块,则会在.config中生成一个 CONFIG_HELLO_MODULE=m的配置,选择Y就是直接编进内核,会在.config中生成一个 CONFIG_HELLO_MODULE=y的配置项。Tristate后的字符串是make menuconfig时显示的配置项名称。

bool:

此类型只能选中或不选中,make menuconfig时显示为[ ],即无法配置成模块。

dependon:

该选项依赖于另一个选项,只有当依赖项被选中时,当前配置项的提示信息才会出现,才能设置当前配置项。

select:

反向依赖关系,该选项选中时,同时选中select后面定义的那一项。 可以在帮助信息里看到。

3、 makefile 与Kconfig的关系

使用Kbuild系统后,子目录的Makefile比较简单了,用来定义哪些内容作为模块编译,哪些条件编译就好了。

A:直接编译

obj-y +=xxx.o

表示由xxx.c或xxx.s编译得到xxx.o并直接编进内核。

B:条件编译

obj -$(CONFIG_HELLO) +=xxx.o

根据.config文件的CONFIG_XXX来决定文件是否编进内核。

C:模块编译

obj-m +=xxx.o

表示xxx作为模块编译,即执行make modules时才会被编译。

三个文件的关系如下:
root/.config
root/drivers/adc/makefile
root/drivers/adc/kconfig
在这里插入图片描述

有用的参考:

https://blog.csdn.net/thisway_diy/article/details/76981113

https://blog.csdn.net/ultraman_hs/article/details/52984929

猜你喜欢

转载自blog.csdn.net/amwha/article/details/86607506
今日推荐