Merge pull request #1043 from dortania/rework-build-libary

build module: Enhance readability
This commit is contained in:
Mykola Grymalyuk
2023-03-31 20:53:52 -06:00
committed by GitHub
14 changed files with 813 additions and 435 deletions

View File

@@ -183,4 +183,4 @@ If you plan to create the USB for another machine, please select the "Change Mod
self.constants.allow_oc_everywhere = True
self.constants.serial_settings = "None"
build.build_opencore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore()
build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants)

View File

@@ -1,34 +1,49 @@
# Class for handling Bluetooth Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import logging
from resources import constants, device_probe
from resources.build import support
from data import smbios_data, bluetooth_data
import logging
class build_bluetooth:
class BuildBluetooth:
"""
Build Library for Bluetooth Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
def build(self):
# Bluetooth patches
def _build(self) -> None:
"""
Kick off Bluetooth Build Process
"""
if not self.constants.custom_model and self.computer.bluetooth_chipset:
self.on_model()
self._on_model()
else:
self.prebuilt_assumption()
self._prebuilt_assumption()
def on_model(self):
def _on_model(self) -> None:
"""
On-Model Hardware Detection Handling
"""
if self.computer.bluetooth_chipset in ["BRCM2070 Hub", "BRCM2046 Hub"]:
logging.info("- Fixing Legacy Bluetooth for macOS Monterey")
support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
support.build_support(self.model, self.constants, self.config).enable_kext("Bluetooth-Spoof.kext", self.constants.btspoof_version, self.constants.btspoof_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Bluetooth-Spoof.kext", self.constants.btspoof_version, self.constants.btspoof_path)
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -btlfxallowanyaddr"
elif self.computer.bluetooth_chipset == "BRCM20702 Hub":
# BCM94331 can include either BCM2070 or BRCM20702 v1 Bluetooth chipsets
@@ -37,15 +52,19 @@ class build_bluetooth:
if self.computer.wifi:
if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360:
logging.info("- Fixing Legacy Bluetooth for macOS Monterey")
support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
elif self.computer.bluetooth_chipset == "3rd Party Bluetooth 4.0 Hub":
logging.info("- Detected 3rd Party Bluetooth Chipset")
support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
logging.info("- Enabling Bluetooth FeatureFlags")
self.config["Kernel"]["Quirks"]["ExtendBTFeatureFlags"] = True
def prebuilt_assumption(self):
def _prebuilt_assumption(self) -> None:
"""
Fall back to pre-built assumptions
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "Bluetooth Model" in smbios_data.smbios_dictionary[self.model]:
@@ -53,7 +72,7 @@ class build_bluetooth:
if smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM20702_v1.value:
logging.info("- Fixing Legacy Bluetooth for macOS Monterey")
support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path)
if smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM2070.value:
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -btlfxallowanyaddr"
support.build_support(self.model, self.constants, self.config).enable_kext("Bluetooth-Spoof.kext", self.constants.btspoof_version, self.constants.btspoof_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Bluetooth-Spoof.kext", self.constants.btspoof_version, self.constants.btspoof_path)

View File

@@ -1,57 +1,69 @@
# Class for generating OpenCore Configurations tailored for Macs
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import copy
import pickle
import plistlib
import shutil
import zipfile
import logging
from pathlib import Path
from datetime import date
import logging
from resources import constants, utilities
from resources.build import bluetooth, firmware, graphics_audio, support, storage, smbios, security, misc
from resources.build.networking import wired, wireless
def rmtree_handler(func, path, exc_info):
def rmtree_handler(func, path, exc_info) -> None:
if exc_info[0] == FileNotFoundError:
return
raise # pylint: disable=misplaced-bare-raise
class build_opencore:
def __init__(self, model, versions):
self.model = model
self.config = None
self.constants: constants.Constants = versions
class BuildOpenCore:
"""
Core Build Library for generating and validating OpenCore EFI Configurations
compatible with genuine Macs
"""
def __init__(self, model: str, global_constants: constants.Constants) -> None:
self.model: str = model
self.config: dict = None
self.constants: constants.Constants = global_constants
self._build_opencore()
def build_efi(self):
def _build_efi(self) -> None:
"""
Build EFI folder
"""
utilities.cls()
if not self.constants.custom_model:
logging.info(f"Building Configuration on model: {self.model}")
else:
logging.info(f"Building Configuration for external model: {self.model}")
logging.info(f"Building Configuration {'for external' if self.constants.custom_model else 'on model'}: {self.model}")
self.generate_base()
self.set_revision()
self._generate_base()
self._set_revision()
# Set Lilu and co.
support.build_support(self.model, self.constants, self.config).enable_kext("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path)
self.config["Kernel"]["Quirks"]["DisableLinkeditJettison"] = True
# Call support functions
firmware.build_firmware(self.model, self.constants, self.config).build()
wired.build_wired(self.model, self.constants, self.config).build()
wireless.build_wireless(self.model, self.constants, self.config).build()
graphics_audio.build_graphics_audio(self.model, self.constants, self.config).build()
bluetooth.build_bluetooth(self.model, self.constants, self.config).build()
storage.build_storage(self.model, self.constants, self.config).build()
smbios.build_smbios(self.model, self.constants, self.config).build()
security.build_security(self.model, self.constants, self.config).build()
misc.build_misc(self.model, self.constants, self.config).build()
for function in [
firmware.BuildFirmware,
wired.BuildWiredNetworking,
wireless.BuildWirelessNetworking,
graphics_audio.BuildGraphicsAudio,
bluetooth.BuildBluetooth,
storage.BuildStorage,
smbios.BuildSMBIOS,
security.BuildSecurity,
misc.BuildMiscellaneous
]:
function(self.model, self.constants, self.config)
# Work-around ocvalidate
if self.constants.validate is False:
@@ -59,8 +71,11 @@ class build_opencore:
self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"]
def generate_base(self):
# Generate OpenCore base folder and config
def _generate_base(self) -> None:
"""
Generate OpenCore base folder and config
"""
if not Path(self.constants.build_path).exists():
logging.info("Creating build folder")
Path(self.constants.build_path).mkdir()
@@ -85,8 +100,11 @@ class build_opencore:
self.config = plistlib.load(Path(self.constants.plist_path).open("rb"))
def set_revision(self):
# Set revision in config
def _set_revision(self) -> None:
"""
Set revision information in config.plist
"""
self.config["#Revision"]["Build-Version"] = f"{self.constants.patcher_version} - {date.today()}"
if not self.constants.custom_model:
self.config["#Revision"]["Build-Type"] = "OpenCore Built on Target Machine"
@@ -101,21 +119,35 @@ class build_opencore:
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model
def save_config(self):
def _save_config(self) -> None:
"""
Save config.plist to disk
"""
plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True)
def build_opencore(self):
def _build_opencore(self) -> None:
"""
Kick off the build process
This is the main function:
- Generates the OpenCore configuration
- Cleans working directory
- Signs files
- Validates generated EFI
"""
# Generate OpenCore Configuration
self.build_efi()
self._build_efi()
if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True or (self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != ""):
smbios.build_smbios(self.model, self.constants, self.config).set_smbios()
support.build_support(self.model, self.constants, self.config).cleanup()
self.save_config()
smbios.BuildSMBIOS(self.model, self.constants, self.config).set_smbios()
support.BuildSupport(self.model, self.constants, self.config).cleanup()
self._save_config()
# Post-build handling
support.build_support(self.model, self.constants, self.config).sign_files()
support.build_support(self.model, self.constants, self.config).validate_pathing()
support.BuildSupport(self.model, self.constants, self.config).sign_files()
support.BuildSupport(self.model, self.constants, self.config).validate_pathing()
logging.info("")
logging.info(f"Your OpenCore EFI for {self.model} has been built at:")

View File

@@ -1,31 +1,50 @@
# Class for handling CPU and Firmware Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
from resources import constants, generate_smbios
import shutil
import logging
import binascii
from pathlib import Path
from resources import constants, generate_smbios, device_probe
from resources.build import support
from data import smbios_data, cpu_data
import binascii, shutil, logging
from pathlib import Path
class build_firmware:
class BuildFirmware:
"""
Build Library for CPU and Firmware Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
def build(self):
self.cpu_compatibility_handling()
self.power_management_handling()
self.acpi_handling()
self.firmware_driver_handling()
self.firmware_compatibility_handling()
def _build(self) -> None:
"""
Kick off CPU and Firmware Build Process
"""
self._cpu_compatibility_handling()
self._power_management_handling()
self._acpi_handling()
self._firmware_driver_handling()
self._firmware_compatibility_handling()
def power_management_handling(self):
def _power_management_handling(self) -> None:
"""
Power Management Handling
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]:
@@ -51,8 +70,8 @@ class build_firmware:
#
# To resolve, we patched AICPUPM to attach regardless of the value of 'intel_cpupm_matching'
logging.info("- Enabling legacy power management support")
support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntelCPUPowerManagement.kext", self.constants.aicpupm_version, self.constants.aicpupm_path)
support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntelCPUPowerManagementClient.kext", self.constants.aicpupm_version, self.constants.aicpupm_client_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleIntelCPUPowerManagement.kext", self.constants.aicpupm_version, self.constants.aicpupm_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleIntelCPUPowerManagementClient.kext", self.constants.aicpupm_version, self.constants.aicpupm_client_path)
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.sandy_bridge.value or self.constants.disable_xcpm is True:
# With macOS 12.3 Beta 1, Apple dropped the 'plugin-type' check within X86PlatformPlugin
@@ -61,18 +80,22 @@ class build_firmware:
# power management tables provided.
# This patch will simply increase ASPP's 'IOProbeScore' to outmatch X86PP
logging.info("- Overriding ACPI SMC matching")
support.build_support(self.model, self.constants, self.config).enable_kext("ASPP-Override.kext", self.constants.aspp_override_version, self.constants.aspp_override_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("ASPP-Override.kext", self.constants.aspp_override_version, self.constants.aspp_override_path)
if self.constants.disable_xcpm is True:
# Only inject on older OSes if user requests
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", "ASPP-Override.kext")["MinKernel"] = ""
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", "ASPP-Override.kext")["MinKernel"] = ""
if self.constants.disable_msr_power_ctl is True and smbios_data.smbios_dictionary[self.model]["CPU Generation"] >= cpu_data.cpu_data.nehalem.value:
logging.info("- Disabling Firmware Throttling")
# Nehalem and newer systems force firmware throttling via MSR_POWER_CTL
support.build_support(self.model, self.constants, self.config).enable_kext("SimpleMSR.kext", self.constants.simplemsr_version, self.constants.simplemsr_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("SimpleMSR.kext", self.constants.simplemsr_version, self.constants.simplemsr_path)
def acpi_handling(self):
def _acpi_handling(self) -> None:
"""
ACPI Table Handling
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]:
@@ -83,19 +106,23 @@ class build_firmware:
# IOPCIFamily will error when enumerating this device, thus we'll power it off via _STA (has no effect in older OSes)
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] == cpu_data.cpu_data.nehalem.value and not (self.model.startswith("MacPro") or self.model.startswith("Xserve")):
logging.info("- Adding SSDT-CPBG.aml")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-CPBG.aml")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-CPBG.aml")["Enabled"] = True
shutil.copy(self.constants.pci_ssdt_path, self.constants.acpi_path)
if cpu_data.cpu_data.sandy_bridge <= smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value and self.model != "MacPro6,1":
# Based on: https://egpu.io/forums/pc-setup/fix-dsdt-override-to-correct-error-12/
# Applicable for Sandy and Ivy Bridge Macs
logging.info("- Enabling Windows 10 UEFI Audio support")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-PCI.aml")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "BUF0 to BUF1")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-PCI.aml")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "BUF0 to BUF1")["Enabled"] = True
shutil.copy(self.constants.windows_ssdt_path, self.constants.acpi_path)
def cpu_compatibility_handling(self):
def _cpu_compatibility_handling(self) -> None:
"""
CPU Compatibility Handling
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]:
@@ -104,14 +131,14 @@ class build_firmware:
# SSE4,1 support (ie. Penryn)
# Required for macOS Mojave and newer
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value:
support.build_support(self.model, self.constants, self.config).enable_kext("AAAMouSSE.kext", self.constants.mousse_version, self.constants.mousse_path)
support.build_support(self.model, self.constants, self.config).enable_kext("telemetrap.kext", self.constants.telemetrap_version, self.constants.telemetrap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AAAMouSSE.kext", self.constants.mousse_version, self.constants.mousse_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("telemetrap.kext", self.constants.telemetrap_version, self.constants.telemetrap_path)
# Force Rosetta Cryptex installation in macOS Ventura
# Restores support for CPUs lacking AVX2.0 support
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value:
logging.info("- Enabling Rosetta Cryptex support in Ventura")
support.build_support(self.model, self.constants, self.config).enable_kext("CryptexFixup.kext", self.constants.cryptexfixup_version, self.constants.cryptexfixup_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CryptexFixup.kext", self.constants.cryptexfixup_version, self.constants.cryptexfixup_path)
# i3 Ivy Bridge iMacs don't support RDRAND
# However for prebuilt, assume they do
@@ -120,14 +147,14 @@ class build_firmware:
# Ref: https://github.com/reenigneorcim/SurPlus
# Enable for all systems missing RDRAND support
logging.info("- Adding SurPlus Patch for Race Condition")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 2 of 2 - Patch register_and_init_prng")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 2 of 2 - Patch register_and_init_prng")["Enabled"] = True
if self.constants.force_surplus is True:
# Syncretic forces SurPlus to only run on Beta 7 and older by default for saftey reasons
# If users desires, allow forcing in newer OSes
logging.info("- Allowing SurPlus on all newer OSes")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["MaxKernel"] = ""
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 2 of 2 - Patch register_and_init_prng")["MaxKernel"] = ""
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["MaxKernel"] = ""
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 2 of 2 - Patch register_and_init_prng")["MaxKernel"] = ""
# In macOS 12.4 and 12.5 Beta 1, Apple added AVX1.0 usage in AppleFSCompressionTypeZlib
# Pre-Sandy Bridge CPUs don't support AVX1.0, thus we'll downgrade the kext to 12.3.1's
@@ -138,17 +165,20 @@ class build_firmware:
# To verify the non-AVX kext is used, check IOService for 'com_apple_AppleFSCompression_NoAVXCompressionTypeZlib'
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.sandy_bridge.value:
support.build_support(self.model, self.constants, self.config).enable_kext("NoAVXFSCompressionTypeZlib.kext", self.constants.apfs_zlib_version, self.constants.apfs_zlib_path)
support.build_support(self.model, self.constants, self.config).enable_kext("NoAVXFSCompressionTypeZlib-AVXpel.kext", self.constants.apfs_zlib_v2_version, self.constants.apfs_zlib_v2_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("NoAVXFSCompressionTypeZlib.kext", self.constants.apfs_zlib_version, self.constants.apfs_zlib_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("NoAVXFSCompressionTypeZlib-AVXpel.kext", self.constants.apfs_zlib_v2_version, self.constants.apfs_zlib_v2_path)
# HID patches
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value:
logging.info("- Adding IOHIDFamily patch")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.iokit.IOHIDFamily")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.iokit.IOHIDFamily")["Enabled"] = True
def firmware_driver_handling(self):
# Firmware Drivers (Drivers/*.efi)
def _firmware_driver_handling(self) -> None:
"""
Firmware Driver Handling (Drivers/*.efi)
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]:
@@ -159,13 +189,13 @@ class build_firmware:
# Sandy Bridge and newer Macs natively support ExFat
logging.info("- Adding ExFatDxeLegacy.efi")
shutil.copy(self.constants.exfat_legacy_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("ExFatDxeLegacy.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("ExFatDxeLegacy.efi", "UEFI", "Drivers")["Enabled"] = True
# NVMe check
if self.constants.nvme_boot is True:
logging.info("- Enabling NVMe boot support")
shutil.copy(self.constants.nvme_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("NvmExpressDxe.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("NvmExpressDxe.efi", "UEFI", "Drivers")["Enabled"] = True
# USB check
if self.constants.xhci_boot is True:
@@ -173,18 +203,22 @@ class build_firmware:
logging.info("- Adding XhciDxe.efi and UsbBusDxe.efi")
shutil.copy(self.constants.xhci_driver_path, self.constants.drivers_path)
shutil.copy(self.constants.usb_bus_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("XhciDxe.efi", "UEFI", "Drivers")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("UsbBusDxe.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("XhciDxe.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("UsbBusDxe.efi", "UEFI", "Drivers")["Enabled"] = True
# PCIe Link Rate check
if self.model == "MacPro3,1":
logging.info("- Adding PCIe Link Rate Patch")
shutil.copy(self.constants.link_rate_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("FixPCIeLinkRate.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("FixPCIeLinkRate.efi", "UEFI", "Drivers")["Enabled"] = True
def firmware_compatibility_handling(self):
self.dual_dp_handling()
def _firmware_compatibility_handling(self) -> None:
"""
Firmware Compatibility Handling (Firmware and Kernel)
"""
self._dual_dp_handling()
# Force VMM as a temporary solution to getting the MacPro6,1 booting in Ventura
# With macOS Ventura, Apple removed AppleIntelCPUPowerManagement.kext and assumed XCPM support across all Macs
@@ -228,21 +262,24 @@ class build_firmware:
if self.model not in affected_smbios:
# If MacPro6,1 host spoofs, we can safely enable it
if self.constants.override_smbios in affected_smbios or generate_smbios.set_smbios_model_spoof(self.model) in affected_smbios:
support.build_support(self.model, self.constants, self.config).enable_kext("AppleMCEReporterDisabler.kext", self.constants.mce_version, self.constants.mce_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleMCEReporterDisabler.kext", self.constants.mce_version, self.constants.mce_path)
def dual_dp_handling(self):
# Check if model has 5K display
# Apple has 2 modes for display handling on 5K iMacs and iMac Pro
# If at any point in the boot chain an "unsupported" entry is loaded, the firmware will tell the
# Display Controller to enter a 4K compatible mode that only uses a single DisplayPort 1.2 stream internally.
# This is to prevent situations where the system would boot into an enviroment that cannot handle the custom
# dual DisplayPort 1.2 streams the 5k Display uses
def _dual_dp_handling(self) -> None:
"""
Dual DisplayPort Stream Handler (ex. 5k iMac)
# To work around this issue, we trick the firmware into loading OpenCore through Apple's Hardware Diagnostic Tests
# Specifically hiding as Product.efi under '/System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers/Product.efi'
# The reason chainloading via ./Drivers/HardwareDrivers is possible is thanks to it being loaded via an encrypted file buffer
# whereas other drivers like ./qa_logger.efi is invoked via Device Path.
Apple has 2 modes for display handling on 5K iMacs and iMac Pro
If at any point in the boot chain an "unsupported" entry is loaded, the firmware will tell the
Display Controller to enter a 4K compatible mode that only uses a single DisplayPort 1.2 stream internally.
This is to prevent situations where the system would boot into an enviroment that cannot handle the custom
dual DisplayPort 1.2 streams the 5k Display uses
To work around this issue, we trick the firmware into loading OpenCore through Apple's Hardware Diagnostic Tests
Specifically hiding as Product.efi under '/System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers/Product.efi'
The reason chainloading via ./Drivers/HardwareDrivers is possible is thanks to it being loaded via an encrypted file buffer
whereas other drivers like ./qa_logger.efi is invoked via Device Path.
"""
if "5K Display" not in smbios_data.smbios_dictionary[self.model]:
return

View File

@@ -1,7 +1,9 @@
# Class for handling Graphics and Audio Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import shutil, binascii, logging
import shutil
import logging
import binascii
from pathlib import Path
@@ -10,30 +12,47 @@ from resources.build import support
from data import smbios_data, model_array, os_data, cpu_data, video_bios_data
class build_graphics_audio:
class BuildGraphicsAudio:
"""
Build Library for Graphics and Audio Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self.gfx0_path = None
def build(self):
self.imac_mxm_patching()
self.graphics_handling()
self.audio_handling()
self.firmware_handling()
self.spoof_handling()
self.ioaccel_workaround()
self._build()
def graphics_handling(self):
def _build(self) -> None:
"""
Kick off Graphics and Audio Build Process
"""
self._imac_mxm_patching()
self._graphics_handling()
self._audio_handling()
self._firmware_handling()
self._spoof_handling()
self._ioaccel_workaround()
def _graphics_handling(self) -> None:
"""
Graphics Handling
Primarily for Mac Pros and systems with Nvidia Maxwell/Pascal GPUs
"""
if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None":
if not support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
if not support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
# Mac Pro handling
if self.model in model_array.MacPro:
@@ -77,8 +96,8 @@ class build_graphics_audio:
logging.info("- Adding Mac Pro, Xserve DRM patches")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 -wegtree"
if not support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
if not support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
# Web Driver specific
if not self.constants.custom_model:
@@ -94,23 +113,23 @@ class build_graphics_audio:
self.config["DeviceProperties"]["Add"][device.pci_path].update({"disable-metal": 1, "force-compat": 1})
else:
self.config["DeviceProperties"]["Add"][device.pci_path] = {"disable-metal": 1, "force-compat": 1}
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"].update({"nvda_drv": binascii.unhexlify("31")})
if "nvda_drv" not in self.config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]:
self.config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"] += ["nvda_drv"]
else:
if "ngfxgl=1 ngfxcompat=1" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]:
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " ngfxgl=1 ngfxcompat=1"
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path)
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"].update({"nvda_drv": binascii.unhexlify("31")})
if "nvda_drv" not in self.config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]:
self.config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"] += ["nvda_drv"]
def backlight_path_detection(self):
def _backlight_path_detection(self) -> None:
"""
iMac MXM dGPU Backlight DevicePath Detection
"""
# self.constants.custom_model: iMac has been modded with new dGPU
# self.computer.dgpu: dGPU has been found using the GFX0 path
# self.computer.dgpu.pci_path:
if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path:
for i, device in enumerate(self.computer.gpus):
logging.info(f"- Found dGPU ({i + 1}): {utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}")
@@ -144,10 +163,14 @@ class build_graphics_audio:
self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"
def nvidia_mxm_patch(self, backlight_path):
if not support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
def _nvidia_mxm_patch(self, backlight_path) -> None:
"""
iMac Nvidia Kepler MXM Handler
"""
if not support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
# Ensure WEG is enabled as we need if for Backlight patching
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_navi_version, self.constants.whatevergreen_navi_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_navi_version, self.constants.whatevergreen_navi_path)
if self.model in ["iMac11,1", "iMac11,2", "iMac11,3", "iMac10,1"]:
logging.info("- Adding Nvidia Brightness Control and DRM patches")
self.config["DeviceProperties"]["Add"][backlight_path] = {
@@ -182,20 +205,24 @@ class build_graphics_audio:
"class-code": binascii.unhexlify("FFFFFFFF"),
}
shutil.copy(self.constants.backlight_injector_path, self.constants.kexts_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("BacklightInjector.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("BacklightInjector.kext")["Enabled"] = True
self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True
self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True
def amd_mxm_patch(self, backlight_path):
def _amd_mxm_patch(self, backlight_path) -> None:
"""
iMac AMD GCN and Navi MXM Handler
"""
logging.info("- Adding AMD DRM patches")
if not support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
if not support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True:
# Ensure WEG is enabled as we need if for Backlight patching
support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_navi_version, self.constants.whatevergreen_navi_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_navi_version, self.constants.whatevergreen_navi_path)
if self.model == "iMac9,1":
logging.info("- Adding iMac9,1 Brightness Control and DRM patches")
support.build_support(self.model, self.constants, self.config).enable_kext("BacklightInjector.kext", self.constants.backlight_injectorA_version, self.constants.backlight_injectorA_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BacklightInjector.kext", self.constants.backlight_injectorA_version, self.constants.backlight_injectorA_path)
if not self.constants.custom_model:
if self.computer.dgpu.device_id == 0x7340:
@@ -222,7 +249,7 @@ class build_graphics_audio:
"class-code": binascii.unhexlify("FFFFFFFF"),
}
elif self.model in ["iMac9,1", "iMac10,1"]:
support.build_support(self.model, self.constants, self.config).enable_kext("AAAMouSSE.kext", self.constants.mousse_version, self.constants.mousse_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AAAMouSSE.kext", self.constants.mousse_version, self.constants.mousse_path)
if self.computer and self.computer.dgpu:
if self.computer.dgpu.arch == device_probe.AMD.Archs.Legacy_GCN_7000:
logging.info("- Adding Legacy GCN Power Gate Patches")
@@ -269,9 +296,13 @@ class build_graphics_audio:
"enable-gva-support": 1
}
def audio_handling(self):
def _audio_handling(self) -> None:
"""
Audio Handler
"""
if (self.model in model_array.LegacyAudio or self.model in model_array.MacPro) and self.constants.set_alc_usage is True:
support.build_support(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
# Audio Patch
if self.constants.set_alc_usage is True:
@@ -297,16 +328,20 @@ class build_graphics_audio:
"use-apple-layout-id": 1,
"use-layout-id": 1,
}
support.build_support(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
elif (self.model.startswith("MacPro") and self.model != "MacPro6,1") or self.model.startswith("Xserve"):
# Used to enable Audio support for non-standard dGPUs
support.build_support(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path)
# Due to regression in AppleALC 1.6.4+, temporarily use 1.6.3 and set override
if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleALC.kext")["Enabled"] is True:
if support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleALC.kext")["Enabled"] is True:
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -lilubetaall"
def firmware_handling(self):
def _firmware_handling(self) -> None:
"""
Firmware Handler
"""
# Add UGA to GOP layer
if "UGA Graphics" in smbios_data.smbios_dictionary[self.model]:
logging.info("- Adding UGA to GOP Patch")
@@ -316,8 +351,8 @@ class build_graphics_audio:
if self.constants.software_demux is True and self.model in ["MacBookPro8,2", "MacBookPro8,3"]:
logging.info("- Enabling software demux")
# Add ACPI patches
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-DGPU.aml")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "_INI to XINI")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-DGPU.aml")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "_INI to XINI")["Enabled"] = True
shutil.copy(self.constants.demux_ssdt_path, self.constants.acpi_path)
# Disable dGPU
# IOACPIPlane:/_SB/PCI0@0/P0P2@10000/GFX0@0
@@ -329,7 +364,7 @@ class build_graphics_audio:
}
self.config["DeviceProperties"]["Delete"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = ["class-code", "device-id", "IOName", "name"]
# Add AMDGPUWakeHandler
support.build_support(self.model, self.constants, self.config).enable_kext("AMDGPUWakeHandler.kext", self.constants.gpu_wake_version, self.constants.gpu_wake_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AMDGPUWakeHandler.kext", self.constants.gpu_wake_version, self.constants.gpu_wake_path)
if self.constants.dGPU_switch is True and "Switchable GPUs" in smbios_data.smbios_dictionary[self.model]:
logging.info("- Allowing GMUX switching in Windows")
@@ -345,16 +380,20 @@ class build_graphics_audio:
if self.constants.amd_gop_injection is True:
logging.info("- Adding AMDGOP.efi")
shutil.copy(self.constants.amd_gop_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("AMDGOP.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("AMDGOP.efi", "UEFI", "Drivers")["Enabled"] = True
# Nvidia Kepler GOP VBIOS injection
if self.constants.nvidia_kepler_gop_injection is True:
logging.info("- Adding NVGOP_GK.efi")
shutil.copy(self.constants.nvidia_kepler_gop_driver_path, self.constants.drivers_path)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("NVGOP_GK.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("NVGOP_GK.efi", "UEFI", "Drivers")["Enabled"] = True
def spoof_handling(self):
def _spoof_handling(self) -> None:
"""
SMBIOS Spoofing Handler
"""
if self.constants.serial_settings == "None":
return
@@ -366,7 +405,7 @@ class build_graphics_audio:
Path(self.constants.amc_kext_folder).mkdir()
Path(self.constants.amc_contents_folder).mkdir()
shutil.copy(amc_map_path, self.constants.amc_contents_folder)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AMC-Override.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AMC-Override.kext")["Enabled"] = True
if self.model not in model_array.NoAGPMSupport:
logging.info("- Adding AppleGraphicsPowerManagement Override")
@@ -374,7 +413,7 @@ class build_graphics_audio:
Path(self.constants.agpm_kext_folder).mkdir()
Path(self.constants.agpm_contents_folder).mkdir()
shutil.copy(agpm_map_path, self.constants.agpm_contents_folder)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AGPM-Override.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AGPM-Override.kext")["Enabled"] = True
if self.model in model_array.AGDPSupport:
logging.info("- Adding AppleGraphicsDevicePolicy Override")
@@ -382,7 +421,7 @@ class build_graphics_audio:
Path(self.constants.agdp_kext_folder).mkdir()
Path(self.constants.agdp_contents_folder).mkdir()
shutil.copy(agdp_map_path, self.constants.agdp_contents_folder)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AGDP-Override.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AGDP-Override.kext")["Enabled"] = True
# AGPM Patch
if self.model in model_array.DualGPUPatch:
@@ -412,15 +451,19 @@ class build_graphics_audio:
self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"}
def imac_mxm_patching(self):
self.backlight_path_detection()
def _imac_mxm_patching(self) -> None:
"""
General iMac MXM Handler
"""
self._backlight_path_detection()
# Check GPU Vendor
if self.constants.metal_build is True:
logging.info("- Adding Metal GPU patches on request")
if self.constants.imac_vendor == "AMD":
self.amd_mxm_patch(self.gfx0_path)
self._amd_mxm_patch(self.gfx0_path)
elif self.constants.imac_vendor == "Nvidia":
self.nvidia_mxm_patch(self.gfx0_path)
self._nvidia_mxm_patch(self.gfx0_path)
else:
logging.info("- Failed to find vendor")
elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu:
@@ -434,15 +477,18 @@ class build_graphics_audio:
device_probe.AMD.Archs.Vega,
device_probe.AMD.Archs.Navi,
]:
self.amd_mxm_patch(self.gfx0_path)
self._amd_mxm_patch(self.gfx0_path)
elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler:
self.nvidia_mxm_patch(self.gfx0_path)
self._nvidia_mxm_patch(self.gfx0_path)
def ioaccel_workaround(self):
# Handle misc IOAccelerator issues
def _ioaccel_workaround(self) -> None:
"""
Miscellaneous IOAccelerator Handler
When MTL bundles are missing from disk, WindowServer will repeatedly crash
This primarily occurs when installing an RSR update, where root is cleaned but AuxKC is not
"""
# When MTL bundles are missing from disk, WindowServer will repeatedly crash
# This primarily occurs when installing an RSR update, where root is cleaned but AuxKC is not
gpu_dict = []
if not self.constants.custom_model:
gpu_dict = self.constants.computer.gpus
@@ -503,7 +549,7 @@ class build_graphics_audio:
if has_kdkless_gpu is True and has_kdk_gpu is False:
# KDKlessWorkaround is required for KDKless GPUs
support.build_support(self.model, self.constants, self.config).enable_kext("KDKlessWorkaround.kext", self.constants.kdkless_version, self.constants.kdkless_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("KDKlessWorkaround.kext", self.constants.kdkless_version, self.constants.kdkless_path)
return
# KDKlessWorkaround supports disabling native AMD stack on Ventura for pre-AVX2.0 CPUs
@@ -519,5 +565,5 @@ class build_graphics_audio:
device_probe.AMD.Archs.Vega,
device_probe.AMD.Archs.Navi,
]:
support.build_support(self.model, self.constants, self.config).enable_kext("KDKlessWorkaround.kext", self.constants.kdkless_version, self.constants.kdkless_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("KDKlessWorkaround.kext", self.constants.kdkless_version, self.constants.kdkless_path)
return

View File

@@ -1,50 +1,69 @@
# Class for handling Misc Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import shutil
import logging
import binascii
from pathlib import Path
from resources import constants, device_probe, generate_smbios, utilities
from resources.build import support
from data import model_array, smbios_data, cpu_data
import binascii, shutil, logging
from pathlib import Path
class BuildMiscellaneous:
"""
Build Library for Miscellaneous Hardware and Software Support
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
class build_misc:
def _build(self) -> None:
"""
Kick off Misc Build Process
"""
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
self._feature_unlock_handling()
self._restrict_events_handling()
self._firewire_handling()
self._trackpad_handling()
self._thunderbolt_handling()
self._webcam_handling()
self._usb_handling()
self._debug_handling()
self._cpu_friend_handling()
self._general_oc_handling()
def rmtree_handler(func, path, exc_info):
if exc_info[0] == FileNotFoundError:
def _feature_unlock_handling(self) -> None:
"""
FeatureUnlock Handler
"""
if self.constants.fu_status is False:
return
raise # pylint: disable=misplaced-bare-raise
def build(self):
self.feature_unlock_handling()
self.restrict_events_handling()
self.firewire_handling()
self.trackpad_handling()
self.thunderbolt_handling()
self.webcam_handling()
self.usb_handling()
self.debug_handling()
self.cpu_friend_handling()
self.general_oc_handling()
support.BuildSupport(self.model, self.constants, self.config).enable_kext("FeatureUnlock.kext", self.constants.featureunlock_version, self.constants.featureunlock_path)
if self.constants.fu_arguments is not None:
logging.info(f"- Adding additional FeatureUnlock args: {self.constants.fu_arguments}")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += self.constants.fu_arguments
def feature_unlock_handling(self):
if self.constants.fu_status is True:
support.build_support(self.model, self.constants, self.config).enable_kext("FeatureUnlock.kext", self.constants.featureunlock_version, self.constants.featureunlock_path)
if self.constants.fu_arguments is not None:
logging.info(f"- Adding additional FeatureUnlock args: {self.constants.fu_arguments}")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += self.constants.fu_arguments
def restrict_events_handling(self):
# RestrictEvents handling
# - revpatch: Process patching
# - revblock: Process blocking
def _restrict_events_handling(self) -> None:
"""
RestrictEvents Handler
"""
block_args = ""
if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]:
block_args += "gmux,"
@@ -73,11 +92,11 @@ class build_misc:
if block_args != "":
logging.info(f"- Setting RestrictEvents block arguments: {block_args}")
support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revblock"] = block_args
patch_args = ""
if support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] is True and self.constants.set_content_caching is True:
if support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] is True and self.constants.set_content_caching is True:
logging.info("- Fixing Content Caching support")
patch_args += "asset,"
@@ -90,7 +109,7 @@ class build_misc:
if patch_args != "":
logging.info(f"- Setting RestrictEvents patch arguments: {patch_args}")
support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revpatch"] = patch_args
if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1:
@@ -100,17 +119,21 @@ class build_misc:
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value
else:
logging.info("- Adding CPU Name Patch")
support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path)
if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False:
if support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False:
# Ensure this is done at the end so all previous RestrictEvents patches are applied
# RestrictEvents and EFICheckDisabler will conflict if both are injected
support.build_support(self.model, self.constants, self.config).enable_kext("EFICheckDisabler.kext", "", self.constants.efi_disabler_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("EFICheckDisabler.kext", "", self.constants.efi_disabler_path)
def cpu_friend_handling(self):
if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.disallow_cpufriend is False and self.constants.serial_settings != "None":
support.build_support(self.model, self.constants, self.config).enable_kext("CPUFriend.kext", self.constants.cpufriend_version, self.constants.cpufriend_path)
def _cpu_friend_handling(self) -> None:
"""
CPUFriend Handler
"""
if self.constants.allow_oc_everywhere is False and self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.disallow_cpufriend is False and self.constants.serial_settings != "None":
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CPUFriend.kext", self.constants.cpufriend_version, self.constants.cpufriend_path)
# CPUFriendDataProvider handling
pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist")
@@ -119,34 +142,53 @@ class build_misc:
Path(self.constants.pp_kext_folder).mkdir()
Path(self.constants.pp_contents_folder).mkdir()
shutil.copy(pp_map_path, self.constants.pp_contents_folder)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("CPUFriendDataProvider.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("CPUFriendDataProvider.kext")["Enabled"] = True
def firewire_handling(self):
if self.constants.firewire_boot is True and generate_smbios.check_firewire(self.model) is True:
# Enable FireWire Boot Support
# Applicable for both native FireWire and Thunderbolt to FireWire adapters
logging.info("- Enabling FireWire Boot Support")
support.build_support(self.model, self.constants, self.config).enable_kext("IOFireWireFamily.kext", self.constants.fw_kext, self.constants.fw_family_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IOFireWireSBP2.kext", self.constants.fw_kext, self.constants.fw_sbp2_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IOFireWireSerialBusProtocolTransport.kext", self.constants.fw_kext, self.constants.fw_bus_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IOFireWireFamily.kext/Contents/PlugIns/AppleFWOHCI.kext")["Enabled"] = True
def trackpad_handling(self):
def _firewire_handling(self) -> None:
"""
FireWire Handler
"""
if self.constants.firewire_boot is False:
return
if generate_smbios.check_firewire(self.model) is False:
return
# Enable FireWire Boot Support
# Applicable for both native FireWire and Thunderbolt to FireWire adapters
logging.info("- Enabling FireWire Boot Support")
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IOFireWireFamily.kext", self.constants.fw_kext, self.constants.fw_family_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IOFireWireSBP2.kext", self.constants.fw_kext, self.constants.fw_sbp2_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IOFireWireSerialBusProtocolTransport.kext", self.constants.fw_kext, self.constants.fw_bus_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IOFireWireFamily.kext/Contents/PlugIns/AppleFWOHCI.kext")["Enabled"] = True
def _trackpad_handling(self) -> None:
"""
Trackpad Handler
"""
# Pre-Force Touch trackpad support for macOS Ventura
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.skylake.value:
if self.model.startswith("MacBook"):
# These units got force touch early, so ignore them
if self.model not in ["MacBookPro11,4", "MacBookPro11,5", "MacBookPro12,1", "MacBook8,1"]:
support.build_support(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path)
# Legacy Trackpad support
if self.model in ["MacBook4,1", "MacBook5,2"]:
support.build_support(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path)
def _thunderbolt_handling(self) -> None:
"""
Thunderbolt Handler
"""
def thunderbolt_handling(self):
if self.constants.disable_tb is True and self.model in ["MacBookPro11,1", "MacBookPro11,2", "MacBookPro11,3", "MacBookPro11,4", "MacBookPro11,5"]:
logging.info("- Disabling 2013-2014 laptop Thunderbolt Controller")
if self.model in ["MacBookPro11,3", "MacBookPro11,5"]:
@@ -158,13 +200,22 @@ class build_misc:
self.config["DeviceProperties"]["Add"][tb_device_path] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000")}
def webcam_handling(self):
# Legacy iSight patches
def _webcam_handling(self) -> None:
"""
iSight Handler
"""
if "Legacy iSight" in smbios_data.smbios_dictionary[self.model]:
if smbios_data.smbios_dictionary[self.model]["Legacy iSight"] is True:
support.build_support(self.model, self.constants, self.config).enable_kext("LegacyUSBVideoSupport.kext", self.constants.apple_isight_version, self.constants.apple_isight_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("LegacyUSBVideoSupport.kext", self.constants.apple_isight_version, self.constants.apple_isight_path)
def _usb_handling(self) -> None:
"""
USB Handler
"""
def usb_handling(self):
# USB Map
usb_map_path = Path(self.constants.plist_folder_path) / Path("AppleUSBMaps/Info.plist")
if (
@@ -179,32 +230,32 @@ class build_misc:
Path(self.constants.map_kext_folder).mkdir()
Path(self.constants.map_contents_folder).mkdir()
shutil.copy(usb_map_path, self.constants.map_contents_folder)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB-Map.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB-Map.kext")["Enabled"] = True
if self.model in model_array.Missing_USB_Map_Ventura and self.constants.serial_settings not in ["Moderate", "Advanced"]:
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB-Map.kext")["MinKernel"] = "22.0.0"
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB-Map.kext")["MinKernel"] = "22.0.0"
# Add UHCI/OHCI drivers
# All Penryn Macs lack an internal USB hub to route USB 1.1 devices to the EHCI controller
# And MacPro4,1 and MacPro5,1 are the only post-Penryn Macs that lack an internal USB hub
# - Ref: https://techcommunity.microsoft.com/t5/microsoft-usb-blog/reasons-to-avoid-companion-controllers/ba-p/270710
#
# Required downgrades:
# - IOUSBHostFamily.kext (only kext itself, not plugins)
# - AppleUSBHub.kext
# - AppleUSBEHCI.kext
# To be paired for sys_patch_dict.py's 'Legacy USB 1.1' patchset
if (
smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value or \
self.model in ["MacPro4,1", "MacPro5,1"]
):
logging.info("- Adding UHCI/OHCI USB support")
shutil.copy(self.constants.apple_usb_11_injector_path, self.constants.kexts_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCI.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCIPCI.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCI.kext")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCIPCI.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCI.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCIPCI.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCI.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCIPCI.kext")["Enabled"] = True
def debug_handling(self):
# DEBUG Settings (OpenCorePkg and Kernel Space)
def _debug_handling(self) -> None:
"""
Debug Handler for OpenCorePkg and Kernel Space
"""
if self.constants.verbose_debug is True:
logging.info("- Enabling Verbose boot")
@@ -216,24 +267,25 @@ class build_misc:
# Disabled due to macOS Monterey crashing shortly after kernel init
# Use DebugEnhancer.kext instead
# self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " msgbuf=1048576"
support.build_support(self.model, self.constants, self.config).enable_kext("DebugEnhancer.kext", self.constants.debugenhancer_version, self.constants.debugenhancer_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("DebugEnhancer.kext", self.constants.debugenhancer_version, self.constants.debugenhancer_path)
if self.constants.opencore_debug is True:
logging.info("- Enabling DEBUG OpenCore")
self.config["Misc"]["Debug"]["Target"] = 0x43
self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042
def general_oc_handling(self):
# OpenCorePkg Settings
# OpenCanopy Settings (GUI)
def _general_oc_handling(self) -> None:
"""
General OpenCorePkg Handler
"""
logging.info("- Adding OpenCanopy GUI")
shutil.rmtree(self.constants.resources_path, onerror=self.rmtree_handler)
shutil.copy(self.constants.gui_path, self.constants.oc_folder)
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("OpenCanopy.efi", "UEFI", "Drivers")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("OpenRuntime.efi", "UEFI", "Drivers")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("OpenLinuxBoot.efi", "UEFI", "Drivers")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("ResetNvramEntry.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("OpenCanopy.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("OpenRuntime.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("OpenLinuxBoot.efi", "UEFI", "Drivers")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("ResetNvramEntry.efi", "UEFI", "Drivers")["Enabled"] = True
if self.constants.showpicker is False:
logging.info("- Hiding OpenCore picker")
@@ -246,4 +298,4 @@ class build_misc:
if self.constants.vault is True and utilities.check_command_line_tools() is True:
logging.info("- Setting Vault configuration")
self.config["Misc"]["Security"]["Vault"] = "Secure"
support.build_support(self.model, self.constants, self.config).get_efi_binary_by_path("OpenShell.efi", "Misc", "Tools")["Enabled"] = False
support.BuildSupport(self.model, self.constants, self.config).get_efi_binary_by_path("OpenShell.efi", "Misc", "Tools")["Enabled"] = False

View File

@@ -1,29 +1,44 @@
# Class for handling Wired Networking Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
from resources import constants, device_probe
from resources.build import support
from data import smbios_data, cpu_data
class build_wired:
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
class BuildWiredNetworking:
"""
Build Library for Wired Networking Support
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
def build(self):
def _build(self) -> None:
"""
Kick off Wired Build Process
"""
# Check if Ethernet was detected, otherwise fall back to assumptions (mainly for 2011 MacBook Airs and TB Ethernet)
if not self.constants.custom_model and self.constants.computer.ethernet:
self.on_model()
self._on_model()
else:
self.prebuilt_assumption()
self._prebuilt_assumption()
def on_model(self):
# On-model hardware detection
def _on_model(self) -> None:
"""
On-Model Hardware Detection Handling
"""
for controller in self.constants.computer.ethernet:
if isinstance(controller, device_probe.BroadcomEthernet) and controller.chipset == device_probe.BroadcomEthernet.Chipsets.AppleBCM5701Ethernet:
if not self.model in smbios_data.smbios_dictionary:
@@ -31,7 +46,7 @@ class build_wired:
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value:
# Required due to Big Sur's BCM5701 requiring VT-D support
# Applicable for pre-Ivy Bridge models
support.build_support(self.model, self.constants, self.config).enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path)
elif isinstance(controller, device_probe.IntelEthernet):
if not self.model in smbios_data.smbios_dictionary:
continue
@@ -39,19 +54,22 @@ class build_wired:
# Apple's IOSkywalkFamily in DriverKit requires VT-D support
# Applicable for pre-Ivy Bridge models
if controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntelI210Ethernet:
support.build_support(self.model, self.constants, self.config).enable_kext("CatalinaIntelI210Ethernet.kext", self.constants.i210_version, self.constants.i210_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CatalinaIntelI210Ethernet.kext", self.constants.i210_version, self.constants.i210_path)
elif controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntel8254XEthernet:
support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntel8254XEthernet.kext", self.constants.intel_8254x_version, self.constants.intel_8254x_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleIntel8254XEthernet.kext", self.constants.intel_8254x_version, self.constants.intel_8254x_path)
elif controller.chipset == device_probe.IntelEthernet.Chipsets.Intel82574L:
support.build_support(self.model, self.constants, self.config).enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path)
elif isinstance(controller, device_probe.NVIDIAEthernet):
support.build_support(self.model, self.constants, self.config).enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path)
elif isinstance(controller, device_probe.Marvell) or isinstance(controller, device_probe.SysKonnect):
support.build_support(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path)
def prebuilt_assumption(self):
# Stock hardware assumptions
def _prebuilt_assumption(self) -> None:
"""
Fall back to pre-built assumptions
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "Ethernet Chipset" in smbios_data.smbios_dictionary[self.model]:
@@ -61,12 +79,12 @@ class build_wired:
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value:
# Required due to Big Sur's BCM5701 requiring VT-D support
# Applicable for pre-Ivy Bridge models
support.build_support(self.model, self.constants, self.config).enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path)
elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Nvidia":
support.build_support(self.model, self.constants, self.config).enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path)
elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Marvell":
support.build_support(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path)
elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Intel 80003ES2LAN":
support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntel8254XEthernet.kext", self.constants.intel_8254x_version, self.constants.intel_8254x_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleIntel8254XEthernet.kext", self.constants.intel_8254x_version, self.constants.intel_8254x_path)
elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Intel 82574L":
support.build_support(self.model, self.constants, self.config).enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path)

View File

@@ -1,38 +1,53 @@
# Class for handling Wireless Networking Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import logging
from resources import constants, device_probe, utilities
from resources.build import support
from data import smbios_data
import logging
class build_wireless:
class BuildWirelessNetworking:
"""
Build Library for Wireless Networking Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
def build(self):
# WiFi patches
def _build(self) -> None:
"""
Kick off Wireless Build Process
"""
if not self.constants.custom_model and self.constants.computer.wifi:
self.on_model()
self._on_model()
else:
self.prebuilt_assumption()
self.wowl_handling()
self._prebuilt_assumption()
self._wowl_handling()
def on_model(self):
def _on_model(self) -> None:
"""
On-Model Hardware Detection Handling
"""
logging.info(f"- Found Wireless Device {utilities.friendly_hex(self.computer.wifi.vendor_id)}:{utilities.friendly_hex(self.computer.wifi.device_id)}")
self.config["#Revision"]["Hardware-Wifi"] = f"{utilities.friendly_hex(self.computer.wifi.vendor_id)}:{utilities.friendly_hex(self.computer.wifi.device_id)}"
if isinstance(self.computer.wifi, device_probe.Broadcom):
# This works around OCLP spoofing the Wifi card and therefore unable to actually detect the correct device
if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirportBrcmNIC and self.constants.validate is False and self.computer.wifi.country_code:
support.build_support(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
logging.info(f"- Setting Wireless Card's Country Code: {self.computer.wifi.country_code}")
if self.computer.wifi.pci_path:
arpt_path = self.computer.wifi.pci_path
@@ -44,65 +59,79 @@ class build_wireless:
logging.info("- Enabling Wake on WLAN support")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl"
elif self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360:
self.wifi_fake_id()
self._wifi_fake_id()
elif self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4331:
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortBrcm4331.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortBrcm4331.kext")["Enabled"] = True
elif self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm43224:
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AppleAirPortBrcm43224.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AppleAirPortBrcm43224.kext")["Enabled"] = True
elif isinstance(self.computer.wifi, device_probe.Atheros) and self.computer.wifi.chipset == device_probe.Atheros.Chipsets.AirPortAtheros40:
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortAtheros40.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortAtheros40.kext")["Enabled"] = True
def prebuilt_assumption(self):
def _prebuilt_assumption(self) -> None:
"""
Fall back to pre-built assumptions
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "Wireless Model" in smbios_data.smbios_dictionary[self.model]:
return
if smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4360:
logging.info("- Enabling BCM943224 and BCM94331 Networking Support")
self.wifi_fake_id()
self._wifi_fake_id()
elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4331:
logging.info("- Enabling BCM94328 Networking Support")
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortBrcm4331.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortBrcm4331.kext")["Enabled"] = True
elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm43224:
logging.info("- Enabling BCM94328 Networking Support")
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AppleAirPortBrcm43224.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AppleAirPortBrcm43224.kext")["Enabled"] = True
elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Atheros.Chipsets.AirPortAtheros40:
logging.info("- Enabling Atheros Networking Support")
support.build_support(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.build_support(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortAtheros40.kext")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortAtheros40.kext")["Enabled"] = True
elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirportBrcmNIC:
support.build_support(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
def wowl_handling(self):
# To avoid reduced networking performance from wake, AirPortBrcmFixup is used to disable wake on WLAN by default.
# However some users may want to enable wake on WLAN, so enable if requested.
def _wowl_handling(self) -> None:
"""
Wake on WLAN handling
To avoid reduced networking performance from wake, AirPortBrcmFixup is used to disable wake on WLAN by default.
However some users may want to enable wake on WLAN, so enable if requested.
"""
if self.constants.enable_wake_on_wlan is False:
return
if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AirportBrcmFixup.kext")["Enabled"] is False:
if support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AirportBrcmFixup.kext")["Enabled"] is False:
return
logging.info("- Enabling Wake on WLAN support")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl"
def wifi_fake_id(self):
# BCM94331 and BCM943224 are both partially supported within Big Sur's native AirPortBrcmNIC stack
# Simply adding the Device IDs and usage of AirPortBrcmFixup will restore full functionality
support.build_support(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AirportBrcmFixup.kext/Contents/PlugIns/AirPortBrcmNIC_Injector.kext")["Enabled"] = True
def _wifi_fake_id(self) -> None:
"""
Fake Device ID Handler for BCM943224 and BCM94331 chipsets
BCM94331 and BCM943224 are both partially supported within Big Sur's native AirPortBrcmNIC stack
Simply adding the Device IDs and usage of AirPortBrcmFixup will restore full functionality
"""
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AirportBrcmFixup.kext/Contents/PlugIns/AirPortBrcmNIC_Injector.kext")["Enabled"] = True
if not self.constants.custom_model and self.computer.wifi and self.computer.wifi.pci_path:
arpt_path = self.computer.wifi.pci_path
logging.info(f"- Found ARPT device at {arpt_path}")

View File

@@ -1,23 +1,34 @@
# Class for handling macOS Security Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
from resources import constants, utilities
import logging
import binascii
from resources import constants, utilities, device_probe
from resources.build import support
import binascii
import logging
class BuildSecurity:
"""
Build Library for Security Patch Support
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
class build_security:
def _build(self) -> None:
"""
Kick off Security Build Process
"""
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
def build(self):
if self.constants.sip_status is False or self.constants.custom_sip_value:
# Work-around 12.3 bug where Electron apps no longer launch with SIP lowered
# Unknown whether this is intended behavior or not, revisit with 12.4
@@ -26,7 +37,7 @@ class build_security:
# Adds AutoPkgInstaller for Automatic OpenCore-Patcher installation
# Only install if running the GUI (AutoPkg-Assets.pkg requires the GUI)
if self.constants.wxpython_variant is True:
support.build_support(self.model, self.constants, self.config).enable_kext("AutoPkgInstaller.kext", self.constants.autopkg_version, self.constants.autopkg_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AutoPkgInstaller.kext", self.constants.autopkg_version, self.constants.autopkg_path)
if self.constants.custom_sip_value:
logging.info(f"- Setting SIP value to: {self.constants.custom_sip_value}")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = utilities.string_to_hex(self.constants.custom_sip_value.lstrip("0x"))
@@ -38,7 +49,7 @@ class build_security:
# This is however hidden behind kern.development, thus we patch _apfs_filevault_allowed to always return true
# Note this function was added in 11.3 (20E232, 20.4), older builds do not support this (ie. 11.2.3)
logging.info("- Allowing FileVault on Root Patched systems")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Force FileVault on Broken Seal")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Force FileVault on Broken Seal")["Enabled"] = True
# Lets us check in sys_patch.py if config supports FileVault
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Settings"] += " -allow_fv"
@@ -46,7 +57,7 @@ class build_security:
# - Ref: https://github.com/dortania/OpenCore-Legacy-Patcher/issues/1019
logging.info("- Enabling KC UUID mismatch patch")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -nokcmismatchpanic"
support.build_support(self.model, self.constants, self.config).enable_kext("RSRHelper.kext", self.constants.rsrhelper_version, self.constants.rsrhelper_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("RSRHelper.kext", self.constants.rsrhelper_version, self.constants.rsrhelper_path)
if self.constants.disable_cs_lv is True:
# In Ventura, LV patch broke. For now, add AMFI arg
@@ -56,18 +67,18 @@ class build_security:
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " amfi=0x80"
else:
logging.info("- Disabling Library Validation")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable Library Validation Enforcement")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable _csr_check() in _vnode_check_signature")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable Library Validation Enforcement")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable _csr_check() in _vnode_check_signature")["Enabled"] = True
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Settings"] += " -allow_amfi"
# CSLVFixup simply patches out __RESTRICT and __restrict out of the Music.app Binary
# Ref: https://pewpewthespells.com/blog/blocking_code_injection_on_ios_and_os_x.html
support.build_support(self.model, self.constants, self.config).enable_kext("CSLVFixup.kext", self.constants.cslvfixup_version, self.constants.cslvfixup_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("CSLVFixup.kext", self.constants.cslvfixup_version, self.constants.cslvfixup_path)
if self.constants.secure_status is False:
logging.info("- Disabling SecureBootModel")
self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled"
if self.constants.force_vmm is True:
logging.info("- Forcing VMM patchset to support OTA updates")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True

View File

@@ -1,48 +1,71 @@
# Class for handling SMBIOS Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import ast
import uuid
import logging
import binascii
import plistlib
import subprocess
from pathlib import Path
from resources import constants, utilities, generate_smbios
from resources.build import support
from data import smbios_data, cpu_data, model_array
import subprocess, plistlib, binascii, uuid, ast, logging
from pathlib import Path
class build_smbios:
class BuildSMBIOS:
"""
Build Library for SMBIOS Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self._build()
def _build(self) -> None:
"""
Kick off SMBIOS Build Process
"""
def build(self):
if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True:
if self.constants.serial_settings == "None":
# Credit to Parrotgeek1 for boot.efi and hv_vmm_present patch sets
logging.info("- Enabling Board ID exemption patch")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Skip Board ID check")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Skip Board ID check")["Enabled"] = True
logging.info("- Enabling VMM exemption patch")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True
else:
logging.info("- Enabling SMC exemption patch")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.driver.AppleSMC")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).enable_kext("SMC-Spoof.kext", self.constants.smcspoof_version, self.constants.smcspoof_path)
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.driver.AppleSMC")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).enable_kext("SMC-Spoof.kext", self.constants.smcspoof_version, self.constants.smcspoof_path)
if self.constants.serial_settings in ["Moderate", "Advanced"]:
logging.info("- Enabling USB Rename Patches")
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "XHC1 to SHC1")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC1 to EH01")["Enabled"] = True
support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC2 to EH02")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "XHC1 to SHC1")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC1 to EH01")["Enabled"] = True
support.BuildSupport(self.model, self.constants, self.config).get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC2 to EH02")["Enabled"] = True
if self.model == self.constants.override_smbios:
logging.info("- Adding -no_compat_check")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check"
def set_smbios(self):
def set_smbios(self) -> None:
"""
SMBIOS Handler
"""
spoofed_model = self.model
if self.constants.override_smbios == "Default":
@@ -70,14 +93,14 @@ class build_smbios:
if self.constants.serial_settings == "Moderate":
logging.info("- Using Moderate SMBIOS patching")
self.moderate_serial_patch()
self._moderate_serial_patch()
elif self.constants.serial_settings == "Advanced":
logging.info("- Using Advanced SMBIOS patching")
self.advanced_serial_patch()
self._advanced_serial_patch()
elif self.constants.serial_settings == "Minimal":
logging.info("- Using Minimal SMBIOS patching")
self.spoofed_model = self.model
self.minimal_serial_patch()
self._minimal_serial_patch()
else:
# Update DataHub to resolve Lilu Race Condition
# macOS Monterey will sometimes not present the boardIdentifier in the DeviceTree on UEFI 1.2 or older Mac,
@@ -178,7 +201,17 @@ class build_smbios:
plistlib.dump(agdp_config, Path(new_agdp_ls).open("wb"), sort_keys=True)
def minimal_serial_patch(self):
def _minimal_serial_patch(self) -> None:
"""
Minimal SMBIOS Spoofing Handler
This function will only spoof the following:
- Board ID
- Firmware Features
- BIOS Version
- Serial Numbers (if override requested)
"""
# Generate Firmware Features
fw_feature = generate_smbios.generate_fw_features(self.model, self.constants.custom_model)
# fw_feature = self.patch_firmware_feature()
@@ -233,7 +266,13 @@ class build_smbios:
self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb
def moderate_serial_patch(self):
def _moderate_serial_patch(self) -> None:
"""
Moderate SMBIOS Spoofing Handler
Implements a full SMBIOS replacement, however retains original serial numbers (unless override requested)
"""
if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1:
self.config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537
if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "":
@@ -251,7 +290,13 @@ class build_smbios:
self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model
def advanced_serial_patch(self):
def _advanced_serial_patch(self) -> None:
"""
Advanced SMBIOS Spoofing Handler
Implements a full SMBIOS replacement, including serial numbers
"""
if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1:
self.config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537
if self.constants.custom_serial_number == "" or self.constants.custom_board_serial_number == "":

View File

@@ -1,29 +1,46 @@
# Class for handling Storage Controller Patches, invocation from build.py
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import logging
from resources import constants, device_probe, utilities
from resources.build import support
from data import model_array, smbios_data, cpu_data
import logging
class build_storage:
class BuildStorage:
"""
Build Library for System Storage Support
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
self.computer = self.constants.computer
Invoke from build.py
"""
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
self.computer: device_probe.Computer = self.constants.computer
self._build()
def build(self):
self.ahci_handling()
self.pata_handling()
self.misc_handling()
self.pcie_handling()
self.trim_handling()
def _build(self) -> None:
"""
Kick off Storage Build Process
"""
self._ahci_handling()
self._pata_handling()
self._misc_handling()
self._pcie_handling()
self._trim_handling()
def _ahci_handling(self) -> None:
"""
AHCI (SATA) Handler
"""
def ahci_handling(self):
# MacBookAir6,x ship with an AHCI over PCIe SSD model 'APPLE SSD TS0128F' and 'APPLE SSD TS0256F'
# This controller is not supported properly in macOS Ventura, instead populating itself as 'Media' with no partitions
# To work-around this, use Monterey's AppleAHCI driver to force support
@@ -33,11 +50,11 @@ class build_storage:
# https://linux-hardware.org/?id=pci:1179-010b-1b4b-9183
if controller.vendor_id == 0x1179 and controller.device_id == 0x010b:
logging.info("- Enabling AHCI SSD patch")
support.build_support(self.model, self.constants, self.config).enable_kext("MonteAHCIPort.kext", self.constants.monterey_ahci_version, self.constants.monterey_ahci_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("MonteAHCIPort.kext", self.constants.monterey_ahci_version, self.constants.monterey_ahci_path)
break
elif self.model in ["MacBookAir6,1", "MacBookAir6,2"]:
logging.info("- Enabling AHCI SSD patch")
support.build_support(self.model, self.constants, self.config).enable_kext("MonteAHCIPort.kext", self.constants.monterey_ahci_version, self.constants.monterey_ahci_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("MonteAHCIPort.kext", self.constants.monterey_ahci_version, self.constants.monterey_ahci_path)
# ThirdPartyDrives Check
if self.constants.allow_3rd_party_drives is True:
@@ -58,7 +75,11 @@ class build_storage:
break
def pata_handling(self):
def _pata_handling(self) -> None:
"""
ATA (PATA) Handler
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "Stock Storage" in smbios_data.smbios_dictionary[self.model]:
@@ -66,10 +87,14 @@ class build_storage:
if not "PATA" in smbios_data.smbios_dictionary[self.model]["Stock Storage"]:
return
support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntelPIIXATA.kext", self.constants.piixata_version, self.constants.piixata_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleIntelPIIXATA.kext", self.constants.piixata_version, self.constants.piixata_path)
def pcie_handling(self):
def _pcie_handling(self) -> None:
"""
PCIe/NVMe Handler
"""
if not self.constants.custom_model and (self.constants.allow_oc_everywhere is True or self.model in model_array.MacPro):
# Use Innie's same logic:
# https://github.com/cdf/Innie/blob/v1.3.0/Innie/Innie.cpp#L90-L97
@@ -79,7 +104,7 @@ class build_storage:
self.config["DeviceProperties"]["Add"][controller.pci_path] = {"built-in": 1}
else:
logging.info(f"- Failed to find Device path for PCIe Storage Controller {i}, falling back to Innie")
support.build_support(self.model, self.constants, self.config).enable_kext("Innie.kext", self.constants.innie_version, self.constants.innie_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("Innie.kext", self.constants.innie_version, self.constants.innie_path)
if not self.constants.custom_model and self.constants.allow_nvme_fixing is True:
nvme_devices = [i for i in self.computer.storage if isinstance(i, device_probe.NVMeController)]
@@ -102,7 +127,7 @@ class build_storage:
if (controller.vendor_id != 0x144D and controller.device_id != 0xA804):
# Avoid injecting NVMeFix when a native Apple NVMe drive is present
# https://github.com/acidanthera/NVMeFix/blob/1.0.9/NVMeFix/NVMeFix.cpp#L220-L225
support.build_support(self.model, self.constants, self.config).enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path)
# Apple RAID Card check
if not self.constants.custom_model:
@@ -110,15 +135,19 @@ class build_storage:
for storage_controller in self.computer.storage:
if storage_controller.vendor_id == 0x106b and storage_controller.device_id == 0x008A:
# AppleRAIDCard.kext only supports pci106b,8a
support.build_support(self.model, self.constants, self.config).enable_kext("AppleRAIDCard.kext", self.constants.apple_raid_version, self.constants.apple_raid_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleRAIDCard.kext", self.constants.apple_raid_version, self.constants.apple_raid_path)
break
elif self.model.startswith("Xserve"):
# For Xserves, assume RAID is present
# Namely due to Xserve2,1 being limited to 10.7, thus no hardware detection
support.build_support(self.model, self.constants, self.config).enable_kext("AppleRAIDCard.kext", self.constants.apple_raid_version, self.constants.apple_raid_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleRAIDCard.kext", self.constants.apple_raid_version, self.constants.apple_raid_path)
def misc_handling(self):
def _misc_handling(self) -> None:
"""
SDXC Handler
"""
if not self.model in smbios_data.smbios_dictionary:
return
if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]:
@@ -128,10 +157,14 @@ class build_storage:
# However pre-Ivy Bridge don't support this feature
if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.sandy_bridge.value:
if (self.constants.computer.sdxc_controller and not self.constants.custom_model) or (self.model.startswith("MacBookPro8") or self.model.startswith("Macmini5")):
support.build_support(self.model, self.constants, self.config).enable_kext("BigSurSDXC.kext", self.constants.bigsursdxc_version, self.constants.bigsursdxc_path)
support.BuildSupport(self.model, self.constants, self.config).enable_kext("BigSurSDXC.kext", self.constants.bigsursdxc_version, self.constants.bigsursdxc_path)
def trim_handling(self):
def _trim_handling(self) -> None:
"""
TRIM Handler
"""
if self.constants.apfs_trim_timeout is False:
logging.info(f"- Disabling APFS TRIM timeout")
self.config["Kernel"]["Quirks"]["SetApfsTrimTimeout"] = 0

View File

@@ -1,22 +1,41 @@
# Utility class for build functions
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
# Copyright (C) 2020-2023, Dhinak G, Mykola Grymalyuk
import shutil
import typing
import logging
import plistlib
import zipfile
import subprocess
from pathlib import Path
from resources import constants, utilities
from pathlib import Path
import shutil, plistlib, subprocess, zipfile
import logging
class build_support:
class BuildSupport:
"""
Support Library for build.py and related libraries
"""
def __init__(self, model, versions, config):
self.model = model
self.constants: constants.Constants = versions
self.config = config
def __init__(self, model: str, global_constants: constants.Constants, config: dict) -> None:
self.model: str = model
self.config: dict = config
self.constants: constants.Constants = global_constants
@staticmethod
def get_item_by_kv(iterable, key, value):
def get_item_by_kv(iterable: dict, key: str, value: typing.Any) -> dict:
"""
Gets an item from a list of dicts by key and value
Parameters:
iterable (list): List of dicts
key (str): Key to search for
value (any): Value to search for
"""
item = None
for i in iterable:
if i[key] == value:
@@ -25,24 +44,49 @@ class build_support:
return item
def get_kext_by_bundle_path(self, bundle_path):
kext = self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", bundle_path)
def get_kext_by_bundle_path(self, bundle_path: str) -> dict:
"""
Gets a kext by bundle path
Parameters:
bundle_path (str): Relative bundle path of the kext in the EFI folder
"""
kext: dict = self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", bundle_path)
if not kext:
logging.info(f"- Could not find kext {bundle_path}!")
raise IndexError
return kext
def get_efi_binary_by_path(self, bundle_path, entry_location, efi_type):
efi_binary = self.get_item_by_kv(self.config[entry_location][efi_type], "Path", bundle_path)
def get_efi_binary_by_path(self, bundle_name: str, entry_type: str, efi_type: str) -> dict:
"""
Gets an EFI binary by name
Parameters:
bundle_name (str): Name of the EFI binary
entry_type (str): Type of EFI binary (UEFI, Misc)
efi_type (str): Type of EFI binary (Drivers, Tools)
"""
efi_binary: dict = self.get_item_by_kv(self.config[entry_type][efi_type], "Path", bundle_name)
if not efi_binary:
logging.info(f"- Could not find {efi_type}: {bundle_path}!")
logging.info(f"- Could not find {efi_type}: {bundle_name}!")
raise IndexError
return efi_binary
def enable_kext(self, kext_name, kext_version, kext_path, check=False):
kext = self.get_kext_by_bundle_path(kext_name)
def enable_kext(self, kext_name: str, kext_version: str, kext_path: Path, check: bool = False) -> None:
"""
Enables a kext in the config.plist
Parameters:
kext_name (str): Name of the kext
kext_version (str): Version of the kext
kext_path (Path): Path to the kext
"""
kext: dict = self.get_kext_by_bundle_path(kext_name)
if callable(check) and not check():
# Check failed
@@ -56,7 +100,11 @@ class build_support:
kext["Enabled"] = True
def sign_files(self):
def sign_files(self) -> None:
"""
Signs files for on OpenCorePkg's Vault system
"""
if self.constants.vault is False:
return
@@ -72,9 +120,13 @@ class build_support:
subprocess.run([str(self.constants.vault_path), f"{self.constants.oc_folder}/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def validate_pathing(self):
# Verify whether all files are accounted for on-disk
# This ensures that OpenCore won't hit a critical error and fail to boot
def validate_pathing(self) -> None:
"""
Validate whether all files are accounted for on-disk
This ensures that OpenCore won't hit a critical error and fail to boot
"""
logging.info("- Validating generated config")
if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")):
logging.info("- OpenCore config file missing!!!")
@@ -124,7 +176,11 @@ class build_support:
raise Exception(f"Found extra driver: {driver_file.name}")
def cleanup(self):
def cleanup(self) -> None:
"""
Clean up files and entries
"""
logging.info("- Cleaning up files")
# Remove unused entries
entries_to_clean = {

View File

@@ -752,7 +752,7 @@ class wx_python_gui:
while self.is_unpack_finished() is False:
time.sleep(0.1)
build.build_opencore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore()
build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants)
# Once finished, change build_opencore button to "Install OpenCore"
self.build_opencore.SetLabel("🔩 Install OpenCore")
self.build_opencore.Bind(wx.EVT_BUTTON, self.install_menu)

View File

@@ -63,7 +63,7 @@ class PatcherValidation:
for model in model_array.SupportedSMBIOS:
logging.info(f"Validating predefined model: {model}")
self.constants.custom_model = model
build.build_opencore(self.constants.custom_model, self.constants).build_opencore()
build.BuildOpenCore(self.constants.custom_model, self.constants)
result = subprocess.run([self.constants.ocvalidate_path, f"{self.constants.opencore_release_folder}/EFI/OC/config.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if result.returncode != 0:
logging.info("Error on build!")
@@ -83,7 +83,7 @@ class PatcherValidation:
self.constants.computer = model
self.constants.custom_model = ""
logging.info(f"Validating dumped model: {self.constants.computer.real_model}")
build.build_opencore(self.constants.computer.real_model, self.constants).build_opencore()
build.BuildOpenCore(self.constants.computer.real_model, self.constants)
result = subprocess.run([self.constants.ocvalidate_path, f"{self.constants.opencore_release_folder}/EFI/OC/config.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if result.returncode != 0:
logging.info("Error on build!")