Heinrich Schuchardt | 72e365b | 2024-11-11 10:05:39 +0100 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
| 3 | Kconfig in U-Boot |
| 4 | ================= |
| 5 | |
| 6 | This document describes the configuration infrastructure of U-Boot. |
| 7 | |
| 8 | The conventional configuration was replaced by Kconfig at v2014.10-rc1 release. |
| 9 | |
| 10 | Language Specification |
| 11 | ---------------------- |
| 12 | |
| 13 | The Kconfig configuration language originates in Linux kernel. |
| 14 | See the Linux document |
| 15 | `Kconfig Language <https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html>`_ |
| 16 | for a description of Kconfig. |
| 17 | |
| 18 | Difference from Linux's Kconfig |
| 19 | ------------------------------- |
| 20 | |
| 21 | Here are some worth-mentioning configuration targets. |
| 22 | |
| 23 | silentoldconfig |
| 24 | This target updates .config, include/generated/autoconf.h and |
| 25 | include/configs/* as in Linux. In U-Boot, it also does the following |
| 26 | for the compatibility with the old configuration system: |
| 27 | |
| 28 | * create a symbolic link "arch/${ARCH}/include/asm/arch" pointing to |
| 29 | the SoC/CPU specific header directory |
| 30 | * create include/config.h |
| 31 | * create include/autoconf.mk |
| 32 | * create spl/include/autoconf.mk (SPL and TPL only) |
| 33 | * create tpl/include/autoconf.mk (TPL only) |
| 34 | |
| 35 | If we could completely switch to Kconfig in a long run |
| 36 | (i.e. remove all the include/configs/\*.h), those additional processings |
| 37 | above would be removed. |
| 38 | |
| 39 | defconfig |
| 40 | In U-Boot, "make defconfig" is a shorthand of "make sandbox_defconfig" |
| 41 | |
| 42 | <board>_defconfig |
| 43 | Now it works as in Linux. |
| 44 | The prefixes such as "+S:" in \*_defconfig are deprecated. |
| 45 | You can simply remove the prefixes. Do not add them for new boards. |
| 46 | |
| 47 | <board>_config |
| 48 | This does not exist in Linux's Kconfig. |
| 49 | "make <board>_config" works the same as "make <board>_defconfig". |
| 50 | Prior to Kconfig, in U-Boot, "make <board>_config" was used for the |
| 51 | configuration. It is still supported for backward compatibility, so |
| 52 | we do not need to update the distro recipes. |
| 53 | |
| 54 | The other configuration targets work as in Linux Kernel. |
| 55 | |
| 56 | Migration steps to Kconfig |
| 57 | -------------------------- |
| 58 | |
| 59 | Prior to Kconfig, the C preprocessor based board configuration had been used |
| 60 | in U-Boot. |
| 61 | |
| 62 | Although Kconfig was introduced and some configs have been moved to Kconfig, |
| 63 | many of configs are still defined in C header files. It will take a very |
| 64 | long term to move all of them to Kconfig. In the interim, the two different |
| 65 | configuration infrastructures should coexist. |
| 66 | The configuration files are generated by both Kconfig and the old preprocessor |
| 67 | based configuration as follows: |
| 68 | |
| 69 | Configuration files for use in C sources |
| 70 | - include/generated/autoconf.h (generated by Kconfig for Normal) |
| 71 | - include/configs/<board>.h (exists for all boards) |
| 72 | |
| 73 | Configuration file for use in makefiles |
| 74 | - include/config/auto.conf (generated by Kconfig) |
| 75 | - include/autoconf.mk (generated by the old config for Normal) |
| 76 | - spl/include/autoconfig.mk (generated by the old config for SPL) |
| 77 | - tpl/include/autoconfig.mk (generated by the old config for TPL) |
| 78 | |
| 79 | When adding a new CONFIG macro, it is highly recommended to add it to Kconfig |
| 80 | rather than to a header file. |
| 81 | |
| 82 | Conversion from boards.cfg to Kconfig |
| 83 | ------------------------------------- |
| 84 | |
| 85 | Prior to Kconfig, boards.cfg was a primary database that contained Arch, CPU, |
| 86 | SoC, etc. of all the supported boards. It was deleted when switching to |
| 87 | Kconfig. Each field of boards.cfg was converted as follows: |
| 88 | |
| 89 | =========== ==================================================== |
| 90 | From To |
| 91 | =========== ==================================================== |
| 92 | Arch CONFIG_SYS_ARCH defined by Kconfig |
| 93 | Board CONFIG_SYS_BOARD defined by Kconfig |
| 94 | CPU CONFIG_SYS_CPU defined by Kconfig |
| 95 | Maintainers "M:" entry of MAINTAINERS |
| 96 | SoC CONFIG_SYS_SOC defined by Kconfig |
| 97 | Status "S:" entry of MAINTAINERS |
| 98 | Target File name of defconfig (configs/<target>\_defconfig) |
| 99 | Vendor CONFIG_SYS_VENDOR defined by Kconfig |
| 100 | =========== ==================================================== |
| 101 | |
| 102 | Tips to add/remove boards |
| 103 | ------------------------- |
| 104 | |
| 105 | When adding a new board, the following steps are generally needed: |
| 106 | |
| 107 | 1. Add a header file include/configs/<target>.h |
| 108 | |
| 109 | 2. Make sure to define necessary CONFIG_SYS_* in Kconfig: |
| 110 | |
| 111 | * Define CONFIG_SYS_CPU="cpu" to compile arch/<arch>/cpu/<cpu> |
| 112 | * Define CONFIG_SYS_SOC="soc" to compile arch/<arch>/cpu/<cpu>/<soc> |
| 113 | * Define CONFIG_SYS_VENDOR="vendor" to compile board/<vendor>/common/\* |
| 114 | and board/<vendor>/<board>/\* |
| 115 | * Define CONFIG_SYS_BOARD="board" to compile board/<board>/\* |
| 116 | (or board/<vendor>/<board>/* if CONFIG_SYS_VENDOR is defined) |
| 117 | Define CONFIG_SYS_CONFIG_NAME="target" to include |
| 118 | include/configs/<target>.h |
| 119 | |
| 120 | 3. Add a new entry to the board select menu in Kconfig. |
| 121 | The board select menu is located in arch/<arch>/Kconfig or |
| 122 | arch/<arch>/\*/Kconfig. |
| 123 | |
| 124 | 4. Add a MAINTAINERS file |
| 125 | It is generally placed at board/<board>/MAINTAINERS or |
| 126 | board/<vendor>/<board>/MAINTAINERS |
| 127 | |
| 128 | 5. Add configs/<target>_defconfig |
| 129 | |
| 130 | When removing an obsolete board, the following steps are generally needed: |
| 131 | |
| 132 | 1. Remove configs/<target>_defconfig |
| 133 | |
| 134 | 2. Remove include/configs/<target>.h if it is not used by any other boards |
| 135 | |
| 136 | 3. Remove board/<vendor>/<board>/\* or board/<board>/\* if it is not used |
| 137 | by any other boards |
| 138 | |
| 139 | 4. Update MAINTAINERS if necessary |
| 140 | |
| 141 | 5. Remove the unused entry from the board select menu in Kconfig |
| 142 | |
| 143 | 6. Add an entry to doc/README.scrapyard |
| 144 | |
| 145 | TODO |
| 146 | ---- |
| 147 | |
| 148 | * In the pre-Kconfig, a single board had multiple entries in the boards.cfg |
| 149 | file with differences in the option fields. The corresponding defconfig |
| 150 | files were auto-generated when switching to Kconfig. Now we have too many |
| 151 | defconfig files compared with the number of the supported boards. It is |
| 152 | recommended to have only one defconfig per board and allow users to select |
| 153 | the config options. |
| 154 | |
| 155 | * Move the config macros in header files to Kconfig. When we move at least |
| 156 | macros used in makefiles, we can drop include/autoconfig.mk, which makes |
| 157 | the build scripts much simpler. |