]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Create split pcrs file also when going through install_uki 3513/head
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 15 Feb 2025 00:58:41 +0000 (00:58 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 15 Feb 2025 13:03:37 +0000 (13:03 +0000)
This happens when building ParticleOS

Follow-up for 393b16cf8410c40695b776e709a4b8029c860c0c

mkosi/__init__.py

index e1f19bee279168131a0c374536dac936651f25c7..0828c87cde33513efab2c9f6e366c5cf65fa6c7e 100644 (file)
@@ -2090,11 +2090,13 @@ def install_uki(
     partitions: Sequence[Partition],
     profiles: Sequence[Path],
     cmdline: list[str],
-) -> None:
+) -> dict[str, Any]:
     boot_binary = context.root / finalize_uki_path(
         context, finalize_bootloader_entry_format(context, kver, token, partitions)
     )
 
+    pcrs: dict[str, Any] = {}
+
     # Make sure the parent directory where we'll be writing the UKI exists.
     with umask(~0o700):
         boot_binary.parent.mkdir(parents=True, exist_ok=True)
@@ -2108,7 +2110,7 @@ def install_uki(
             if context.config.bootable == ConfigFeature.enabled:
                 die(f"Couldn't find a signed UKI binary installed at /usr/lib/modules/{kver} in the image")
 
-            return
+            return pcrs
     else:
         microcodes = finalize_microcode(context)
 
@@ -2116,7 +2118,7 @@ def install_uki(
         if context.config.kernel_modules_initrd:
             initrds += [build_kernel_modules_initrd(context, kver)]
 
-        build_uki(
+        pcrs = build_uki(
             context,
             systemd_stub_binary(context),
             kver,
@@ -2149,6 +2151,8 @@ def install_uki(
 
             f.write("fi\n")
 
+    return pcrs
+
 
 def systemd_addon_stub_binary(context: Context) -> Path:
     arch = context.config.architecture.to_efi()
@@ -2230,16 +2234,23 @@ def install_kernel(context: Context, partitions: Sequence[Partition]) -> None:
     token = find_entry_token(context)
     cmdline = finalize_cmdline(context, partitions, finalize_roothash(partitions))
     profiles = build_uki_profiles(context, cmdline) if want_uki(context) else []
+    # The first processed UKI is the one that will be used as split artifact, so take pcrs from
+    # it and ignore the rest
+    # TODO: we should probably support signing pcrs for all built UKIs
+    pcrs: dict[str, Any] = {}
 
     for kver, kimg in gen_kernel_images(context):
         if want_uki(context):
-            install_uki(context, kver, kimg, token, partitions, profiles, cmdline)
+            pcrs = pcrs or install_uki(context, kver, kimg, token, partitions, profiles, cmdline)
         if not want_uki(context) or want_grub_bios(context, partitions):
             install_type1(context, kver, kimg, token, partitions, cmdline)
 
         if context.config.bootloader.is_uki():
             break
 
+    if ArtifactOutput.pcrs in context.config.split_artifacts and pcrs:
+        (context.staging / context.config.output_split_pcrs).write_text(json.dumps(pcrs))
+
 
 def make_uki(
     context: Context,