https://cloud.tencent.com/developer/article/1431908
When using Kconfig, need to pay attention
- 1. In Kconfig configuration defined macros, prefixes are not "CONFIG_" , only compile the kernel, the automatic generation of autoconf.h appear before the prefix.
- 2. If XX_defconfig when the board configuration file to define a new macro = y, while in Kconfig and did not declare it , then compile the kernel inside out autoconf.h would not define it in.
- 3. If XX_defconfig board configuration file is not set CONFIG_MODULES = Y , the compiler make modules time will fail , while make menuconfig, tristate Kconfig parameters will be read in as bool Parameters (i.e. not set m)
CONFIG macro variable parameters
- bool: indicates that the macro can select CONFIG y (compiled kernel) or n (not compiled), m can not be selected (as a module)
- tristate: indicates that the macro can be provided CONFIG y / m / n three modes (Tristate)
- string: indicates that the CONFIG macro can be set to a string of characters, such as #define CONFIG_XXX "config test"
- hex: indicates that the CONFIG macro can be set to a hexadecimal, such as #define CONFIG_XXX 0x1234
- int: indicates that the CONFIG macro can be set to an integer, such as #define CONFIG_XXX 1234
Common parameters
- default y: represents the default is on the hook, of course, may be written as default m or default n
- help: help information
- depends on: dependencies, such as depends on XXX represents the current macro requires the premise CONFIG_ XXX macro open in order to set it (note dependencies config parameter is valid only bool or tristate)
- select: anti-dependencies, and depends on the contrary, such selecton XXX represents the current macro or if y m, set automatically or XXX = y m (note that the parameter is valid only bool or tristate)
- choice: generates a single box , which is selected from a mode selection by a multi-config, note the config parameters only choice bool or tristate
- prompt: prompt information, if for choice, the box will be used as a single entry point label
- range: set the data range entered by the user, such as Range 0 100 represents data only at 0 to 100
- menuconfig: menuconfig config XXX XXX and the like, the only difference is that in addition to the option provided y / m / n, the effect can also be achieved menu (can enter into the interior)
Example 1 - Create a checkbox (multiple choice and more) - explore the macro variable parameters then we'll try how to set different parameters for different macros to MY_SYMBOL1 ~ MY_SYMBOL5 an example set MY_SYMBOL3 ~ MY_SYMBOL5 dependent on MY_SYMBOL2 modify the kernel top Kconfig file, Add content:
menuconfig MY_SYMBOL_TEST #生成一个菜单宏项
bool "MY_SYMBOL_TEST"
default y
config MY_SYMBOL1
bool "my symbol is bool"
default y
depends on MY_SYMBOL_TEST
config MY_SYMBOL2
tristate "my symbo2 is tristate"
default m depends on MY_SYMBOL_TEST config MY_SYMBOL3 string "my symbo3 is string" default "test symbo3" depends on MY_SYMBOL2 && MY_SYMBOL_TEST config MY_SYMBOL4 hex "my symbo4 is hex" range 0 0x2000 #设置hex区间 default 0x1234 depends on MY_SYMBOL2 && MY_SYMBOL_TEST config MY_SYMBOL5 int "my symbo5 is int" range 0 2000 # Set the interval int default 1234 The depends ON MY_SYMBOL2 && MY_SYMBOL_TEST
Results as shown below:
As shown above, we can see the set my symbol5 beyond the interval [0,2000] , the data being given directly
Compiled kernel autoconf.h view the automatically generated, is defined as follows:
Wherein the above macro CONFIG_MY_SYMBOL2_MODULE because we set it to the default m Kconfig, so CONFIG_MY_SYMBOL2_MODULE a macro modules.
Example 2 - choice by creating a single box (one of many)
choice
prompt "choice example" #作为该单选框入口点的标签
default y
default MY_SYMBOL3 #默认选择MY_SYMBOL3配置项
config MY_SYMBOL1
bool "my symbol1 is bool"
help
MY_SYMBOL1 example
config MY_SYMBOL2
bool "my symbo2 is bool"
help
MY_SYMBOL2 example
config MY_SYMBOL3
tristate "my symbo3 is tristate" help MY_SYMBOL3 example endchoice
编译内核后,查看autoconf.h,如下图所示,可以看到对于choice单选框来说,tristate属性其实并没有module功能,只有y/n
未完,后续再遇到不懂的再总结~