Skip to content

Commit 82efab3

Browse files
committed
Add DevicetreeAutoDirectory option for dynamic DTB discovery
Adds DevicetreeAutoDirectory= config option to complement the DevicetreeAuto= list. This recursively scans the specified directory for .dtb files and includes them as .dtbauto sections in UKI builds. This is useful for when the full list of dtbs to include is not known at configuration time.
1 parent 258f8ad commit 82efab3

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

mkosi/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,16 +1585,22 @@ def find_devicetree(context: Context, kver: str) -> Path:
15851585
die(f"Requested devicetree {context.config.devicetree} not found")
15861586

15871587

1588-
def find_devicetrees_auto(context: Context, kver: str) -> list[Path]:
1588+
def find_devicetrees_auto(context: Context, kver: str, directory: Optional[Path] = None) -> list[Path]:
15891589
dtbs: list[Path] = []
15901590

1591+
# Search for any listed devicetrees
15911592
for d in (
15921593
context.root / f"usr/lib/firmware/{kver}/device-tree",
15931594
context.root / f"usr/lib/linux-image-{kver}",
15941595
context.root / f"usr/lib/modules/{kver}/dtb",
15951596
):
15961597
dtbs.extend(d.rglob("*.dtb"))
15971598

1599+
# Search for devicetrees in a given directory
1600+
if directory:
1601+
dtb_dir = context.root / os.fspath(directory).lstrip("/")
1602+
dtbs.extend(dtb_dir.rglob("*.dtb"))
1603+
15981604
return dtbs
15991605

16001606

@@ -1760,8 +1766,8 @@ def build_uki(
17601766
arguments += ["--devicetree", workdir(dtb)]
17611767
options += ["--ro-bind", dtb, workdir(dtb)]
17621768

1763-
if context.config.devicetree_auto:
1764-
dtbs_auto = find_devicetrees_auto(context, kver)
1769+
if context.config.devicetree_auto or context.config.devicetree_auto_directory:
1770+
dtbs_auto = find_devicetrees_auto(context, kver, context.config.devicetree_auto_directory)
17651771
for dtb in dtbs_auto:
17661772
arguments += ["--devicetree-auto", workdir(dtb)]
17671773
options += ["--ro-bind", dtb, workdir(dtb)]

mkosi/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,7 @@ class Config:
20152015
microcode_host: bool
20162016
devicetree: Optional[Path]
20172017
devicetree_auto: list[Path]
2018+
devicetree_auto_directory: Optional[Path]
20182019
splash: Optional[Path]
20192020
kernel_command_line: list[str]
20202021
kernel_modules_include: list[str]
@@ -3173,6 +3174,12 @@ def parse_kernel_module_filter_regexp(p: str) -> str:
31733174
parse=config_make_list_parser(delimiter=",", parse=make_path_parser(required=False)),
31743175
help="Devicetrees for automatic hardware-based selection in UKI builds",
31753176
),
3177+
ConfigSetting(
3178+
dest="devicetree_auto_directory",
3179+
section="Content",
3180+
parse=config_make_path_parser(required=False),
3181+
help="Directory containing devicetrees for automatic hardware-based selection",
3182+
),
31763183
ConfigSetting(
31773184
dest="splash",
31783185
section="Content",
@@ -5478,6 +5485,7 @@ def summary(config: Config) -> str:
54785485
Initrd Volatile Packages: {line_join_list(config.initrd_volatile_packages)}
54795486
Devicetree: {none_to_none(config.devicetree)}
54805487
Devicetree Auto: {line_join_list(config.devicetree_auto)}
5488+
Devicetree Auto Directory: {none_to_none(config.devicetree_auto_directory)}
54815489
Splash: {none_to_none(config.splash)}
54825490
Kernel Command Line: {line_join_list(config.kernel_command_line)}
54835491
Kernel Modules: {line_join_list(config.kernel_modules_include)}

mkosi/resources/man/mkosi.1.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
10891089
when both are specified. Only affects UKI builds; ignored for Type 1 boot
10901090
entries which support single devicetree only.
10911091

1092+
`DevicetreeAutoDirectory=`, `--devicetree-auto-directory=`
1093+
: Directory containing Devicetree blobs for automatic hardware-based selection
1094+
in UKI builds. All `.dtb` files found recursively in this directory are
1095+
included as `.dtbauto` sections. Results are merged with `DevicetreeAuto=`
1096+
list entries. Useful when DTB requirements are determined after
1097+
configuration time (e.g. in finalize.) Only affects UKI builds; ignored for
1098+
Type 1 boot entries which support single devicetree only.
1099+
10921100
`Splash=`, `--splash=`
10931101
: When set, the boot splash for any unified kernel image built by **mkosi** will
10941102
be picked up from the given path inside the image.

tests/test_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test_config() -> None:
155155
"vendor/board1.dtb",
156156
"vendor/board2.dtb"
157157
],
158+
"DevicetreeAutoDirectory": "boot/dtbs",
158159
"Distribution": "fedora",
159160
"Drives": [
160161
{
@@ -516,6 +517,7 @@ def test_config() -> None:
516517
microcode_host=True,
517518
devicetree=Path("freescale/imx8mm-verdin-nonwifi-dev.dtb"),
518519
devicetree_auto=[Path("vendor/board1.dtb"), Path("vendor/board2.dtb")],
520+
devicetree_auto_directory=Path("boot/dtbs"),
519521
minimum_version="123",
520522
mirror=None,
521523
nspawn_settings=None,

0 commit comments

Comments
 (0)