Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for embedding devicetree into UKI #2440

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,11 @@ def build_uki(
"--ro-bind", stub, stub,
]

if context.config.devicetree:
dtb = context.root / f"usr/lib/linux-image-{kver}" / context.config.devicetree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably be some checking here for the case that the file does not exist in the image.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "other" options like e.g. initrds also do not check the existence of the files.

If a non existing dtb will be configured the current output looks like this:

‣  Generating unified kernel image for kernel version 6.6.15-arm64
bwrap: Can't find source path /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/linux-image-6.6.15-arm64/idonot/exist.dtb: No such file or directory
bwrap: Can't find source path /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/linux-image-6.6.15-arm64/idonot/exist.dtb: No such file or directory
‣ "/usr/bin/ukify --cmdline @/home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/cmdline --os-release @/home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/os-release --stub /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/systemd/boot/efi/linuxaa64.efi.stub --output /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/boot/EFI/Linux/debian-6.6.15-arm64.efi --efi-arch aa64 --uname 6.6.15-arm64 --devicetree /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/linux-image-6.6.15-arm64/idonot/exist.dtb --sign-kernel --signtool sbsign --secureboot-private-key /home/manut/qemu/mkosi.key --secureboot-certificate /home/manut/qemu/mkosi.crt --pcr-private-key /home/manut/qemu/mkosi.key --pcr-banks sha1,sha256 build --linux /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/root/usr/lib/modules/6.6.15-arm64/vmlinuz --initrd /home/manut/.cache/mkosi/mkosi-workspaceuw1qmalv/initrd/image.raw-initrd" returned non-zero exit code 1.

Shall we fail with a nicer looking message?

Copy link
Contributor

@DaanDeMeyer DaanDeMeyer Mar 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a completely arbitrary location to me for putting device trees. Is there any kind of spec mandating that this is where device trees should be installed? If not, we need such a spec first. See for example uapi-group/specifications#91 where a standard location for UKI addons is proposed. We'd need such a proposal for device trees as well.

Until then, I'd prefer if you used a ukify config file in a package manager tree to accomplish this.

cmd += ["--devicetree", dtb]
options += ["--ro-bind", dtb, dtb]

if context.config.secure_boot:
assert context.config.secure_boot_key
assert context.config.secure_boot_certificate
Expand Down
8 changes: 8 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ class Config:
initrds: list[Path]
initrd_packages: list[str]
microcode_host: bool
devicetree: Optional[Path]
kernel_command_line: list[str]
kernel_modules_include: list[str]
kernel_modules_exclude: list[str]
Expand Down Expand Up @@ -2134,6 +2135,12 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
parse=config_make_list_parser(delimiter=","),
help="Add additional packages to the default initrd",
),
ConfigSetting(
dest="devicetree",
section="Content",
parse=config_parse_string,
manut marked this conversation as resolved.
Show resolved Hide resolved
help="Devicetree included in UKI",
),
ConfigSetting(
dest="kernel_command_line",
metavar="OPTIONS",
Expand Down Expand Up @@ -3548,6 +3555,7 @@ def bold(s: Any) -> str:
Shim Bootloader: {config.shim_bootloader}
Initrds: {line_join_list(config.initrds)}
Initrd Packages: {line_join_list(config.initrd_packages)}
Devicetree: {config.devicetree}
Kernel Command Line: {line_join_list(config.kernel_command_line)}
Kernel Modules Include: {line_join_list(config.kernel_modules_include)}
Kernel Modules Exclude: {line_join_list(config.kernel_modules_exclude)}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_config() -> None:
"Dependencies": [
"dep1"
],
"Devicetree": "freescale/imx8mm-verdin-nonwifi-dev.dtb",
"Distribution": "fedora",
"Environment": {},
"EnvironmentFiles": [],
Expand Down Expand Up @@ -320,6 +321,7 @@ def test_config() -> None:
compress_output = Compression.bz2,
credentials = {"credkey": "credval"},
dependencies = ("dep1",),
devicetree = Path("freescale/imx8mm-verdin-nonwifi-dev.dtb"),
distribution = Distribution.fedora,
environment = {},
environment_files = [],
Expand Down
Loading