Kconfig详解-文件的基本要素 ***

  当执行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"

原文地址:https://www.cnblogs.com/jiangzhaowei/p/7528099.html