Refactor microcode (#2099)

This commit is contained in:
codefiles 2023-09-24 05:18:52 -04:00 committed by GitHub
parent 360a1b4f33
commit 9e3e4a5df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 33 deletions

View File

@ -10,6 +10,32 @@ from .networking import list_interfaces, enrich_iface_types
from .output import debug from .output import debug
class CpuVendor(Enum):
AuthenticAMD = 'amd'
GenuineIntel = 'intel'
_Unknown = 'unknown'
@classmethod
def get_vendor(cls, name: str) -> 'CpuVendor':
if vendor := getattr(cls, name, None):
return vendor
else:
debug(f"Unknown CPU vendor '{name}' detected.")
return cls._Unknown
def _has_microcode(self) -> bool:
match self:
case CpuVendor.AuthenticAMD | CpuVendor.GenuineIntel:
return True
case _:
return False
def get_ucode(self) -> Optional[Path]:
if self._has_microcode():
return Path(self.value + '-ucode.img')
return None
class GfxPackage(Enum): class GfxPackage(Enum):
IntelMediaDriver = 'intel-media-driver' IntelMediaDriver = 'intel-media-driver'
LibvaIntelDriver = 'libva-intel-driver' LibvaIntelDriver = 'libva-intel-driver'
@ -180,8 +206,10 @@ class SysInfo:
return any('intel' in x.lower() for x in SysInfo._graphics_devices()) return any('intel' in x.lower() for x in SysInfo._graphics_devices())
@staticmethod @staticmethod
def cpu_vendor() -> Optional[str]: def cpu_vendor() -> Optional[CpuVendor]:
return _sys_info.cpu_info.get('vendor_id', None) if vendor := _sys_info.cpu_info.get('vendor_id'):
return CpuVendor.get_vendor(vendor)
return None
@staticmethod @staticmethod
def cpu_model() -> Optional[str]: def cpu_model() -> Optional[str]:

View File

@ -574,6 +574,12 @@ class Installer:
log(error.worker._trace_log.decode()) log(error.worker._trace_log.decode())
return False return False
def _get_microcode(self) -> Optional[Path]:
if not SysInfo.is_vm():
if vendor := SysInfo.cpu_vendor():
return vendor.get_ucode()
return None
def minimal_installation( def minimal_installation(
self, self,
testing: bool = False, testing: bool = False,
@ -610,18 +616,11 @@ class Installer:
if not SysInfo.has_uefi(): if not SysInfo.has_uefi():
self.base_packages.append('grub') self.base_packages.append('grub')
if not SysInfo.is_vm(): if ucode := self._get_microcode():
vendor = SysInfo.cpu_vendor() (self.target / 'boot' / ucode).unlink(missing_ok=True)
if vendor == "AuthenticAMD": self.base_packages.append(ucode.stem)
self.base_packages.append("amd-ucode") else:
if (ucode := Path(f"{self.target}/boot/amd-ucode.img")).exists(): debug('Archinstall will not install any ucode.')
ucode.unlink()
elif vendor == "GenuineIntel":
self.base_packages.append("intel-ucode")
if (ucode := Path(f"{self.target}/boot/intel-ucode.img")).exists():
ucode.unlink()
else:
debug(f"Unknown CPU vendor '{vendor}' detected. Archinstall won't install any ucode")
# Determine whether to enable multilib/testing repositories before running pacstrap if testing flag is set. # Determine whether to enable multilib/testing repositories before running pacstrap if testing flag is set.
# This action takes place on the host system as pacstrap copies over package repository lists. # This action takes place on the host system as pacstrap copies over package repository lists.
@ -840,17 +839,10 @@ class Installer:
microcode = [] microcode = []
if not SysInfo.is_vm(): if ucode := self._get_microcode():
vendor = SysInfo.cpu_vendor() microcode.append(f'initrd /{ucode}\n')
if vendor == "AuthenticAMD": else:
microcode.append('initrd /amd-ucode.img\n') debug('Archinstall will not add any ucode to systemd-boot config.')
elif vendor == "GenuineIntel":
microcode.append('initrd /intel-ucode.img\n')
else:
debug(
f"Unknown CPU vendor '{vendor}' detected.",
"Archinstall won't add any ucode to systemd-boot config.",
)
options = 'options ' + ' '.join(self._get_kernel_params(root_partition)) + '\n' options = 'options ' + ' '.join(self._get_kernel_params(root_partition)) + '\n'
@ -1065,14 +1057,10 @@ TIMEOUT=5
microcode = [] microcode = []
if not SysInfo.is_vm(): if ucode := self._get_microcode():
vendor = SysInfo.cpu_vendor() microcode.append(f'initrd=\\{ucode}')
if vendor == "AuthenticAMD": else:
microcode.append("initrd=\\amd-ucode.img") debug('Archinstall will not add any ucode to firmware boot entry.')
elif vendor == "GenuineIntel":
microcode.append("initrd=\\intel-ucode.img")
else:
debug(f"Unknown CPU vendor '{vendor}' detected. Archinstall won't add any ucode to firmware boot entry.")
kernel_parameters = self._get_kernel_params(root_partition) kernel_parameters = self._get_kernel_params(root_partition)