Debian Codegraph @

Documentation/getting_started/kconfig.md

raw symbols SCIP
1 # Kconfig in coreboot
2
3 ## Overview
4 Kconfig is a tool used in coreboot, Linux, and many other projects as the main
5 configuration mechanism. In coreboot, it allows a developer both to select
6 which platform to build and to modify various features within the platform. The
7 Kconfig language was developed as a way to configure the Linux kernel, and is
8 still maintained as a part of the Linux kernel tree. Starting in Linux 2.5.45,
9 the ncurses based menuconfig was added, which is still used as the main
10 configuration front end in coreboot today.
11
12 The official Kconfig source and documentation is kept at kernel.org:
13
14 - [Kconfig source](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig)
15 - [Kconfig Language Documentation](https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt)
16
17 The advantage to using Kconfig is that it allows users to easily select the
18 high level features of the project to be enabled or disabled at build time.
19 Ultimately the Kconfig tool generates a list of values which are used by the
20 source code and Makefiles of the project. This allows the source files to
21 select features, and allows the build to determine which files should be
22 compiled and linked to the rom.
23
24
25 ## Kconfig targets in Make
26 The Kconfig program in coreboot is built from source in util/kconfig. There are
27 various targets in the makefile to build Kconfig in different ways. These give
28 the user control over how to build the platform
29
30
31 ### Front end configuration targets
32 These are the make targets that would be used to update the configuration of
33 the platform.
34 - config - Text mode configuration tool, asks each configuration option in turn.
35 This does actually run in coreboot, but it is recommended that this not be
36 used as there is no way to save a partial config.
37 - gconfig - Graphical configuration tool based on GTK+ 2.0.
38 - menuconfig - Text mode, menu driven configuration tool.
39 - nconfig - Text mode, menu driven configuration tool.
40 - xconfig - Graphical front end based on QT.
41
42
43 ### Targets that update config files
44 These options are used to update the coreboot config files, typically .config.
45 The target file can be changed with variables in the environment or on the make
46 command line.
47
48 - defconfig - This generates a config based on another config file. Use the
49 environment variable KBUILD_DEFCONFIG to specify the base config file.
50 - oldconfig - Displays the answers to all configuration questions as it
51 generates the config.h file. If an interactive question is found that does
52 not have an answer yet, it stops and queries the user for the desired value.
53 - olddefconfig - Generates a config, using the default value for any symbols not
54 listed in the .config file.
55 - savedefconfig - Creates a ‘defconfig’ file, stripping out all of the symbols
56 that were left as default values. This is very useful for debugging, and is
57 how config files should be saved.
58
59
60 ### Targets not typically used in coreboot
61 - localmodconfig, localnoconfig, randconfig, allyesconfig, allnoconfig - These
62 are all used to generate various Kconfig files for testing.
63
64
65 ### Environment Variables that affect Kconfig
66 These variables are typically set in the makefiles or on the make command line.
67
68 #### Variables added to the coreboot Kconfig source
69 These variables were added to Kconfig specifically for coreboot and are not
70 included in the Linux version.
71
72 - KCONFIG_NEGATIVES=value. Define to show negative values in the autoconf.h file
73 (build/config.h). This is enabled in coreboot, and should not be changed.
74
75
76 #### Variables used to control the input and output config files
77 - KBUILD_DEFCONFIG=inputname of the defconfig file. This defaults to
78 ‘configs/defconfig’ and is used by the ‘defconfig’ target.
79
80 - DEFCONFIG=output name of the defconfig file. This defaults to ‘defconfig’
81 and is used by ‘savedefconfig’ target as the output filename.
82
83 - DOTCONFIG=name of the .config file. This defaults to '.config' and is used
84 by most config type targets.
85
86
87 #### Variables used by the makefiles for controlling Kconfig
88 - Kconfig=root Kconfig file. This is set to 'src/Kconfig' in the coreboot
89 makefile.
90
91 - KCONFIG_CONFIG=input config file. coreboot sets this to $(DOTCONFIG).
92
93 - KCONFIG_AUTOHEADER=path and filename of autoconf.h file. coreboot sets this
94 to $(obj)/config.h.
95
96 - KCONFIG_DEPENDENCIES=”kbuild dependency file". This defaults to
97 auto.conf.cmd and outputs the name of all of the Kconfig files used.
98
99 - KCONFIG_SPLITCONFIG=”directory name for individual SYMBOL.h files”.
100 coreboot sets this to $(obj)/config.
101
102 - KCONFIG_WERROR=value. Define to enable warnings as errors. This is enabled
103 in coreboot, and should not be changed.
104
105 #### Used only for ‘make menuconfig’
106 - MENUCONFIG_MODE=single_menu. Set to "single_menu" to enable. All other
107 values disable the option. This makes submenus appear below the menu option
108 instead of opening a new screen.
109
110 - MENUCONFIG_COLOR=<theme>. This sets the color theme for the menu from
111 these options:
112
113 - mono => selects colors suitable for monochrome displays.
114 - blackbg => selects a color scheme with black background.
115 - classic => theme with blue background. The classic look.
116 - bluetitle => an LCD friendly version of classic. (default).
117
118
119 #### Used only for ‘make nconfig’
120
121 - NCONFIG_MODE=single_menu
122
123 Submenus appear below the menu option instead of opening a new screen.
124
125
126 #### Unused in coreboot
127
128 Although these variables are not used by coreboot, their values should be left
129 at the default values. Other values may have unexpected effects on the
130 codebase.
131
132 - KCONFIG_SEED=randconfig seed value.
133 - KCONFIG_PROBABILITY=randconfig percent to set to y.
134 - KCONFIG_NOSILENTUPDATE=value. Define to prevent silent updates to .config
135 file.
136 - KCONFIG_OVERWRITECONFIG=value. Define to prevent breaking a .config symlink.
137 - KCONFIG_TRISTATE=filename of tristate.conf file.
138 - SRCTREE=path to src directory.
139 - KCONFIG_AUTOCONFIG=path and filename of the auto.conf file.
140
141 coreboot sets this to $(obj)/auto.conf. Although this value is actually
142 set by coreboot, the resulting file is not used.
143
144 - CONFIG_=prefix for Kconfig output symbols.
145
146 coreboot expects this to *NOT* be set.
147
148
149
150 ## Kconfig Language
151
152 The Kconfig language has about 30 keywords, some overloaded, and some with the
153 same meaning. Whitespace may have specific meaning, for example in the 'help'
154 keyword. There are 8 logical operators for use in expressions, which allow
155 values to be set based on other values.
156
157
158 ### Terminology
159
160 - Symbols - There are two types of symbols, "constant" and “non-constant”.
161 - Constant symbols are alphanumeric values used in expressions for
162 comparison. The Kconfig language specification says that these must be
163 surrounded by single or double quotes.
164 - Non-constant symbols are the 'config' values that are output into the
165 saved .config, auto.conf and config.h files. Non-constant symbols are
166 typically defined with the 'config' keyword, although they can also be
167 defined with the 'choice' keyword. These symbols may be used in a file's
168 expressions before they are defined. Valid characters for non-constant
169 symbols are any combination of alphanumeric characters, underscore.
170 Although “1234” is accepted as a symbol name, as is “o_o”, convention is
171 to use all uppercase words that are descriptive of the symbol's use so
172 they make sense when turned into CONFIG_NAME #defines.
173
174 - Expressions - An expression is a logical evaluation. It can be as simple as
175 a static 'y' or 'n', or can be a symbol. Alternatively, expressions can be
176 complex evaluations of multiple symbols using the various logical operators.
177 The Kconfig language allows these logical evaluations in several places. The
178 most common use for complex expressions is following 'if' or ‘depends on’
179 keywords, but they can also be used to set the value for a prompt or default
180 values.
181
182 - Types - Each Kconfig symbol is one of the following types: bool, hex, int,
183 string, or tristate. The tristate type is not used for coreboot, leaving just
184 four types. As noted in the keyword summaries, a symbol must have a consistent
185 type anywhere it is defined. Also, Kconfig will simply not display a symbol
186 that has no type defined. A warning will be displayed in the terminal where
187 menuconfig was run if this happens:
188 _src/Kconfig:25:warning: config symbol defined without type_.
189
190 - Prompts - Input prompts are the text associated with the symbols which shown
191 to the user. The Kconfig language definition does not require surrounding the
192 prompt’s text with quotes, however it is recommended that quotes be used for
193 maximum compatibility.
194
195 - Menu Entries - These keyword blocks create the symbols and questions that are
196 visible in the front end.
197
198
199 ### Keywords
200
201 #### bool
202
203 The 'bool' keyword assigns a boolean type to a symbol. The allowable values for
204 a boolean type are 'n' or 'y'. The keyword can be followed by an optional prompt
205 string which makes the symbol editable in one of the configuration front ends.
206
207
208 ##### Usage:
209 bool \[prompt\] \[if <expr>\]
210
211
212 ##### Example:
213 config ANY_TOOLCHAIN
214 bool "Allow building with any toolchain"
215 default n
216 depends on COMPILER_GCC
217
218
219 ##### Notes:
220 - Putting the prompt after the 'bool' keyword is the same as using a 'prompt'
221 keyword later. See the 'prompt' keyword for more notes.
222 - Only the first type definition for each symbol is valid. Further matching
223 definitions are fine, although unnecessary. Conflicting type definitions will
224 be ignored, and a warning will be presented on the console where the
225 configuration front end was run:
226 _warning: ignoring type redefinition of 'SYMBOL' from 'hex' to 'integer'_.
227 - Boolean symbols do not need a default and will default to ‘n’.
228
229
230 ##### Restrictions:
231
232 - This keyword must be within a symbol definition block, started by the
233 'config' keyword.
234
235 --------------------------------------------------------------------------------
236
237 #### choice
238
239 This creates a selection list of one or more boolean symbols. For bools, only
240 one of the symbols can be selected, and one will be be forced to be selected,
241 either by a ‘default’ statement, or by selecting the first config option if
242 there is no default value listed.
243
244 ##### Usage:
245 choice \[symbol\]
246 - \[prompt\]
247 - \[default\]
248
249
250 ##### Example:
251 choice TESTCHOICE
252 prompt "Test choice"
253 default TESTCHOICE2 if TESTCHOICE_DEFAULT_2
254 default TESTCHOICE3
255
256 config TESTCHOICE1
257 bool "Choice 1"
258 config TESTCHOICE2
259 bool "Choice 2"
260 config TESTCHOICE3
261 bool "Choice 3"
262 config TESTCHOICE4
263 bool "Choice 4" if TESTCHOICE_SHOW_4
264 endchoice
265
266 config TESTCHOICE_DEFAULT_2
267 def_bool y
268
269 config TESTCHOICE_SHOW_4
270 def_bool n
271
272 config TESTSTRING
273 string
274 default “String #1” if TESTCHOICE1
275 default “String #2” if TESTCHOICE2
276 default “String #4” if TESTCHOICE3
277 default “String #4” if TESTCHOICE4
278 default “”
279
280
281 ##### Notes:
282 - If no symbol is associated with a choice, then you can not have multiple
283 definitions of that choice. If a symbol is associated to the choice, then
284 you may define the same choice (ie. with the same entries) in another place.
285 Any selection in either location will update both choice menu selections. In
286 coreboot, the value of the symbol is always 1.
287 - As shown in the example above, the choice between bools can be used to set
288 the default for a non-bool type. This works best when the non-bool type
289 does not have an input prompt.
290
291
292 ##### Restrictions:
293 - Symbols used for 'choice' entries must have input prompts defined using the
294 'prompt' keyword.
295 - Symbols used in 'choice' entries may not be enabled with a 'select'
296 statement, they can be defaulted using a second Kconfig symbol however.
297
298 --------------------------------------------------------------------------------
299
300 #### comment
301
302 This keyword defines a line of text that is displayed to the user in the
303 configuration frontend and is additionally written to the output files.
304
305
306 ##### Usage:
307 comment <prompt>
308 - \[depends on\]
309
310
311 ##### Example:
312
313 if CONSOLE_SERIAL
314 comment "I/O mapped, 8250-compatible"
315 depends on DRIVERS_UART_8250IO
316 endif
317
318
319 ##### Notes:
320 - Comments are only valid outside of config blocks, but can be within menu and
321 if blocks.
322
323 --------------------------------------------------------------------------------
324
325 #### config
326
327 This is the keyword that starts a block defining a Kconfig symbol. The symbol
328 modifiers follow the 'config' statement.
329
330 ##### Usage:
331 config <symbol>
332
333 - \[bool | def_bool | int | hex | string\]
334 - \[depends on\]
335 - \[prompt\]
336 - \[help\]
337 - \[range\]
338 - \[select\]
339
340
341 ##### Example:
342 config SEABIOS_PS2_TIMEOUT
343 prompt "PS/2 keyboard timeout" if PAYLOAD_SEABIOS
344 default 0
345 depends on PAYLOAD_SEABIOS
346 int
347 help
348 Some PS/2 keyboard controllers don't respond to commands
349 immediately after powering on. This specifies how long
350 SeaBIOS will wait for the keyboard controller to become
351 ready before giving up.
352
353
354 ##### Notes:
355 - Non-coreboot projects also use the 'tristate' and 'def_tristate' types.
356 - Ends at the next Kconfig keyword that is not valid inside the config block:
357
358 menu | endmenu | if | endif | choice | config | source | comment
359
360 --------------------------------------------------------------------------------
361
362 #### default
363
364 The ‘default’ keyword assigns a value to a symbol in the case where no preset
365 value exists, i.e. the symbol is not present and assigned in .config. If there
366 is no preset value, and no ‘default’ keyword, the user will be asked to enter a
367 valid value when building coreboot.
368
369
370 ##### Usage:
371 default <expr> \[if <expr>\]
372
373
374 ##### Example:
375 config GENERATE_MP_TABLE
376 prompt "Generate an MP table" if HAVE_MP_TABLE || DRIVERS_GENERIC_IOAPIC
377 bool
378 default HAVE_MP_TABLE || DRIVERS_GENERIC_IOAPIC
379 help
380 Generate an MP table (conforming to the Intel
381 MultiProcessor specification 1.4) for this board.
382
383
384 ##### Notes:
385 - Kconfig defaults for symbols without a prompt *NEVER* affect existing legal
386 symbol definitions in a .config file. The default only affects the symbol if
387 there is no valid definition in a config file. This is a frequent source of
388 confusion. It’s covered again in the Tips section below.
389 - The first valid 'default' entry for a symbol is always used. Any further
390 'default' statements for a symbol are ignored. This means that the order of
391 Kconfig files is very important as the earlier files get to set the defaults
392 first. They should be sourced in the order from most specific (mainboard
393 Kconfig files) to the most generic (architecture-specific Kconfig files).
394 - If there is no 'default' entry for a symbol, it gets set to 'n', 0, 0x0, or
395 “” depending on the type, however the 'bool' type is the only type that
396 should be left without a default value.
397 - If possible, the declaration should happen before all default entries to make
398 it visible in Kconfig tools like menuconfig.
399
400 --------------------------------------------------------------------------------
401
402 #### def_bool
403
404 ‘def_bool’ is similar to the 'bool' keyword in that it sets a symbol’s type to
405 boolean. It lets you set the type and default value at the same time, instead
406 of setting the type and the prompt at the same time. It's typically used for
407 symbols that don't have prompts.
408
409
410 ##### Usage:
411 def_bool <expr> \[if <expr>\]
412
413
414 ##### Example:
415 config EC_GOOGLE_CHROMEEC_LPC
416 depends on EC_GOOGLE_CHROMEEC && ARCH_X86
417 def_bool y
418 select SERIRQ_CONTINUOUS_MODE
419 help
420 Google Chrome EC via LPC bus.
421
422
423 ##### Notes:
424 - Only the first type definition for each symbol is valid. Further matching
425 definitions are fine, although unnecessary. Conflicting type definitions will
426 be ignored, and a warning will be presented on the console where the
427 configuration front end was run:
428 _warning: ignoring type redefinition of 'SYMBOL' from 'hex' to 'integer'_.
429
430 ##### Restrictions:
431 - This keyword must be within a symbol definition block, started by the
432 'config' keyword.
433
434 --------------------------------------------------------------------------------
435
436 #### depends on
437
438 This defines a dependency for a menu entry, including symbols and comments. It
439 behaves the same as surrounding the menu entry with an if/endif block. If the
440 ‘depends on’ expression evaluates to false, the 'prompt' value will not be
441 printed, and defaults will not be set based on this block.
442
443
444 ##### Usage:
445 depends on <expr>
446
447
448 ##### Example:
449 config COMMON_CBFS_SPI_WRAPPER
450 bool
451 default n
452 depends on SPI_FLASH
453 depends on !ARCH_X86
454 help
455 Use common wrapper to interface CBFS to SPI bootrom.
456
457
458 ##### Notes:
459 - Symbols that have multiple ‘depends on’ sections as above are equivalent to a
460 single ‘depends on’ statement with sections joined by &&. So the above is
461 the same as “depends on SPI_FLASH && ! ARCH_X86”.
462
463 --------------------------------------------------------------------------------
464
465 #### endchoice
466
467 This ends a choice block. See the 'choice' keyword for more information and an
468 example.
469
470 --------------------------------------------------------------------------------
471
472 #### endif
473
474 This ends a block started by the 'if' keyword. See the 'if' keyword for more
475 information and an example.
476
477 --------------------------------------------------------------------------------
478
479 #### endmenu
480
481 This ends a menu block. See the 'menu' keyword for more information and an
482 example.
483
484 --------------------------------------------------------------------------------
485
486 #### help
487
488 The 'help' keyword defines the subsequent block of text as help for a config or
489 choice block. The help block is started by the 'help' keyword on a line by
490 itself, and the indentation level of the next line controls the end of the help
491 block. The help ends on the next non-blank line that has an indentation level
492 less than the indentation level of the first line following the 'help' keyword.
493
494 ##### Usage:
495 help <help text>
496
497
498 ##### Example:
499 config COMPILER_GCC
500 bool "GCC"
501 help
502 Use the GNU Compiler Collection (GCC) to build coreboot. For details
503 see http://gcc.gnu.org.
504
505
506 ##### Notes:
507 - Identical to the '---help---' keyword which isn’t used in coreboot.
508 - Other keywords are allowed inside the help block, and are not recognized as
509 keywords so long as the indentation rules are followed, even if they start a
510 line.
511
512
513 ##### Restrictions:
514 - Only used for 'config' and 'choice' keywords.
515
516 --------------------------------------------------------------------------------
517
518 #### hex
519
520 This is another symbol type specifier, specifying an unsigned integer value
521 formatted as hexadecimal.
522
523 ##### Usage:
524 hex <expr> \[if <expr>\]
525
526
527 ##### Example:
528 config INTEL_PCH_UART_CONSOLE_NUMBER
529 hex "Serial IO UART number to use for console"
530 default 0x0
531 depends on INTEL_PCH_UART_CONSOLE
532
533
534 ##### Notes:
535 - Kconfig doesn’t complain if you don’t start the default value for a hex
536 symbol with ‘0x’, but not doing so will lead to issues. It will update 10
537 to 0x10 without warning the user.
538 - Putting the prompt text after the 'hex' keyword is the same as using a
539 'prompt' keyword later. See the 'prompt' keyword for more notes.
540 - Only the first type definition for each symbol is valid. Further matching
541 definitions are fine, although unnecessary. Conflicting type definitions will
542 be ignored, and a warning will be presented on the console where the
543 configuration front end was run:
544 _warning: ignoring type redefinition of 'SYMBOL' from 'hex' to 'integer'_.
545
546
547 ##### Restrictions:
548 - This keyword must be within a symbol definition block, started by the
549 'config' keyword.
550 - 'hex' type symbols must have a 'default' entry set.
551
552 --------------------------------------------------------------------------------
553
554 #### if
555
556 The 'if' keyword is overloaded, used in two different ways. The first definition
557 enables and disables various other keywords, and follows the other keyword
558 definition. This usage is shown in each of the other keywords' usage listings.
559
560 The second usage of the 'if' keyword is part of an if/endif block. Most items
561 within an if/endif block are not evaluated, while others, such as the 'source'
562 keyword, ignore the existence of the if/endif block completely. Symbols defined
563 within an if/endif block are still created, although their default values are
564 ignored - all values are set to 'n'.
565
566
567 ##### Usage:
568 if <expr>
569
570 - \[config\]
571 - \[choice\]
572 - \[comment\]
573 - \[menu\]
574
575 endif
576
577
578 ##### Example:
579 if ARCH_X86
580
581 config SMP
582 bool
583 default y if MAX_CPUS != 1
584 default n
585 help
586 This option is used to enable certain functions to make
587 coreboot work correctly on symmetric multi processor (SMP) systems.
588 endif
589
590 ##### Restrictions:
591 - Corresponding ‘if’ and ‘endif’ statements must exist in the same file.
592
593 --------------------------------------------------------------------------------
594
595 #### int
596
597 A type setting keyword, defines a symbol as an integer, accepting only signed
598 numeric values. The values can be further restricted with the ‘range’ keyword.
599
600
601 ##### Usage:
602 int <expr> \[if <expr>\]
603
604
605 ##### Example:
606 config PRE_GRAPHICS_DELAY_MS
607 int "Graphics initialization delay in ms"
608 default 0
609 help
610 On some systems, coreboot boots so fast that connected
611 monitors (mostly TVs) won't be able to wake up fast enough
612 to talk to the VBIOS. On those systems we need to wait for a
613 bit before executing the VBIOS.
614
615
616 ##### Notes:
617 - Only the first type definition for each symbol is valid. Further matching
618 definitions are fine, although unnecessary. Conflicting type definitions will
619 be ignored, and a warning will be presented on the console where the
620 configuration front end was run:
621 _warning: ignoring type redefinition of 'SYMBOL' from 'hex' to 'integer'_.
622
623
624 ##### Restrictions:
625 - This keyword must be within a symbol definition block, started by the 'config'
626 keyword.
627 - 'int' type symbols must have a default value set.
628
629 --------------------------------------------------------------------------------
630
631 #### mainmenu
632
633 The 'mainmenu' keyword sets the title or title bar of the configuration front
634 end, depending on how the configuration program decides to use it. It can only
635 be specified once and at the very beginning of the top level Kconfig file,
636 before any other statements.
637
638
639 ##### Usage:
640 mainmenu <prompt>
641
642 ##### Example:
643 mainmenu "coreboot configuration"
644
645 ##### Restrictions:
646 - Must be the first statement in the top level Kconfig.
647 - Must only be used once in the entire Kconfig tree.
648
649 --------------------------------------------------------------------------------
650
651 #### menu
652
653 The 'menu' and 'endmenu' keywords tell the configuration front end that the
654 enclosed statements are part of a group of related pieces.
655
656
657 ##### Usage:
658 menu <prompt>
659
660 - \[choice\]
661 - \[config\]
662 - \[menu\]
663 - \[if/endif\]
664
665 endmenu
666
667
668 ##### Example:
669 menu "On-Chip Device Power Down Control"
670 config TEMP_POWERDOWN
671 bool "Temperature sensor power-down"
672
673 config SATA_POWERDOWN
674 bool "SATA power-down"
675
676 config ADC_POWERDOWN
677 bool "ADC power-down"
678
679 config PCIE0_POWERDOWN
680 bool "PCIE0 power-down"
681
682 config MAC_POWERDOWN
683 bool "MAC power-down"
684
685 config USB1_POWERDOWN
686 bool "USB2.0 Host Controller 1 power-down"
687
688 config IDE_POWERDOWN
689 bool "IDE power-down"
690
691 endmenu
692
693 ##### Restrictions:
694 - Must be closed by a corresponding ‘endmenu’ keyword in the same file.
695
696 --------------------------------------------------------------------------------
697
698 #### prompt
699
700 The 'prompt' keyword sets the text displayed for a config symbol or choice in
701 configuration front end.
702
703
704 ##### Usage:
705 prompt <prompt> \[if <expr>\]
706
707
708 ##### Example:
709 config REALMODE_DEBUG
710 prompt "Enable debug messages for option ROM execution"
711 bool
712 default n
713 depends on PCI_OPTION_ROM_RUN_REALMODE
714 depends on DEFAULT_CONSOLE_LOGLEVEL_7 || DEFAULT_CONSOLE_LOGLEVEL_8
715 help
716 This option enables additional x86emu related debug
717 messages. Note: This option will increase the time to emulate a ROM.
718
719 If unsure, say N.
720
721
722 ##### Notes:
723 - The same rules apply for menu entries defined by the 'prompt' keyword and
724 other prompt types such as those defined by the 'int' or 'string' keywords.
725 - Redefining the prompt text in multiple instances of config symbols is allowed.
726 Only the current prompt statement for a particular entry will be displayed by
727 the front end in any given location. This means that multiple mainboards can
728 set different prompt values for a symbol, and it would appear differently in
729 each mainboard’s menu. The symbol can even have multiple entries in the same
730 menu with different prompts if desired. For example, both of these would get
731 printed, and changing either entry would change the other.
732
733 config PROMPT_TEST
734 string "Prompt value 1"
735
736 config PROMPT_TEST
737 prompt "Prompt value 2"
738
739 - Although not required, it's recommended that you use quotes around prompt
740 statements.
741 * If the prompt is redefined inside the SAME config entry, you will get a
742 warning:
743 _warning: prompt redefined_.
744 For example, this is not allowed:
745
746 config PROMPT_TEST
747 string "Prompt value 1"
748 prompt "Prompt value 2"
749 --------------------------------------------------------------------------------
750
751 #### range
752
753 This sets the allowable minimum and maximum entries for hex or int type config
754 symbols.
755
756
757 ##### Usage:
758 range <symbol> <symbol> \[if <expr>\]
759
760
761 ##### Example:
762 config TEST1
763 hex "test 1"
764 range 0x0 0x10
765
766
767 ##### Notes:
768 - Only the first definition of a range is used for any symbol. Further
769 definitions will be ignored without warning.
770
771 --------------------------------------------------------------------------------
772
773 #### select
774
775 The ‘select’ keyword is used within a bool type config block. In coreboot (and
776 other projects that don't use modules), the 'select' keyword can force an
777 unassociated bool type symbol to 'y'. When the symbol for the config block is
778 ‘y’, the ‘select’ action is taken. Otherwise the bool is unaffected.
779
780
781 ##### Usage:
782 select <symbol> \[if <expr>\]
783
784
785 ##### Example:
786 config TPM
787 bool
788 default n
789 select MEMORY_MAPPED_TPM if ARCH_X86
790 select I2C_TPM if ARCH_ARM
791 select I2C_TPM if ARCH_ARM64
792 help
793 Enable this option to enable TPM support in coreboot.
794 If unsure, say N.
795
796 ##### Notes:
797 - Using the 'select' keyword can create logical contradictions in Kconfig, which
798 will create warnings and fail to save the .config. Following is an example of
799 an obviously invalid configuration, where selecting BOOLTEST violates the
800 ‘depends on’ of BOOLTEST2:
801
802 config BOOLTEST
803 bool "bool Test"
804 select BOOLTEST2
805
806 config BOOLTEST2
807 bool "Bool Test 2"
808 depends on !BOOLTEST
809
810 ##### Restrictions:
811 - The ‘select’ keyword only works on bool type symbols.
812 - Symbols created inside of choice blocks cannot be selected, and should be
813 enabled by using default values instead.
814
815 --------------------------------------------------------------------------------
816
817 #### source
818
819 The 'source' keyword functions much the same as an 'include' statement in c.
820 This pulls one or more files into Kconfig at the location of the 'source'
821 command. This statement is always parsed - there is no way to conditionally
822 source a file. coreboot has modified the source statement slightly to handle
823 directory globbing. The '*' character will match with any directory.
824
825
826 ##### Usage:
827 source <prompt>
828
829
830 ##### Example:
831
832 choice
833 prompt "Mainboard vendor"
834 default VENDOR_EMULATION
835
836 source "src/mainboard/*/Kconfig.name"
837
838 endchoice
839
840 source "src/mainboard/*/Kconfig"
841
842
843 ##### Notes:
844 - As with all prompt values, the 'source' prompt may be enclosed in single or
845 double quotes, or left without any quotes. Using quotes is highly recommended
846 however.
847 - The 'source' keyword loads files relative to the working directory where the
848 Kconfig command was run. For coreboot, this is the root coreboot directory, so
849 all source commands in the src directory need to start with ‘src/’.
850 - In coreboot's Kconfig, if a sourced file does not exist, the statement is
851 simply ignored. This is different than other versions of Kconfig.
852 - 'source' pulls a file into the Kconfig tree at the location of the keyword.
853 This allows for files containing small bits of the Kconfig tree to be pulled
854 into a larger construct. A restriction on this is that the starting/ending
855 keyword pairs must be within the same file - ‘endif’ cannot appear in a
856 different file than the ‘if’ statement that it ends. The same is true of
857 menu/endmenu and choice/endchoice pairs.
858
859 The coreboot Kconfig structure uses this along with globbing to build up the
860 mainboard directory. Each mainboard’s Kconfig.name file contains just two
861 statements that generate a list of all the platform names:
862
863 config BOARD_AMD_NORWICH
864 bool "Norwich"
865
866
867 ##### Restrictions:
868 - 'source' keywords always load in the specified file or files. There is no way
869 to optionally pull in a file. Putting an if/endif block around a source
870 command does not affect the source command, although it does affect the
871 content. To avoid confusion, use if/endif blocks inside sourced files to
872 remove their content if necessary.
873
874 --------------------------------------------------------------------------------
875
876 #### string
877
878 The last of the symbol type assignment keywords. 'string' allows a text value to
879 be entered.
880
881
882 ##### Usage:
883 string <expr> \[if <expr>\]
884
885
886 ##### Example:
887 config BOOTBLOCK_SOUTHBRIDGE_INIT
888 string
889 default "southbridge/amd/pi/hudson/bootblock.c"
890
891 config HUDSON_GEC_FWM_FILE
892 string "GEC firmware path and filename"
893 depends on HUDSON_GEC_FWM
894
895
896 ##### Notes:
897 - Putting the prompt after the 'string' keyword is the same as using a 'prompt'
898 keyword later. See the prompt keyword for more notes.
899 - Only the first type definition for each symbol is valid. Further matching
900 definitions are fine, although unnecessary. Conflicting type definitions will
901 be ignored, and a warning will be presented on the console where the
902 configuration front end was run:
903 _warning: ignoring type redefinition of 'SYMBOL' from 'hex' to 'string'_.
904 - Some characters may not get interpreted correctly when inside a string entry
905 depending on how they are used - inside a C file, inside a Makefile, passed
906 through a Makefile to a C file, or something else. It may be necessary to
907 escape the characters at times. Because this is very dependent upon how the
908 symbol is actually used, a definitive guide cannot be given here.
909 - 'string' type variables do NOT need a default, and will default to the
910 value “”.
911
912
913 ##### Restrictions:
914 - This keyword must be within a symbol definition block, started by the 'config'
915 keyword.
916
917 --------------------------------------------------------------------------------
918
919
920
921
922 ### Keywords not used in coreboot at the time of writing:
923
924 - allnoconfig_y:
925 - defconfig_list
926 - def_tristate
927 - env
928 - ---help---
929 - menuconfig
930 - modules
931 - optional
932 - option
933 - tristate
934 - visible if
935
936
937 ## Build files generated by Kconfig
938
939 ### build/config.h
940
941 The config.h file is a very basic header file made up of a list of #define
942 statements:
943
944 #define SYMBOL NAME XXX
945
946
947 #### Symbol types:
948 - bool, int, and hex types - Every symbol of one of these types created in the
949 Kconfig tree is defined. It doesn’t matter whether they’re in an if/endif
950 block, or have a ‘depends on’ statement - they ALL end up being defined in
951 this file.
952 - String - Only string types that actually have a value associated with them
953 are defined.
954
955 The config.h file uses 0 and 1 to represent Kconfig's 'n' and 'y' values
956 respectively. String values are placed inside double quotes.
957
958 The name of the file is controlled by the $KCONFIG_AUTOHEADER environment
959 variable, which is set to $(obj)/config.h by the coreboot makefiles.
960
961 The prefix used for the symbols is controlled by the $CONFIG_ environment
962 variable. This is not set in coreboot, which uses the default CONFIG_ prefix
963 for all of its symbols.
964
965 The coreboot makefile forces the config.h file to be included into all coreboot
966 C files. This is done in Makefile.mk on the compiler command line using the
967 “-include $(obj)/config.h” command line option.
968
969 Example of various symbol types in the config.h file:
970
971 #define CONFIG_BOOTBLOCK_SOURCE "bootblock_simple.c" # String
972 #define CONFIG_CBFS_SIZE 0x00300000 # Hex
973 #define CONFIG_TTYS0_BAUD 115200 # Int
974 #define CONFIG_HAVE_ACPI_TABLES 1 # Bool enabled
975 #define CONFIG_EXPERT 0 # Bool disabled
976 #define CONFIG_NORTHBRIDGE_INTEL_I440LX 0 # Bool excluded
977
978
979 ### .config
980
981 The .config file in the root directory is used as the input file, but also by
982 the makefiles to set variable values. The main difference is that it does not
983 contain all of the symbols. It excludes symbols defined in an if/endif block
984 whose expression evaluated as false. Note that the symbol
985 CONFIG_NORTHBRIDGE_INTEL_I440LX shown in the config.h example above is not
986 present in the .config file.
987
988 In addition, the .config file below contains the 'comment' prompt text from the
989 Kconfig, separating the blocks.
990
991 ## General setup ##
992 CONFIG_BOOTBLOCK_SOURCE="bootblock_simple.c" # String
993 CONFIG_CBFS_SIZE=0x00300000 # Hex
994 CONFIG_TTYS0_BAUD=115200 # Int
995 CONFIG_HAVE_ACPI_TABLES=y # Bool enabled
996 # CONFIG_EXPERT is not set # Bool disabled
997
998 This file is included directly by the makefile, and sets the CONFIG symbols so
999 that they are available during the build process.
1000
1001
1002 ### build/auto.conf
1003
1004 Although the controlling variable for the auto.conf filename,
1005 KCONFIG_AUTOCONFIG, is set in the coreboot makefiles, the auto.conf file itself
1006 is not used by coreboot. This file has the same syntax and structure as the
1007 .config file, but contains all symbols in the Kconfig tree, including those that
1008 are not enabled, or are excluded by if/endif blocks, or the 'depends on'
1009 keyword. The kconfig tool could be updated to not generate this file, but since
1010 it's not hurting anything, it's still being generated.
1011
1012
1013
1014 ## Defconfig or Miniconfig files
1015
1016 Miniconfig files are the standard .config files with all of the symbols which
1017 are set to their default values stripped out. These files are very useful for
1018 debugging your config, as well as being the best way to store your .config file.
1019 If you store your config as a full config file, it will be much harder to
1020 maintain. Any Kconfig symbols with updated default values will retain their old
1021 values, and any symbols which have been removed will still remain in the file.
1022 Storing full config files just generally leads to a lot more maintenance than
1023 storing miniconfig files.
1024
1025 The easiest way to generate the miniconfig file is by running
1026
1027 make savedefconfig DOTCONFIG=.config DEFCONFIG=[output file]
1028
1029 DEFCONFIG defaults to ‘defconfig’, DOTCONFIG defaults to ‘.config’.
1030
1031
1032 To turn the miniconfig back into a full config file, use one of the two targets:
1033
1034 make olddefconfig DOTCONFIG=[input/output file]
1035
1036 or
1037
1038 make defconfig KBUILD_DEFCONFIG=[input file] DOTCONFIG=[output file]
1039
1040 In both of these cases, DOTCONFIG defaults to .config.
1041
1042
1043
1044 ## Editing and updating saved .config files
1045
1046
1047 ### Don’t save full config files
1048
1049 Save miniconfig files, as mentioned in the previous section.
1050
1051
1052 ### Disable values with ‘# CONFIG_SYMBOL is not set’
1053
1054 A common mistake when trying to disable a value is to edit the .config file and
1055 change it from ‘CONFIG_SYMBOL=y’ to ‘CONFIG_SYMBOL=n’, but this doesn’t
1056 correctly disable the symbol. If the default value for the symbol is ‘n’ to
1057 begin with, this isn’t an issue - the symbol just gets ignored, and the default
1058 value is used. The problem is where the default for the symbol is ‘y’. When
1059 the bad entry in the .config file gets ignored, the value is set back to ‘y’,
1060 leading to much frustration.
1061
1062 Always disable the Kconfig symbols in the .config file with the syntax:
1063
1064 # CONFIG_SYMBOL is not set
1065
1066 ### Only the LAST instance of a symbol is used
1067
1068 When reading a saved .config file, Kconfig uses the LAST instance of a symbol
1069 that it comes across, and ignores any previous instances. This can be used to
1070 override symbols in a saved .config file by appending the new value to a config
1071 file.
1072
1073 For example:
1074
1075 A .config file that contains these two lines:
1076
1077 # CONFIG_BOOLTEST is not set
1078 CONFIG_BOOLTEST=y
1079
1080 After running ‘make olddefconfig’, ends up with the value:
1081
1082 CONFIG_BOOLTEST=y
1083
1084 A case where this can be used is by a making a script to create two versions of
1085 a coreboot rom for a single platform. The first ROM could be built with serial
1086 console disabled, and the second ROM, built as a debug version, could have
1087 serial console enabled by overriding the "CONFIG_CONSOLE_SERIAL" symbol, and
1088 setting it to enabled.
1089
1090 ## General Kconfig Tips and Notes
1091
1092 ### Default values for config options
1093
1094 The FIRST valid default that the Kconfig parser comes across will be used for
1095 each symbol. This means that the organization of the tree is very important.
1096 The structure should go from most specific at the top of the Kconfig tree to the
1097 most general later in the tree. In coreboot, the mainboard directories get
1098 loaded first, as they are sourced very early in the src/Kconfig file. Chipset
1099 Kconfig files get sourced later, and the architecture specific Kconfig files get
1100 sourced even later. This allows the mainboards to set their defaults early,
1101 overriding the default values set in chipset or architecture.
1102
1103 Due to this mechanism, a default defined early cannot be changed by a default
1104 set in a later Kconfig file. There are ways around this, involving 'depends on'
1105 statements, but they add additional variables which are generally just used
1106 internal to Kconfig.
1107
1108
1109 ### Select statement usage
1110
1111 The 'select' keyword forces the value of a symbol with a bool type to 'y'. It
1112 overrides any dependencies of the symbol, so using it carelessly can lead to
1113 unpredictable results.
1114
1115
1116
1117 ### All bool, int, and hex Kconfig symbols are ALWAYS defined in the C code
1118
1119 All bool, int, and hex Kconfig symbols are ALWAYS defined in the C code if they
1120 are in a sourced Kconfig - do NOT use #ifdef CONFIG_SYMBOL
1121
1122 String symbols are the exception. All others (int, hex, etc.) are always
1123 defined in config.h. Never use an #ifdef statement for a Kconfig symbol other
1124 than strings in C to determine whether the symbol is enabled or disabled. So
1125 long as the symbol is in ANY sourced Kconfig file, it will be defined. Even if
1126 the symbol is only inside of an if/endif block where the if expression evaluates
1127 as false, the symbol STILL gets defined in the config.h file (though not in the
1128 .config file).
1129
1130 Use \#if CONFIG(SYMBOL) to be sure (it returns false for undefined symbols
1131 and defined-to-0 symbols alike).
1132
1133
1134
1135 ### Symbols with prompts use defaults *ONLY* when initially created or enabled.
1136
1137 Symbols with a prompt which may be user-modified are NOT updated to default
1138 values when changing between platforms or modifying other symbols. There are
1139 only two times the default values are used:
1140 1. When a config is initially created.
1141 2. When a dependency which had previously kept the symbol from being active
1142 changes to allowing it to be active.
1143
1144 Because of this, starting with a saved .config for one platform and updating it
1145 for another platform can lead to very different results than creating a platform
1146 from scratch.
1147
1148
1149
1150 ### Symbols with no prompt will be the default value (unless 'select' is used).
1151
1152 Symbols that do not have a prompt will always use the first valid default value
1153 specified in Kconfig. They cannot be updated, even if they are modified in a
1154 saved .config file. As always, a 'select' statement overrides any specified
1155 'default' or 'depends on' statement.
1156
1157
1158 ## Differences between coreboot's Kconfig and other Kconfig implementations.
1159
1160 - coreboot has added the glob operator '*' for the 'source' keyword.
1161 - coreboot’s Kconfig always defines variables except for strings. In other
1162 Kconfig implementations, bools set to false/0/no are not defined.
1163
1164
1165 ## Kconfig Editor Highlighting
1166
1167 ### vim:
1168
1169 vim has syntax highlighting for Kconfig built in (or at least as a part of
1170 vim-common), but most editors do not.
1171
1172
1173 ### ultraedit:
1174
1175 <https://github.com/martinlroth/wordfiles/blob/master/kconfig.uew>
1176
1177
1178
1179 ### atom:
1180
1181 <https://github.com/martinlroth/language-kconfig>
1182
1183
1184 ## Syntax Checking:
1185
1186 The Kconfig utility does some basic syntax checking on the Kconfig tree.
1187 Running "make oldconfig" will show any errors that the Kconfig utility
1188 sees.
1189
1190 ### util/kconfig_lint
1191
1192 Because the Kconfig utility is relatively forgiving, and ignores issues that a
1193 developer might be interested in, kconfig_lint, another Kconfig checker has been
1194 written.
1195
1196 The file kconfig_lint and its associated readme can be found in the coreboot
1197 utils/lint directory. It is useful for parsing the Kconfig tree, and for
1198 showing warnings, errors, and notes about coreboot’s Kconfig files.
1199
1200
1201 kconfig_lint <options>
1202 -o|--output=file Set output filename
1203 -p|--print Print full output
1204 -e|--errors_off Don't print warnings or errors
1205 -w|--warnings_off Don't print warnings
1206 -n|--notes Show minor notes
1207 --path=dir Path to top level kconfig
1208 -c|--config=file Filename of config file to load
1209 -G|--no_git_grep Use standard grep tools instead of git grep
1210
1211
1212 The -p option is very useful for debugging Kconfig issues, because it reads all
1213 of the Kconfig files in the order that the Kconfig tools would read them, and
1214 prints it out, along with where each line came from and which menu it appears
1215 in.
1216
1217 ## License:
1218 This work is licensed under the Creative Commons Attribution 4.0 International
1219 License. To view a copy of this license, visit
1220 <https://creativecommons.org/licenses/by/4.0/> or send a letter to Creative
1221 Commons, PO Box 1866, Mountain View, CA 94042, USA.
1222
1223 Code examples snippets are licensed under GPLv2, and are used here under fair
1224 use laws.