From: Joerg Behrmann Date: Tue, 23 Jan 2024 15:48:44 +0000 (+0100) Subject: kernel-install: Use CPU detection to find host-specific microcode X-Git-Tag: v21~89^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2310%2Fhead;p=thirdparty%2Fmkosi.git kernel-install: Use CPU detection to find host-specific microcode --- 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)