當執行make menuconfig時會出現內核的配置界面,所有配置工具都是通過讀取"arch/$(ARCH)Kconfig"文件來生成配置界面,這個文件就是所有配置的總入口,它會包含其他目錄的Kconfig
Kconfig的作用:Kconfig用來配置內核,它就是各種配置界面的源文件,內核的配置工具讀取各個Kconfig文件,生成配置界面供開發人員配置內核,最后生成配置文件.config
Kconfig的語法可以參考“Documentation/kbuild/kconfig-language.txt”
Kconfig文件的基本要素:
1.config條目(entry)
config SUPPORT_CEC_TV bool "Support CEC" default y config SUPPORT_ARC bool "Support ARC" depends on SUPPORT_CEC_TV default y config SUPPORT_CEC_VOLUME_KEY_CONTINUE bool "Support CEC VOLUME KEY CONTINUE" default n
解析:
config是關鍵字,表示一個配置選項的開始;緊跟着的SUPPORT_CEC_TV是配置選項的名稱,省略了前綴"CONFIG_"
bool表示變量類型,即"CONFIG_ SUPPORT_CEC_TV "的類型,有5種類型:bool、tristate、string、hex和int,其中tristate和string是基本的類型
bool變量的值: y和n
tristate變量的值:y、n和m
string變量的值: 字符串
bool之后的字符串“Support CEC”是字串提示信息,在配置界面中上下移動光標選中它時,就可以通過按空格或回車鍵來設置“CONFIG_ SUPPORT_CEC_TV”
depends on:表示依賴於XXX,“depends on SUPPORT_CEC_TV”表示只有當SUPPORT_CEC_TV配置選項被選中時,當前配置選項的提示信息才會出現,才能設置當前配置選項

2.menu條目
menu條目用於生成菜單,其格式如下:
menu "Unicode Trans Support" config SUPPORT_CHARSETDET bool "Support Match Character Set Codepage" default n config SUPPORT_ISO88591_CP28591 bool "Codepage ISO8859-1 Latin 1" default y config SUPPORT_ISO88592_CP28592 bool "Codepage ISO8859-2 Central European" default y config SUPPORT_ISO88593_CP28593 bool "Codepage ISO8859-3 Latin 3" default y config SUPPORT_ISO88594_CP28594 bool "Codepage ISO8859-4 Baltic" default y config SUPPORT_ISO88595_CP28595 bool "Codepage ISO8859-5 Cyrillic" default y endmenu
menu之后的“Unicode Trans Support”是菜單名,menu和endmenu間有很多config條目,在配置界面中如下所示:
Unicode Trans Support--->
[ ] Support Match Character Set Codepage
[*] Codepage ISO8859-1 Latin 1
[ ] Codepage ISO8859-2 Central European

3.choice條目
1)choice條目將多個類似的配置選項組合在一起,供用戶單選或多選
menu "Upgrade Select" config SUPPORT_USB_UPGRADE bool "SUPPORT_USB_UPGRADE" default y help Define USB Upgrade comment "BOOTROM" config CODE_INCOMPLETE_CHECK bool "CODE_INCOMPLETE_CHECK" default y help DO NOT USE WHEN ROMTER IS ENABLE choice prompt "AC Upgrade Options" optional config AC_PWRKEY_UPGRADE depends on SUPPORT_USB_UPGRADE bool "AC PWRKEY UPGRADE" config AC_AUTO_UPGRADE depends on SUPPORT_USB_UPGRADE bool "AC AUTO UPGRADE" config AC_UART_UPGRADE depends on SUPPORT_USB_UPGRADE bool "AC UART UPGRADE" endchoice endmenu
prompt "AC Upgrade Options"給出提示信息“AC Upgrade Options”,光標選中
后回車進入就可以看到多個config條目定義的配置選項
choice條目中定義的變量只有bool和tristate

2)choice的默認值&依賴:
如下choice默認值為“formal”勾選,即定義的宏為“”
choice prompt "OSD STYLE" default NODISPLAY_OSD_STYLE_FORMAL config NODISPLAY_OSD_STYLE_FORMAL bool "formal" config NODISPLAY_OSD_STYLE_MSTAR bool "mstar" config NODISPLAY_OSD_STYLE_HAIER bool "haier" config NODISPLAY_OSD_STYLE_BBK bool "bbk" help input current you want to select osd style endchoice config OSD_CUSDEF string default "formal" if(NODISPLAY_OSD_STYLE_FORMAL) default "mstar" if(NODISPLAY_OSD_STYLE_MSTAR) default "haier" if(NODISPLAY_OSD_STYLE_HAIER) default "bbk" if(NODISPLAY_OSD_STYLE_BBK) config TV_NEW_UI bool default y if(NODISPLAY_OSD_STYLE_FORMAL)

4、select 條目
A depends on B 那么只有在B選中才能選A A select B 那么只要選中A就會選中B 所以select叫反向依賴。
如下面:如果“SUPPORT_TTX”別選擇了,那么“TTX_BYPASS_MODE”會被自動選擇,反之亦成立。
menu "TT or CC or VCHIP Select" config SUPPORT_TTX bool "Teletext Support" default y select TTX_BYPASS_MODE help Select Teletext config TTX_BYPASS_MODE depends on SUPPORT_TTX bool "TT BYPASS version" default y help SW collect TTX packet config TTX_COMPRESS_STORE depends on SUPPORT_TTX bool "TT Data compress" default n help TT Pagedata compress store config CC_SUPPORT bool "CC Support" help Select Closed Caption config VCHIP_SUPPORT bool "VCHIP Support" help Select VChip endmenu
"TT BYPASS version"不能被用戶選擇

5、range 條目
代表可以選擇的范圍:
menu "Default Setting" config DEFAULT_PANEL_INVERT int range 0 1 prompt "Panel invert" default 0 help input current you want to select panel invert config DEFAULT_PANEL_LVDS_TYPE int range 0 2 prompt "LVDS Type" default 2 help 0: JEDIA, 1: VESA(LSB), 2: VESA(MSB) config INPUT_CURRENT_BL int prompt "CURRENT for BL mA" default 300 help input current value

6. 條件默認值
如果選擇了“CHIP_533”,則CHIPED=0x533
選擇了“CHIP_8501”,則CHIPED=0x331
選擇了“CHIP_8053”,則CHIPED=0x131
choice prompt "IC Version Config" config CHIP_533 bool "533" config CHIP_8501 bool "8501" config CHIP_8503 bool "8503" endchoice config CHIPID hex default 0x533 if CHIP_533 default 0x331 if (CHIP_8501) default 0x131 if (CHIP_8503) default 0x131
這里要注意,條件依賴的默認值是不能有提示符的,即根據條件自動默認值,如果在UI用戶可設置,依據條件的默認值將不起作用,如下面橙色的配置。
choice prompt "IC Version Config" config CHIP_533 bool "533" config CHIP_8501 bool "8501" config CHIP_8503 bool "8503" endchoice config CHIPID hex "Chip Setting" default 0x533 if CHIP_533 default 0x331 if (CHIP_8501) default 0x131 if (CHIP_8503) default 0x131

7.comment條目
comment條目用於定義一些幫助信息,出現在界面的第一行,如在arch/arm/Kconifg中有如下代碼:
menu "Floating point emulation" comment "At least one emulation must be selected" config FPE_NWFPE ......... config FPE_NWFPE_XP
在界面中如下所示:
8.source條目
source條目用於讀取另一個Kconfig文件,如:
source "net/Kconifg"

