【内核驱动】 Kconfig简介
當(dāng)執(zhí)行make menuconfig時(shí)會(huì)出現(xiàn)內(nèi)核的配置界面,所有配置工具都是通過(guò)讀取"arch/$(ARCH)Kconfig"文件來(lái)生成配置界面,這個(gè)文件就是所有配置的總?cè)肟?#xff0c;它會(huì)包含其他目錄的Kconfig
Kconfig的作用:Kconfig用來(lái)配置內(nèi)核,它就是各種配置界面的源文件,內(nèi)核的配置工具讀取各個(gè)Kconfig文件,生成配置界面供開(kāi)發(fā)人員配置內(nèi)核,最后生成配置文件.config
Kconfig的語(yǔ)法可以參考“Documentation/kbuild/kconfig-language.txt”
?
Kconfig文件的基本要素:
1. config條目(entry)
?? config TMPFS_POSIX_ACL
???? bool "Tmpfs POSIX Access Control Lists"
???? depends on TMPFS
???? select GENERIC_ACL
???? help
?????? POSIX Access Control Lists (ACLs) support permissions for users and
?????? groups beyond the owner/group/world scheme.
???? To learn more about Access Control Lists, visit the POSIX ACLs for
????? ?Linux website <http://acl.bestbits.at/>.
????? If you don't know what Access Control Lists are, say N.
解析:
??? config是關(guān)鍵字,表示一個(gè)配置選項(xiàng)的開(kāi)始;緊跟著的TMPFS_POSIX_ACL是配置選項(xiàng)的名稱(chēng),省略了前綴"CONFIG_"
???? bool表示變量類(lèi)型,即"CONFIG_ TMPFS_POSIX_ACL "的類(lèi)型,有5種類(lèi)型:bool、tristate、string、hex和int,其中tristate和string是基本的類(lèi)型
?????????????? bool變量的值:????y和n
?????????????? tristate變量的值:y、n和m
?????????????? string變量的值:??字符串
??? bool之后的字符串“Tmpfs POSIX Access Control Lists”是提示信息,在配置界面中上下移動(dòng)光標(biāo)選中它時(shí),就可以通過(guò)按空格或回車(chē)鍵來(lái)設(shè)置
CONFIG_ TMPFS_POSIX_ACL的值
???? depends on:表示依賴(lài)于XXX,“depends on TMPFS”表示只有當(dāng)TMPFS配置選項(xiàng)被選中時(shí),當(dāng)前配置選項(xiàng)的提示信息才會(huì)出現(xiàn),才能設(shè)置當(dāng)前配置選項(xiàng)
2. menu條目
??? menu條目用于生成菜單,其格式如下:
?????????menu "Floating poing emulation"
?????????config FPE_NWFPE
?????????..............
?????????config FPE_NWFPE_XP
?????????.............
?????????endmenu
??? menu之后的Floating poing emulation是菜單名,menu和endmenu間有很多config條目,在配置界面中如下所示:
?????????Floating poing emulation--->
???????????????????????[] FPE_NWFPE
???????????????????????[] FPE_NWFPE_XP
3. choice條目
??? choice條目將多個(gè)類(lèi)似的配置選項(xiàng)組合在一起,供用戶(hù)單選或多選
??????? choice
?????????????prompt "ARM system type"
?????????????default ARCH_VERSATILE
?????????????config ARCH_AAEC2000
??????????????????.........
?????????????config ARCH_REALVIEW
??????????????????.........
????????endchoice
?????? prompt "ARM system type"給出提示信息“ARM system type”,光標(biāo)選中后回車(chē)進(jìn)入就可以看到多個(gè)config條目定義的配置選項(xiàng)
????? choice條目中定義的變量只有bool和tristate
4. comment條目
???comment條目用于定義一些幫助信息,出現(xiàn)在界面的第一行,如在arch/arm/Kconifg中有如下代碼:
menu "Floating point emulation"? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
comment "At least one emulation must be selected"? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
config FPE_NWFPE
.........???????????????????????????????????????????????????????????????????????????????
config FPE_NWFPE_XP
5. source條目
??? source條目用于讀取另一個(gè)Kconfig文件,如:
???????? source "net/Kconifg"
實(shí)戰(zhàn)
eg1.?
[root@localhost linux-3.5]# make menuconfig?
出現(xiàn)如下界面:
eg2:
解析Kconfig的代碼的位置如下
[root@localhost kconfig]# pwd
/var/opt/linux-3.5/scripts/kconfig
[root@localhost kconfig]# vim mconf.c?
編譯之后會(huì)生成mconf可執(zhí)行文件
[root@localhost linux-3.5]# ./scripts/kconfig/mconf ?./arch/arm/Kconfig
生成如下圖形界面:
eg3:?
創(chuàng)建自己的Kconfig
[root@localhost uplooking]# pwd
/var/opt/linux-3.5/drivers/uplooking
[root@localhost uplooking]# touch Kconfig?
? ? ??Kconfig文件內(nèi)容如下
[root@localhost linux-3.5]# ./scripts/kconfig/mconf ?./drivers/uplooking/Kconfig?
解析結(jié)果如下:
? ? ? ? ? ??
修改上一層Kconfig
最后會(huì)添加到Drivers選項(xiàng)中,結(jié)果如下圖所示:
嵌入式學(xué)習(xí)交流群:143847203
二維碼:
總結(jié)
以上是生活随笔為你收集整理的【内核驱动】 Kconfig简介的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【内核数据结构】 内核链表分析
- 下一篇: 【Tiny4412】 编译dnw源码报错