From: Michael Ferrari Date: Sat, 28 Sep 2024 22:35:47 +0000 (+0200) Subject: Add support for building PE addons X-Git-Tag: v25~261^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F3074%2Fhead;p=thirdparty%2Fmkosi.git Add support for building PE addons --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index edcde2320..fb87670f5 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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) diff --git a/mkosi/config.py b/mkosi/config.py index 4ab7824a0..1822d44b4 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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)} diff --git a/mkosi/resources/man/mkosi.md b/mkosi/resources/man/mkosi.md index 8c8531061..25945d50e 100644 --- a/mkosi/resources/man/mkosi.md +++ b/mkosi/resources/man/mkosi.md @@ -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 diff --git a/tests/test_json.py b/tests/test_json.py index 8b56e7334..c27e1102f 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -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")],