Part 1
요약·해설
prj.conf, CONF_FILE, board·SoC fragment, Kconfig.defconfig의 역할과 우선순위를 설명합니다.
Prompt 있음
Default · select
Board · CMake · App
zephyr/.config
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
30E999124BB4CD7847849CD7BC3386405A99D82B57AB32EB396FC58F3BF54458
.. _setting_configuration_values:
Setting Kconfig configuration values
####################################
The :ref:`menuconfig and guiconfig interfaces <menuconfig>` can be used to test
out configurations during application development. This page explains how to
make settings permanent.
All Kconfig options can be searched in the :ref:`Kconfig search page
<kconfig-search>`.
.. note::
Before making changes to Kconfig files, it's a good idea to also go through
the :ref:`kconfig_tips_and_tricks` page.
Visible and invisible Kconfig symbols
*************************************
When making Kconfig changes, it's important to understand the difference
between *visible* and *invisible* symbols.
- A visible symbol is a symbol defined with a prompt. Visible symbols show
up in the interactive configuration interfaces (hence *visible*), and can be
set in configuration files.
Here's an example of a visible symbol:
.. code-block:: kconfig
config FPU
bool "Support floating point operations"
depends on HAS_FPU
The symbol is shown like this in ``menuconfig``, where it can be toggled:
.. code-block:: none
[ ] Support floating point operations
- An *invisible* symbol is a symbol without a prompt. Invisible symbols are
not shown in the interactive configuration interfaces, and users have no
direct control over their value. They instead get their value from defaults
or from other symbols.
Here's an example of an invisible symbol:
.. code-block:: kconfig
config CPU_HAS_FPU
bool
help
This symbol is y if the CPU has a hardware floating point unit.
In this case, ``CPU_HAS_FPU`` is enabled through other symbols having
``select CPU_HAS_FPU``.
Setting symbols in configuration files
**************************************
Visible symbols can be configured by setting them in configuration files. The
initial configuration is produced by merging a :file:`*_defconfig` file for the
board with application settings, usually from :file:`prj.conf`. See
:ref:`initial-conf` below for more details.
Assignments in configuration files use this syntax:
.. code-block:: cfg
CONFIG_<symbol name>=<value>
There should be no spaces around the equals sign.
``bool`` symbols can be enabled or disabled by setting them to ``y`` or ``n``,
respectively. The ``FPU`` symbol from the example above could be enabled like
this:
.. code-block:: cfg
CONFIG_FPU=y
.. note::
A boolean symbol can also be set to ``n`` with a comment formatted like
this:
.. code-block:: cfg
# CONFIG_SOME_OTHER_BOOL is not set
This is the format you will see in the merged configuration in
:file:`zephyr/.config`.
This style is accepted for historical reasons: Kconfig configuration files
can be parsed as makefiles (though Zephyr doesn't use this). Having
``n``-valued symbols correspond to unset variables simplifies tests in Make.
Other symbol types are assigned like this:
.. code-block:: cfg
CONFIG_SOME_STRING="cool value"
CONFIG_SOME_INT=123
Comments use a #:
.. code-block:: cfg
# This is a comment
Assignments in configuration files are only respected if the dependencies for
the symbol are satisfied. A warning is printed otherwise. To figure out what
the dependencies of a symbol are, use one of the :ref:`interactive
configuration interfaces <menuconfig>` (you can jump directly to a symbol with
:kbd:`/`), or look up the symbol in the :ref:`Kconfig search page
<kconfig-search>`.
.. _initial-conf:
The Initial Configuration
*************************
The initial configuration for an application comes from merging configuration
settings from three sources:
1. A ``BOARD``-specific configuration file stored in
:file:`boards/<VENDOR>/<BOARD>/<BOARD>_defconfig`
2. Any CMake cache entries prefix with ``CONFIG_``
3. The application configuration
The application configuration can come from the sources below (each file is
known as a Kconfig fragment, which are then merged to get the final
configuration used for a particular build). By default, :file:`prj.conf` is
used.
#. If ``CONF_FILE`` is set, the configuration file(s) specified in it are
merged and used as the application configuration. ``CONF_FILE`` can be set
in various ways:
1. In :file:`CMakeLists.txt`, before calling ``find_package(Zephyr)``
2. By passing ``-DCONF_FILE=<conf file(s)>``, either directly or via ``west``
3. From the CMake variable cache
Furthermore if ``CONF_FILE`` is set as single configuration file of the
form :file:`prj_<build>.conf` and if file
:file:`boards/<BOARD>_<build>.conf` exists in same folder as file
:file:`prj_<build>.conf`, the result of merging :file:`prj_<build>.conf` and
:file:`boards/<BOARD>_<build>.conf` is used - note that this feature is
deprecated, :ref:`application-file-suffixes` should be used instead.
#. Otherwise, if :file:`boards/<BOARD>.conf` exists in the application
configuration directory, the result of merging it with :file:`prj.conf` is
used.
#. Otherwise, if board revisions are used and
:file:`boards/<BOARD>_<revision>.conf` exists in the application
configuration directory, the result of merging it with :file:`prj.conf` and
:file:`boards/<BOARD>.conf` is used.
#. Otherwise, :file:`prj.conf` is used from the application configuration
directory. If it does not exist then a fatal error will be emitted.
Furthermore, applications can have SoC overlay configuration that is applied to
it, the file :file:`socs/<SOC>_<BOARD_QUALIFIERS>.conf` will be applied if it exists,
after the main project configuration has been applied and before any board overlay
configuration files have been applied.
All configuration files will be taken from the application's configuration
directory except for files with an absolute path that are given with the
``CONF_FILE``, ``EXTRA_CONF_FILE``, ``DTC_OVERLAY_FILE``, and
``EXTRA_DTC_OVERLAY_FILE`` arguments. For these,
a file in a Zephyr module can be referred by escaping the Zephyr module dir
variable like this ``\${ZEPHYR_<module>_MODULE_DIR}/<path-to>/<file>``
when setting any of said variables in the application's :file:`CMakeLists.txt`.
See :ref:`Application Configuration Directory <application-configuration-directory>`
on how the application configuration directory is defined.
If a symbol is assigned both in :file:`<BOARD>_defconfig` and in the
application configuration, the value set in the application configuration takes
precedence.
The merged configuration is saved to :file:`zephyr/.config` in the build
directory.
As long as :file:`zephyr/.config` exists and is up-to-date (is newer than any
``BOARD`` and application configuration files), it will be used in preference
to producing a new merged configuration. :file:`zephyr/.config` is also the
configuration that gets modified when making changes in the :ref:`interactive
configuration interfaces <menuconfig>`.
Tracking Kconfig symbols
************************
It is possible to create Kconfig symbols which takes the default value of
another Kconfig symbol.
This is valuable when you want a symbol specific to an application or subsystem
but do not want to rely directly on the common symbol. For example, you might
want to decouple the settings so they can be independently configured, or to
ensure you always have a locally named setting, even if the external setting name changes.
is later changed.
For example, consider the common ``FOO_STRING`` setting where a subsystem wants
to have a ``SUB_FOO_STRING`` but still allow for customization.
This can be done like this:
.. code-block:: kconfig
config FOO_STRING
string "Foo"
default "foo"
config SUB_FOO_STRING
string "Sub-foo"
default FOO_STRING
This ensures that the default value of ``SUB_FOO_STRING`` is identical to
``FOO_STRING`` while still allows users to configure both settings
independently.
It is also possible to make ``SUB_FOO_STRING`` invisible and thereby keep the
two symbols in sync, unless the value of the tracking symbol is changed in a
:file:`defconfig` file.
.. code-block:: kconfig
config FOO_STRING
string "Foo"
default "foo"
config SUB_FOO_STRING
string
default FOO_STRING
help
Hidden symbol which follows FOO_STRING
Can be changed through *.defconfig files.
Configuring invisible Kconfig symbols
*************************************
When making changes to the default configuration for a board, you might have to
configure invisible symbols. This is done in
:file:`boards/<VENDOR>/<BOARD>/Kconfig.defconfig`, which is a regular
:file:`Kconfig` file.
.. note::
Assignments in :file:`.config` files have no effect on invisible symbols,
so this scheme is not just an organizational issue.
Assigning values in :file:`Kconfig.defconfig` relies on defining a Kconfig
symbol in multiple locations. As an example, say we want to set ``FOO_WIDTH``
below to 32:
.. code-block:: kconfig
config FOO_WIDTH
int
To do this, we extend the definition of ``FOO_WIDTH`` as follows, in
:file:`Kconfig.defconfig`:
.. code-block:: kconfig
if BOARD_MY_BOARD
config FOO_WIDTH
default 32
endif
.. note::
Since the type of the symbol (``int``) has already been given at the first
definition location, it does not need to be repeated here. Only giving the
type once at the "base" definition of the symbol is a good idea for reasons
explained in :ref:`kconfig_shorthands`.
``default`` values in :file:`Kconfig.defconfig` files have priority over
``default`` values given on the "base" definition of a symbol. Internally, this
is implemented by including the :file:`Kconfig.defconfig` files first. Kconfig
uses the first ``default`` with a satisfied condition, where an empty condition
corresponds to ``if y`` (is always satisfied).
Note that conditions from surrounding top-level ``if``\ s are propagated to
symbol properties, so the above ``default`` is equivalent to
``default 32 if BOARD_MY_BOARD``.
.. _multiple_symbol_definitions:
Multiple symbol definitions
---------------------------
When a symbol is defined in multiple locations, each definition acts as an
independent symbol that happens to share the same name. This means that
properties are not appended to previous definitions. If the conditions
for **ANY** definition result in the symbol resolving to ``y``, the symbol
will be ``y``. It is therefore not possible to make the dependencies of a
symbol more restrictive by defining it in multiple locations.
For example, the dependencies of the symbol ``FOO`` below are satisfied if
either ``DEP1`` **OR** ``DEP2`` are true, it does not require both:
.. code-block:: none
config FOO
...
depends on DEP1
config FOO
...
depends on DEP2
.. warning::
Symbols without explicit dependencies still follow the above rule. A
symbol without any dependencies will result in the symbol always being
assignable. The definition below will result in ``FOO`` always being
enabled by default, regardless of the value of ``DEP1``.
.. code-block:: kconfig
config FOO
bool "FOO"
depends on DEP1
config FOO
default y
This dependency weakening can be avoided with the :ref:`configdefault
<kconfig_extensions>` extension if the desire is only to add a new default
without modifying any other behaviour of the symbol.
.. note::
When making changes to :file:`Kconfig.defconfig` files, always check the
symbol's direct dependencies in one of the :ref:`interactive configuration
interfaces <menuconfig>` afterwards. It is often necessary to repeat
dependencies from the base definition of the symbol to avoid weakening a
symbol's dependencies.
Motivation for Kconfig.defconfig files
--------------------------------------
One motivation for this configuration scheme is to avoid making fixed
``BOARD``-specific settings configurable in the interactive configuration
interfaces. If all board configuration were done via :file:`<BOARD>_defconfig`,
all symbols would have to be visible, as values given in
:file:`<BOARD>_defconfig` have no effect on invisible symbols.
Having fixed settings be user-configurable would clutter up the configuration
interfaces and make them harder to understand, and would make it easier to
accidentally create broken configurations.
When dealing with fixed board-specific settings, also consider whether they
should be handled via :ref:`devicetree <dt-guide>` instead.
Configuring choices
-------------------
There are two ways to configure a Kconfig ``choice``:
1. By setting one of the choice symbols to ``y`` in a configuration file.
Setting one choice symbol to ``y`` automatically gives all other choice
symbols the value ``n``.
If multiple choice symbols are set to ``y``, only the last one set to ``y``
will be honored (the rest will get the value ``n``). This allows a choice
selection from a board :file:`defconfig` file to be overridden from an
application :file:`prj.conf` file.
2. By changing the ``default`` of the choice in :file:`Kconfig.defconfig`.
As with symbols, changing the default for a choice is done by defining the
choice in multiple locations. For this to work, the choice must have a name.
As an example, assume that a choice has the following base definition (here,
the name of the choice is ``FOO``):
.. code-block:: kconfig
choice FOO
bool "Foo choice"
default B
config A
bool "A"
config B
bool "B"
endchoice
To change the default symbol of ``FOO`` to ``A``, you would add the
following definition to :file:`Kconfig.defconfig`:
.. code-block:: kconfig
choice FOO
default A
endchoice
The :file:`Kconfig.defconfig` method should be used when the dependencies of
the choice might not be satisfied. In that case, you're setting the default
selection whenever the user makes the choice visible.
More Kconfig resources
======================
The :ref:`kconfig_tips_and_tricks` page has some tips for writing Kconfig
files.
The :zephyr_file:`kconfiglib.py <scripts/kconfig/kconfiglib.py>` docstring
(at the top of the file) goes over how symbol values are calculated in detail.
Part 3
한국어 전문 번역
Kconfig 값을 영구 설정하는 방법
menuconfig와 guiconfig는 application 개발 중 configuration을 시험하는 데 유용합니다. 이 문서는 시험한 값을 영구 설정하는 방법을 설명합니다. 모든 option은 Kconfig 검색 페이지에서 찾을 수 있으며, Kconfig file을 바꾸기 전에는 작성 tip과 best practice도 확인하는 것이 좋습니다.
Visible symbol과 invisible symbol
Kconfig를 변경할 때 prompt가 있는 visible symbol과 prompt가 없는 invisible symbol의 차이를 이해해야 합니다.
Visible symbol
Prompt로 정의한 symbol은 interactive configuration interface에 나타나며 configuration file에서도 설정할 수 있습니다.
config FPU
bool "Support floating point operations"
depends on HAS_FPUmenuconfig에서는 다음처럼 toggle 가능한 항목으로 보입니다.
[ ] Support floating point operationsInvisible symbol
Prompt가 없는 symbol은 interface에 표시되지 않고 user가 값을 직접 제어할 수 없습니다. Default나 다른 symbol에서 값을 받습니다.
config CPU_HAS_FPU
bool
help
This symbol is y if the CPU has a hardware floating point unit.이 예제의 CPU_HAS_FPU는 다른 symbol의 select CPU_HAS_FPU에 의해 enable됩니다.
Configuration file에서 symbol 설정
Visible symbol은 configuration file에서 설정합니다. 초기 configuration은 board의 *_defconfig와 보통 prj.conf에 있는 application 설정을 merge해 만듭니다.
Assignment 문법은 다음과 같고 equals sign 양쪽에 공백을 넣으면 안 됩니다.
CONFIG_<symbol name>=<value>bool symbol은 y로 enable하고 n으로 disable합니다.
CONFIG_FPU=yBoolean을 n으로 설정하는 역사적 comment 형식도 허용되며 merge 결과인 zephyr/.config에서 이 형식을 볼 수 있습니다.
# CONFIG_SOME_OTHER_BOOL is not setKconfig configuration file을 makefile로 parse할 수 있었던 역사 때문에 unset variable이 n을 나타내는 이 형식이 남아 있습니다. Zephyr 자체는 이 방식으로 Make를 사용하지 않습니다.
String과 integer는 다음처럼 값을 씁니다.
CONFIG_SOME_STRING="cool value"
CONFIG_SOME_INT=123Comment는 hash sign으로 시작합니다.
# This is a commentSymbol dependency가 충족될 때만 assignment가 적용됩니다. 그렇지 않으면 warning이 출력됩니다. Dependency는 menuconfig에서 /로 symbol에 jump하거나 Kconfig 검색 페이지에서 확인합니다.
초기 configuration의 merge 순서
Application 초기 configuration은 다음 세 source를 merge합니다.
boards/<VENDOR>/<BOARD>/<BOARD>_defconfig의 board별 설정- 이름이
CONFIG_으로 시작하는 CMake cache entry - Application configuration
Application configuration은 여러 Kconfig fragment를 merge해 만들며 기본은 prj.conf입니다. 선택 규칙은 다음과 같습니다.
CONF_FILE이 설정되면 지정한 file들을 merge합니다.CMakeLists.txt에서find_package(Zephyr)호출 전, command line의-DCONF_FILE=..., 또는 CMake variable cache로 설정할 수 있습니다.CONF_FILE이 단일prj_<build>.conf이고 같은 folder에boards/<BOARD>_<build>.conf가 있으면 둘을 merge합니다. 이 기능은 deprecated이며 application file suffix를 사용해야 합니다.- 그렇지 않고 application configuration directory에
boards/<BOARD>.conf가 있으면prj.conf와 merge합니다. - Board revision을 사용하고
boards/<BOARD>_<revision>.conf가 있으면prj.conf와 board·revision fragment를 merge합니다. - 그 밖에는 application configuration directory의
prj.conf를 사용하며 file이 없으면 fatal error가 발생합니다.
Application에는 SoC overlay configuration도 적용할 수 있습니다. socs/<SOC>_<BOARD_QUALIFIERS>.conf가 있으면 main project configuration 뒤, board overlay configuration 전에 적용합니다.
Absolute path로 넘긴 CONF_FILE, EXTRA_CONF_FILE, DTC_OVERLAY_FILE, EXTRA_DTC_OVERLAY_FILE을 제외한 configuration file은 application configuration directory에서 찾습니다. Module file은 CMakeLists.txt에서 ${ZEPHYR_<module>_MODULE_DIR}/<path>/<file>처럼 module directory variable을 escape해 참조할 수 있습니다.
같은 symbol이 <BOARD>_defconfig와 application configuration에 모두 있으면 application 값이 우선합니다. Merge 결과는 build directory의 zephyr/.config에 저장됩니다.
zephyr/.config가 존재하고 board·application fragment보다 새로우면 새 merge 결과를 만들지 않고 기존 file을 우선 사용합니다. Interactive interface에서 바뀌는 file도 이 zephyr/.config입니다.
다른 Kconfig symbol을 추적하는 symbol
Application이나 subsystem 전용 symbol이 공통 symbol의 default 값을 따라가게 만들 수 있습니다. 두 설정을 나중에 독립 구성하거나 외부 symbol 이름이 바뀌어도 local 이름을 유지하고 싶을 때 유용합니다.
config FOO_STRING
string "Foo"
default "foo"
config SUB_FOO_STRING
string "Sub-foo"
default FOO_STRINGSUB_FOO_STRING의 default는 FOO_STRING과 같지만 user는 두 값을 독립적으로 바꿀 수 있습니다. Tracking symbol을 invisible로 만들면 defconfig에서 별도 값을 주지 않는 한 계속 동기화할 수 있습니다.
config FOO_STRING
string "Foo"
default "foo"
config SUB_FOO_STRING
string
default FOO_STRING
help
Hidden symbol which follows FOO_STRING
Can be changed through *.defconfig files.Invisible symbol 구성
Board의 default configuration을 바꿀 때 invisible symbol을 설정해야 할 수 있습니다. 일반 Kconfig file인 boards/<VENDOR>/<BOARD>/Kconfig.defconfig에서 처리합니다. .config assignment는 invisible symbol에 아무 효과가 없습니다.
예를 들어 base definition의 FOO_WIDTH가 다음과 같다고 하겠습니다.
config FOO_WIDTH
int특정 board에서 32로 만들려면 Kconfig.defconfig에서 정의를 확장합니다.
if BOARD_MY_BOARD
config FOO_WIDTH
default 32
endifSymbol type은 base definition에 이미 있으므로 반복하지 않는 것이 좋습니다. Kconfig.defconfig의 default가 base definition의 default보다 우선하는 이유는 이 file들이 먼저 include되고, Kconfig가 condition을 만족하는 첫 default를 사용하기 때문입니다. 빈 condition은 항상 참인 if y입니다.
바깥 if condition은 symbol property에 전달되므로 위 default는 default 32 if BOARD_MY_BOARD와 같습니다.
Symbol을 여러 위치에서 정의할 때
각 정의는 같은 이름을 공유하지만 독립된 symbol처럼 작동합니다. Property가 이전 정의에 단순 append되는 것이 아니며, 어느 한 정의의 condition이라도 y가 되면 symbol이 y가 될 수 있습니다. 따라서 여러 정의로 dependency를 더 엄격하게 만들 수 없습니다.
config FOO
...
depends on DEP1
config FOO
...
depends on DEP2위 FOO는 DEP1과 DEP2가 모두 아니라 둘 중 하나만 true여도 dependency가 충족됩니다.
config FOO
bool "FOO"
depends on DEP1
config FOO
default yDefault만 추가하려는 목적이라면 다른 behavior와 dependency를 바꾸지 않는 configdefault 확장으로 약화를 피할 수 있습니다. Kconfig.defconfig을 수정한 뒤에는 menuconfig에서 direct dependency를 반드시 확인하고, base definition의 dependency를 반복해야 하는지 검토합니다.
Kconfig.defconfig을 쓰는 이유
Board에 고정된 설정을 interactive interface에 불필요하게 노출하지 않기 위해서입니다. 모든 board 설정을 <BOARD>_defconfig으로만 하면 invisible symbol에는 값이 적용되지 않아 모든 symbol을 visible로 만들어야 합니다. 그러면 interface가 복잡해지고 깨진 configuration을 만들기 쉬워집니다. 고정 hardware 설정이라면 Kconfig 대신 Devicetree가 더 적절한지도 확인해야 합니다.
Choice 구성
Kconfig choice는 두 방식으로 구성합니다.
- Configuration file에서 choice symbol 하나를
y로 설정합니다. 나머지는 자동으로n이 됩니다. 여러 symbol이y면 마지막 assignment만 적용되어 board defconfig의 선택을 applicationprj.conf가 override할 수 있습니다. Kconfig.defconfig에서 choice의default를 바꿉니다. 여러 위치에서 다시 정의하려면 choice에 이름이 있어야 합니다.
이름이 FOO인 base choice가 다음과 같다고 하겠습니다.
choice FOO
bool "Foo choice"
default B
config A
bool "A"
config B
bool "B"
endchoiceDefault를 A로 바꾸려면 Kconfig.defconfig에 다음을 추가합니다.
choice FOO
default A
endchoiceChoice dependency가 항상 충족되지 않을 수 있다면 Kconfig.defconfig 방식이 적합합니다. User가 choice를 visible하게 만들었을 때 적용할 기본 선택을 정의하기 때문입니다.
추가 자료
Kconfig 작성 tip 문서는 실전 권장 사항을 제공하며 scripts/kconfig/kconfiglib.py 첫 부분의 docstring은 symbol 값 계산 방식을 자세히 설명합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.