kconfig-language.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. Introduction
  2. ------------
  3. The configuration database is a collection of configuration options
  4. organized in a tree structure:
  5. +- Code maturity level options
  6. | +- Prompt for development and/or incomplete code/drivers
  7. +- General setup
  8. | +- Networking support
  9. | +- System V IPC
  10. | +- BSD Process Accounting
  11. | +- Sysctl support
  12. +- Loadable module support
  13. | +- Enable loadable module support
  14. | +- Set version information on all module symbols
  15. | +- Kernel module loader
  16. +- ...
  17. Every entry has its own dependencies. These dependencies are used
  18. to determine the visibility of an entry. Any child entry is only
  19. visible if its parent entry is also visible.
  20. Menu entries
  21. ------------
  22. Most entries define a config option; all other entries help to organize
  23. them. A single configuration option is defined like this:
  24. config MODVERSIONS
  25. bool "Set version information on all module symbols"
  26. depends on MODULES
  27. help
  28. Usually, modules have to be recompiled whenever you switch to a new
  29. kernel. ...
  30. Every line starts with a key word and can be followed by multiple
  31. arguments. "config" starts a new config entry. The following lines
  32. define attributes for this config option. Attributes can be the type of
  33. the config option, input prompt, dependencies, help text and default
  34. values. A config option can be defined multiple times with the same
  35. name, but every definition can have only a single input prompt and the
  36. type must not conflict.
  37. Menu attributes
  38. ---------------
  39. A menu entry can have a number of attributes. Not all of them are
  40. applicable everywhere (see syntax).
  41. - type definition: "bool"/"tristate"/"string"/"hex"/"int"
  42. Every config option must have a type. There are only two basic types:
  43. tristate and string; the other types are based on these two. The type
  44. definition optionally accepts an input prompt, so these two examples
  45. are equivalent:
  46. bool "Networking support"
  47. and
  48. bool
  49. prompt "Networking support"
  50. - input prompt: "prompt" <prompt> ["if" <expr>]
  51. Every menu entry can have at most one prompt, which is used to display
  52. to the user. Optionally dependencies only for this prompt can be added
  53. with "if".
  54. - default value: "default" <expr> ["if" <expr>]
  55. A config option can have any number of default values. If multiple
  56. default values are visible, only the first defined one is active.
  57. Default values are not limited to the menu entry where they are
  58. defined. This means the default can be defined somewhere else or be
  59. overridden by an earlier definition.
  60. The default value is only assigned to the config symbol if no other
  61. value was set by the user (via the input prompt above). If an input
  62. prompt is visible the default value is presented to the user and can
  63. be overridden by him.
  64. Optionally, dependencies only for this default value can be added with
  65. "if".
  66. - type definition + default value:
  67. "def_bool"/"def_tristate" <expr> ["if" <expr>]
  68. This is a shorthand notation for a type definition plus a value.
  69. Optionally dependencies for this default value can be added with "if".
  70. - dependencies: "depends on" <expr>
  71. This defines a dependency for this menu entry. If multiple
  72. dependencies are defined, they are connected with '&&'. Dependencies
  73. are applied to all other options within this menu entry (which also
  74. accept an "if" expression), so these two examples are equivalent:
  75. bool "foo" if BAR
  76. default y if BAR
  77. and
  78. depends on BAR
  79. bool "foo"
  80. default y
  81. - reverse dependencies: "select" <symbol> ["if" <expr>]
  82. While normal dependencies reduce the upper limit of a symbol (see
  83. below), reverse dependencies can be used to force a lower limit of
  84. another symbol. The value of the current menu symbol is used as the
  85. minimal value <symbol> can be set to. If <symbol> is selected multiple
  86. times, the limit is set to the largest selection.
  87. Reverse dependencies can only be used with boolean or tristate
  88. symbols.
  89. Note:
  90. select should be used with care. select will force
  91. a symbol to a value without visiting the dependencies.
  92. By abusing select you are able to select a symbol FOO even
  93. if FOO depends on BAR that is not set.
  94. In general use select only for non-visible symbols
  95. (no prompts anywhere) and for symbols with no dependencies.
  96. That will limit the usefulness but on the other hand avoid
  97. the illegal configurations all over.
  98. - limiting menu display: "visible if" <expr>
  99. This attribute is only applicable to menu blocks, if the condition is
  100. false, the menu block is not displayed to the user (the symbols
  101. contained there can still be selected by other symbols, though). It is
  102. similar to a conditional "prompt" attribute for individual menu
  103. entries. Default value of "visible" is true.
  104. - numerical ranges: "range" <symbol> <symbol> ["if" <expr>]
  105. This allows to limit the range of possible input values for int
  106. and hex symbols. The user can only input a value which is larger than
  107. or equal to the first symbol and smaller than or equal to the second
  108. symbol.
  109. - help text: "help" or "---help---"
  110. This defines a help text. The end of the help text is determined by
  111. the indentation level, this means it ends at the first line which has
  112. a smaller indentation than the first line of the help text.
  113. "---help---" and "help" do not differ in behaviour, "---help---" is
  114. used to help visually separate configuration logic from help within
  115. the file as an aid to developers.
  116. - misc options: "option" <symbol>[=<value>]
  117. Various less common options can be defined via this option syntax,
  118. which can modify the behaviour of the menu entry and its config
  119. symbol. These options are currently possible:
  120. - "defconfig_list"
  121. This declares a list of default entries which can be used when
  122. looking for the default configuration (which is used when the main
  123. .config doesn't exists yet.)
  124. - "modules"
  125. This declares the symbol to be used as the MODULES symbol, which
  126. enables the third modular state for all config symbols.
  127. At most one symbol may have the "modules" option set.
  128. - "env"=<value>
  129. This imports the environment variable into Kconfig. It behaves like
  130. a default, except that the value comes from the environment, this
  131. also means that the behaviour when mixing it with normal defaults is
  132. undefined at this point. The symbol is currently not exported back
  133. to the build environment (if this is desired, it can be done via
  134. another symbol).
  135. - "allnoconfig_y"
  136. This declares the symbol as one that should have the value y when
  137. using "allnoconfig". Used for symbols that hide other symbols.
  138. Menu dependencies
  139. -----------------
  140. Dependencies define the visibility of a menu entry and can also reduce
  141. the input range of tristate symbols. The tristate logic used in the
  142. expressions uses one more state than normal boolean logic to express the
  143. module state. Dependency expressions have the following syntax:
  144. <expr> ::= <symbol> (1)
  145. <symbol> '=' <symbol> (2)
  146. <symbol> '!=' <symbol> (3)
  147. '(' <expr> ')' (4)
  148. '!' <expr> (5)
  149. <expr> '&&' <expr> (6)
  150. <expr> '||' <expr> (7)
  151. Expressions are listed in decreasing order of precedence.
  152. (1) Convert the symbol into an expression. Boolean and tristate symbols
  153. are simply converted into the respective expression values. All
  154. other symbol types result in 'n'.
  155. (2) If the values of both symbols are equal, it returns 'y',
  156. otherwise 'n'.
  157. (3) If the values of both symbols are equal, it returns 'n',
  158. otherwise 'y'.
  159. (4) Returns the value of the expression. Used to override precedence.
  160. (5) Returns the result of (2-/expr/).
  161. (6) Returns the result of min(/expr/, /expr/).
  162. (7) Returns the result of max(/expr/, /expr/).
  163. An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
  164. respectively for calculations). A menu entry becomes visible when its
  165. expression evaluates to 'm' or 'y'.
  166. There are two types of symbols: constant and non-constant symbols.
  167. Non-constant symbols are the most common ones and are defined with the
  168. 'config' statement. Non-constant symbols consist entirely of alphanumeric
  169. characters or underscores.
  170. Constant symbols are only part of expressions. Constant symbols are
  171. always surrounded by single or double quotes. Within the quote, any
  172. other character is allowed and the quotes can be escaped using '\'.
  173. Menu structure
  174. --------------
  175. The position of a menu entry in the tree is determined in two ways. First
  176. it can be specified explicitly:
  177. menu "Network device support"
  178. depends on NET
  179. config NETDEVICES
  180. ...
  181. endmenu
  182. All entries within the "menu" ... "endmenu" block become a submenu of
  183. "Network device support". All subentries inherit the dependencies from
  184. the menu entry, e.g. this means the dependency "NET" is added to the
  185. dependency list of the config option NETDEVICES.
  186. The other way to generate the menu structure is done by analyzing the
  187. dependencies. If a menu entry somehow depends on the previous entry, it
  188. can be made a submenu of it. First, the previous (parent) symbol must
  189. be part of the dependency list and then one of these two conditions
  190. must be true:
  191. - the child entry must become invisible, if the parent is set to 'n'
  192. - the child entry must only be visible, if the parent is visible
  193. config MODULES
  194. bool "Enable loadable module support"
  195. config MODVERSIONS
  196. bool "Set version information on all module symbols"
  197. depends on MODULES
  198. comment "module support disabled"
  199. depends on !MODULES
  200. MODVERSIONS directly depends on MODULES, this means it's only visible if
  201. MODULES is different from 'n'. The comment on the other hand is only
  202. visible when MODULES is set to 'n'.
  203. Kconfig syntax
  204. --------------
  205. The configuration file describes a series of menu entries, where every
  206. line starts with a keyword (except help texts). The following keywords
  207. end a menu entry:
  208. - config
  209. - menuconfig
  210. - choice/endchoice
  211. - comment
  212. - menu/endmenu
  213. - if/endif
  214. - source
  215. The first five also start the definition of a menu entry.
  216. config:
  217. "config" <symbol>
  218. <config options>
  219. This defines a config symbol <symbol> and accepts any of above
  220. attributes as options.
  221. menuconfig:
  222. "menuconfig" <symbol>
  223. <config options>
  224. This is similar to the simple config entry above, but it also gives a
  225. hint to front ends, that all suboptions should be displayed as a
  226. separate list of options. To make sure all the suboptions will really
  227. show up under the menuconfig entry and not outside of it, every item
  228. from the <config options> list must depend on the menuconfig symbol.
  229. In practice, this is achieved by using one of the next two constructs:
  230. (1):
  231. menuconfig M
  232. if M
  233. config C1
  234. config C2
  235. endif
  236. (2):
  237. menuconfig M
  238. config C1
  239. depends on M
  240. config C2
  241. depends on M
  242. In the following examples (3) and (4), C1 and C2 still have the M
  243. dependency, but will not appear under menuconfig M anymore, because
  244. of C0, which doesn't depend on M:
  245. (3):
  246. menuconfig M
  247. config C0
  248. if M
  249. config C1
  250. config C2
  251. endif
  252. (4):
  253. menuconfig M
  254. config C0
  255. config C1
  256. depends on M
  257. config C2
  258. depends on M
  259. choices:
  260. "choice" [symbol]
  261. <choice options>
  262. <choice block>
  263. "endchoice"
  264. This defines a choice group and accepts any of the above attributes as
  265. options. A choice can only be of type bool or tristate. If no type is
  266. specified for a choice, it's type will be determined by the type of
  267. the first choice element in the group or remain unknown if none of the
  268. choice elements have a type specified, as well.
  269. While a boolean choice only allows a single config entry to be
  270. selected, a tristate choice also allows any number of config entries
  271. to be set to 'm'. This can be used if multiple drivers for a single
  272. hardware exists and only a single driver can be compiled/loaded into
  273. the kernel, but all drivers can be compiled as modules.
  274. A choice accepts another option "optional", which allows to set the
  275. choice to 'n' and no entry needs to be selected.
  276. If no [symbol] is associated with a choice, then you can not have multiple
  277. definitions of that choice. If a [symbol] is associated to the choice,
  278. then you may define the same choice (ie. with the same entries) in another
  279. place.
  280. comment:
  281. "comment" <prompt>
  282. <comment options>
  283. This defines a comment which is displayed to the user during the
  284. configuration process and is also echoed to the output files. The only
  285. possible options are dependencies.
  286. menu:
  287. "menu" <prompt>
  288. <menu options>
  289. <menu block>
  290. "endmenu"
  291. This defines a menu block, see "Menu structure" above for more
  292. information. The only possible options are dependencies and "visible"
  293. attributes.
  294. if:
  295. "if" <expr>
  296. <if block>
  297. "endif"
  298. This defines an if block. The dependency expression <expr> is appended
  299. to all enclosed menu entries.
  300. source:
  301. "source" <prompt>
  302. This reads the specified configuration file. This file is always parsed.
  303. mainmenu:
  304. "mainmenu" <prompt>
  305. This sets the config program's title bar if the config program chooses
  306. to use it. It should be placed at the top of the configuration, before any
  307. other statement.
  308. Kconfig hints
  309. -------------
  310. This is a collection of Kconfig tips, most of which aren't obvious at
  311. first glance and most of which have become idioms in several Kconfig
  312. files.
  313. Adding common features and make the usage configurable
  314. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  315. It is a common idiom to implement a feature/functionality that are
  316. relevant for some architectures but not all.
  317. The recommended way to do so is to use a config variable named HAVE_*
  318. that is defined in a common Kconfig file and selected by the relevant
  319. architectures.
  320. An example is the generic IOMAP functionality.
  321. We would in lib/Kconfig see:
  322. # Generic IOMAP is used to ...
  323. config HAVE_GENERIC_IOMAP
  324. config GENERIC_IOMAP
  325. depends on HAVE_GENERIC_IOMAP && FOO
  326. And in lib/Makefile we would see:
  327. obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
  328. For each architecture using the generic IOMAP functionality we would see:
  329. config X86
  330. select ...
  331. select HAVE_GENERIC_IOMAP
  332. select ...
  333. Note: we use the existing config option and avoid creating a new
  334. config variable to select HAVE_GENERIC_IOMAP.
  335. Note: the use of the internal config variable HAVE_GENERIC_IOMAP, it is
  336. introduced to overcome the limitation of select which will force a
  337. config option to 'y' no matter the dependencies.
  338. The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the
  339. situation where select forces a symbol equals to 'y'.
  340. Build as module only
  341. ~~~~~~~~~~~~~~~~~~~~
  342. To restrict a component build to module-only, qualify its config symbol
  343. with "depends on m". E.g.:
  344. config FOO
  345. depends on BAR && m
  346. limits FOO to module (=m) or disabled (=n).
  347. Kconfig recursive dependency limitations
  348. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  349. If you've hit the Kconfig error: "recursive dependency detected" you've run
  350. into a recursive dependency issue with Kconfig, a recursive dependency can be
  351. summarized as a circular dependency. The kconfig tools need to ensure that
  352. Kconfig files comply with specified configuration requirements. In order to do
  353. that kconfig must determine the values that are possible for all Kconfig
  354. symbols, this is currently not possible if there is a circular relation
  355. between two or more Kconfig symbols. For more details refer to the "Simple
  356. Kconfig recursive issue" subsection below. Kconfig does not do recursive
  357. dependency resolution; this has a few implications for Kconfig file writers.
  358. We'll first explain why this issues exists and then provide an example
  359. technical limitation which this brings upon Kconfig developers. Eager
  360. developers wishing to try to address this limitation should read the next
  361. subsections.
  362. Simple Kconfig recursive issue
  363. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  364. Read: Documentation/kbuild/Kconfig.recursion-issue-01
  365. Test with:
  366. make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-01 allnoconfig
  367. Cumulative Kconfig recursive issue
  368. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  369. Read: Documentation/kbuild/Kconfig.recursion-issue-02
  370. Test with:
  371. make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-02 allnoconfig
  372. Practical solutions to kconfig recursive issue
  373. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  374. Developers who run into the recursive Kconfig issue have three options
  375. at their disposal. We document them below and also provide a list of
  376. historical issues resolved through these different solutions.
  377. a) Remove any superfluous "select FOO" or "depends on FOO"
  378. b) Match dependency semantics:
  379. b1) Swap all "select FOO" to "depends on FOO" or,
  380. b2) Swap all "depends on FOO" to "select FOO"
  381. The resolution to a) can be tested with the sample Kconfig file
  382. Documentation/kbuild/Kconfig.recursion-issue-01 through the removal
  383. of the "select CORE" from CORE_BELL_A_ADVANCED as that is implicit already
  384. since CORE_BELL_A depends on CORE. At times it may not be possible to remove
  385. some dependency criteria, for such cases you can work with solution b).
  386. The two different resolutions for b) can be tested in the sample Kconfig file
  387. Documentation/kbuild/Kconfig.recursion-issue-02.
  388. Below is a list of examples of prior fixes for these types of recursive issues;
  389. all errors appear to involve one or more select's and one or more "depends on".
  390. commit fix
  391. ====== ===
  392. 06b718c01208 select A -> depends on A
  393. c22eacfe82f9 depends on A -> depends on B
  394. 6a91e854442c select A -> depends on A
  395. 118c565a8f2e select A -> select B
  396. f004e5594705 select A -> depends on A
  397. c7861f37b4c6 depends on A -> (null)
  398. 80c69915e5fb select A -> (null) (1)
  399. c2218e26c0d0 select A -> depends on A (1)
  400. d6ae99d04e1c select A -> depends on A
  401. 95ca19cf8cbf select A -> depends on A
  402. 8f057d7bca54 depends on A -> (null)
  403. 8f057d7bca54 depends on A -> select A
  404. a0701f04846e select A -> depends on A
  405. 0c8b92f7f259 depends on A -> (null)
  406. e4e9e0540928 select A -> depends on A (2)
  407. 7453ea886e87 depends on A > (null) (1)
  408. 7b1fff7e4fdf select A -> depends on A
  409. 86c747d2a4f0 select A -> depends on A
  410. d9f9ab51e55e select A -> depends on A
  411. 0c51a4d8abd6 depends on A -> select A (3)
  412. e98062ed6dc4 select A -> depends on A (3)
  413. 91e5d284a7f1 select A -> (null)
  414. (1) Partial (or no) quote of error.
  415. (2) That seems to be the gist of that fix.
  416. (3) Same error.
  417. Future kconfig work
  418. ~~~~~~~~~~~~~~~~~~~
  419. Work on kconfig is welcomed on both areas of clarifying semantics and on
  420. evaluating the use of a full SAT solver for it. A full SAT solver can be
  421. desirable to enable more complex dependency mappings and / or queries,
  422. for instance on possible use case for a SAT solver could be that of handling
  423. the current known recursive dependency issues. It is not known if this would
  424. address such issues but such evaluation is desirable. If support for a full SAT
  425. solver proves too complex or that it cannot address recursive dependency issues
  426. Kconfig should have at least clear and well defined semantics which also
  427. addresses and documents limitations or requirements such as the ones dealing
  428. with recursive dependencies.
  429. Further work on both of these areas is welcomed on Kconfig. We elaborate
  430. on both of these in the next two subsections.
  431. Semantics of Kconfig
  432. ~~~~~~~~~~~~~~~~~~~~
  433. The use of Kconfig is broad, Linux is now only one of Kconfig's users:
  434. one study has completed a broad analysis of Kconfig use in 12 projects [0].
  435. Despite its widespread use, and although this document does a reasonable job
  436. in documenting basic Kconfig syntax a more precise definition of Kconfig
  437. semantics is welcomed. One project deduced Kconfig semantics through
  438. the use of the xconfig configurator [1]. Work should be done to confirm if
  439. the deduced semantics matches our intended Kconfig design goals.
  440. Having well defined semantics can be useful for tools for practical
  441. evaluation of depenencies, for instance one such use known case was work to
  442. express in boolean abstraction of the inferred semantics of Kconfig to
  443. translate Kconfig logic into boolean formulas and run a SAT solver on this to
  444. find dead code / features (always inactive), 114 dead features were found in
  445. Linux using this methodology [1] (Section 8: Threats to validity).
  446. Confirming this could prove useful as Kconfig stands as one of the the leading
  447. industrial variability modeling languages [1] [2]. Its study would help
  448. evaluate practical uses of such languages, their use was only theoretical
  449. and real world requirements were not well understood. As it stands though
  450. only reverse engineering techniques have been used to deduce semantics from
  451. variability modeling languages such as Kconfig [3].
  452. [0] http://www.eng.uwaterloo.ca/~shshe/kconfig_semantics.pdf
  453. [1] http://gsd.uwaterloo.ca/sites/default/files/vm-2013-berger.pdf
  454. [2] http://gsd.uwaterloo.ca/sites/default/files/ase241-berger_0.pdf
  455. [3] http://gsd.uwaterloo.ca/sites/default/files/icse2011.pdf
  456. Full SAT solver for Kconfig
  457. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  458. Although SAT solvers [0] haven't yet been used by Kconfig directly, as noted in
  459. the previous subsection, work has been done however to express in boolean
  460. abstraction the inferred semantics of Kconfig to translate Kconfig logic into
  461. boolean formulas and run a SAT solver on it [1]. Another known related project
  462. is CADOS [2] (former VAMOS [3]) and the tools, mainly undertaker [4], which has
  463. been introduced first with [5]. The basic concept of undertaker is to exract
  464. variability models from Kconfig, and put them together with a propositional
  465. formula extracted from CPP #ifdefs and build-rules into a SAT solver in order
  466. to find dead code, dead files, and dead symbols. If using a SAT solver is
  467. desirable on Kconfig one approach would be to evaluate repurposing such efforts
  468. somehow on Kconfig. There is enough interest from mentors of existing projects
  469. to not only help advise how to integrate this work upstream but also help
  470. maintain it long term. Interested developers should visit:
  471. http://kernelnewbies.org/KernelProjects/kconfig-sat
  472. [0] http://www.cs.cornell.edu/~sabhar/chapters/SATSolvers-KR-Handbook.pdf
  473. [1] http://gsd.uwaterloo.ca/sites/default/files/vm-2013-berger.pdf
  474. [2] https://cados.cs.fau.de
  475. [3] https://vamos.cs.fau.de
  476. [4] https://undertaker.cs.fau.de
  477. [5] https://www4.cs.fau.de/Publications/2011/tartler_11_eurosys.pdf