Kconfig は Linux カーネル設定を構築するための選択肢を記述します。カーネル開発者は Kconfig ファイルを編集してシンボルとその関係を定義し、
ユーザーは make menuconfig、make nconfig、make xconfig、または olddefconfig などの非対話的ターゲットで値を選択します。
生成された .config は Kbuild への入力であり、完全なビルドスクリプトではありません。設定同期は Make と C が消費するファイルを生成し、
include/config/auto.conf と include/generated/autoconf.h もその中に含まれます。
ルートファイルから 1 つの設定へ #
解析はトップレベルの Kconfig から始まります。source 文がサブシステムファイルを含め、アーキテクチャ選択が arch/$(SRCARCH)/Kconfig を取り込みます。
その他のインクルード形式は次のとおりです。
rsource: パスがインクルード元ファイルからの相対になる。osource: ファイルがない場合に無視する。orsource: 相対指定と任意指定を組み合わせる。
mainmenu はフロントエンドのタイトルを設定します。menu/endmenu、if/endif、choice/endchoice、comment、config、menuconfig がエントリー構造を構築します。
同じシンボルを複数のインクルードファイルで定義できます。Kconfig はシンボルのプロパティを結合し、アーキテクチャローカル変数を作成しません。 定義は一貫した型を使い、依存関係節は累積し、既定値の順序は依然として重要です。 そのため共通ファイルが不可視の機能を宣言し、アーキテクチャ定義がそれを select できます。
# lib/Kconfig
config HAVE_FAST_CHECKSUM
bool
config FAST_CHECKSUM
bool "Use the generic fast checksum implementation"
depends on HAVE_FAST_CHECKSUM
# arch/example/Kconfig
config EXAMPLE
bool
select HAVE_FAST_CHECKSUMHAVE_* symbols express implementation capability. A user-visible feature then depends on that capability, which avoids using select to bypass the feature’s real dependencies.
マクロとプリプロセッサー層 #
Kconfig はメニューエントリー言語が行を消費する前にテキスト展開を行います。変数構文は Make に似ています。
immediate := $(ARCH)
deferred = $(ARCH)
message = architecture $(1), compiler $(2)
$(info,configuring $(immediate))
label := $(message,$(ARCH),$(CC))
:=は右辺を直ちに展開する。=は再帰展開される値を保存する。+=は変数の既存の展開形式に従って追加する。$(name)は変数を展開する。$(name,arg1,arg2)はパラメーター化変数を展開し、$(1)、$(2)などが位置引数になる。
Make と異なり、パラメーター化された Kconfig 変数は直接呼び出し、$(call ...) はありません。コンマが関数引数を区切ります。
組み込み関数には shell、info、warning-if、error-if、filename、lineno があります。
カーネルは Kconfig 関数機構を通じてコンパイラーオプション検査などの関数を追加します。
Macro expansion is textual, so quoting and whitespace remain significant to the language that receives the result. Use preprocessing for small repeated expressions and feature probes rather than generating large, difficult-to-audit menu fragments.
シンボル、型、プロンプト #
config NAME は NAME というシンボルを定義し、.config と C では CONFIG_NAME として公開します。
menuconfig は同じ種類のシンボルを定義しますが、対応するフロントエンドにそのエントリーがサブメニューを含むことを伝えます。
利用できるシンボル型は 5 つです。
| 型 | .config の例 | 生成される C 形式 |
|---|---|---|
bool | CONFIG_FOO=y または # CONFIG_FOO is not set | #define CONFIG_FOO 1 または不在 |
tristate | CONFIG_FOO=y、CONFIG_FOO=m、または未設定 | CONFIG_FOO、CONFIG_FOO_MODULE、またはいずれもなし |
string | CONFIG_FOO="value" | 引用符付き文字列マクロ |
int | CONFIG_FOO=42 | 整数マクロ |
hex | CONFIG_FOO=0x2a | 16 進整数マクロ |
bool "Enable foo" and tristate "Build foo" combine a type with a prompt. A symbol without a visible prompt is not editable in a configuration front end, although defaults, select, or other expressions can still give it a value.
config FOO
tristate "Foo transport"
depends on NET
default m if MODULES
help
Build support for the Foo transport.def_bool EXPR and def_tristate EXPR are shorthands for a type plus default EXPR. range MIN MAX limits an int or hex symbol when its optional condition is true.
tristate 式 #
論理 Kconfig 式は順序付きの値 n = 0、m = 1、y = 2 を使います。したがって、
A && Bは 2 値の最小値。A || Bは最大値。!Aは2 - A。
Comparisons produce a tristate result. Parentheses control grouping, and quoted literals represent string values. A bool cannot retain m; module-related expressions collapse according to the symbol type and whether modules are enabled.
Direct dependencies impose an upper bound:
config USB_WIDGET
tristate "USB widget"
depends on USB && HAS_IOMEMIf USB=m, USB_WIDGET cannot become y. The optional condition on a prompt affects whether the prompt is visible, while the symbol’s direct dependencies constrain its value regardless of front-end presentation.
既定値、逆依存関係、可視性 #
プロパティは異なる問題を解決します。
default VALUE if CONDITIONはユーザーがまだ設定していない場合にだけ値を提供する。複数の既定値が可視なら最初の可視値が勝つ。 既存.configから保持された値を既定値が上書きすることはない。depends on EXPRはシンボルの最大値とプロンプトの可視性を制限する。select TARGET if CONDITIONは逆依存関係を作り、TARGETを選択式の値以上に引き上げる。TARGET自身の直接依存関係は尊重しないため、 前提条件が保証された単純で不可視のシンボルだけを select する。imply TARGET if CONDITIONは弱い逆依存関係である。可視のユーザー選択で減らせる下限を提供し、ターゲットの直接依存関係は結果を引き続き上限設定する。visible if EXPRは内部のシンボル値を変更せずにmenuブロックの可視性を制限する。
For example:
config DRIVER_FOO
tristate "Foo device"
depends on PCI
select CRC32
imply FW_LOADERCRC32 should be an internal helper with no unmet dependencies. FW_LOADER is merely encouraged because the driver can operate without it. Adding select to repair a dependency cycle is incorrect because Kconfig rejects recursive dependencies and does not use a SAT solver to infer a preferred solution.
メニュー位置は依存関係グラフではない #
Source order and explicit containers determine most displayed positions:
menu "Network drivers"
visible if NET
config NET_VENDOR_EXAMPLE
bool "Example devices"
if NET_VENDOR_EXAMPLE
source "drivers/net/ethernet/example/Kconfig"
endif
endmenuFront ends also infer an implicit submenu when a later entry depends on the preceding entry strongly enough that the child cannot be visible unless the parent is visible. The language documentation describes the precise prompt-dependency rule.
依存関係がエントリーを別の場所へ移動させることはありません。シンボルは別セクションに表示されたシンボルへ依存でき、
select もターゲットをセレクターの下に表示しません。したがってメニューレイアウトはナビゲーションを伝え、
依存関係式は有効な値を伝えます。一方を他方の描画として扱うと、分かりにくい Kconfig ファイルになります。
生成される設定アーティファクト #
フロントエンドが .config を書き込んだ後、Kbuild は生成入力を同期します。重要な表現は次のとおりです。
.config
include/config/auto.conf
include/generated/autoconf.h.config は永続的なユーザー向け割り当てファイルです。auto.conf は Make に割り当てを提示するため、規則は次のような式を使えます。
obj-$(CONFIG_USB_WIDGET) += usb-widget.o
autoconf.h は有効なシンボルを C プリプロセッサーに提示します。カーネル C コードは autoconf.h を直接 include せず通常のカーネルヘッダーを含めます。
IS_ENABLED(CONFIG_FOO) などのヘルパーは、すべてのプリプロセッサー組み合わせを手書きせず、組み込みとモジュールの形式を処理します。
Configuration updates can add symbols introduced by a newer tree. make oldconfig asks about new choices, whereas make olddefconfig accepts their defaults. make savedefconfig writes a minimal defconfig relative to defaults; it is not interchangeable with archiving the full .config.
コメント
GitHub で閲覧・コメントする(投稿にはログインが必要です)