]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add support for building PE addons 3074/head
authorMichael Ferrari <nekkodroid404@gmail.com>
Sat, 28 Sep 2024 22:35:47 +0000 (00:35 +0200)
committerMichael Ferrari <nekkodroid404@gmail.com>
Sat, 28 Sep 2024 22:38:58 +0000 (00:38 +0200)
mkosi/__init__.py
mkosi/config.py
mkosi/resources/man/mkosi.md
tests/test_json.py

index edcde2320608f3556a4da01537b37bd33a872fee..fb87670f554edd7f2c8233f898c8b1a51288e4ad 100644 (file)
@@ -1901,6 +1901,45 @@ def install_uki(
             f.write("fi\n")
 
 
+def build_pe_addon(context: Context, arch: str, stub: Path, config: Path, output: Path) -> None:
+    arguments: list[PathString] = [
+        "--config", config,
+    ]  # fmt: skip
+
+    options: list[PathString] = [
+        "--ro-bind", config, config,
+    ]  # fmt: skip
+
+    with complete_step(f"Generating PE addon /{output.relative_to(context.root)}"):
+        run_ukify(context, arch, stub, output, arguments, options)
+
+
+def install_pe_addons(context: Context) -> None:
+    if not context.config.pe_addons:
+        return
+
+    if not (arch := context.config.architecture.to_efi()):
+        die(f"Architecture {context.config.architecture} does not support UEFI")
+
+    stub = systemd_addon_stub_binary(context)
+    if not stub.exists():
+        die(f"sd-stub not found at /{stub.relative_to(context.root)} in the image")
+
+    addon_dir = context.root / "boot/loader/addons"
+    with umask(~0o755):
+        addon_dir.mkdir(parents=True, exist_ok=True)
+
+    for addon in context.config.pe_addons:
+        output = addon_dir / addon.with_suffix(".addon.efi").name
+        build_pe_addon(context, arch, stub, config=addon, output=output)
+
+
+def systemd_addon_stub_binary(context: Context) -> Path:
+    arch = context.config.architecture.to_efi()
+    stub = context.root / f"usr/lib/systemd/boot/efi/addon{arch}.efi.stub"
+    return stub
+
+
 def install_kernel(context: Context, partitions: Sequence[Partition]) -> None:
     # Iterates through all kernel versions included in the image and generates a combined
     # kernel+initrd+cmdline+osrelease EFI file from it and places it in the /EFI/Linux directory of
@@ -3369,6 +3408,7 @@ def build_image(context: Context) -> None:
         install_systemd_boot(context)
         install_grub(context)
         install_shim(context)
+        install_pe_addons(context)
         run_sysusers(context)
         run_tmpfiles(context)
         run_preset(context)
index 4ab7824a0fce78ca1ae534c798eba021173d3754..1822d44b4ca78043a5a31c3f609cf25c96a08e48 100644 (file)
@@ -1588,6 +1588,7 @@ class Config:
     shim_bootloader: ShimBootloader
     unified_kernel_images: ConfigFeature
     unified_kernel_image_format: str
+    pe_addons: list[Path]
     initrds: list[Path]
     initrd_packages: list[str]
     initrd_volatile_packages: list[str]
@@ -2552,6 +2553,15 @@ SETTINGS = (
         # default=
         help="Specify the format used for the UKI filename",
     ),
+    ConfigSetting(
+        dest="pe_addons",
+        long="--pe-addon",
+        metavar="PATH",
+        section="Content",
+        parse=config_make_list_parser(delimiter=",", parse=make_path_parser()),
+        recursive_paths=("mkosi.pe-addons/",),
+        help="Configuration files to generate PE addons",
+    ),
     ConfigSetting(
         dest="initrds",
         long="--initrd",
@@ -4479,6 +4489,7 @@ def summary(config: Config) -> str:
                     Shim Bootloader: {config.shim_bootloader}
               Unified Kernel Images: {config.unified_kernel_images}
         Unified Kernel Image Format: {config.unified_kernel_image_format}
+        Unified Kernel Image Addons: {line_join_list(config.pe_addons)}
                             Initrds: {line_join_list(config.initrds)}
                     Initrd Packages: {line_join_list(config.initrd_packages)}
            Initrd Volatile Packages: {line_join_list(config.initrd_volatile_packages)}
index 8c8531061c6882b68d3281498812e804555a164b..25945d50eca3958ea2378a5b530c94b040256b15 100644 (file)
@@ -984,6 +984,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     | `&h`      | `roothash=` or `usrhash=` value of kernel argument |
     | `&c`      | Number of tries used for boot attempt counting     |
 
+`PeAddons=`, `--pe-addon`
+:   Build additional PE addons. Takes a comma separated list of paths to
+    `ukify` config files. This option may be used multiple times in which case
+    each config gets built into a corresponding addon. Each addon has the name
+    of the config file, with the extension replaced with `.addon.efi`.
+    Config files in the `mkosi.pe-addons/` directory are automatically picked
+    up.
+
 `Initrds=`, `--initrd`
 :   Use user-provided initrd(s). Takes a comma separated list of paths to initrd
     files. This option may be used multiple times in which case the initrd lists
index 8b56e733482aa6b8e8caaab53984e8a476750516..c27e1102f0d15b948ec99202ee066d69216cae04 100644 (file)
@@ -207,6 +207,9 @@ def test_config() -> None:
                 "abc"
             ],
             "Passphrase": null,
+            "PeAddons": [
+                "/my-addon.conf"
+            ],
             "PostInstallationScripts": [
                 "/bar/qux"
             ],
@@ -442,6 +445,7 @@ def test_config() -> None:
         packages=[],
         pass_environment=["abc"],
         passphrase=None,
+        pe_addons=[Path("/my-addon.conf")],
         postinst_scripts=[Path("/bar/qux")],
         postoutput_scripts=[Path("/foo/src")],
         prepare_scripts=[Path("/run/foo")],