From 3b2ecfcd3f77679596b0e9df48481bbe358dad5d Mon Sep 17 00:00:00 2001 From: Joerg Behrmann Date: Tue, 23 Jan 2024 16:48:44 +0100 Subject: [PATCH] kernel-install: Use CPU detection to find host-specific microcode --- kernel-install/50-mkosi.install | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/kernel-install/50-mkosi.install b/kernel-install/50-mkosi.install index dd6cf184b..227aed443 100644 --- a/kernel-install/50-mkosi.install +++ b/kernel-install/50-mkosi.install @@ -9,6 +9,7 @@ import tempfile from pathlib import Path from typing import NamedTuple, Optional +from mkosi import identify_cpu from mkosi.archive import make_cpio from mkosi.config import OutputFormat, __version__ from mkosi.log import die, log_setup @@ -44,11 +45,14 @@ def mandatory_variable(name: str) -> str: def build_microcode_initrd(output: Path) -> Optional[Path]: - amd = Path("/usr/lib/firmware/amd-ucode") - intel = Path("/usr/lib/firmware/intel-ucode") + vendor, ucode = identify_cpu(Path("/")) - if not amd.exists() and not intel.exists(): - logging.debug("/usr/lib/firmware/{amd-ucode,intel-ucode} not found, not adding microcode initrd") + if vendor is None: + logging.warning("Unable to determine the vendor of your CPU, not adding microcode") + return None + + if ucode is None: + logging.warning("Unable to find microcode for your CPU in /usr/lib/firmware, not adding microcode") return None with tempfile.TemporaryDirectory() as tmp: @@ -58,15 +62,8 @@ def build_microcode_initrd(output: Path) -> Optional[Path]: with umask(~0o755): destdir.mkdir(parents=True, exist_ok=True) - if amd.exists(): - with (destdir / "AuthenticAMD.bin").open("wb") as f: - for p in amd.iterdir(): - f.write(p.read_bytes()) - - if intel.exists(): - with (destdir / "GenuineIntel.bin").open("wb") as f: - for p in intel.iterdir(): - f.write(p.read_bytes()) + with (destdir / f"{vendor}.bin").open("wb") as f: + f.write(ucode.read_bytes()) make_cpio(root, output) -- 2.47.2