前言
内核配置的目的是裁剪C代码,C代码编译一般由Makefile管理
一个菜单有三个相关内容:
1、 菜单;-----------Kconfig文件
2、 Makefile;------根据 .config抽取文件
3、 C代码。--------通过Makefile文件进行关联
源码目录下一般都有两个文件Kconfig和Makefile,所以我们添加菜单的时候就需要去修改这两个文件,我们可以通过make menuconfig来生成图形化界面去操作他
Kconfig语法
他有点像makefile的编写,直接来看源码吧
#menuconfig,config
#if/endif
#bool, tristate, hex, int, string
#prompt, comment,depends on, choice/endchoice
#select
#memu/endmenu
#range numberleft numberright
menuconfig UPLOOK_LESSON //定义主菜单
bool "linxu kerniel driver lesson about Kconfig" //主菜单为bool类型
---help--- //帮助
it is a simple examle for Kconfig
if UPLOOK_LESSON //进入子菜单
config TINY4412_LED //添加选项
bool "about led driver"
---help---
there is 4 led on tiny4412
endif
他的语法类似于
menuconfig 加入到总的Kconfig的名字
类型 "选项名字名字"
同时我们还需要去修改他的Makefile,将这个文件的路径加进去
下来我们执行make menuconfig,将这两个选项打开,做完这些后我们可以看见,在总目录下的.Kconfig中,都变成了y
Kconfig的关键字
我们在上面定于这些关键字都是声明的下来就来说明一下这些关键字
- bool 二选一,是否使用,使用为
- tristate:三态选项(n、m、y)
- hex:用户需要输入一个16进制数
- int:用户需要输入一个整形(只能0~9数字组合其他非法
- string: 用户需要输入一个字符串
下来是其他的选项关键字
- comment 添加注释
- select 选中当前的就必须选select的那一个
- depend on 只有他依赖的为真,才可以去选择他
- choice/endchoice 在两个关键字的范围内只能选一个
- menu/endmenu 在两个菜单间添加一个菜单
- range 添加范围
- prompt 打印提示
具体的测试代码在下方
#menuconfig,config
#if/endif
#bool, tristate, hex, int, string
#prompt, comment,depends on, choice/endchoice
#select
#memu/endmenu
#range numberleft numberright
menuconfig UPLOOK_LESSON
bool "linxu kerniel driver lesson about Kconfig"
---help---
it is a simple examle for Kconfig
if UPLOOK_LESSON
comment "welcome to my driver"
config TINY4412_LED
bool "about led driver"
---help---
there is 4 led on tiny4412
config TINY4412_LED_4
int "about 4 led driver"
range 1 4
---help---
nothing
menu "all of TS && io"
config TINY4412_ts
tristate "about TS driver"
---help---
there is 4 led on tiny4412
config TINY4412_io
string "about io driver"
---help---
there is 4 led on tiny4412
choice
prompt "please choice ont diver"
config TINY4412_input
bool "input io driver"
---help---
there is 4 led on tiny4412
config TINY4412_out
bool "output io driver"
---help---
there is 4 led on tiny4412
endchoice
endmenu
endif
显示的界面为