From 21c40277bb73ad077899badc669e7f95acc87129 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 12 Nov 2022 17:10:40 -0700 Subject: [PATCH 01/19] Modularize build.py --- gui/gui_main.py | 3 +- resources/arguments.py | 3 +- resources/build.py | 1561 ------------------------ resources/build/bluetooth.py | 39 + resources/build/build.py | 413 +++++++ resources/build/firmware.py | 224 ++++ resources/build/graphics_audio.py | 342 ++++++ resources/build/networking/wired.py | 54 + resources/build/networking/wireless.py | 108 ++ resources/build/security.py | 17 + resources/build/smbios.py | 245 ++++ resources/build/storage.py | 110 ++ resources/build/support.py | 174 +++ resources/main.py | 3 +- resources/validation.py | 3 +- 15 files changed, 1734 insertions(+), 1565 deletions(-) delete mode 100644 resources/build.py create mode 100644 resources/build/bluetooth.py create mode 100644 resources/build/build.py create mode 100644 resources/build/firmware.py create mode 100644 resources/build/graphics_audio.py create mode 100644 resources/build/networking/wired.py create mode 100644 resources/build/networking/wireless.py create mode 100644 resources/build/security.py create mode 100644 resources/build/smbios.py create mode 100644 resources/build/storage.py create mode 100644 resources/build/support.py diff --git a/gui/gui_main.py b/gui/gui_main.py index c350a3a65..0ba259f40 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -16,7 +16,8 @@ from pathlib import Path import binascii import hashlib -from resources import constants, defaults, build, install, installer, sys_patch_download, utilities, sys_patch_detect, sys_patch, run, generate_smbios, updates, integrity_verification, global_settings, kdk_handler +from resources import constants, defaults, install, installer, sys_patch_download, utilities, sys_patch_detect, sys_patch, run, generate_smbios, updates, integrity_verification, global_settings, kdk_handler +from resources.build import build from data import model_array, os_data, smbios_data, sip_data from gui import menu_redirect, gui_help diff --git a/resources/arguments.py b/resources/arguments.py index 19db0350a..238f93be6 100644 --- a/resources/arguments.py +++ b/resources/arguments.py @@ -1,5 +1,6 @@ import sys -from resources import defaults, build, utilities, validation, sys_patch, sys_patch_auto +from resources import defaults, utilities, validation, sys_patch, sys_patch_auto +from resources.build import build from data import model_array import threading import time diff --git a/resources/build.py b/resources/build.py deleted file mode 100644 index b452c6cfa..000000000 --- a/resources/build.py +++ /dev/null @@ -1,1561 +0,0 @@ -# Commands for building the EFI and SMBIOS -# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk - -import binascii -import copy -import pickle -import plistlib -import shutil -import subprocess -import uuid -import zipfile -import ast -from pathlib import Path -from datetime import date - -from resources import constants, utilities, device_probe, generate_smbios -from data import smbios_data, bluetooth_data, cpu_data, os_data, model_array - - -def rmtree_handler(func, path, exc_info): - if exc_info[0] == FileNotFoundError: - return - raise # pylint: disable=misplaced-bare-raise - - -class BuildOpenCore: - def __init__(self, model, versions): - self.model = model - self.config = None - self.constants: constants.Constants = versions - self.computer = self.constants.computer - self.gfx0_path = None - - def disk_type(self): - drive_host_info = plistlib.loads(subprocess.run(f"diskutil info -plist {self.constants.disk}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()) - sd_type = drive_host_info["MediaName"] - try: - ssd_type = drive_host_info["SolidState"] - except KeyError: - ssd_type = False - # Array filled with common SD Card names - # Note most USB-based SD Card readers generally report as "Storage Device", and no reliable way to detect further - if sd_type in ["SD Card Reader", "SD/MMC"]: - print("- Adding SD Card icon") - shutil.copy(self.constants.icon_path_sd, self.constants.opencore_release_folder) - elif ssd_type is True: - print("- Adding SSD icon") - shutil.copy(self.constants.icon_path_ssd, self.constants.opencore_release_folder) - elif drive_host_info["BusProtocol"] == "USB": - print("- Adding External USB Drive icon") - shutil.copy(self.constants.icon_path_external, self.constants.opencore_release_folder) - else: - print("- Adding Internal Drive icon") - shutil.copy(self.constants.icon_path_internal, self.constants.opencore_release_folder) - - def chainload_diags(self): - Path(self.constants.opencore_release_folder / Path("System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers")).mkdir(parents=True, exist_ok=True) - if self.constants.boot_efi is True: - path_oc_loader = self.constants.opencore_release_folder / Path("EFI/BOOT/BOOTx64.efi") - else: - path_oc_loader = self.constants.opencore_release_folder / Path("System/Library/CoreServices/boot.efi") - shutil.move(path_oc_loader, self.constants.opencore_release_folder / Path("System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers/Product.efi")) - shutil.copy(self.constants.diags_launcher_path, self.constants.opencore_release_folder) - shutil.move(self.constants.opencore_release_folder / Path("diags.efi"), self.constants.opencore_release_folder / Path("boot.efi")) - - def build_efi(self): - utilities.cls() - if not self.constants.custom_model: - print(f"Building Configuration on model: {self.model}") - else: - print(f"Building Configuration for external model: {self.model}") - if not Path(self.constants.build_path).exists(): - Path(self.constants.build_path).mkdir() - print("Created build folder") - else: - print("Build folder already present, skipping") - - if Path(self.constants.opencore_zip_copied).exists(): - print("Deleting old copy of OpenCore zip") - Path(self.constants.opencore_zip_copied).unlink() - if Path(self.constants.opencore_release_folder).exists(): - print("Deleting old copy of OpenCore folder") - shutil.rmtree(self.constants.opencore_release_folder, onerror=rmtree_handler, ignore_errors=True) - - print(f"\n- Adding OpenCore v{self.constants.opencore_version} {self.constants.opencore_build}") - shutil.copy(self.constants.opencore_zip_source, self.constants.build_path) - zipfile.ZipFile(self.constants.opencore_zip_copied).extractall(self.constants.build_path) - - print("- Adding config.plist for OpenCore") - # Setup config.plist for editing - shutil.copy(self.constants.plist_template, self.constants.oc_folder) - self.config = plistlib.load(Path(self.constants.plist_path).open("rb")) - - # Set revision in config - 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" - computer_copy = copy.copy(self.computer) - computer_copy.ioregistry = None - self.config["#Revision"]["Hardware-Probe"] = pickle.dumps(computer_copy) - else: - self.config["#Revision"]["Build-Type"] = "OpenCore Built for External Machine" - self.config["#Revision"]["OpenCore-Version"] = f"{self.constants.opencore_version} - {self.constants.opencore_build} - {self.constants.opencore_commit}" - self.config["#Revision"]["Original-Model"] = self.model - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model - - for name, version, path, check in [ - # Essential kexts - ("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path, lambda: True), - ("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), - ("SMC-Spoof.kext", self.constants.smcspoof_version, self.constants.smcspoof_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), - # CPU patches - ("AAAMouSSE.kext", self.constants.mousse_version, self.constants.mousse_path, lambda: smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value), - ( - "CPUFriend.kext", - self.constants.cpufriend_version, - self.constants.cpufriend_path, - lambda: self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.disallow_cpufriend is False and self.constants.serial_settings != "None", - ), - ( - "telemetrap.kext", - self.constants.telemetrap_version, - self.constants.telemetrap_path, - lambda: smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value, - ), - # Legacy audio - ( - "AppleALC.kext", - self.constants.applealc_version, - self.constants.applealc_path, - lambda: (self.model in model_array.LegacyAudio or self.model in model_array.MacPro) and self.constants.set_alc_usage is True, - ), - # IDE patch - ("AppleIntelPIIXATA.kext", self.constants.piixata_version, self.constants.piixata_path, lambda: "PATA" in smbios_data.smbios_dictionary[self.model]["Stock Storage"]), - # Misc - ("DebugEnhancer.kext", self.constants.debugenhancer_version, self.constants.debugenhancer_path, lambda: self.constants.kext_debug is True), - ("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path, lambda: self.model in ["MacBook4,1", "MacBook5,2"]), - ]: - self.enable_kext(name, version, path, check) - - 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 - # print("- Enabling Board ID exemption patch") - # self.get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Skip Board ID check")["Enabled"] = True - - print("- Enabling VMM exemption patch") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True - - # Patch HW_BID to OC_BID - # Set OC_BID to iMac18,1 Board ID (Mac-F60DEB81FF30ACF6) - # Goal is to only allow OS booting through OCLP, otherwise failing - print("- Enabling HW_BID reroute") - self.get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Reroute HW_BID to OC_BID")["Enabled"] = True - self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["OC_BID"] = "Mac-BE088AF8C5EB4FA2" - self.config["NVRAM"]["Delete"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"] += ["OC_BID"] - else: - print("- Enabling SMC exemption patch") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.driver.AppleSMC")["Enabled"] = True - - if self.get_kext_by_bundle_path("Lilu.kext")["Enabled"] is True: - # Required for Lilu in 11.0+ - self.config["Kernel"]["Quirks"]["DisableLinkeditJettison"] = True - - if self.constants.serial_settings != "None": - # AppleMCEReporter is very picky about which models attach to the kext - # Commonly it will kernel panic on multi-socket systems, however even on single-socket systems it may cause instability - # To avoid any issues, we'll disable it if the spoof is set to an affected SMBIOS - affected_smbios = ["MacPro6,1", "MacPro7,1", "iMacPro1,1"] - 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: - self.enable_kext("AppleMCEReporterDisabler.kext", self.constants.mce_version, self.constants.mce_path) - - if self.constants.fu_status is True: - # Enable FeatureUnlock.kext - self.enable_kext("FeatureUnlock.kext", self.constants.featureunlock_version, self.constants.featureunlock_path) - if self.constants.fu_arguments is not None: - print(f"- Adding additional FeatureUnlock args: {self.constants.fu_arguments}") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += self.constants.fu_arguments - - 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 - # Because of this, X86PP will match onto the CPU instead of ACPI_SMC_PlatformPlugin - # This causes power management to break on pre-Ivy Bridge CPUs as they don't have correct - # power management tables provided. - # This patch will simply increase ASPP's 'IOProbeScore' to outmatch X86PP - print("- Overriding ACPI SMC matching") - self.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 - self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", "ASPP-Override.kext")["MinKernel"] = "" - - if not self.constants.custom_model and self.constants.computer.ethernet: - for controller in self.constants.computer.ethernet: - if isinstance(controller, device_probe.BroadcomEthernet) and controller.chipset == device_probe.BroadcomEthernet.Chipsets.AppleBCM5701Ethernet: - 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 - if self.get_kext_by_bundle_path("CatalinaBCM5701Ethernet.kext")["Enabled"] is False: - self.enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path) - elif isinstance(controller, device_probe.IntelEthernet): - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value: - # Apple's IOSkywalkFamily in DriverKit requires VT-D support - # Applicable for pre-Ivy Bridge models - if controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntelI210Ethernet: - if self.get_kext_by_bundle_path("CatalinaIntelI210Ethernet.kext")["Enabled"] is False: - self.enable_kext("CatalinaIntelI210Ethernet.kext", self.constants.i210_version, self.constants.i210_path) - elif controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntel8254XEthernet: - if self.get_kext_by_bundle_path("AppleIntel8254XEthernet.kext")["Enabled"] is False: - self.enable_kext("AppleIntel8254XEthernet.kext", self.constants.intel_8254x_version, self.constants.intel_8254x_path) - elif controller.chipset == device_probe.IntelEthernet.Chipsets.Intel82574L: - if self.get_kext_by_bundle_path("Intel82574L.kext")["Enabled"] is False: - self.enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path) - elif isinstance(controller, device_probe.NVIDIAEthernet): - if self.get_kext_by_bundle_path("nForceEthernet.kext")["Enabled"] is False: - self.enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path) - elif isinstance(controller, device_probe.Marvell) or isinstance(controller, device_probe.SysKonnect): - if self.get_kext_by_bundle_path("MarvelYukonEthernet.kext")["Enabled"] is False: - self.enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path) - else: - if smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Broadcom": - 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 - self.enable_kext("CatalinaBCM5701Ethernet.kext", self.constants.bcm570_version, self.constants.bcm570_path) - elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Nvidia": - self.enable_kext("nForceEthernet.kext", self.constants.nforce_version, self.constants.nforce_path) - elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Marvell": - self.enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path) - elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Intel 80003ES2LAN": - self.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": - self.enable_kext("Intel82574L.kext", self.constants.intel_82574l_version, self.constants.intel_82574l_path) - - - # i3 Ivy Bridge iMacs don't support RDRAND - # However for prebuilt, assume they do - if (not self.constants.custom_model and "RDRAND" not in self.computer.cpu.flags) or \ - (smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.sandy_bridge.value): - # Ref: https://github.com/reenigneorcim/SurPlus - # Enable for all systems missing RDRAND support - print("- Adding SurPlus Patch for Race Condition") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["Enabled"] = True - self.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 - print("- Allowing SurPlus on all newer OSes") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "SurPlus v1 - PART 1 of 2 - Patch read_erandom (inlined in _early_random)")["MaxKernel"] = "" - self.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 - # Currently a (hopefully) temporary workaround for the issue, proper fix needs to be investigated - # Ref: - # https://forums.macrumors.com/threads/macos-12-monterey-on-unsupported-macs-thread.2299557/post-31120235 - # https://forums.macrumors.com/threads/monterand-probably-the-start-of-an-ongoing-saga.2320479/post-31123553 - - # 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: - self.enable_kext("NoAVXFSCompressionTypeZlib.kext", self.constants.apfs_zlib_version, self.constants.apfs_zlib_path) - self.enable_kext("NoAVXFSCompressionTypeZlib-AVXpel.kext", self.constants.apfs_zlib_v2_version, self.constants.apfs_zlib_v2_path) - - 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 - for i, controller in enumerate(self.computer.storage): - print(f"- Fixing PCIe Storage Controller ({i + 1}) reporting") - if controller.pci_path: - self.config["DeviceProperties"]["Add"][controller.pci_path] = {"built-in": 1} - else: - print(f"- Failed to find Device path for PCIe Storage Controller {i}, falling back to Innie") - if self.get_kext_by_bundle_path("Innie.kext")["Enabled"] is False: - self.enable_kext("Innie.kext", self.constants.innie_version, self.constants.innie_path) - if not self.computer.storage: - print("- No PCIe Storage Controllers found to fix") - - 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)] - for i, controller in enumerate(nvme_devices): - print(f"- Found 3rd Party NVMe SSD ({i + 1}): {utilities.friendly_hex(controller.vendor_id)}:{utilities.friendly_hex(controller.device_id)}") - self.config["#Revision"][f"Hardware-NVMe-{i}"] = f"{utilities.friendly_hex(controller.vendor_id)}:{utilities.friendly_hex(controller.device_id)}" - - # Disable Bit 0 (L0s), enable Bit 1 (L1) - nvme_aspm = (controller.aspm & (~0b11)) | 0b10 - - if controller.pci_path: - print(f"- Found NVMe ({i}) at {controller.pci_path}") - self.config["DeviceProperties"]["Add"].setdefault(controller.pci_path, {})["pci-aspm-default"] = nvme_aspm - self.config["DeviceProperties"]["Add"][controller.pci_path.rpartition("/")[0]] = {"pci-aspm-default": nvme_aspm} - else: - if "-nvmefaspm" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: - print("- Falling back to -nvmefaspm") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -nvmefaspm" - - 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 - if self.get_kext_by_bundle_path("NVMeFix.kext")["Enabled"] is False: - self.enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path) - - if not nvme_devices: - print("- No 3rd Party NVMe drives found") - - def wifi_fake_id(self): - self.enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path) - self.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 - print(f"- Found ARPT device at {arpt_path}") - else: - try: - smbios_data.smbios_dictionary[self.model]["nForce Chipset"] - # Nvidia chipsets all have the same path to ARPT - arpt_path = "PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)" - except KeyError: - if self.model in ("iMac7,1", "iMac8,1", "MacPro3,1", "MacBookPro4,1"): - arpt_path = "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)" - elif self.model in ("iMac13,1", "iMac13,2"): - arpt_path = "PciRoot(0x0)/Pci(0x1C,0x3)/Pci(0x0,0x0)" - elif self.model in ("MacPro4,1", "MacPro5,1"): - arpt_path = "PciRoot(0x0)/Pci(0x1C,0x5)/Pci(0x0,0x0)" - else: - # Assumes we have a laptop with Intel chipset - # iMac11,x-12,x also apply - arpt_path = "PciRoot(0x0)/Pci(0x1C,0x1)/Pci(0x0,0x0)" - print(f"- Using known DevicePath {arpt_path}") - # self.config["DeviceProperties"]["Add"][arpt_path] = {"device-id": binascii.unhexlify("ba430000"), "compatible": "pci14e4,43ba"} - - if not self.constants.custom_model and self.computer.wifi and self.constants.validate is False and self.computer.wifi.country_code: - print(f"- Applying fake ID for WiFi, setting Country Code: {self.computer.wifi.country_code}") - self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} - if self.constants.enable_wake_on_wlan is True: - print("- Enabling Wake on WLAN support") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl" - - # WiFi patches - if not self.constants.custom_model: - if self.computer.wifi: - print(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)}" - else: - print("- Unable to run Wireless hardware detection") - - if not self.constants.custom_model: - if self.computer.wifi: - 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: - self.enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path) - print(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 - print(f"- Found ARPT device at {arpt_path}") - self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} - else: - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" brcmfx-country={self.computer.wifi.country_code}" - if self.constants.enable_wake_on_wlan is True: - print("- 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: - wifi_fake_id(self) - elif self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4331: - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortBrcm4331.kext")["Enabled"] = True - elif self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm43224: - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.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: - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.get_kext_by_bundle_path("IO80211ElCap.kext/Contents/PlugIns/AirPortAtheros40.kext")["Enabled"] = True - else: - if smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4360: - print("- Enabling BCM943224 and BCM94331 Networking Support") - wifi_fake_id(self) - elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4331: - print("- Enabling BCM94328 Networking Support") - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.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: - print("- Enabling BCM94328 Networking Support") - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.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: - print("- Enabling Atheros Networking Support") - self.enable_kext("corecaptureElCap.kext", self.constants.corecaptureelcap_version, self.constants.corecaptureelcap_path) - self.enable_kext("IO80211ElCap.kext", self.constants.io80211elcap_version, self.constants.io80211elcap_path) - self.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: - self.enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path) - # print(f"- Setting Wireless Card's Country Code: {self.computer.wifi.country_code}") - # self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" brcmfx-country={self.computer.wifi.country_code}" - if self.constants.enable_wake_on_wlan is True: - print("- Enabling Wake on WLAN support") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl" - - # CPUFriend - if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": - pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") - if not pp_map_path.exists(): - raise Exception(f"{pp_map_path} does not exist!!! Please file an issue stating file is missing for {self.model}.") - Path(self.constants.pp_kext_folder).mkdir() - Path(self.constants.pp_contents_folder).mkdir() - shutil.copy(pp_map_path, self.constants.pp_contents_folder) - self.get_kext_by_bundle_path("CPUFriendDataProvider.kext")["Enabled"] = True - - # HID patches - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value: - print("- Adding IOHIDFamily patch") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Identifier", "com.apple.iokit.IOHIDFamily")["Enabled"] = True - - # Legacy iSight patches - try: - if smbios_data.smbios_dictionary[self.model]["Legacy iSight"] is True: - self.enable_kext("LegacyUSBVideoSupport.kext", self.constants.apple_isight_version, self.constants.apple_isight_path) - except KeyError: - pass - - # SSDT patches - 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")): - # Applicable for consumer Nehalem - print("- Adding SSDT-CPBG.aml") - self.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 - print("- Enabling Windows 10 UEFI Audio support") - self.get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-PCI.aml")["Enabled"] = True - self.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) - - # In macOS Ventura, Apple dropped AppleIntelCPUPowerManagement* kexts as they're unused on Haswell+ - # However re-injecting the AICPUPM kexts is not enough, as Ventura changed how 'intel_cpupm_matching' is set: - # https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/osfmk/i386/pal_routines.h#L153-L163 - # - # Specifically Apple has this logic for power management: - # - 0: Kext Based Power Management - # - 3: Kernel Based Power Management (For Haswell+ and Virtual Machines) - # - 4: Generic Virtual Machine Power Management - # - # Apple determines which to use by verifying whether 'plugin-type' exists in ACPI (with a value of 1 for Haswell, 2 for VMs) - # By default however, the plugin-type is not set, and thus the default value of '0' is used - # https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/osfmk/i386/pal_native.h#L62 - # - # With Ventura, Apple no longer sets '0' as the default value, and instead sets it to '3' - # This breaks AppleIntelCPUPowerManagement.kext matching as it no longer matches against the correct criteria - # - # To resolve, we patched AICPUPM to attach regardless of the value of 'intel_cpupm_matching' - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value: - print("- Enabling legacy power management support") - self.enable_kext("AppleIntelCPUPowerManagement.kext", self.constants.aicpupm_version, self.constants.aicpupm_path) - self.enable_kext("AppleIntelCPUPowerManagementClient.kext", self.constants.aicpupm_version, self.constants.aicpupm_client_path) - - # With macOS Monterey, Apple's SDXC driver requires the system to support VT-D - # 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")): - self.enable_kext("BigSurSDXC.kext", self.constants.bigsursdxc_version, self.constants.bigsursdxc_path) - - # USB Map - usb_map_path = Path(self.constants.plist_folder_path) / Path("AppleUSBMaps/Info.plist") - if ( - usb_map_path.exists() - and (self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True) - and self.model not in ["Xserve2,1", "Dortania1,1"] - and ( - (self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) - or self.constants.serial_settings in ["Moderate", "Advanced"]) - ): - print("- Adding USB-Map.kext") - Path(self.constants.map_kext_folder).mkdir() - Path(self.constants.map_contents_folder).mkdir() - shutil.copy(usb_map_path, self.constants.map_contents_folder) - self.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"]: - self.get_kext_by_bundle_path("USB-Map.kext")["MinKernel"] = "22.0.0" - - if self.constants.allow_oc_everywhere is False: - if self.constants.serial_settings != "None": - if self.model == "MacBookPro9,1": - print("- Adding AppleMuxControl Override") - amc_map_path = Path(self.constants.plist_folder_path) / Path("AppleMuxControl/Info.plist") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"agdpmod": "vit9696"} - Path(self.constants.amc_kext_folder).mkdir() - Path(self.constants.amc_contents_folder).mkdir() - shutil.copy(amc_map_path, self.constants.amc_contents_folder) - self.get_kext_by_bundle_path("AMC-Override.kext")["Enabled"] = True - - if self.model not in model_array.NoAGPMSupport: - print("- Adding AppleGraphicsPowerManagement Override") - agpm_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsPowerManagement/Info.plist") - Path(self.constants.agpm_kext_folder).mkdir() - Path(self.constants.agpm_contents_folder).mkdir() - shutil.copy(agpm_map_path, self.constants.agpm_contents_folder) - self.get_kext_by_bundle_path("AGPM-Override.kext")["Enabled"] = True - - if self.model in model_array.AGDPSupport: - print("- Adding AppleGraphicsDevicePolicy Override") - agdp_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsDevicePolicy/Info.plist") - Path(self.constants.agdp_kext_folder).mkdir() - Path(self.constants.agdp_contents_folder).mkdir() - shutil.copy(agdp_map_path, self.constants.agdp_contents_folder) - self.get_kext_by_bundle_path("AGDP-Override.kext")["Enabled"] = True - - if self.constants.serial_settings != "None": - # AGPM Patch - if self.model in model_array.DualGPUPatch: - print("- Adding dual GPU patch") - if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: - self.gfx0_path = self.computer.dgpu.pci_path - print(f"- Found GFX0 Device Path: {self.gfx0_path}") - else: - if not self.constants.custom_model: - print("- Failed to find GFX0 Device path, falling back on known logic") - self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" - - if self.model in model_array.IntelNvidiaDRM and self.constants.drm_support is True: - print("- Prioritizing DRM support over Intel QuickSync") - self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696", "shikigva": 256} - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "class-code": binascii.unhexlify("FFFFFFFF"), - } - elif self.constants.serial_settings != "None": - self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696"} - if self.model.startswith("iMac14,"): - if self.computer.igpu and not self.computer.dgpu: - # Ensure that agdpmod is applied to iMac14,x with iGPU only - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"} - - # Audio Patch - if self.constants.set_alc_usage is True: - if smbios_data.smbios_dictionary[self.model]["Max OS Supported"] <= os_data.os_data.high_sierra: - # Models dropped in Mojave also lost Audio support - # Xserves and MacPro4,1 are exceptions - # iMac7,1 and iMac8,1 require AppleHDA/IOAudioFamily downgrade - if not (self.model.startswith("Xserve") or self.model in ["MacPro4,1", "iMac7,1", "iMac8,1"]): - try: - smbios_data.smbios_dictionary[self.model]["nForce Chipset"] - hdef_path = "PciRoot(0x0)/Pci(0x8,0x0)" - except KeyError: - hdef_path = "PciRoot(0x0)/Pci(0x1b,0x0)" - # In AppleALC, MacPro3,1's original layout is already in use, forcing layout 13 instead - if self.model == "MacPro3,1": - self.config["DeviceProperties"]["Add"][hdef_path] = { - "apple-layout-id": 90, - "use-apple-layout-id": 1, - "alc-layout-id": 13, - } - else: - self.config["DeviceProperties"]["Add"][hdef_path] = { - "apple-layout-id": 90, - "use-apple-layout-id": 1, - "use-layout-id": 1, - } - self.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 - self.enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path) - - - 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 - print("- Enabling FireWire Boot Support") - self.enable_kext("IOFireWireFamily.kext", self.constants.fw_kext, self.constants.fw_family_path) - self.enable_kext("IOFireWireSBP2.kext", self.constants.fw_kext, self.constants.fw_sbp2_path) - self.enable_kext("IOFireWireSerialBusProtocolTransport.kext", self.constants.fw_kext, self.constants.fw_bus_path) - self.get_kext_by_bundle_path("IOFireWireFamily.kext/Contents/PlugIns/AppleFWOHCI.kext")["Enabled"] = True - - - def backlight_path_detection(self): - if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: - self.gfx0_path = self.computer.dgpu.pci_path - print(f"- Found GFX0 Device Path: {self.gfx0_path}") - else: - if not self.constants.custom_model: - print("- Failed to find GFX0 Device path, falling back on known logic") - if self.model in ["iMac11,1", "iMac11,3"]: - self.gfx0_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)" - elif self.model == "iMac10,1": - self.gfx0_path = "PciRoot(0x0)/Pci(0xc,0x0)/Pci(0x0,0x0)" - else: - self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" - - def nvidia_patch(self, backlight_path): - if not self.get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True: - # Ensure WEG is enabled as we need if for Backlight patching - self.enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) - if self.model in ["iMac11,1", "iMac11,2", "iMac11,3", "iMac10,1"]: - print("- Adding Nvidia Brightness Control and DRM patches") - self.config["DeviceProperties"]["Add"][backlight_path] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - if self.constants.custom_model and self.model == "iMac11,2": - # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) - # Set both properties when we cannot run hardware detection - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - elif self.model in ["iMac12,1", "iMac12,2"]: - print("- Adding Nvidia Brightness Control and DRM patches") - self.config["DeviceProperties"]["Add"][backlight_path] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - print("- Disabling unsupported iGPU") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "class-code": binascii.unhexlify("FFFFFFFF"), - } - shutil.copy(self.constants.backlight_injector_path, self.constants.kexts_path) - self.get_kext_by_bundle_path("BacklightInjector.kext")["Enabled"] = True - self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - - def amd_patch(self, backlight_path): - print("- Adding AMD DRM patches") - if not self.get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True: - # Ensure WEG is enabled as we need if for Backlight patching - self.enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) - self.config["DeviceProperties"]["Add"][backlight_path] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} - if self.constants.custom_model and self.model == "iMac11,2": - # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) - # Set both properties when we cannot run hardware detection - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} - if self.model in ["iMac12,1", "iMac12,2"]: - print("- Disabling unsupported iGPU") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "class-code": binascii.unhexlify("FFFFFFFF"), - } - elif self.model == "iMac10,1": - if self.get_kext_by_bundle_path("AAAMouSSE.kext")["Enabled"] is False: - self.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: - print("- Adding Legacy GCN Power Gate Patches") - self.config["DeviceProperties"]["Add"][backlight_path].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - if self.constants.imac_model == "Legacy GCN": - print("- Adding Legacy GCN Power Gate Patches") - self.config["DeviceProperties"]["Add"][backlight_path].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - if self.model == "iMac11,2": - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - - # Check GPU Vendor - if self.constants.metal_build is True: - backlight_path_detection(self) - print("- Adding Metal GPU patches on request") - if self.constants.imac_vendor == "AMD": - amd_patch(self, self.gfx0_path) - elif self.constants.imac_vendor == "Nvidia": - nvidia_patch(self, self.gfx0_path) - else: - print("- Failed to find vendor") - elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: - print(f"- Detected dGPU: {utilities.friendly_hex(self.computer.dgpu.vendor_id)}:{utilities.friendly_hex(self.computer.dgpu.device_id)}") - if self.computer.dgpu.arch in [ - device_probe.AMD.Archs.Legacy_GCN_7000, - device_probe.AMD.Archs.Legacy_GCN_8000, - device_probe.AMD.Archs.Legacy_GCN_9000, - device_probe.AMD.Archs.Polaris, - device_probe.AMD.Archs.Vega, - device_probe.AMD.Archs.Navi, - ]: - backlight_path_detection(self) - amd_patch(self, self.gfx0_path) - elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: - backlight_path_detection(self) - nvidia_patch(self, self.gfx0_path) - if self.model in model_array.MacPro: - if not self.constants.custom_model: - for i, device in enumerate(self.computer.gpus): - print(f"- Found dGPU ({i + 1}): {utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}") - self.config["#Revision"][f"Hardware-MacPro-dGPU-{i + 1}"] = f"{utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}" - - if device.pci_path and device.acpi_path: - print(f"- Found dGPU ({i + 1}) at {device.pci_path}") - if isinstance(device, device_probe.AMD): - print("- Adding Mac Pro, Xserve DRM patches") - self.config["DeviceProperties"]["Add"][device.pci_path] = {"shikigva": 128, "unfairgva": 1, "rebuild-device-tree": 1, "agdpmod": "pikera", "enable-gva-support": 1} - elif isinstance(device, device_probe.NVIDIA): - print("- Enabling Nvidia Output Patch") - self.config["DeviceProperties"]["Add"][device.pci_path] = {"rebuild-device-tree": 1, "agdpmod": "vit9696"} - self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - - else: - print(f"- Failed to find Device path for dGPU {i + 1}") - if isinstance(device, device_probe.AMD): - print("- Adding Mac Pro, Xserve DRM patches") - if "shikigva=128 unfairgva=1" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: - print("- Falling back to boot-args") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 agdpmod=pikera radgva=1" + ( - " -wegtree" if "-wegtree" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] else "" - ) - elif isinstance(device, device_probe.NVIDIA): - print("- Enabling Nvidia Output Patch") - if "-wegtree agdpmod=vit9696" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: - print("- Falling back to boot-args") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -wegtree agdpmod=vit9696" - self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - - if not self.computer.gpus: - print("- No socketed dGPU found") - - else: - print("- Adding Mac Pro, Xserve DRM patches") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 -wegtree" - - if not self.get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is True: - self.enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) - - if not self.constants.custom_model: - for i, device in enumerate(self.computer.gpus): - if isinstance(device, device_probe.NVIDIA): - if ( - device.arch in [device_probe.NVIDIA.Archs.Fermi, device_probe.NVIDIA.Archs.Maxwell, device_probe.NVIDIA.Archs.Pascal] or - (self.constants.force_nv_web is True and device.arch in [device_probe.NVIDIA.Archs.Tesla, device_probe.NVIDIA.Archs.Kepler]) - ): - print(f"- Enabling Web Driver Patches for GPU ({i + 1}): {utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}") - if device.pci_path and device.acpi_path: - if device.pci_path in self.config["DeviceProperties"]["Add"]: - 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} - if self.get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: - self.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" - if self.get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: - self.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"] - - - if self.constants.disable_tb is True and self.model in ["MacBookPro11,1", "MacBookPro11,2", "MacBookPro11,3", "MacBookPro11,4", "MacBookPro11,5"]: - print("- Disabling 2013-2014 laptop Thunderbolt Controller") - if self.model in ["MacBookPro11,3", "MacBookPro11,5"]: - # 15" dGPU models: IOACPIPlane:/_SB/PCI0@0/PEG1@10001/UPSB@0/DSB0@0/NHI0@0 - tb_device_path = "PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" - else: - # 13" and 15" iGPU 2013-2014 models: IOACPIPlane:/_SB/PCI0@0/P0P2@10000/UPSB@0/DSB0@0/NHI0@0 - tb_device_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" - - self.config["DeviceProperties"]["Add"][tb_device_path] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000")} - - if self.constants.software_demux is True and self.model in ["MacBookPro8,2", "MacBookPro8,3"]: - print("- Enabling software demux") - # Add ACPI patches - self.get_item_by_kv(self.config["ACPI"]["Add"], "Path", "SSDT-DGPU.aml")["Enabled"] = True - self.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 - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000"), "IOName": "Dortania Disabled Card", "name": "Dortania Disabled Card"} - self.config["DeviceProperties"]["Delete"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = ["class-code", "device-id", "IOName", "name"] - # Add AMDGPUWakeHandler - self.enable_kext("AMDGPUWakeHandler.kext", self.constants.gpu_wake_version, self.constants.gpu_wake_path) - - # 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"]: - self.enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path) - self.get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True - self.get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True - self.get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True - self.enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path) - - # Bluetooth Detection - if not self.constants.custom_model and self.computer.bluetooth_chipset: - if self.computer.bluetooth_chipset in ["BRCM2070 Hub", "BRCM2046 Hub"]: - print("- Fixing Legacy Bluetooth for macOS Monterey") - self.enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) - self.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 - # Note Monterey only natively supports BRCM20702 v2 (found with BCM94360) - # Due to this, BlueToolFixup is required to resolve Firmware Uploading on legacy chipsets - if self.computer.wifi: - if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360: - print("- Fixing Legacy Bluetooth for macOS Monterey") - self.enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) - elif self.computer.bluetooth_chipset == "3rd Party Bluetooth 4.0 Hub": - print("- Detected 3rd Party Chipset") - self.enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) - print("- Enabling Bluetooth FeatureFlags") - self.config["Kernel"]["Quirks"]["ExtendBTFeatureFlags"] = True - elif smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM20702_v1.value: - print("- Fixing Legacy Bluetooth for macOS Monterey") - self.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" - self.enable_kext("Bluetooth-Spoof.kext", self.constants.btspoof_version, self.constants.btspoof_path) - - if self.constants.nvme_boot is True: - print("- Enabling NVMe boot support") - shutil.copy(self.constants.nvme_driver_path, self.constants.drivers_path) - self.get_efi_binary_by_path("NvmExpressDxe.efi", "UEFI", "Drivers")["Enabled"] = True - - # Add OpenCanopy - print("- Adding OpenCanopy GUI") - shutil.rmtree(self.constants.resources_path, onerror=rmtree_handler) - shutil.copy(self.constants.gui_path, self.constants.oc_folder) - self.get_efi_binary_by_path("OpenCanopy.efi", "UEFI", "Drivers")["Enabled"] = True - self.get_efi_binary_by_path("OpenRuntime.efi", "UEFI", "Drivers")["Enabled"] = True - self.get_efi_binary_by_path("OpenLinuxBoot.efi", "UEFI", "Drivers")["Enabled"] = True - self.get_efi_binary_by_path("ResetNvramEntry.efi", "UEFI", "Drivers")["Enabled"] = True - # Exfat check - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.sandy_bridge.value: - # Sandy Bridge and newer Macs natively support ExFat - print("- Adding ExFatDxeLegacy.efi") - shutil.copy(self.constants.exfat_legacy_driver_path, self.constants.drivers_path) - self.get_efi_binary_by_path("ExFatDxeLegacy.efi", "UEFI", "Drivers")["Enabled"] = True - - # Add UGA to GOP layer - try: - smbios_data.smbios_dictionary[self.model]["UGA Graphics"] - print("- Adding UGA to GOP Patch") - self.config["UEFI"]["Output"]["GopPassThrough"] = "Apple" - except KeyError: - pass - - # 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 - if self.model in ["MacBookAir6,1", "MacBookAir6,2"]: - print("- Enabling AHCI SSD patch") - self.enable_kext("MonteAHCIPort.kext", self.constants.monterey_ahci_version, self.constants.monterey_ahci_path) - - # 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 - # This change resulted in broken OS booting as the machine had no power management support - # Currently the AICPUPM fix is not fully functional, thus forcing VMM is a temporary solution - # Waiting for XNU source to be released to fix this properly - if self.model == "MacPro6,1": - print("- Enabling VMM patch") - self.config["Kernel"]["Emulate"]["Cpuid1Data"] = binascii.unhexlify("00000000000000000000008000000000") - self.config["Kernel"]["Emulate"]["Cpuid1Mask"] = binascii.unhexlify("00000000000000000000008000000000") - self.config["Kernel"]["Emulate"]["MinKernel"] = "22.0.0" - - # 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 - - # 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. - - try: - smbios_data.smbios_dictionary[self.model]["5K Display"] - print("- Adding 5K Display Patch") - # Set LauncherPath to '/boot.efi' - # This is to ensure that only the Mac's firmware presents the boot option, but not OpenCore - # https://github.com/acidanthera/OpenCorePkg/blob/0.7.6/Library/OcAppleBootPolicyLib/OcAppleBootPolicyLib.c#L50-L73 - self.config["Misc"]["Boot"]["LauncherPath"] = "\\boot.efi" - # Setup diags.efi chainloading - self.chainload_diags() - except KeyError: - pass - - if self.constants.xhci_boot is True: - print("- Adding USB 3.0 Controller Patch") - print("- 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) - self.get_efi_binary_by_path("XhciDxe.efi", "UEFI", "Drivers")["Enabled"] = True - self.get_efi_binary_by_path("UsbBusDxe.efi", "UEFI", "Drivers")["Enabled"] = True - - # # Add UHCI/OHCI drivers - # if not self.constants.custom_model: - # if self.constants.computer.usb_controllers: - # for controller in self.constants.computer.usb_controllers: - # if isinstance(controller, device_probe.UHCIController) or isinstance(controller, device_probe.OHCIController): - # print("- Adding UHCI/OHCI USB support") - # shutil.copy(self.constants.apple_usb_11_injector_path, self.constants.kexts_path) - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCIPCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCIPCI.kext")["Enabled"] = True - # break - # else: - # if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.sandy_bridge.value: - # print("- Adding UHCI/OHCI USB support") - # shutil.copy(self.constants.apple_usb_11_injector_path, self.constants.kexts_path) - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBOHCIPCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCI.kext")["Enabled"] = True - # self.get_kext_by_bundle_path("USB1.1-Injector.kext/Contents/PlugIns/AppleUSBUHCIPCI.kext")["Enabled"] = True - - # ThirdPartDrives Check - if self.constants.allow_3rd_party_drives is True: - for drive in ["SATA 2.5", "SATA 3.5", "mSATA"]: - if drive in smbios_data.smbios_dictionary[self.model]["Stock Storage"]: - if not self.constants.custom_model: - if self.computer.third_party_sata_ssd is True: - print("- Adding SATA Hibernation Patch") - self.config["Kernel"]["Quirks"]["ThirdPartyDrives"] = True - break - else: - print("- Adding SATA Hibernation Patch") - self.config["Kernel"]["Quirks"]["ThirdPartyDrives"] = True - break - - # Apple RAID Card check - if not self.constants.custom_model: - if self.computer.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 - self.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 - self.enable_kext("AppleRAIDCard.kext", self.constants.apple_raid_version, self.constants.apple_raid_path) - - # Force Output support PC VBIOS on Mac Pros - if self.constants.force_output_support is True: - print("- Forcing GOP Support") - self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - - # RestrictEvents handling - block_args = "" - if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]: - block_args += "gmux," - if self.model in model_array.MacPro: - print("- Disabling memory error reporting") - block_args += "pcie," - gpu_dict = [] - if not self.constants.custom_model: - gpu_dict = self.constants.computer.gpus - else: - if self.model in smbios_data.smbios_dictionary: - gpu_dict = smbios_data.smbios_dictionary[self.model]["Stock GPUs"] - for gpu in gpu_dict: - if not self.constants.custom_model: - gpu = gpu.arch - if gpu in [ - device_probe.Intel.Archs.Ivy_Bridge, - device_probe.Intel.Archs.Haswell, - device_probe.NVIDIA.Archs.Kepler, - ]: - print("- Disabling mediaanalysisd") - block_args += "media," - break - if block_args.endswith(","): - block_args = block_args[:-1] - - if block_args != "": - print(f"- Setting RestrictEvents block arguments: {block_args}") - if self.get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - self.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 self.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: - print("- Fixing Content Caching support") - patch_args += "content-caching," - - if patch_args.endswith(","): - patch_args = patch_args[:-1] - - if block_args != "" and patch_args == "": - # Disable unneeded Userspace patching (cs_validate_page is quite expensive) - patch_args = "none" - - if patch_args != "": - print(f"- Setting RestrictEvents patch arguments: {patch_args}") - if self.get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - self.enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revpatch"] = patch_args - - # DEBUG Settings - if self.constants.verbose_debug is True: - print("- Enabling Verbose boot") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -v" - if self.constants.kext_debug is True: - print("- Enabling DEBUG Kexts") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -liludbgall liludump=90" - # 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" - if self.constants.opencore_debug is True: - print("- Enabling DEBUG OpenCore") - self.config["Misc"]["Debug"]["Target"] = 0x43 - self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042 - if self.constants.showpicker is True: - print("- Enabling ShowPicker") - self.config["Misc"]["Boot"]["ShowPicker"] = True - else: - print("- Hiding OpenCore picker") - self.config["Misc"]["Boot"]["ShowPicker"] = False - if self.constants.oc_timeout != 5: - print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") - self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout - if self.constants.vault is True: - print("- Setting Vault configuration") - self.config["Misc"]["Security"]["Vault"] = "Secure" - self.get_efi_binary_by_path("OpenShell.efi", "Misc", "Tools")["Enabled"] = False - 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 - print("- Adding ipc_control_port_options=0 to boot-args") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " ipc_control_port_options=0" - # 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: - self.enable_kext("AutoPkgInstaller.kext", self.constants.autopkg_version, self.constants.autopkg_path) - if self.constants.custom_sip_value: - print(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")) - elif self.constants.sip_status is False: - print("- Set SIP to allow Root Volume patching") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = binascii.unhexlify("03080000") - - # apfs.kext has an undocumented boot-arg that allows FileVault usage on broken APFS seals (-arv_allow_fv) - # 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) - print("- Allowing FileVault on Root Patched systems") - self.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" - - if self.constants.disable_cs_lv is True: - print("- Disabling Library Validation") - # In Ventura, LV patch broke. For now, add AMFI arg - # Before merging into mainline, this needs to be resolved - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable Library Validation Enforcement")["Enabled"] = True - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Disable _csr_check() in _vnode_check_signature")["Enabled"] = True - if self.constants.disable_amfi is True: - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " amfi=0x80" - 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 - self.enable_kext("CSLVFixup.kext", self.constants.cslvfixup_version, self.constants.cslvfixup_path) - if self.constants.secure_status is False: - print("- Disabling SecureBootModel") - self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled" - if self.constants.force_vmm is True: - print("- Forcing VMM patchset to support OTA updates") - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (1)")["Enabled"] = True - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Legacy")["Enabled"] = True - self.get_item_by_kv(self.config["Kernel"]["Patch"], "Comment", "Reroute kern.hv_vmm_present patch (2) Ventura")["Enabled"] = True - if self.constants.serial_settings in ["Moderate", "Advanced"]: - print("- Enabling USB Rename Patches") - self.get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "XHC1 to SHC1")["Enabled"] = True - self.get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC1 to EH01")["Enabled"] = True - self.get_item_by_kv(self.config["ACPI"]["Patch"], "Comment", "EHC2 to EH02")["Enabled"] = True - if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = self.constants.custom_cpu_model - if self.constants.custom_cpu_model_value != "": - print(f"- Adding custom CPU Name: {self.constants.custom_cpu_model_value}") - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value - else: - print("- Adding CPU Name Patch") - if self.get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - self.enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) - if self.model == self.constants.override_smbios: - print("- Adding -no_compat_check") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check" - if self.constants.disk != "": - self.disk_type() - if self.constants.validate is False: - print("- Adding bootmgfw.efi BlessOverride") - self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"] - try: - if self.constants.dGPU_switch is True: - smbios_data.smbios_dictionary[self.model]["Switchable GPUs"] - print("- Allowing GMUX switching in Windows") - self.config["Booter"]["Quirks"]["SignalAppleOS"] = True - except KeyError: - pass - if ( - self.model.startswith("MacBook") - and ( - smbios_data.smbios_dictionary[self.model]["CPU Generation"] == cpu_data.cpu_data.haswell.value or - smbios_data.smbios_dictionary[self.model]["CPU Generation"] == cpu_data.cpu_data.broadwell.value - ) - ): - # Fix Virtual Machine support for non-macOS OSes - # Haswell and Broadwell MacBooks lock out the VMX bit if booting UEFI Windows - print("- Enabling VMX Bit for non-macOS OSes") - self.config["UEFI"]["Quirks"]["EnableVmx"] = True - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value: - print("- Enabling Rosetta Cryptex support in Ventura") - self.enable_kext("CryptexFixup.kext", self.constants.cryptexfixup_version, self.constants.cryptexfixup_path) - if self.constants.disable_msr_power_ctl is True: - print("- Disabling Firmware Throttling") - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] >= cpu_data.cpu_data.nehalem.value: - # Nehalem and newer systems force firmware throttling via MSR_POWER_CTL - self.enable_kext("SimpleMSR.kext", self.constants.simplemsr_version, self.constants.simplemsr_path) - if self.constants.disable_connectdrivers is True: - print("- Disabling ConnectDrivers") - self.config["UEFI"]["ConnectDrivers"] = False - if self.constants.nvram_write is False: - print("- Disabling Hardware NVRAM Write") - self.config["NVRAM"]["WriteFlash"] = False - if self.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 - self.enable_kext("EFICheckDisabler.kext", "", self.constants.efi_disabler_path) - if self.constants.set_vmm_cpuid is True: - # Should be unneeded with our sysctl VMM patch, however for reference purposes we'll leave it here - # Ref: https://forums.macrumors.com/threads/opencore-on-the-mac-pro.2207814/ - self.config["Kernel"]["Emulate"]["Cpuid1Data"] = binascii.unhexlify("00000000000000000000008000000000") - self.config["Kernel"]["Emulate"]["Cpuid1Mask"] = binascii.unhexlify("00000000000000000000008000000000") - - def set_smbios(self): - spoofed_model = self.model - if self.constants.override_smbios == "Default": - if self.constants.serial_settings != "None": - print("- Setting macOS Monterey Supported SMBIOS") - if self.constants.allow_native_spoofs is True: - spoofed_model = self.model - else: - spoofed_model = generate_smbios.set_smbios_model_spoof(self.model) - else: - spoofed_model = self.constants.override_smbios - print(f"- Using Model ID: {spoofed_model}") - try: - spoofed_board = smbios_data.smbios_dictionary[spoofed_model]["Board ID"] - print(f"- Using Board ID: {spoofed_board}") - except KeyError: - spoofed_board = "" - self.spoofed_model = spoofed_model - self.spoofed_board = spoofed_board - if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True: - self.config["#Revision"]["Spoofed-Model"] = f"{self.spoofed_model} - {self.constants.serial_settings}" - - # Setup menu - def minimal_serial_patch(self): - # Generate Firmware Features - fw_feature = generate_smbios.generate_fw_features(self.model, self.constants.custom_model) - # fw_feature = self.patch_firmware_feature() - fw_feature = hex(fw_feature).lstrip("0x").rstrip("L").strip() - print(f"- Setting Firmware Feature: {fw_feature}") - fw_feature = utilities.string_to_hex(fw_feature) - - # FirmwareFeatures - self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeatures"] = fw_feature - self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeaturesMask"] = fw_feature - self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeatures"] = fw_feature - self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeaturesMask"] = fw_feature - - # Board ID - self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board - self.config["PlatformInfo"]["PlatformNVRAM"]["BID"] = self.spoofed_board - self.config["PlatformInfo"]["SMBIOS"]["BoardProduct"] = self.spoofed_board - - # Model (ensures tables are not mismatched, even if we're not spoofing) - self.config["PlatformInfo"]["DataHub"]["SystemProductName"] = self.model - self.config["PlatformInfo"]["SMBIOS"]["SystemProductName"] = self.model - self.config["PlatformInfo"]["SMBIOS"]["BoardVersion"] = self.model - - # ProcessorType (when RestrictEvent's CPU naming is used) - if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: - self.config["PlatformInfo"]["SMBIOS"]["ProcessorType"] = 1537 - - # Avoid incorrect Firmware Updates - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["SMBIOS"]["BIOSVersion"] = "9999.999.999.999.999" - - # Update tables - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - - if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": - print("- Adding custom serial numbers") - sn = self.constants.custom_serial_number - mlb = self.constants.custom_board_serial_number - - # Serial Number - self.config["PlatformInfo"]["SMBIOS"]["ChassisSerialNumber"] = sn - self.config["PlatformInfo"]["SMBIOS"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["DataHub"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["PlatformNVRAM"]["SystemSerialNumber"] = sn - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn - - # Board Serial Number - self.config["PlatformInfo"]["SMBIOS"]["BoardSerialNumber"] = mlb - self.config["PlatformInfo"]["PlatformNVRAM"]["BoardSerialNumber"] = mlb - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb - - - - def moderate_serial_patch(self): - 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 != "": - print("- Adding custom serial numbers") - self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number - self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["Automatic"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True - self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model - - def advanced_serial_patch(self): - 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 == "": - macserial_output = subprocess.run([self.constants.macserial_path] + f"-g -m {self.spoofed_model} -n 1".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - macserial_output = macserial_output.stdout.decode().strip().split(" | ") - sn = macserial_output[0] - mlb = macserial_output[1] - else: - sn = self.constants.custom_serial_number - mlb = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["Automatic"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True - self.config["PlatformInfo"]["Generic"]["ROM"] = binascii.unhexlify("0016CB445566") - self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model - self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["Generic"]["MLB"] = mlb - self.config["PlatformInfo"]["Generic"]["SystemUUID"] = str(uuid.uuid4()).upper() - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb - - - if self.constants.serial_settings == "Moderate": - print("- Using Moderate SMBIOS patching") - moderate_serial_patch(self) - elif self.constants.serial_settings == "Advanced": - print("- Using Advanced SMBIOS patching") - advanced_serial_patch(self) - elif self.constants.serial_settings == "Minimal": - print("- Using Minimal SMBIOS patching") - self.spoofed_model = self.model - minimal_serial_patch(self) - 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, - # Thus resulting in an infinite loop as Lilu tries to request the Board ID - # To resolve this, set PlatformInfo -> DataHub -> BoardProduct and enable UpdateDataHub - - # Note 1: Only apply if system is UEFI 1.2, this is generally Ivy Bridge and older - # Note 2: Flipping 'UEFI -> ProtocolOverrides -> DataHub' will break hibernation - if (smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value and self.model): - print("- Detected UEFI 1.2 or older Mac, updating BoardProduct") - self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board - self.config["PlatformInfo"]["UpdateDataHub"] = True - - if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": - print("- Adding custom serial numbers") - self.config["PlatformInfo"]["Automatic"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True - self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number - self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number - self.config["PlatformInfo"]["Generic"]["MaxBIOSVersion"] = False - self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number - - # USB Map and CPUFriend Patching - if ( - self.constants.allow_oc_everywhere is False - and self.model not in ["Xserve2,1", "Dortania1,1"] - and ((self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) or self.constants.serial_settings in ["Moderate", "Advanced"]) - ): - new_map_ls = Path(self.constants.map_contents_folder) / Path("Info.plist") - map_config = plistlib.load(Path(new_map_ls).open("rb")) - # Strip unused USB maps - for entry in list(map_config["IOKitPersonalities_x86_64"]): - if not entry.startswith(self.model): - map_config["IOKitPersonalities_x86_64"].pop(entry) - else: - try: - map_config["IOKitPersonalities_x86_64"][entry]["model"] = self.spoofed_model - if self.constants.serial_settings in ["Minimal", "None"]: - if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "EH01": - map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "EHC1" - if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "EH02": - map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "EHC2" - if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "SHC1": - map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "XHC1" - except KeyError: - continue - plistlib.dump(map_config, Path(new_map_ls).open("wb"), sort_keys=True) - 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": - # Adjust CPU Friend Data to correct SMBIOS - new_cpu_ls = Path(self.constants.pp_contents_folder) / Path("Info.plist") - cpu_config = plistlib.load(Path(new_cpu_ls).open("rb")) - string_stuff = str(cpu_config["IOKitPersonalities"]["CPUFriendDataProvider"]["cf-frequency-data"]) - string_stuff = string_stuff.replace(self.model, self.spoofed_model) - string_stuff = ast.literal_eval(string_stuff) - cpu_config["IOKitPersonalities"]["CPUFriendDataProvider"]["cf-frequency-data"] = string_stuff - plistlib.dump(cpu_config, Path(new_cpu_ls).open("wb"), sort_keys=True) - - if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None": - if self.model == "MacBookPro9,1": - new_amc_ls = Path(self.constants.amc_contents_folder) / Path("Info.plist") - amc_config = plistlib.load(Path(new_amc_ls).open("rb")) - amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"][self.spoofed_board] = amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"].pop(self.model) - for entry in list(amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"]): - if not entry.startswith(self.spoofed_board): - amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"].pop(entry) - plistlib.dump(amc_config, Path(new_amc_ls).open("wb"), sort_keys=True) - if self.model not in model_array.NoAGPMSupport: - new_agpm_ls = Path(self.constants.agpm_contents_folder) / Path("Info.plist") - agpm_config = plistlib.load(Path(new_agpm_ls).open("rb")) - agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board] = agpm_config["IOKitPersonalities"]["AGPM"]["Machines"].pop(self.model) - if self.model == "MacBookPro6,2": - # Force G State to not exceed moderate state - # Ref: https://github.com/fabioiop/MBP-2010-GPU-Panic-fix - print("- Patching G State for MacBookPro6,2") - for gpu in ["Vendor10deDevice0a34", "Vendor10deDevice0a29"]: - agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board][gpu]["BoostPState"] = [2, 2, 2, 2] - agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board][gpu]["BoostTime"] = [2, 2, 2, 2] - - for entry in list(agpm_config["IOKitPersonalities"]["AGPM"]["Machines"]): - if not entry.startswith(self.spoofed_board): - agpm_config["IOKitPersonalities"]["AGPM"]["Machines"].pop(entry) - - plistlib.dump(agpm_config, Path(new_agpm_ls).open("wb"), sort_keys=True) - if self.model in model_array.AGDPSupport: - new_agdp_ls = Path(self.constants.agdp_contents_folder) / Path("Info.plist") - agdp_config = plistlib.load(Path(new_agdp_ls).open("rb")) - agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"][self.spoofed_board] = agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"].pop( - self.model - ) - for entry in list(agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"]): - if not entry.startswith(self.spoofed_board): - agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"].pop(entry) - plistlib.dump(agdp_config, Path(new_agdp_ls).open("wb"), sort_keys=True) - - @staticmethod - def get_item_by_kv(iterable, key, value): - item = None - for i in iterable: - if i[key] == value: - item = i - break - return item - - def get_kext_by_bundle_path(self, bundle_path): - kext = self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", bundle_path) - if not kext: - print(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) - if not efi_binary: - print(f"- Could not find {efi_type}: {bundle_path}!") - 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) - - if callable(check) and not check(): - # Check failed - return - - print(f"- Adding {kext_name} {kext_version}") - shutil.copy(kext_path, self.constants.kexts_path) - kext["Enabled"] = True - - def cleanup(self): - print("- Cleaning up files") - # Remove unused entries - entries_to_clean = { - "ACPI": ["Add", "Delete", "Patch"], - "Booter": ["Patch"], - "Kernel": ["Add", "Block", "Force", "Patch"], - "Misc": ["Tools"], - "UEFI": ["Drivers"], - } - - for entry in entries_to_clean: - for sub_entry in entries_to_clean[entry]: - for item in list(self.config[entry][sub_entry]): - if item["Enabled"] is False: - self.config[entry][sub_entry].remove(item) - - plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True) - for kext in self.constants.kexts_path.rglob("*.zip"): - with zipfile.ZipFile(kext) as zip_file: - zip_file.extractall(self.constants.kexts_path) - kext.unlink() - - for item in self.constants.oc_folder.rglob("*.zip"): - with zipfile.ZipFile(item) as zip_file: - zip_file.extractall(self.constants.oc_folder) - item.unlink() - - if not self.constants.recovery_status: - # Crashes in RecoveryOS for unknown reason - for i in self.constants.build_path.rglob("__MACOSX"): - shutil.rmtree(i) - - # Remove unused plugins inside of kexts - # Following plugins are sometimes unused as there's different variants machines need - known_unused_plugins = [ - "AirPortBrcm4331.kext", - "AirPortAtheros40.kext", - "AppleAirPortBrcm43224.kext", - "AirPortBrcm4360_Injector.kext", - "AirPortBrcmNIC_Injector.kext" - ] - for kext in Path(self.constants.opencore_release_folder / Path("EFI/OC/Kexts")).glob("*.kext"): - for plugin in Path(kext / "Contents/PlugIns/").glob("*.kext"): - should_remove = True - for enabled_kexts in self.config["Kernel"]["Add"]: - if enabled_kexts["BundlePath"].endswith(plugin.name): - should_remove = False - break - if should_remove: - if plugin.name not in known_unused_plugins: - raise Exception(f" - Unknown plugin found: {plugin.name}") - shutil.rmtree(plugin) - - Path(self.constants.opencore_zip_copied).unlink() - - def sign_files(self): - if self.constants.vault is True: - if utilities.check_command_line_tools() is True: - # sign.command checks for the existence of '/usr/bin/strings' however does not verify whether it's executable - # sign.command will continue to run and create an unbootable OpenCore.efi due to the missing strings binary - # macOS has dummy binaries that just reroute to the actual binaries after you install Xcode's Command Line Tools - print("- Vaulting EFI") - subprocess.run([str(self.constants.vault_path), f"{self.constants.oc_folder}/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - else: - print("- Missing Command Line tools, skipping Vault for saftey reasons") - print("- Install via 'xcode-select --install' and rerun OCLP if you wish to vault this config") - - def validate_pathing(self): - print("- Validating generated config") - if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")): - print("- OpenCore config file missing!!!") - raise Exception("OpenCore config file missing") - - config_plist = plistlib.load(Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")).open("rb")) - - for acpi in config_plist["ACPI"]["Add"]: - # print(f" - Validating {acpi['Path']}") - if not Path(self.constants.opencore_release_folder / Path("EFI/OC/ACPI") / Path(acpi["Path"])).exists(): - print(f" - Missing ACPI Table: {acpi['Path']}") - raise Exception(f"Missing ACPI Table: {acpi['Path']}") - - for kext in config_plist["Kernel"]["Add"]: - # print(f" - Validating {kext['BundlePath']}") - kext_path = Path(self.constants.opencore_release_folder / Path("EFI/OC/Kexts") / Path(kext["BundlePath"])) - kext_binary_path = Path(kext_path / Path(kext["ExecutablePath"])) - kext_plist_path = Path(kext_path / Path(kext["PlistPath"])) - if not kext_path.exists(): - print(f"- Missing kext: {kext_path}") - raise Exception(f"Missing {kext_path}") - if not kext_binary_path.exists(): - print(f"- Missing {kext['BundlePath']}'s binary: {kext_binary_path}") - raise Exception(f"Missing {kext_binary_path}") - if not kext_plist_path.exists(): - print(f"- Missing {kext['BundlePath']}'s plist: {kext_plist_path}") - raise Exception(f"Missing {kext_plist_path}") - - for tool in config_plist["Misc"]["Tools"]: - # print(f" - Validating {tool['Path']}") - if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools") / Path(tool["Path"])).exists(): - print(f" - Missing tool: {tool['Path']}") - raise Exception(f"Missing tool: {tool['Path']}") - - for driver in config_plist["UEFI"]["Drivers"]: - # print(f" - Validating {driver['Path']}") - if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Drivers") / Path(driver["Path"])).exists(): - print(f" - Missing driver: {driver['Path']}") - raise Exception(f"Missing driver: {driver['Path']}") - - # Validating local files - # Validate Tools - for tool_files in Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools")).glob("*"): - if tool_files.name not in [x["Path"] for x in config_plist["Misc"]["Tools"]]: - print(f" - Missing tool from config: {tool_files.name}") - raise Exception(f"Missing tool from config: {tool_files.name}") - - for driver_file in Path(self.constants.opencore_release_folder / Path("EFI/OC/Drivers")).glob("*"): - if driver_file.name not in [x["Path"] for x in config_plist["UEFI"]["Drivers"]]: - print(f"- Found extra driver: {driver_file.name}") - raise Exception(f"Found extra driver: {driver_file.name}") - - def build_opencore(self): - 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 != ""): - self.set_smbios() - self.cleanup() - self.sign_files() - self.validate_pathing() - print("") - print(f"Your OpenCore EFI for {self.model} has been built at:") - print(f" {self.constants.opencore_release_folder}") - print("") - if self.constants.gui_mode is False: - input("Press [Enter] to continue\n") diff --git a/resources/build/bluetooth.py b/resources/build/bluetooth.py new file mode 100644 index 000000000..4353f7df5 --- /dev/null +++ b/resources/build/bluetooth.py @@ -0,0 +1,39 @@ +from resources import constants, device_probe +from resources.build import support +from data import smbios_data, bluetooth_data + +class build_bluetooth: + + 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): + # Bluetooth Detection + if not self.constants.custom_model and self.computer.bluetooth_chipset: + if self.computer.bluetooth_chipset in ["BRCM2070 Hub", "BRCM2046 Hub"]: + print("- 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) + 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 + # Note Monterey only natively supports BRCM20702 v2 (found with BCM94360) + # Due to this, BlueToolFixup is required to resolve Firmware Uploading on legacy chipsets + if self.computer.wifi: + if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360: + print("- Fixing Legacy Bluetooth for macOS Monterey") + self.enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) + elif self.computer.bluetooth_chipset == "3rd Party Bluetooth 4.0 Hub": + print("- Detected 3rd Party Chipset") + support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) + print("- Enabling Bluetooth FeatureFlags") + self.config["Kernel"]["Quirks"]["ExtendBTFeatureFlags"] = True + elif smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM20702_v1.value: + print("- 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) + 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) \ No newline at end of file diff --git a/resources/build/build.py b/resources/build/build.py new file mode 100644 index 000000000..b7b3fb7e6 --- /dev/null +++ b/resources/build/build.py @@ -0,0 +1,413 @@ +# Commands for building the EFI and SMBIOS +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + +import binascii +import copy +import pickle +import plistlib +import shutil +import subprocess +import zipfile +from pathlib import Path +from datetime import date + +from resources import constants, utilities, device_probe, generate_smbios +from resources.build import bluetooth, firmware, graphics_audio, support, storage, smbios, security +from resources.build.networking import wired, wireless +from data import smbios_data, cpu_data, os_data, model_array + + +def rmtree_handler(func, path, exc_info): + if exc_info[0] == FileNotFoundError: + return + raise # pylint: disable=misplaced-bare-raise + + +class BuildOpenCore: + def __init__(self, model, versions): + self.model = model + self.config = None + self.constants: constants.Constants = versions + self.computer = self.constants.computer + self.gfx0_path = None + + def disk_type(self): + drive_host_info = plistlib.loads(subprocess.run(f"diskutil info -plist {self.constants.disk}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()) + sd_type = drive_host_info["MediaName"] + try: + ssd_type = drive_host_info["SolidState"] + except KeyError: + ssd_type = False + # Array filled with common SD Card names + # Note most USB-based SD Card readers generally report as "Storage Device", and no reliable way to detect further + if sd_type in ["SD Card Reader", "SD/MMC"]: + print("- Adding SD Card icon") + shutil.copy(self.constants.icon_path_sd, self.constants.opencore_release_folder) + elif ssd_type is True: + print("- Adding SSD icon") + shutil.copy(self.constants.icon_path_ssd, self.constants.opencore_release_folder) + elif drive_host_info["BusProtocol"] == "USB": + print("- Adding External USB Drive icon") + shutil.copy(self.constants.icon_path_external, self.constants.opencore_release_folder) + else: + print("- Adding Internal Drive icon") + shutil.copy(self.constants.icon_path_internal, self.constants.opencore_release_folder) + + + + def build_efi(self): + utilities.cls() + if not self.constants.custom_model: + print(f"Building Configuration on model: {self.model}") + else: + print(f"Building Configuration for external model: {self.model}") + if not Path(self.constants.build_path).exists(): + Path(self.constants.build_path).mkdir() + print("Created build folder") + else: + print("Build folder already present, skipping") + + if Path(self.constants.opencore_zip_copied).exists(): + print("Deleting old copy of OpenCore zip") + Path(self.constants.opencore_zip_copied).unlink() + if Path(self.constants.opencore_release_folder).exists(): + print("Deleting old copy of OpenCore folder") + shutil.rmtree(self.constants.opencore_release_folder, onerror=rmtree_handler, ignore_errors=True) + + print(f"\n- Adding OpenCore v{self.constants.opencore_version} {self.constants.opencore_build}") + shutil.copy(self.constants.opencore_zip_source, self.constants.build_path) + zipfile.ZipFile(self.constants.opencore_zip_copied).extractall(self.constants.build_path) + + print("- Adding config.plist for OpenCore") + # Setup config.plist for editing + shutil.copy(self.constants.plist_template, self.constants.oc_folder) + self.config = plistlib.load(Path(self.constants.plist_path).open("rb")) + + # Set revision in config + 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" + computer_copy = copy.copy(self.computer) + computer_copy.ioregistry = None + self.config["#Revision"]["Hardware-Probe"] = pickle.dumps(computer_copy) + else: + self.config["#Revision"]["Build-Type"] = "OpenCore Built for External Machine" + self.config["#Revision"]["OpenCore-Version"] = f"{self.constants.opencore_version} - {self.constants.opencore_build} - {self.constants.opencore_commit}" + self.config["#Revision"]["Original-Model"] = self.model + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model + + for name, version, path, check in [ + # Essential kexts + ("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path, lambda: True), + ("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), + ("SMC-Spoof.kext", self.constants.smcspoof_version, self.constants.smcspoof_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), + ( + "CPUFriend.kext", + self.constants.cpufriend_version, + self.constants.cpufriend_path, + lambda: self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.disallow_cpufriend is False and self.constants.serial_settings != "None", + ), + # Misc + ("DebugEnhancer.kext", self.constants.debugenhancer_version, self.constants.debugenhancer_path, lambda: self.constants.kext_debug is True), + ("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path, lambda: self.model in ["MacBook4,1", "MacBook5,2"]), + ]: + support.build_support(self.model, self.constants, self.config).enable_kext(name, version, path, check) + + 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 + # print("- 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 + + print("- 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 + + # Patch HW_BID to OC_BID + # Set OC_BID to iMac18,1 Board ID (Mac-F60DEB81FF30ACF6) + # Goal is to only allow OS booting through OCLP, otherwise failing + print("- Enabling HW_BID reroute") + support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Reroute HW_BID to OC_BID")["Enabled"] = True + self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["OC_BID"] = "Mac-BE088AF8C5EB4FA2" + self.config["NVRAM"]["Delete"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"] += ["OC_BID"] + else: + print("- 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 + + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Lilu.kext")["Enabled"] is True: + # Required for Lilu in 11.0+ + self.config["Kernel"]["Quirks"]["DisableLinkeditJettison"] = True + + + + if self.constants.fu_status is True: + # Enable FeatureUnlock.kext + 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: + print(f"- Adding additional FeatureUnlock args: {self.constants.fu_arguments}") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += self.constants.fu_arguments + + 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() + + + + + + + + # CPUFriend + if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": + pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") + if not pp_map_path.exists(): + raise Exception(f"{pp_map_path} does not exist!!! Please file an issue stating file is missing for {self.model}.") + 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 + + + # Legacy iSight patches + try: + 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) + except KeyError: + pass + + + + # USB Map + usb_map_path = Path(self.constants.plist_folder_path) / Path("AppleUSBMaps/Info.plist") + if ( + usb_map_path.exists() + and (self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True) + and self.model not in ["Xserve2,1", "Dortania1,1"] + and ( + (self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) + or self.constants.serial_settings in ["Moderate", "Advanced"]) + ): + print("- Adding USB-Map.kext") + 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 + 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" + + + 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 + print("- 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 + + + + if self.constants.disable_tb is True and self.model in ["MacBookPro11,1", "MacBookPro11,2", "MacBookPro11,3", "MacBookPro11,4", "MacBookPro11,5"]: + print("- Disabling 2013-2014 laptop Thunderbolt Controller") + if self.model in ["MacBookPro11,3", "MacBookPro11,5"]: + # 15" dGPU models: IOACPIPlane:/_SB/PCI0@0/PEG1@10001/UPSB@0/DSB0@0/NHI0@0 + tb_device_path = "PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" + else: + # 13" and 15" iGPU 2013-2014 models: IOACPIPlane:/_SB/PCI0@0/P0P2@10000/UPSB@0/DSB0@0/NHI0@0 + tb_device_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" + + self.config["DeviceProperties"]["Add"][tb_device_path] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000")} + + + + # 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) + + # Add OpenCanopy + print("- Adding OpenCanopy GUI") + shutil.rmtree(self.constants.resources_path, onerror=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 + + + # RestrictEvents handling + block_args = "" + if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]: + block_args += "gmux," + if self.model in model_array.MacPro: + print("- Disabling memory error reporting") + block_args += "pcie," + gpu_dict = [] + if not self.constants.custom_model: + gpu_dict = self.constants.computer.gpus + else: + if self.model in smbios_data.smbios_dictionary: + gpu_dict = smbios_data.smbios_dictionary[self.model]["Stock GPUs"] + for gpu in gpu_dict: + if not self.constants.custom_model: + gpu = gpu.arch + if gpu in [ + device_probe.Intel.Archs.Ivy_Bridge, + device_probe.Intel.Archs.Haswell, + device_probe.NVIDIA.Archs.Kepler, + ]: + print("- Disabling mediaanalysisd") + block_args += "media," + break + if block_args.endswith(","): + block_args = block_args[:-1] + + if block_args != "": + print(f"- Setting RestrictEvents block arguments: {block_args}") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(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: + print("- Fixing Content Caching support") + patch_args += "content-caching," + + if patch_args.endswith(","): + patch_args = patch_args[:-1] + + if block_args != "" and patch_args == "": + # Disable unneeded Userspace patching (cs_validate_page is quite expensive) + patch_args = "none" + + if patch_args != "": + print(f"- Setting RestrictEvents patch arguments: {patch_args}") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(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 + + # DEBUG Settings + if self.constants.verbose_debug is True: + print("- Enabling Verbose boot") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -v" + if self.constants.kext_debug is True: + print("- Enabling DEBUG Kexts") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -liludbgall liludump=90" + # 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" + if self.constants.opencore_debug is True: + print("- Enabling DEBUG OpenCore") + self.config["Misc"]["Debug"]["Target"] = 0x43 + self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042 + if self.constants.showpicker is True: + print("- Enabling ShowPicker") + self.config["Misc"]["Boot"]["ShowPicker"] = True + else: + print("- Hiding OpenCore picker") + self.config["Misc"]["Boot"]["ShowPicker"] = False + if self.constants.oc_timeout != 5: + print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") + self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout + if self.constants.vault is True: + print("- 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 + 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 + print("- Adding ipc_control_port_options=0 to boot-args") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " ipc_control_port_options=0" + # 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) + if self.constants.custom_sip_value: + print(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")) + elif self.constants.sip_status is False: + print("- Set SIP to allow Root Volume patching") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = binascii.unhexlify("03080000") + + # apfs.kext has an undocumented boot-arg that allows FileVault usage on broken APFS seals (-arv_allow_fv) + # 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) + print("- 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 + # Lets us check in sys_patch.py if config supports FileVault + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Settings"] += " -allow_fv" + + if self.constants.disable_cs_lv is True: + print("- Disabling Library Validation") + # In Ventura, LV patch broke. For now, add AMFI arg + # Before merging into mainline, this needs to be resolved + 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 + if self.constants.disable_amfi is True: + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " amfi=0x80" + 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) + if self.constants.secure_status is False: + print("- Disabling SecureBootModel") + self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled" + if self.constants.force_vmm is True: + print("- 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 + if self.constants.serial_settings in ["Moderate", "Advanced"]: + print("- 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 + if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = self.constants.custom_cpu_model + if self.constants.custom_cpu_model_value != "": + print(f"- Adding custom CPU Name: {self.constants.custom_cpu_model_value}") + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value + else: + print("- Adding CPU Name Patch") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) + if self.model == self.constants.override_smbios: + print("- Adding -no_compat_check") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check" + if self.constants.disk != "": + self.disk_type() + if self.constants.validate is False: + print("- Adding bootmgfw.efi BlessOverride") + self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"] + + + if support.build_support(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) + + + def build_opencore(self): + 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() + support.build_support(self.model, self.constants, self.config).sign_files() + support.build_support(self.model, self.constants, self.config).validate_pathing() + print("") + print(f"Your OpenCore EFI for {self.model} has been built at:") + print(f" {self.constants.opencore_release_folder}") + print("") + if self.constants.gui_mode is False: + input("Press [Enter] to continue\n") diff --git a/resources/build/firmware.py b/resources/build/firmware.py new file mode 100644 index 000000000..5e3ebe208 --- /dev/null +++ b/resources/build/firmware.py @@ -0,0 +1,224 @@ +from resources import constants, generate_smbios +from resources.build import support +from data import smbios_data, cpu_data + +import binascii, shutil +from pathlib import Path + +class build_firmware: + + 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): + self.power_management_handling() + self.acpi_handling() + self.firmware_driver_handling() + self.firmware_compatibility_handling() + self.cpu_compatibility_handling() + + def power_management_handling(self): + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value: + # In macOS Ventura, Apple dropped AppleIntelCPUPowerManagement* kexts as they're unused on Haswell+ + # However re-injecting the AICPUPM kexts is not enough, as Ventura changed how 'intel_cpupm_matching' is set: + # https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/osfmk/i386/pal_routines.h#L153-L163 + # + # Specifically Apple has this logic for power management: + # - 0: Kext Based Power Management + # - 3: Kernel Based Power Management (For Haswell+ and Virtual Machines) + # - 4: Generic Virtual Machine Power Management + # + # Apple determines which to use by verifying whether 'plugin-type' exists in ACPI (with a value of 1 for Haswell, 2 for VMs) + # By default however, the plugin-type is not set, and thus the default value of '0' is used + # https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/osfmk/i386/pal_native.h#L62 + # + # With Ventura, Apple no longer sets '0' as the default value, and instead sets it to '3' + # This breaks AppleIntelCPUPowerManagement.kext matching as it no longer matches against the correct criteria + # + # To resolve, we patched AICPUPM to attach regardless of the value of 'intel_cpupm_matching' + print("- 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) + + 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 + # Because of this, X86PP will match onto the CPU instead of ACPI_SMC_PlatformPlugin + # This causes power management to break on pre-Ivy Bridge CPUs as they don't have correct + # power management tables provided. + # This patch will simply increase ASPP's 'IOProbeScore' to outmatch X86PP + print("- 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) + 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"] = "" + + if self.constants.disable_msr_power_ctl is True and smbios_data.smbios_dictionary[self.model]["CPU Generation"] >= cpu_data.cpu_data.nehalem.value: + print("- 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) + + def acpi_handling(self): + 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")): + # Applicable for consumer Nehalem + print("- 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 + 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 + print("- 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 + shutil.copy(self.constants.windows_ssdt_path, self.constants.acpi_path) + + def cpu_compatibility_handling(self): + 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) + + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value: + print("- 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) + + # i3 Ivy Bridge iMacs don't support RDRAND + # However for prebuilt, assume they do + if (not self.constants.custom_model and "RDRAND" not in self.computer.cpu.flags) or \ + (smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.sandy_bridge.value): + # Ref: https://github.com/reenigneorcim/SurPlus + # Enable for all systems missing RDRAND support + print("- 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 + 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 + print("- 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"] = "" + + # 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 + # Currently a (hopefully) temporary workaround for the issue, proper fix needs to be investigated + # Ref: + # https://forums.macrumors.com/threads/macos-12-monterey-on-unsupported-macs-thread.2299557/post-31120235 + # https://forums.macrumors.com/threads/monterand-probably-the-start-of-an-ongoing-saga.2320479/post-31123553 + + # 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) + + # HID patches + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value: + print("- 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 + + + + def firmware_driver_handling(self): + # Firmware Drivers (Drivers/*.efi) + + # Exfat check + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.sandy_bridge.value: + # Sandy Bridge and newer Macs natively support ExFat + print("- 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 + + # NVMe check + if self.constants.nvme_boot is True: + print("- 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 + + # USB check + if self.constants.xhci_boot is True: + print("- Adding USB 3.0 Controller Patch") + print("- 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 + + def firmware_compatibility_handling(self): + 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 + # This change resulted in broken OS booting as the machine had no power management support + # Currently the AICPUPM fix is not fully functional, thus forcing VMM is a temporary solution + # Waiting for XNU source to be released to fix this properly + # Ref: https://forums.macrumors.com/threads/opencore-on-the-mac-pro.2207814/ + if self.model == "MacPro6,1" or self.constants.set_vmm_cpuid is True: + print("- Enabling VMM patch") + self.config["Kernel"]["Emulate"]["Cpuid1Data"] = binascii.unhexlify("00000000000000000000008000000000") + self.config["Kernel"]["Emulate"]["Cpuid1Mask"] = binascii.unhexlify("00000000000000000000008000000000") + self.config["Kernel"]["Emulate"]["MinKernel"] = "22.0.0" + + if ( + self.model.startswith("MacBook") + and ( + smbios_data.smbios_dictionary[self.model]["CPU Generation"] == cpu_data.cpu_data.haswell.value or + smbios_data.smbios_dictionary[self.model]["CPU Generation"] == cpu_data.cpu_data.broadwell.value + ) + ): + # Fix Virtual Machine support for non-macOS OSes + # Haswell and Broadwell MacBooks lock out the VMX bit if booting UEFI Windows + print("- Enabling VMX Bit for non-macOS OSes") + self.config["UEFI"]["Quirks"]["EnableVmx"] = True + + + if self.constants.disable_connectdrivers is True: + print("- Disabling ConnectDrivers") + self.config["UEFI"]["ConnectDrivers"] = False + if self.constants.nvram_write is False: + print("- Disabling Hardware NVRAM Write") + self.config["NVRAM"]["WriteFlash"] = False + + if self.constants.serial_settings != "None": + # AppleMCEReporter is very picky about which models attach to the kext + # Commonly it will kernel panic on multi-socket systems, however even on single-socket systems it may cause instability + # To avoid any issues, we'll disable it if the spoof is set to an affected SMBIOS + affected_smbios = ["MacPro6,1", "MacPro7,1", "iMacPro1,1"] + 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) + + + 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 + + # 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 + + print("- Adding 5K Display Patch") + # Set LauncherPath to '/boot.efi' + # This is to ensure that only the Mac's firmware presents the boot option, but not OpenCore + # https://github.com/acidanthera/OpenCorePkg/blob/0.7.6/Library/OcAppleBootPolicyLib/OcAppleBootPolicyLib.c#L50-L73 + self.config["Misc"]["Boot"]["LauncherPath"] = "\\boot.efi" + + # Setup diags.efi chainloading + Path(self.constants.opencore_release_folder / Path("System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers")).mkdir(parents=True, exist_ok=True) + if self.constants.boot_efi is True: + path_oc_loader = self.constants.opencore_release_folder / Path("EFI/BOOT/BOOTx64.efi") + else: + path_oc_loader = self.constants.opencore_release_folder / Path("System/Library/CoreServices/boot.efi") + shutil.move(path_oc_loader, self.constants.opencore_release_folder / Path("System/Library/CoreServices/.diagnostics/Drivers/HardwareDrivers/Product.efi")) + shutil.copy(self.constants.diags_launcher_path, self.constants.opencore_release_folder) + shutil.move(self.constants.opencore_release_folder / Path("diags.efi"), self.constants.opencore_release_folder / Path("boot.efi")) \ No newline at end of file diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py new file mode 100644 index 000000000..1c4e293da --- /dev/null +++ b/resources/build/graphics_audio.py @@ -0,0 +1,342 @@ +from resources import constants, device_probe, utilities +from resources.build import support +from data import smbios_data, model_array, os_data + +from pathlib import Path + +import shutil, binascii + +class build_graphics_audio: + + def __init__(self, model, versions, config): + self.model = model + self.constants: constants.Constants = versions + self.config = config + self.computer = self.constants.computer + + self.gfx0_path = None + + + def build(self): + self.graphics_handling() + self.firmware_handling() + + def graphics_handling(self): + def backlight_path_detection(self): + if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: + self.gfx0_path = self.computer.dgpu.pci_path + print(f"- Found GFX0 Device Path: {self.gfx0_path}") + else: + if not self.constants.custom_model: + print("- Failed to find GFX0 Device path, falling back on known logic") + if self.model in ["iMac11,1", "iMac11,3"]: + self.gfx0_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)" + elif self.model == "iMac10,1": + self.gfx0_path = "PciRoot(0x0)/Pci(0xc,0x0)/Pci(0x0,0x0)" + else: + self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" + + def nvidia_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: + # 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_version, self.constants.whatevergreen_path) + if self.model in ["iMac11,1", "iMac11,2", "iMac11,3", "iMac10,1"]: + print("- Adding Nvidia Brightness Control and DRM patches") + self.config["DeviceProperties"]["Add"][backlight_path] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + if self.constants.custom_model and self.model == "iMac11,2": + # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) + # Set both properties when we cannot run hardware detection + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + elif self.model in ["iMac12,1", "iMac12,2"]: + print("- Adding Nvidia Brightness Control and DRM patches") + self.config["DeviceProperties"]["Add"][backlight_path] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + print("- Disabling unsupported iGPU") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "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 + self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True + + def amd_patch(self, backlight_path): + print("- 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: + # 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_version, self.constants.whatevergreen_path) + self.config["DeviceProperties"]["Add"][backlight_path] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} + if self.constants.custom_model and self.model == "iMac11,2": + # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) + # Set both properties when we cannot run hardware detection + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} + if self.model in ["iMac12,1", "iMac12,2"]: + print("- Disabling unsupported iGPU") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "class-code": binascii.unhexlify("FFFFFFFF"), + } + elif self.model == "iMac10,1": + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AAAMouSSE.kext")["Enabled"] is False: + support.build_support(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: + print("- Adding Legacy GCN Power Gate Patches") + self.config["DeviceProperties"]["Add"][backlight_path].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + if self.constants.imac_model == "Legacy GCN": + print("- Adding Legacy GCN Power Gate Patches") + self.config["DeviceProperties"]["Add"][backlight_path].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + if self.model == "iMac11,2": + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + + # Check GPU Vendor + if self.constants.metal_build is True: + backlight_path_detection(self) + print("- Adding Metal GPU patches on request") + if self.constants.imac_vendor == "AMD": + amd_patch(self, self.gfx0_path) + elif self.constants.imac_vendor == "Nvidia": + nvidia_patch(self, self.gfx0_path) + else: + print("- Failed to find vendor") + elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: + print(f"- Detected dGPU: {utilities.friendly_hex(self.computer.dgpu.vendor_id)}:{utilities.friendly_hex(self.computer.dgpu.device_id)}") + if self.computer.dgpu.arch in [ + device_probe.AMD.Archs.Legacy_GCN_7000, + device_probe.AMD.Archs.Legacy_GCN_8000, + device_probe.AMD.Archs.Legacy_GCN_9000, + device_probe.AMD.Archs.Polaris, + device_probe.AMD.Archs.Vega, + device_probe.AMD.Archs.Navi, + ]: + backlight_path_detection(self) + amd_patch(self, self.gfx0_path) + elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: + backlight_path_detection(self) + nvidia_patch(self, self.gfx0_path) + if self.model in model_array.MacPro: + if not self.constants.custom_model: + for i, device in enumerate(self.computer.gpus): + print(f"- Found dGPU ({i + 1}): {utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}") + self.config["#Revision"][f"Hardware-MacPro-dGPU-{i + 1}"] = f"{utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}" + + if device.pci_path and device.acpi_path: + print(f"- Found dGPU ({i + 1}) at {device.pci_path}") + if isinstance(device, device_probe.AMD): + print("- Adding Mac Pro, Xserve DRM patches") + self.config["DeviceProperties"]["Add"][device.pci_path] = {"shikigva": 128, "unfairgva": 1, "rebuild-device-tree": 1, "agdpmod": "pikera", "enable-gva-support": 1} + elif isinstance(device, device_probe.NVIDIA): + print("- Enabling Nvidia Output Patch") + self.config["DeviceProperties"]["Add"][device.pci_path] = {"rebuild-device-tree": 1, "agdpmod": "vit9696"} + self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True + + else: + print(f"- Failed to find Device path for dGPU {i + 1}") + if isinstance(device, device_probe.AMD): + print("- Adding Mac Pro, Xserve DRM patches") + if "shikigva=128 unfairgva=1" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: + print("- Falling back to boot-args") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 agdpmod=pikera radgva=1" + ( + " -wegtree" if "-wegtree" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] else "" + ) + elif isinstance(device, device_probe.NVIDIA): + print("- Enabling Nvidia Output Patch") + if "-wegtree agdpmod=vit9696" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: + print("- Falling back to boot-args") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -wegtree agdpmod=vit9696" + self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True + + if not self.computer.gpus: + print("- No socketed dGPU found") + + else: + print("- 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 self.constants.custom_model: + for i, device in enumerate(self.computer.gpus): + if isinstance(device, device_probe.NVIDIA): + if ( + device.arch in [device_probe.NVIDIA.Archs.Fermi, device_probe.NVIDIA.Archs.Maxwell, device_probe.NVIDIA.Archs.Pascal] or + (self.constants.force_nv_web is True and device.arch in [device_probe.NVIDIA.Archs.Tesla, device_probe.NVIDIA.Archs.Kepler]) + ): + print(f"- Enabling Web Driver Patches for GPU ({i + 1}): {utilities.friendly_hex(device.vendor_id)}:{utilities.friendly_hex(device.device_id)}") + if device.pci_path and device.acpi_path: + if device.pci_path in self.config["DeviceProperties"]["Add"]: + 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} + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: + support.build_support(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" + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: + support.build_support(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"] + if self.constants.allow_oc_everywhere is False: + if self.constants.serial_settings != "None": + if self.model == "MacBookPro9,1": + print("- Adding AppleMuxControl Override") + amc_map_path = Path(self.constants.plist_folder_path) / Path("AppleMuxControl/Info.plist") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"agdpmod": "vit9696"} + 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 + + if self.model not in model_array.NoAGPMSupport: + print("- Adding AppleGraphicsPowerManagement Override") + agpm_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsPowerManagement/Info.plist") + 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 + + if self.model in model_array.AGDPSupport: + print("- Adding AppleGraphicsDevicePolicy Override") + agdp_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsDevicePolicy/Info.plist") + 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 + + if self.constants.serial_settings != "None": + # AGPM Patch + if self.model in model_array.DualGPUPatch: + print("- Adding dual GPU patch") + if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: + self.gfx0_path = self.computer.dgpu.pci_path + print(f"- Found GFX0 Device Path: {self.gfx0_path}") + else: + if not self.constants.custom_model: + print("- Failed to find GFX0 Device path, falling back on known logic") + self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" + + if self.model in model_array.IntelNvidiaDRM and self.constants.drm_support is True: + print("- Prioritizing DRM support over Intel QuickSync") + self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696", "shikigva": 256} + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "class-code": binascii.unhexlify("FFFFFFFF"), + } + elif self.constants.serial_settings != "None": + self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696"} + if self.model.startswith("iMac14,"): + if self.computer.igpu and not self.computer.dgpu: + # Ensure that agdpmod is applied to iMac14,x with iGPU only + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"} + + + def audio_handling(self): + 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) + + # Audio Patch + if self.constants.set_alc_usage is True: + if smbios_data.smbios_dictionary[self.model]["Max OS Supported"] <= os_data.os_data.high_sierra: + # Models dropped in Mojave also lost Audio support + # Xserves and MacPro4,1 are exceptions + # iMac7,1 and iMac8,1 require AppleHDA/IOAudioFamily downgrade + if not (self.model.startswith("Xserve") or self.model in ["MacPro4,1", "iMac7,1", "iMac8,1"]): + try: + smbios_data.smbios_dictionary[self.model]["nForce Chipset"] + hdef_path = "PciRoot(0x0)/Pci(0x8,0x0)" + except KeyError: + hdef_path = "PciRoot(0x0)/Pci(0x1b,0x0)" + # In AppleALC, MacPro3,1's original layout is already in use, forcing layout 13 instead + if self.model == "MacPro3,1": + self.config["DeviceProperties"]["Add"][hdef_path] = { + "apple-layout-id": 90, + "use-apple-layout-id": 1, + "alc-layout-id": 13, + } + else: + self.config["DeviceProperties"]["Add"][hdef_path] = { + "apple-layout-id": 90, + "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) + 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) + + + + + def firmware_handling(self): + # Add UGA to GOP layer + if "UGA Graphics" in smbios_data.smbios_dictionary[self.model]: + print("- Adding UGA to GOP Patch") + self.config["UEFI"]["Output"]["GopPassThrough"] = "Apple" + + # GMUX handling + if self.constants.software_demux is True and self.model in ["MacBookPro8,2", "MacBookPro8,3"]: + print("- 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 + shutil.copy(self.constants.demux_ssdt_path, self.constants.acpi_path) + # Disable dGPU + # IOACPIPlane:/_SB/PCI0@0/P0P2@10000/GFX0@0 + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000"), "IOName": "Dortania Disabled Card", "name": "Dortania Disabled Card"} + 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) + + if self.constants.dGPU_switch is True and "Switchable GPUs" in smbios_data.smbios_dictionary[self.model]: + print("- Allowing GMUX switching in Windows") + self.config["Booter"]["Quirks"]["SignalAppleOS"] = True + + # Force Output support PC VBIOS on Mac Pros + if self.constants.force_output_support is True: + print("- Forcing GOP Support") + self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True \ No newline at end of file diff --git a/resources/build/networking/wired.py b/resources/build/networking/wired.py new file mode 100644 index 000000000..489ad282a --- /dev/null +++ b/resources/build/networking/wired.py @@ -0,0 +1,54 @@ +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 + + def build(self): + if not self.constants.custom_model and self.constants.computer.ethernet: + for controller in self.constants.computer.ethernet: + if isinstance(controller, device_probe.BroadcomEthernet) and controller.chipset == device_probe.BroadcomEthernet.Chipsets.AppleBCM5701Ethernet: + 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 + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("CatalinaBCM5701Ethernet.kext")["Enabled"] is False: + support.build_support(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 smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value: + # Apple's IOSkywalkFamily in DriverKit requires VT-D support + # Applicable for pre-Ivy Bridge models + if controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntelI210Ethernet: + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("CatalinaIntelI210Ethernet.kext")["Enabled"] is False: + support.build_support(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: + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleIntel8254XEthernet.kext")["Enabled"] is False: + support.build_support(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: + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Intel82574L.kext")["Enabled"] is False: + support.build_support(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): + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("nForceEthernet.kext")["Enabled"] is False: + support.build_support(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): + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("MarvelYukonEthernet.kext")["Enabled"] is False: + support.build_support(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path) + else: + if smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Broadcom": + 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) + 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) + 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) + 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) + 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) diff --git a/resources/build/networking/wireless.py b/resources/build/networking/wireless.py new file mode 100644 index 000000000..88b335a23 --- /dev/null +++ b/resources/build/networking/wireless.py @@ -0,0 +1,108 @@ +from resources import constants, device_probe, utilities +from resources.build import support +from data import smbios_data + +class build_wireless: + + 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): + + # WiFi patches + if not self.constants.custom_model: + if self.computer.wifi: + print(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)}" + else: + print("- Unable to run Wireless hardware detection") + + if not self.constants.custom_model: + if self.computer.wifi: + 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) + print(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 + print(f"- Found ARPT device at {arpt_path}") + self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} + else: + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" brcmfx-country={self.computer.wifi.country_code}" + if self.constants.enable_wake_on_wlan is True: + print("- 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() + 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 + 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 + 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 + else: + if smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4360: + print("- Enabling BCM943224 and BCM94331 Networking Support") + self.wifi_fake_id() + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4331: + print("- 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 + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm43224: + print("- 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 + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Atheros.Chipsets.AirPortAtheros40: + print("- 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 + 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) + if self.constants.enable_wake_on_wlan is True: + print("- Enabling Wake on WLAN support") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl" + + def wifi_fake_id(self): + 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 + if not self.constants.custom_model and self.computer.wifi and self.computer.wifi.pci_path: + arpt_path = self.computer.wifi.pci_path + print(f"- Found ARPT device at {arpt_path}") + else: + try: + smbios_data.smbios_dictionary[self.model]["nForce Chipset"] + # Nvidia chipsets all have the same path to ARPT + arpt_path = "PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)" + except KeyError: + if self.model in ("iMac7,1", "iMac8,1", "MacPro3,1", "MacBookPro4,1"): + arpt_path = "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)" + elif self.model in ("iMac13,1", "iMac13,2"): + arpt_path = "PciRoot(0x0)/Pci(0x1C,0x3)/Pci(0x0,0x0)" + elif self.model in ("MacPro4,1", "MacPro5,1"): + arpt_path = "PciRoot(0x0)/Pci(0x1C,0x5)/Pci(0x0,0x0)" + else: + # Assumes we have a laptop with Intel chipset + # iMac11,x-12,x also apply + arpt_path = "PciRoot(0x0)/Pci(0x1C,0x1)/Pci(0x0,0x0)" + print(f"- Using known DevicePath {arpt_path}") + + if not self.constants.custom_model and self.computer.wifi and self.constants.validate is False and self.computer.wifi.country_code: + print(f"- Applying fake ID for WiFi, setting Country Code: {self.computer.wifi.country_code}") + self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} + if self.constants.enable_wake_on_wlan is True: + print("- Enabling Wake on WLAN support") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl" \ No newline at end of file diff --git a/resources/build/security.py b/resources/build/security.py new file mode 100644 index 000000000..77802d2f4 --- /dev/null +++ b/resources/build/security.py @@ -0,0 +1,17 @@ + +from resources import constants, device_probe, utilities +from resources.build import support +from data import model_array, smbios_data, cpu_data + + +class build_security: + + 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): + return \ No newline at end of file diff --git a/resources/build/smbios.py b/resources/build/smbios.py new file mode 100644 index 000000000..fa136def2 --- /dev/null +++ b/resources/build/smbios.py @@ -0,0 +1,245 @@ + +from resources import constants, utilities, generate_smbios +from data import smbios_data, cpu_data, model_array + +import subprocess, plistlib, binascii, uuid, ast +from pathlib import Path + +class build_smbios: + + def __init__(self, model, versions, config): + self.model = model + self.constants: constants.Constants = versions + self.config = config + + + def set_smbios(self): + spoofed_model = self.model + if self.constants.override_smbios == "Default": + if self.constants.serial_settings != "None": + print("- Setting macOS Monterey Supported SMBIOS") + if self.constants.allow_native_spoofs is True: + spoofed_model = self.model + else: + spoofed_model = generate_smbios.set_smbios_model_spoof(self.model) + else: + spoofed_model = self.constants.override_smbios + print(f"- Using Model ID: {spoofed_model}") + try: + spoofed_board = smbios_data.smbios_dictionary[spoofed_model]["Board ID"] + print(f"- Using Board ID: {spoofed_board}") + except KeyError: + spoofed_board = "" + self.spoofed_model = spoofed_model + self.spoofed_board = spoofed_board + if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True: + self.config["#Revision"]["Spoofed-Model"] = f"{self.spoofed_model} - {self.constants.serial_settings}" + + # Setup menu + def minimal_serial_patch(self): + # Generate Firmware Features + fw_feature = generate_smbios.generate_fw_features(self.model, self.constants.custom_model) + # fw_feature = self.patch_firmware_feature() + fw_feature = hex(fw_feature).lstrip("0x").rstrip("L").strip() + print(f"- Setting Firmware Feature: {fw_feature}") + fw_feature = utilities.string_to_hex(fw_feature) + + # FirmwareFeatures + self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeatures"] = fw_feature + self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeaturesMask"] = fw_feature + self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeatures"] = fw_feature + self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeaturesMask"] = fw_feature + + # Board ID + self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board + self.config["PlatformInfo"]["PlatformNVRAM"]["BID"] = self.spoofed_board + self.config["PlatformInfo"]["SMBIOS"]["BoardProduct"] = self.spoofed_board + + # Model (ensures tables are not mismatched, even if we're not spoofing) + self.config["PlatformInfo"]["DataHub"]["SystemProductName"] = self.model + self.config["PlatformInfo"]["SMBIOS"]["SystemProductName"] = self.model + self.config["PlatformInfo"]["SMBIOS"]["BoardVersion"] = self.model + + # ProcessorType (when RestrictEvent's CPU naming is used) + if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: + self.config["PlatformInfo"]["SMBIOS"]["ProcessorType"] = 1537 + + # Avoid incorrect Firmware Updates + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["SMBIOS"]["BIOSVersion"] = "9999.999.999.999.999" + + # Update tables + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + + if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": + print("- Adding custom serial numbers") + sn = self.constants.custom_serial_number + mlb = self.constants.custom_board_serial_number + + # Serial Number + self.config["PlatformInfo"]["SMBIOS"]["ChassisSerialNumber"] = sn + self.config["PlatformInfo"]["SMBIOS"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["DataHub"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["PlatformNVRAM"]["SystemSerialNumber"] = sn + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn + + # Board Serial Number + self.config["PlatformInfo"]["SMBIOS"]["BoardSerialNumber"] = mlb + self.config["PlatformInfo"]["PlatformNVRAM"]["BoardSerialNumber"] = mlb + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb + + + + def moderate_serial_patch(self): + 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 != "": + print("- Adding custom serial numbers") + self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number + self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["Automatic"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True + self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model + + def advanced_serial_patch(self): + 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 == "": + macserial_output = subprocess.run([self.constants.macserial_path] + f"-g -m {self.spoofed_model} -n 1".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + macserial_output = macserial_output.stdout.decode().strip().split(" | ") + sn = macserial_output[0] + mlb = macserial_output[1] + else: + sn = self.constants.custom_serial_number + mlb = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["Automatic"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True + self.config["PlatformInfo"]["Generic"]["ROM"] = binascii.unhexlify("0016CB445566") + self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model + self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["Generic"]["MLB"] = mlb + self.config["PlatformInfo"]["Generic"]["SystemUUID"] = str(uuid.uuid4()).upper() + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb + + + if self.constants.serial_settings == "Moderate": + print("- Using Moderate SMBIOS patching") + moderate_serial_patch(self) + elif self.constants.serial_settings == "Advanced": + print("- Using Advanced SMBIOS patching") + advanced_serial_patch(self) + elif self.constants.serial_settings == "Minimal": + print("- Using Minimal SMBIOS patching") + self.spoofed_model = self.model + minimal_serial_patch(self) + 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, + # Thus resulting in an infinite loop as Lilu tries to request the Board ID + # To resolve this, set PlatformInfo -> DataHub -> BoardProduct and enable UpdateDataHub + + # Note 1: Only apply if system is UEFI 1.2, this is generally Ivy Bridge and older + # Note 2: Flipping 'UEFI -> ProtocolOverrides -> DataHub' will break hibernation + if (smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value and self.model): + print("- Detected UEFI 1.2 or older Mac, updating BoardProduct") + self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board + self.config["PlatformInfo"]["UpdateDataHub"] = True + + if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": + print("- Adding custom serial numbers") + self.config["PlatformInfo"]["Automatic"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True + self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number + self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number + self.config["PlatformInfo"]["Generic"]["MaxBIOSVersion"] = False + self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number + + # USB Map and CPUFriend Patching + if ( + self.constants.allow_oc_everywhere is False + and self.model not in ["Xserve2,1", "Dortania1,1"] + and ((self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) or self.constants.serial_settings in ["Moderate", "Advanced"]) + ): + new_map_ls = Path(self.constants.map_contents_folder) / Path("Info.plist") + map_config = plistlib.load(Path(new_map_ls).open("rb")) + # Strip unused USB maps + for entry in list(map_config["IOKitPersonalities_x86_64"]): + if not entry.startswith(self.model): + map_config["IOKitPersonalities_x86_64"].pop(entry) + else: + try: + map_config["IOKitPersonalities_x86_64"][entry]["model"] = self.spoofed_model + if self.constants.serial_settings in ["Minimal", "None"]: + if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "EH01": + map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "EHC1" + if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "EH02": + map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "EHC2" + if map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] == "SHC1": + map_config["IOKitPersonalities_x86_64"][entry]["IONameMatch"] = "XHC1" + except KeyError: + continue + plistlib.dump(map_config, Path(new_map_ls).open("wb"), sort_keys=True) + 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": + # Adjust CPU Friend Data to correct SMBIOS + new_cpu_ls = Path(self.constants.pp_contents_folder) / Path("Info.plist") + cpu_config = plistlib.load(Path(new_cpu_ls).open("rb")) + string_stuff = str(cpu_config["IOKitPersonalities"]["CPUFriendDataProvider"]["cf-frequency-data"]) + string_stuff = string_stuff.replace(self.model, self.spoofed_model) + string_stuff = ast.literal_eval(string_stuff) + cpu_config["IOKitPersonalities"]["CPUFriendDataProvider"]["cf-frequency-data"] = string_stuff + plistlib.dump(cpu_config, Path(new_cpu_ls).open("wb"), sort_keys=True) + + if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None": + if self.model == "MacBookPro9,1": + new_amc_ls = Path(self.constants.amc_contents_folder) / Path("Info.plist") + amc_config = plistlib.load(Path(new_amc_ls).open("rb")) + amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"][self.spoofed_board] = amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"].pop(self.model) + for entry in list(amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"]): + if not entry.startswith(self.spoofed_board): + amc_config["IOKitPersonalities"]["AppleMuxControl"]["ConfigMap"].pop(entry) + plistlib.dump(amc_config, Path(new_amc_ls).open("wb"), sort_keys=True) + if self.model not in model_array.NoAGPMSupport: + new_agpm_ls = Path(self.constants.agpm_contents_folder) / Path("Info.plist") + agpm_config = plistlib.load(Path(new_agpm_ls).open("rb")) + agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board] = agpm_config["IOKitPersonalities"]["AGPM"]["Machines"].pop(self.model) + if self.model == "MacBookPro6,2": + # Force G State to not exceed moderate state + # Ref: https://github.com/fabioiop/MBP-2010-GPU-Panic-fix + print("- Patching G State for MacBookPro6,2") + for gpu in ["Vendor10deDevice0a34", "Vendor10deDevice0a29"]: + agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board][gpu]["BoostPState"] = [2, 2, 2, 2] + agpm_config["IOKitPersonalities"]["AGPM"]["Machines"][self.spoofed_board][gpu]["BoostTime"] = [2, 2, 2, 2] + + for entry in list(agpm_config["IOKitPersonalities"]["AGPM"]["Machines"]): + if not entry.startswith(self.spoofed_board): + agpm_config["IOKitPersonalities"]["AGPM"]["Machines"].pop(entry) + + plistlib.dump(agpm_config, Path(new_agpm_ls).open("wb"), sort_keys=True) + if self.model in model_array.AGDPSupport: + new_agdp_ls = Path(self.constants.agdp_contents_folder) / Path("Info.plist") + agdp_config = plistlib.load(Path(new_agdp_ls).open("rb")) + agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"][self.spoofed_board] = agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"].pop( + self.model + ) + for entry in list(agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"]): + if not entry.startswith(self.spoofed_board): + agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"].pop(entry) + plistlib.dump(agdp_config, Path(new_agdp_ls).open("wb"), sort_keys=True) \ No newline at end of file diff --git a/resources/build/storage.py b/resources/build/storage.py new file mode 100644 index 000000000..8b445f6d0 --- /dev/null +++ b/resources/build/storage.py @@ -0,0 +1,110 @@ + +from resources import constants, device_probe, utilities +from resources.build import support +from data import model_array, smbios_data, cpu_data + + +class build_storage: + + 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): + self.ahci_handling() + self.pata_handling() + self.misc_handling() + + 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 + if self.model in ["MacBookAir6,1", "MacBookAir6,2"]: + print("- 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) + + + # ThirdPartyDrives Check + if self.constants.allow_3rd_party_drives is True: + for drive in ["SATA 2.5", "SATA 3.5", "mSATA"]: + if drive in smbios_data.smbios_dictionary[self.model]["Stock Storage"]: + if not self.constants.custom_model: + if self.computer.third_party_sata_ssd is True: + print("- Adding SATA Hibernation Patch") + self.config["Kernel"]["Quirks"]["ThirdPartyDrives"] = True + break + else: + print("- Adding SATA Hibernation Patch") + self.config["Kernel"]["Quirks"]["ThirdPartyDrives"] = True + break + + def pata_handling(self): + if "PATA" in smbios_data.smbios_dictionary[self.model]["Stock Storage"]: + support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntelPIIXATA.kext", self.constants.piixata_version, self.constants.piixata_path) + + def pcie_handling(self): + 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 + for i, controller in enumerate(self.computer.storage): + print(f"- Fixing PCIe Storage Controller ({i + 1}) reporting") + if controller.pci_path: + self.config["DeviceProperties"]["Add"][controller.pci_path] = {"built-in": 1} + else: + print(f"- Failed to find Device path for PCIe Storage Controller {i}, falling back to Innie") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Innie.kext")["Enabled"] is False: + support.build_support(self.model, self.constants, self.config).enable_kext("Innie.kext", self.constants.innie_version, self.constants.innie_path) + if not self.computer.storage: + print("- No PCIe Storage Controllers found to fix") + + + 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)] + for i, controller in enumerate(nvme_devices): + print(f"- Found 3rd Party NVMe SSD ({i + 1}): {utilities.friendly_hex(controller.vendor_id)}:{utilities.friendly_hex(controller.device_id)}") + self.config["#Revision"][f"Hardware-NVMe-{i}"] = f"{utilities.friendly_hex(controller.vendor_id)}:{utilities.friendly_hex(controller.device_id)}" + + # Disable Bit 0 (L0s), enable Bit 1 (L1) + nvme_aspm = (controller.aspm & (~0b11)) | 0b10 + + if controller.pci_path: + print(f"- Found NVMe ({i}) at {controller.pci_path}") + self.config["DeviceProperties"]["Add"].setdefault(controller.pci_path, {})["pci-aspm-default"] = nvme_aspm + self.config["DeviceProperties"]["Add"][controller.pci_path.rpartition("/")[0]] = {"pci-aspm-default": nvme_aspm} + else: + if "-nvmefaspm" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]: + print("- Falling back to -nvmefaspm") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -nvmefaspm" + + 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 + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("NVMeFix.kext")["Enabled"] is False: + support.build_support(self.model, self.constants, self.config).enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path) + + if not nvme_devices: + print("- No 3rd Party NVMe drives found") + + # Apple RAID Card check + if not self.constants.custom_model: + if self.computer.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) + 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) + + + def misc_handling(self): + # With macOS Monterey, Apple's SDXC driver requires the system to support VT-D + # 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) \ No newline at end of file diff --git a/resources/build/support.py b/resources/build/support.py new file mode 100644 index 000000000..e5432861f --- /dev/null +++ b/resources/build/support.py @@ -0,0 +1,174 @@ +# Support files for build + +from resources import constants, utilities + +from pathlib import Path +import shutil, plistlib, subprocess, zipfile + +class build_support: + + def __init__(self, model, versions, config): + self.model = model + self.constants: constants.Constants = versions + self.config = config + + + @staticmethod + def get_item_by_kv(iterable, key, value): + item = None + for i in iterable: + if i[key] == value: + item = i + break + return item + + def get_kext_by_bundle_path(self, bundle_path): + kext = self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", bundle_path) + if not kext: + print(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) + if not efi_binary: + print(f"- Could not find {efi_type}: {bundle_path}!") + 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) + + if callable(check) and not check(): + # Check failed + return + + # Is the kext already enabled? + if kext["Enabled"] is True: + return + + print(f"- Adding {kext_name} {kext_version}") + shutil.copy(kext_path, self.constants.kexts_path) + kext["Enabled"] = True + + def sign_files(self): + if self.constants.vault is True: + if utilities.check_command_line_tools() is True: + # sign.command checks for the existence of '/usr/bin/strings' however does not verify whether it's executable + # sign.command will continue to run and create an unbootable OpenCore.efi due to the missing strings binary + # macOS has dummy binaries that just reroute to the actual binaries after you install Xcode's Command Line Tools + print("- Vaulting EFI") + subprocess.run([str(self.constants.vault_path), f"{self.constants.oc_folder}/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + else: + print("- Missing Command Line tools, skipping Vault for saftey reasons") + print("- Install via 'xcode-select --install' and rerun OCLP if you wish to vault this config") + + + def validate_pathing(self): + print("- Validating generated config") + if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")): + print("- OpenCore config file missing!!!") + raise Exception("OpenCore config file missing") + + config_plist = plistlib.load(Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")).open("rb")) + + for acpi in config_plist["ACPI"]["Add"]: + # print(f" - Validating {acpi['Path']}") + if not Path(self.constants.opencore_release_folder / Path("EFI/OC/ACPI") / Path(acpi["Path"])).exists(): + print(f" - Missing ACPI Table: {acpi['Path']}") + raise Exception(f"Missing ACPI Table: {acpi['Path']}") + + for kext in config_plist["Kernel"]["Add"]: + # print(f" - Validating {kext['BundlePath']}") + kext_path = Path(self.constants.opencore_release_folder / Path("EFI/OC/Kexts") / Path(kext["BundlePath"])) + kext_binary_path = Path(kext_path / Path(kext["ExecutablePath"])) + kext_plist_path = Path(kext_path / Path(kext["PlistPath"])) + if not kext_path.exists(): + print(f"- Missing kext: {kext_path}") + raise Exception(f"Missing {kext_path}") + if not kext_binary_path.exists(): + print(f"- Missing {kext['BundlePath']}'s binary: {kext_binary_path}") + raise Exception(f"Missing {kext_binary_path}") + if not kext_plist_path.exists(): + print(f"- Missing {kext['BundlePath']}'s plist: {kext_plist_path}") + raise Exception(f"Missing {kext_plist_path}") + + for tool in config_plist["Misc"]["Tools"]: + # print(f" - Validating {tool['Path']}") + if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools") / Path(tool["Path"])).exists(): + print(f" - Missing tool: {tool['Path']}") + raise Exception(f"Missing tool: {tool['Path']}") + + for driver in config_plist["UEFI"]["Drivers"]: + # print(f" - Validating {driver['Path']}") + if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Drivers") / Path(driver["Path"])).exists(): + print(f" - Missing driver: {driver['Path']}") + raise Exception(f"Missing driver: {driver['Path']}") + + # Validating local files + # Validate Tools + for tool_files in Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools")).glob("*"): + if tool_files.name not in [x["Path"] for x in config_plist["Misc"]["Tools"]]: + print(f" - Missing tool from config: {tool_files.name}") + raise Exception(f"Missing tool from config: {tool_files.name}") + + for driver_file in Path(self.constants.opencore_release_folder / Path("EFI/OC/Drivers")).glob("*"): + if driver_file.name not in [x["Path"] for x in config_plist["UEFI"]["Drivers"]]: + print(f"- Found extra driver: {driver_file.name}") + raise Exception(f"Found extra driver: {driver_file.name}") + + def cleanup(self): + print("- Cleaning up files") + # Remove unused entries + entries_to_clean = { + "ACPI": ["Add", "Delete", "Patch"], + "Booter": ["Patch"], + "Kernel": ["Add", "Block", "Force", "Patch"], + "Misc": ["Tools"], + "UEFI": ["Drivers"], + } + + for entry in entries_to_clean: + for sub_entry in entries_to_clean[entry]: + for item in list(self.config[entry][sub_entry]): + if item["Enabled"] is False: + self.config[entry][sub_entry].remove(item) + + plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True) + for kext in self.constants.kexts_path.rglob("*.zip"): + with zipfile.ZipFile(kext) as zip_file: + zip_file.extractall(self.constants.kexts_path) + kext.unlink() + + for item in self.constants.oc_folder.rglob("*.zip"): + with zipfile.ZipFile(item) as zip_file: + zip_file.extractall(self.constants.oc_folder) + item.unlink() + + if not self.constants.recovery_status: + # Crashes in RecoveryOS for unknown reason + for i in self.constants.build_path.rglob("__MACOSX"): + shutil.rmtree(i) + + # Remove unused plugins inside of kexts + # Following plugins are sometimes unused as there's different variants machines need + known_unused_plugins = [ + "AirPortBrcm4331.kext", + "AirPortAtheros40.kext", + "AppleAirPortBrcm43224.kext", + "AirPortBrcm4360_Injector.kext", + "AirPortBrcmNIC_Injector.kext" + ] + for kext in Path(self.constants.opencore_release_folder / Path("EFI/OC/Kexts")).glob("*.kext"): + for plugin in Path(kext / "Contents/PlugIns/").glob("*.kext"): + should_remove = True + for enabled_kexts in self.config["Kernel"]["Add"]: + if enabled_kexts["BundlePath"].endswith(plugin.name): + should_remove = False + break + if should_remove: + if plugin.name not in known_unused_plugins: + raise Exception(f" - Unknown plugin found: {plugin.name}") + shutil.rmtree(plugin) + + Path(self.constants.opencore_zip_copied).unlink() \ No newline at end of file diff --git a/resources/main.py b/resources/main.py index 2fa3ba218..0fcf49884 100644 --- a/resources/main.py +++ b/resources/main.py @@ -6,7 +6,8 @@ from pathlib import Path import time import threading -from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, commit_info +from resources import cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, commit_info +from resources.build import build from data import model_array class OpenCoreLegacyPatcher: diff --git a/resources/validation.py b/resources/validation.py index 67087269f..b29928914 100644 --- a/resources/validation.py +++ b/resources/validation.py @@ -1,5 +1,6 @@ import subprocess -from resources import build, sys_patch_helpers +from resources import sys_patch_helpers +from resources.build import build from data import example_data, model_array, sys_patch_dict, os_data from pathlib import Path From 55061bc86d4bca8b0e3cee64b017c4567e349b6b Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 12 Nov 2022 17:14:39 -0700 Subject: [PATCH 02/19] build.py: Use pythonic class name --- gui/gui_main.py | 2 +- resources/arguments.py | 2 +- resources/build/build.py | 8 +------- resources/main.py | 2 +- resources/validation.py | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gui/gui_main.py b/gui/gui_main.py index 0ba259f40..0bb727b76 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -628,7 +628,7 @@ class wx_python_gui: while self.is_unpack_finished() is False: time.sleep(0.1) - build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore() + build.build_opencore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore() # 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) diff --git a/resources/arguments.py b/resources/arguments.py index 238f93be6..ddddc2167 100644 --- a/resources/arguments.py +++ b/resources/arguments.py @@ -93,7 +93,7 @@ class arguments: print("- Building for natively supported model") settings.allow_oc_everywhere = True settings.serial_settings = "None" - build.BuildOpenCore(settings.custom_model or settings.computer.real_model, settings).build_opencore() + build.build_opencore(settings.custom_model or settings.computer.real_model, settings).build_opencore() elif self.args.patch_sys_vol: print("- Set System Volume patching") diff --git a/resources/build/build.py b/resources/build/build.py index b7b3fb7e6..4f339ec75 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -23,7 +23,7 @@ def rmtree_handler(func, path, exc_info): raise # pylint: disable=misplaced-bare-raise -class BuildOpenCore: +class build_opencore: def __init__(self, model, versions): self.model = model self.config = None @@ -156,12 +156,6 @@ class BuildOpenCore: bluetooth.build_bluetooth(self.model, self.constants, self.config).build() storage.build_storage(self.model, self.constants, self.config).build() - - - - - - # CPUFriend if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") diff --git a/resources/main.py b/resources/main.py index 0fcf49884..773f18a60 100644 --- a/resources/main.py +++ b/resources/main.py @@ -106,7 +106,7 @@ class OpenCoreLegacyPatcher: menu = tui_helpers.TUIMenu(title, "Please select an option: ", in_between=in_between, auto_number=True, top_level=True) options = ( - [["Build OpenCore", build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore]] + [["Build OpenCore", build.build_opencore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore]] if ((self.constants.custom_model or self.computer.real_model) in model_array.SupportedSMBIOS) or self.constants.allow_oc_everywhere is True else [] ) + [ diff --git a/resources/validation.py b/resources/validation.py index b29928914..4c3829f94 100644 --- a/resources/validation.py +++ b/resources/validation.py @@ -43,7 +43,7 @@ def validate(settings): for model in model_array.SupportedSMBIOS: print(f"Validating predefined model: {model}") settings.custom_model = model - build.BuildOpenCore(settings.custom_model, settings).build_opencore() + build.build_opencore(settings.custom_model, settings).build_opencore() result = subprocess.run([settings.ocvalidate_path, f"{settings.opencore_release_folder}/EFI/OC/config.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if result.returncode != 0: print("Error on build!") @@ -57,7 +57,7 @@ def validate(settings): settings.computer = model settings.custom_model = "" print(f"Validating dumped model: {settings.computer.real_model}") - build.BuildOpenCore(settings.computer.real_model, settings).build_opencore() + build.build_opencore(settings.computer.real_model, settings).build_opencore() result = subprocess.run([settings.ocvalidate_path, f"{settings.opencore_release_folder}/EFI/OC/config.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if result.returncode != 0: print("Error on build!") From f8e91feff43771dd05c750ff43ef0505d5bbb5b4 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 12 Nov 2022 17:29:37 -0700 Subject: [PATCH 03/19] build: Enable Audio and fix invocation --- resources/build/bluetooth.py | 2 +- resources/build/graphics_audio.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/build/bluetooth.py b/resources/build/bluetooth.py index 4353f7df5..377193186 100644 --- a/resources/build/bluetooth.py +++ b/resources/build/bluetooth.py @@ -25,7 +25,7 @@ class build_bluetooth: if self.computer.wifi: if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360: print("- Fixing Legacy Bluetooth for macOS Monterey") - self.enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) + support.build_support(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": print("- Detected 3rd Party Chipset") support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index 1c4e293da..a336bd793 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -19,6 +19,7 @@ class build_graphics_audio: def build(self): self.graphics_handling() + self.audio_handling() self.firmware_handling() def graphics_handling(self): From 956d0cffccbd7f6e9457e0568265cf798421a353 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 12 Nov 2022 20:15:43 -0700 Subject: [PATCH 04/19] Further modularize --- resources/build/build.py | 310 +----------------------------- resources/build/graphics_audio.py | 4 + resources/build/misc.py | 217 +++++++++++++++++++++ resources/build/security.py | 49 ++++- resources/build/smbios.py | 36 ++++ 5 files changed, 312 insertions(+), 304 deletions(-) create mode 100644 resources/build/misc.py diff --git a/resources/build/build.py b/resources/build/build.py index 4f339ec75..6996a1c0b 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -11,10 +11,9 @@ import zipfile from pathlib import Path from datetime import date -from resources import constants, utilities, device_probe, generate_smbios -from resources.build import bluetooth, firmware, graphics_audio, support, storage, smbios, security +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 -from data import smbios_data, cpu_data, os_data, model_array def rmtree_handler(func, path, exc_info): @@ -31,29 +30,6 @@ class build_opencore: self.computer = self.constants.computer self.gfx0_path = None - def disk_type(self): - drive_host_info = plistlib.loads(subprocess.run(f"diskutil info -plist {self.constants.disk}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()) - sd_type = drive_host_info["MediaName"] - try: - ssd_type = drive_host_info["SolidState"] - except KeyError: - ssd_type = False - # Array filled with common SD Card names - # Note most USB-based SD Card readers generally report as "Storage Device", and no reliable way to detect further - if sd_type in ["SD Card Reader", "SD/MMC"]: - print("- Adding SD Card icon") - shutil.copy(self.constants.icon_path_sd, self.constants.opencore_release_folder) - elif ssd_type is True: - print("- Adding SSD icon") - shutil.copy(self.constants.icon_path_ssd, self.constants.opencore_release_folder) - elif drive_host_info["BusProtocol"] == "USB": - print("- Adding External USB Drive icon") - shutil.copy(self.constants.icon_path_external, self.constants.opencore_release_folder) - else: - print("- Adding Internal Drive icon") - shutil.copy(self.constants.icon_path_internal, self.constants.opencore_release_folder) - - def build_efi(self): utilities.cls() @@ -97,57 +73,8 @@ class build_opencore: self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model - for name, version, path, check in [ - # Essential kexts - ("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path, lambda: True), - ("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), - ("SMC-Spoof.kext", self.constants.smcspoof_version, self.constants.smcspoof_path, lambda: self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None"), - ( - "CPUFriend.kext", - self.constants.cpufriend_version, - self.constants.cpufriend_path, - lambda: self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.disallow_cpufriend is False and self.constants.serial_settings != "None", - ), - # Misc - ("DebugEnhancer.kext", self.constants.debugenhancer_version, self.constants.debugenhancer_path, lambda: self.constants.kext_debug is True), - ("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path, lambda: self.model in ["MacBook4,1", "MacBook5,2"]), - ]: - support.build_support(self.model, self.constants, self.config).enable_kext(name, version, path, check) - - 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 - # print("- 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 - - print("- 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 - - # Patch HW_BID to OC_BID - # Set OC_BID to iMac18,1 Board ID (Mac-F60DEB81FF30ACF6) - # Goal is to only allow OS booting through OCLP, otherwise failing - print("- Enabling HW_BID reroute") - support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Reroute HW_BID to OC_BID")["Enabled"] = True - self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["OC_BID"] = "Mac-BE088AF8C5EB4FA2" - self.config["NVRAM"]["Delete"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"] += ["OC_BID"] - else: - print("- 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 - - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Lilu.kext")["Enabled"] is True: - # Required for Lilu in 11.0+ - self.config["Kernel"]["Quirks"]["DisableLinkeditJettison"] = True - - - - if self.constants.fu_status is True: - # Enable FeatureUnlock.kext - 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: - print(f"- Adding additional FeatureUnlock args: {self.constants.fu_arguments}") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += self.constants.fu_arguments + support.build_support(self.model, self.constants, self.config).enable_kext("Lilu.kext", self.constants.lilu_version, self.constants.lilu_path) + self.config["Kernel"]["Quirks"]["DisableLinkeditJettison"] = True firmware.build_firmware(self.model, self.constants, self.config).build() wired.build_wired(self.model, self.constants, self.config).build() @@ -155,237 +82,14 @@ class build_opencore: 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() + misc.build_misc(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() - # CPUFriend - if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": - pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") - if not pp_map_path.exists(): - raise Exception(f"{pp_map_path} does not exist!!! Please file an issue stating file is missing for {self.model}.") - 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 - - - # Legacy iSight patches - try: - 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) - except KeyError: - pass - - - - # USB Map - usb_map_path = Path(self.constants.plist_folder_path) / Path("AppleUSBMaps/Info.plist") - if ( - usb_map_path.exists() - and (self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True) - and self.model not in ["Xserve2,1", "Dortania1,1"] - and ( - (self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) - or self.constants.serial_settings in ["Moderate", "Advanced"]) - ): - print("- Adding USB-Map.kext") - 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 - 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" - - - 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 - print("- 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 - - - - if self.constants.disable_tb is True and self.model in ["MacBookPro11,1", "MacBookPro11,2", "MacBookPro11,3", "MacBookPro11,4", "MacBookPro11,5"]: - print("- Disabling 2013-2014 laptop Thunderbolt Controller") - if self.model in ["MacBookPro11,3", "MacBookPro11,5"]: - # 15" dGPU models: IOACPIPlane:/_SB/PCI0@0/PEG1@10001/UPSB@0/DSB0@0/NHI0@0 - tb_device_path = "PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" - else: - # 13" and 15" iGPU 2013-2014 models: IOACPIPlane:/_SB/PCI0@0/P0P2@10000/UPSB@0/DSB0@0/NHI0@0 - tb_device_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" - - self.config["DeviceProperties"]["Add"][tb_device_path] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000")} - - - - # 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) - - # Add OpenCanopy - print("- Adding OpenCanopy GUI") - shutil.rmtree(self.constants.resources_path, onerror=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 - - - # RestrictEvents handling - block_args = "" - if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]: - block_args += "gmux," - if self.model in model_array.MacPro: - print("- Disabling memory error reporting") - block_args += "pcie," - gpu_dict = [] - if not self.constants.custom_model: - gpu_dict = self.constants.computer.gpus - else: - if self.model in smbios_data.smbios_dictionary: - gpu_dict = smbios_data.smbios_dictionary[self.model]["Stock GPUs"] - for gpu in gpu_dict: - if not self.constants.custom_model: - gpu = gpu.arch - if gpu in [ - device_probe.Intel.Archs.Ivy_Bridge, - device_probe.Intel.Archs.Haswell, - device_probe.NVIDIA.Archs.Kepler, - ]: - print("- Disabling mediaanalysisd") - block_args += "media," - break - if block_args.endswith(","): - block_args = block_args[:-1] - - if block_args != "": - print(f"- Setting RestrictEvents block arguments: {block_args}") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(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: - print("- Fixing Content Caching support") - patch_args += "content-caching," - - if patch_args.endswith(","): - patch_args = patch_args[:-1] - - if block_args != "" and patch_args == "": - # Disable unneeded Userspace patching (cs_validate_page is quite expensive) - patch_args = "none" - - if patch_args != "": - print(f"- Setting RestrictEvents patch arguments: {patch_args}") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(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 - - # DEBUG Settings - if self.constants.verbose_debug is True: - print("- Enabling Verbose boot") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -v" - if self.constants.kext_debug is True: - print("- Enabling DEBUG Kexts") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -liludbgall liludump=90" - # 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" - if self.constants.opencore_debug is True: - print("- Enabling DEBUG OpenCore") - self.config["Misc"]["Debug"]["Target"] = 0x43 - self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042 - if self.constants.showpicker is True: - print("- Enabling ShowPicker") - self.config["Misc"]["Boot"]["ShowPicker"] = True - else: - print("- Hiding OpenCore picker") - self.config["Misc"]["Boot"]["ShowPicker"] = False - if self.constants.oc_timeout != 5: - print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") - self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout - if self.constants.vault is True: - print("- 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 - 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 - print("- Adding ipc_control_port_options=0 to boot-args") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " ipc_control_port_options=0" - # 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) - if self.constants.custom_sip_value: - print(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")) - elif self.constants.sip_status is False: - print("- Set SIP to allow Root Volume patching") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = binascii.unhexlify("03080000") - - # apfs.kext has an undocumented boot-arg that allows FileVault usage on broken APFS seals (-arv_allow_fv) - # 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) - print("- 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 - # Lets us check in sys_patch.py if config supports FileVault - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Settings"] += " -allow_fv" - - if self.constants.disable_cs_lv is True: - print("- Disabling Library Validation") - # In Ventura, LV patch broke. For now, add AMFI arg - # Before merging into mainline, this needs to be resolved - 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 - if self.constants.disable_amfi is True: - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " amfi=0x80" - 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) - if self.constants.secure_status is False: - print("- Disabling SecureBootModel") - self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled" - if self.constants.force_vmm is True: - print("- 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 - if self.constants.serial_settings in ["Moderate", "Advanced"]: - print("- 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 - if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = self.constants.custom_cpu_model - if self.constants.custom_cpu_model_value != "": - print(f"- Adding custom CPU Name: {self.constants.custom_cpu_model_value}") - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value - else: - print("- Adding CPU Name Patch") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) - if self.model == self.constants.override_smbios: - print("- Adding -no_compat_check") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check" - if self.constants.disk != "": - self.disk_type() if self.constants.validate is False: print("- Adding bootmgfw.efi BlessOverride") self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"] - if support.build_support(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 diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index a336bd793..cb4f17f95 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -23,6 +23,10 @@ class build_graphics_audio: self.firmware_handling() def graphics_handling(self): + if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None": + support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) + + def backlight_path_detection(self): if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: self.gfx0_path = self.computer.dgpu.pci_path diff --git a/resources/build/misc.py b/resources/build/misc.py new file mode 100644 index 000000000..140170ec4 --- /dev/null +++ b/resources/build/misc.py @@ -0,0 +1,217 @@ + +from resources import constants, device_probe, utilities, generate_smbios +from resources.build import support +from data import model_array, smbios_data, cpu_data + +import binascii, shutil +from pathlib import Path + + +class build_misc: + + def __init__(self, model, versions, config): + self.model = model + self.constants: constants.Constants = versions + self.config = config + self.computer = self.constants.computer + + def rmtree_handler(func, path, exc_info): + if exc_info[0] == FileNotFoundError: + 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() + + 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: + print(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): + block_args = "" + if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]: + block_args += "gmux," + if self.model in model_array.MacPro: + print("- Disabling memory error reporting") + block_args += "pcie," + gpu_dict = [] + if not self.constants.custom_model: + gpu_dict = self.constants.computer.gpus + else: + if self.model in smbios_data.smbios_dictionary: + gpu_dict = smbios_data.smbios_dictionary[self.model]["Stock GPUs"] + for gpu in gpu_dict: + if not self.constants.custom_model: + gpu = gpu.arch + if gpu in [ + device_probe.Intel.Archs.Ivy_Bridge, + device_probe.Intel.Archs.Haswell, + device_probe.NVIDIA.Archs.Kepler, + ]: + print("- Disabling mediaanalysisd") + block_args += "media," + break + if block_args.endswith(","): + block_args = block_args[:-1] + + if block_args != "": + print(f"- Setting RestrictEvents block arguments: {block_args}") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(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: + print("- Fixing Content Caching support") + patch_args += "content-caching," + + if patch_args.endswith(","): + patch_args = patch_args[:-1] + + if block_args != "" and patch_args == "": + # Disable unneeded Userspace patching (cs_validate_page is quite expensive) + patch_args = "none" + + if patch_args != "": + print(f"- Setting RestrictEvents patch arguments: {patch_args}") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(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: + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = self.constants.custom_cpu_model + if self.constants.custom_cpu_model_value != "": + print(f"- Adding custom CPU Name: {self.constants.custom_cpu_model_value}") + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value + else: + print("- Adding CPU Name Patch") + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: + support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_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) + + # CPUFriend + if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": + pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") + if not pp_map_path.exists(): + raise Exception(f"{pp_map_path} does not exist!!! Please file an issue stating file is missing for {self.model}.") + 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 + + 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 + print("- 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): + # 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) + # 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) + + 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"]: + print("- Disabling 2013-2014 laptop Thunderbolt Controller") + if self.model in ["MacBookPro11,3", "MacBookPro11,5"]: + # 15" dGPU models: IOACPIPlane:/_SB/PCI0@0/PEG1@10001/UPSB@0/DSB0@0/NHI0@0 + tb_device_path = "PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" + else: + # 13" and 15" iGPU 2013-2014 models: IOACPIPlane:/_SB/PCI0@0/P0P2@10000/UPSB@0/DSB0@0/NHI0@0 + tb_device_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)" + + self.config["DeviceProperties"]["Add"][tb_device_path] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000")} + + def webcam_handling(self): + # Legacy iSight patches + 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) + + def usb_handling(self): + # USB Map + usb_map_path = Path(self.constants.plist_folder_path) / Path("AppleUSBMaps/Info.plist") + if ( + usb_map_path.exists() + and (self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True) + and self.model not in ["Xserve2,1", "Dortania1,1"] + and ( + (self.model in model_array.Missing_USB_Map or self.model in model_array.Missing_USB_Map_Ventura) + or self.constants.serial_settings in ["Moderate", "Advanced"]) + ): + print("- Adding USB-Map.kext") + 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 + 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" + + + def debug_handling(self): + # DEBUG Settings + if self.constants.verbose_debug is True: + print("- Enabling Verbose boot") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -v" + if self.constants.kext_debug is True: + print("- Enabling DEBUG Kexts") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -liludbgall liludump=90" + # 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) + if self.constants.opencore_debug is True: + print("- Enabling DEBUG OpenCore") + self.config["Misc"]["Debug"]["Target"] = 0x43 + self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042 + + def general_oc_handling(self): + # Add OpenCanopy + print("- 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 + + + if self.constants.showpicker is True: + print("- Enabling ShowPicker") + self.config["Misc"]["Boot"]["ShowPicker"] = True + else: + print("- Hiding OpenCore picker") + self.config["Misc"]["Boot"]["ShowPicker"] = False + if self.constants.oc_timeout != 5: + print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") + self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout \ No newline at end of file diff --git a/resources/build/security.py b/resources/build/security.py index 77802d2f4..9aaafa584 100644 --- a/resources/build/security.py +++ b/resources/build/security.py @@ -14,4 +14,51 @@ class build_security: def build(self): - return \ No newline at end of file + if self.constants.vault is True: + print("- 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 + 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 + print("- Adding ipc_control_port_options=0 to boot-args") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " ipc_control_port_options=0" + # 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) + if self.constants.custom_sip_value: + print(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")) + elif self.constants.sip_status is False: + print("- Set SIP to allow Root Volume patching") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = binascii.unhexlify("03080000") + + # apfs.kext has an undocumented boot-arg that allows FileVault usage on broken APFS seals (-arv_allow_fv) + # 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) + print("- 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 + # Lets us check in sys_patch.py if config supports FileVault + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Settings"] += " -allow_fv" + + if self.constants.disable_cs_lv is True: + print("- Disabling Library Validation") + # In Ventura, LV patch broke. For now, add AMFI arg + # Before merging into mainline, this needs to be resolved + 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 + if self.constants.disable_amfi is True: + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " amfi=0x80" + 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) + if self.constants.secure_status is False: + print("- Disabling SecureBootModel") + self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled" + if self.constants.force_vmm is True: + print("- 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 diff --git a/resources/build/smbios.py b/resources/build/smbios.py index fa136def2..8588d7b76 100644 --- a/resources/build/smbios.py +++ b/resources/build/smbios.py @@ -1,5 +1,6 @@ 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 @@ -12,6 +13,41 @@ class build_smbios: self.constants: constants.Constants = versions self.config = config + 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 + # print("- 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 + + print("- 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 + + # Patch HW_BID to OC_BID + # Set OC_BID to iMac18,1 Board ID (Mac-F60DEB81FF30ACF6) + # Goal is to only allow OS booting through OCLP, otherwise failing + print("- Enabling HW_BID reroute") + support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Reroute HW_BID to OC_BID")["Enabled"] = True + self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["OC_BID"] = "Mac-BE088AF8C5EB4FA2" + self.config["NVRAM"]["Delete"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"] += ["OC_BID"] + else: + print("- 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) + + + + if self.constants.serial_settings in ["Moderate", "Advanced"]: + print("- 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 + + if self.model == self.constants.override_smbios: + print("- Adding -no_compat_check") + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check" def set_smbios(self): spoofed_model = self.model From 7c43cf090163fe85c5547a31486deb9a50870691 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 12 Nov 2022 20:18:37 -0700 Subject: [PATCH 05/19] Remove unused imports --- resources/build/build.py | 4 ++-- resources/build/misc.py | 2 +- resources/build/security.py | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/resources/build/build.py b/resources/build/build.py index 6996a1c0b..0721b4834 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -1,12 +1,10 @@ # Commands for building the EFI and SMBIOS # Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk -import binascii import copy import pickle import plistlib import shutil -import subprocess import zipfile from pathlib import Path from datetime import date @@ -73,9 +71,11 @@ class build_opencore: self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model + # 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) 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() diff --git a/resources/build/misc.py b/resources/build/misc.py index 140170ec4..eda6189da 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -1,5 +1,5 @@ -from resources import constants, device_probe, utilities, generate_smbios +from resources import constants, device_probe, generate_smbios from resources.build import support from data import model_array, smbios_data, cpu_data diff --git a/resources/build/security.py b/resources/build/security.py index 9aaafa584..665129a2a 100644 --- a/resources/build/security.py +++ b/resources/build/security.py @@ -1,7 +1,6 @@ -from resources import constants, device_probe, utilities +from resources import constants, utilities from resources.build import support -from data import model_array, smbios_data, cpu_data class build_security: From 2e5a61b7fd002657e35ca1f402984675dbebf677 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 09:45:36 -0700 Subject: [PATCH 06/19] Adjust function levels --- resources/build/graphics_audio.py | 226 +++++++++++++++--------------- resources/build/misc.py | 17 ++- resources/build/security.py | 2 + 3 files changed, 129 insertions(+), 116 deletions(-) diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index cb4f17f95..7ec88a7a0 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -26,117 +26,14 @@ class build_graphics_audio: if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None": support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) - - def backlight_path_detection(self): - if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: - self.gfx0_path = self.computer.dgpu.pci_path - print(f"- Found GFX0 Device Path: {self.gfx0_path}") - else: - if not self.constants.custom_model: - print("- Failed to find GFX0 Device path, falling back on known logic") - if self.model in ["iMac11,1", "iMac11,3"]: - self.gfx0_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)" - elif self.model == "iMac10,1": - self.gfx0_path = "PciRoot(0x0)/Pci(0xc,0x0)/Pci(0x0,0x0)" - else: - self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" - - def nvidia_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: - # 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_version, self.constants.whatevergreen_path) - if self.model in ["iMac11,1", "iMac11,2", "iMac11,3", "iMac10,1"]: - print("- Adding Nvidia Brightness Control and DRM patches") - self.config["DeviceProperties"]["Add"][backlight_path] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - if self.constants.custom_model and self.model == "iMac11,2": - # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) - # Set both properties when we cannot run hardware detection - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - elif self.model in ["iMac12,1", "iMac12,2"]: - print("- Adding Nvidia Brightness Control and DRM patches") - self.config["DeviceProperties"]["Add"][backlight_path] = { - "applbkl": binascii.unhexlify("01000000"), - "@0,backlight-control": binascii.unhexlify("01000000"), - "@0,built-in": binascii.unhexlify("01000000"), - "shikigva": 256, - "agdpmod": "vit9696", - } - print("- Disabling unsupported iGPU") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "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 - self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - - def amd_patch(self, backlight_path): - print("- 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: - # 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_version, self.constants.whatevergreen_path) - self.config["DeviceProperties"]["Add"][backlight_path] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} - if self.constants.custom_model and self.model == "iMac11,2": - # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) - # Set both properties when we cannot run hardware detection - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} - if self.model in ["iMac12,1", "iMac12,2"]: - print("- Disabling unsupported iGPU") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "class-code": binascii.unhexlify("FFFFFFFF"), - } - elif self.model == "iMac10,1": - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AAAMouSSE.kext")["Enabled"] is False: - support.build_support(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: - print("- Adding Legacy GCN Power Gate Patches") - self.config["DeviceProperties"]["Add"][backlight_path].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - if self.constants.imac_model == "Legacy GCN": - print("- Adding Legacy GCN Power Gate Patches") - self.config["DeviceProperties"]["Add"][backlight_path].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - if self.model == "iMac11,2": - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"].update({ - "CAIL,CAIL_DisableDrmdmaPowerGating": 1, - "CAIL,CAIL_DisableGfxCGPowerGating": 1, - "CAIL,CAIL_DisableUVDPowerGating": 1, - "CAIL,CAIL_DisableVCEPowerGating": 1, - }) - # Check GPU Vendor if self.constants.metal_build is True: - backlight_path_detection(self) + self.backlight_path_detection(self) print("- Adding Metal GPU patches on request") if self.constants.imac_vendor == "AMD": - amd_patch(self, self.gfx0_path) + self.amd_patch(self, self.gfx0_path) elif self.constants.imac_vendor == "Nvidia": - nvidia_patch(self, self.gfx0_path) + self.nvidia_patch(self, self.gfx0_path) else: print("- Failed to find vendor") elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: @@ -149,11 +46,11 @@ class build_graphics_audio: device_probe.AMD.Archs.Vega, device_probe.AMD.Archs.Navi, ]: - backlight_path_detection(self) - amd_patch(self, self.gfx0_path) + self.backlight_path_detection(self) + self.amd_patch(self, self.gfx0_path) elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: - backlight_path_detection(self) - nvidia_patch(self, self.gfx0_path) + self.backlight_path_detection(self) + self.nvidia_patch(self, self.gfx0_path) if self.model in model_array.MacPro: if not self.constants.custom_model: for i, device in enumerate(self.computer.gpus): @@ -278,6 +175,108 @@ class build_graphics_audio: # Ensure that agdpmod is applied to iMac14,x with iGPU only self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"} + def backlight_path_detection(self): + if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: + self.gfx0_path = self.computer.dgpu.pci_path + print(f"- Found GFX0 Device Path: {self.gfx0_path}") + else: + if not self.constants.custom_model: + print("- Failed to find GFX0 Device path, falling back on known logic") + if self.model in ["iMac11,1", "iMac11,3"]: + self.gfx0_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)" + elif self.model == "iMac10,1": + self.gfx0_path = "PciRoot(0x0)/Pci(0xc,0x0)/Pci(0x0,0x0)" + else: + self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" + + def nvidia_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: + # 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_version, self.constants.whatevergreen_path) + if self.model in ["iMac11,1", "iMac11,2", "iMac11,3", "iMac10,1"]: + print("- Adding Nvidia Brightness Control and DRM patches") + self.config["DeviceProperties"]["Add"][backlight_path] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + if self.constants.custom_model and self.model == "iMac11,2": + # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) + # Set both properties when we cannot run hardware detection + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + elif self.model in ["iMac12,1", "iMac12,2"]: + print("- Adding Nvidia Brightness Control and DRM patches") + self.config["DeviceProperties"]["Add"][backlight_path] = { + "applbkl": binascii.unhexlify("01000000"), + "@0,backlight-control": binascii.unhexlify("01000000"), + "@0,built-in": binascii.unhexlify("01000000"), + "shikigva": 256, + "agdpmod": "vit9696", + } + print("- Disabling unsupported iGPU") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "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 + self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True + + def amd_patch(self, backlight_path): + print("- 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: + # 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_version, self.constants.whatevergreen_path) + self.config["DeviceProperties"]["Add"][backlight_path] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} + if self.constants.custom_model and self.model == "iMac11,2": + # iMac11,2 can have either PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0) or PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0) + # Set both properties when we cannot run hardware detection + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"] = {"shikigva": 128, "unfairgva": 1, "agdpmod": "pikera", "rebuild-device-tree": 1, "enable-gva-support": 1} + if self.model in ["iMac12,1", "iMac12,2"]: + print("- Disabling unsupported iGPU") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "class-code": binascii.unhexlify("FFFFFFFF"), + } + elif self.model == "iMac10,1": + if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AAAMouSSE.kext")["Enabled"] is False: + support.build_support(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: + print("- Adding Legacy GCN Power Gate Patches") + self.config["DeviceProperties"]["Add"][backlight_path].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + if self.constants.imac_model == "Legacy GCN": + print("- Adding Legacy GCN Power Gate Patches") + self.config["DeviceProperties"]["Add"][backlight_path].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + if self.model == "iMac11,2": + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"].update({ + "CAIL,CAIL_DisableDrmdmaPowerGating": 1, + "CAIL,CAIL_DisableGfxCGPowerGating": 1, + "CAIL,CAIL_DisableUVDPowerGating": 1, + "CAIL,CAIL_DisableVCEPowerGating": 1, + }) + def audio_handling(self): if (self.model in model_array.LegacyAudio or self.model in model_array.MacPro) and self.constants.set_alc_usage is True: @@ -331,7 +330,12 @@ class build_graphics_audio: shutil.copy(self.constants.demux_ssdt_path, self.constants.acpi_path) # Disable dGPU # IOACPIPlane:/_SB/PCI0@0/P0P2@10000/GFX0@0 - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"class-code": binascii.unhexlify("FFFFFFFF"), "device-id": binascii.unhexlify("FFFF0000"), "IOName": "Dortania Disabled Card", "name": "Dortania Disabled Card"} + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = { + "class-code": binascii.unhexlify("FFFFFFFF"), + "device-id": binascii.unhexlify("FFFF0000"), + "IOName": "Dortania Disabled Card", + "name": "Dortania Disabled Card" + } 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) diff --git a/resources/build/misc.py b/resources/build/misc.py index eda6189da..76c1253a1 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -40,6 +40,9 @@ class build_misc: 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 block_args = "" if self.model in ["MacBookPro6,1", "MacBookPro6,2", "MacBookPro9,1", "MacBookPro10,1"]: block_args += "gmux," @@ -105,8 +108,7 @@ class build_misc: 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) - # CPUFriend - if self.model not in ["iMac7,1", "Xserve2,1", "Dortania1,1"] and self.constants.serial_settings != "None": + # CPUFriendDataProvider handling pp_map_path = Path(self.constants.platform_plugin_plist_path) / Path(f"{self.model}/Info.plist") if not pp_map_path.exists(): raise Exception(f"{pp_map_path} does not exist!!! Please file an issue stating file is missing for {self.model}.") @@ -179,10 +181,12 @@ class build_misc: def debug_handling(self): - # DEBUG Settings + # DEBUG Settings (OpenCorePkg and Kernel Space) + if self.constants.verbose_debug is True: print("- Enabling Verbose boot") self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -v" + if self.constants.kext_debug is True: print("- Enabling DEBUG Kexts") self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -liludbgall liludump=90" @@ -190,13 +194,16 @@ class build_misc: # 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) + if self.constants.opencore_debug is True: print("- Enabling DEBUG OpenCore") self.config["Misc"]["Debug"]["Target"] = 0x43 self.config["Misc"]["Debug"]["DisplayLevel"] = 0x80000042 def general_oc_handling(self): - # Add OpenCanopy + # OpenCorePkg Settings + + # OpenCanopy Settings (GUI) print("- Adding OpenCanopy GUI") shutil.rmtree(self.constants.resources_path, onerror=self.rmtree_handler) shutil.copy(self.constants.gui_path, self.constants.oc_folder) @@ -205,13 +212,13 @@ class build_misc: 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 - if self.constants.showpicker is True: print("- Enabling ShowPicker") self.config["Misc"]["Boot"]["ShowPicker"] = True else: print("- Hiding OpenCore picker") self.config["Misc"]["Boot"]["ShowPicker"] = False + if self.constants.oc_timeout != 5: print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout \ No newline at end of file diff --git a/resources/build/security.py b/resources/build/security.py index 665129a2a..0c6a1994d 100644 --- a/resources/build/security.py +++ b/resources/build/security.py @@ -2,6 +2,8 @@ from resources import constants, utilities from resources.build import support +import binascii + class build_security: From 50d730b45a9a94d2e433fc70cde9e5090df2dc86 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 15:25:56 -0700 Subject: [PATCH 07/19] build: fix invocation --- resources/build/graphics_audio.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index 7ec88a7a0..5d09af9d0 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -28,12 +28,12 @@ class build_graphics_audio: # Check GPU Vendor if self.constants.metal_build is True: - self.backlight_path_detection(self) + self.backlight_path_detection() print("- Adding Metal GPU patches on request") if self.constants.imac_vendor == "AMD": - self.amd_patch(self, self.gfx0_path) + self.amd_patch(self.gfx0_path) elif self.constants.imac_vendor == "Nvidia": - self.nvidia_patch(self, self.gfx0_path) + self.nvidia_patch(self.gfx0_path) else: print("- Failed to find vendor") elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: @@ -46,11 +46,11 @@ class build_graphics_audio: device_probe.AMD.Archs.Vega, device_probe.AMD.Archs.Navi, ]: - self.backlight_path_detection(self) - self.amd_patch(self, self.gfx0_path) + self.backlight_path_detection() + self.amd_patch(self.gfx0_path) elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: - self.backlight_path_detection(self) - self.nvidia_patch(self, self.gfx0_path) + self.backlight_path_detection() + self.nvidia_patch(self.gfx0_path) if self.model in model_array.MacPro: if not self.constants.custom_model: for i, device in enumerate(self.computer.gpus): From 235a9985f45d2bf0b0f338f5bc009cea70d061f3 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 15:59:23 -0700 Subject: [PATCH 08/19] wired.py: Refactor --- resources/build/networking/wired.py | 78 +++++++++++++++++------------ 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/resources/build/networking/wired.py b/resources/build/networking/wired.py index 489ad282a..8dbf1a7f7 100644 --- a/resources/build/networking/wired.py +++ b/resources/build/networking/wired.py @@ -11,44 +11,56 @@ class build_wired: self.computer = self.constants.computer def build(self): + # 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: - for controller in self.constants.computer.ethernet: - if isinstance(controller, device_probe.BroadcomEthernet) and controller.chipset == device_probe.BroadcomEthernet.Chipsets.AppleBCM5701Ethernet: - 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 - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("CatalinaBCM5701Ethernet.kext")["Enabled"] is False: - support.build_support(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 smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value: - # Apple's IOSkywalkFamily in DriverKit requires VT-D support - # Applicable for pre-Ivy Bridge models - if controller.chipset == device_probe.IntelEthernet.Chipsets.AppleIntelI210Ethernet: - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("CatalinaIntelI210Ethernet.kext")["Enabled"] is False: - support.build_support(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: - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleIntel8254XEthernet.kext")["Enabled"] is False: - support.build_support(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: - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Intel82574L.kext")["Enabled"] is False: - support.build_support(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): - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("nForceEthernet.kext")["Enabled"] is False: - support.build_support(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): - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("MarvelYukonEthernet.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("MarvelYukonEthernet.kext", self.constants.marvel_version, self.constants.marvel_path) + self.on_model() else: - if smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Broadcom": + self.prebuilt_assumption() + + def on_model(self): + # On-model hardware detection + 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: + continue 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) - elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Nvidia": + elif isinstance(controller, device_probe.IntelEthernet): + if not self.model in smbios_data.smbios_dictionary: + continue + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.ivy_bridge.value: + # 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) + 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) + 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) + 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) - elif smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Marvell": + 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) - 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) - 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) + + def prebuilt_assumption(self): + # Stock hardware assumptions + if not self.model in smbios_data.smbios_dictionary: + return + if not "Ethernet Chipset" in smbios_data.smbios_dictionary[self.model]: + return + + if smbios_data.smbios_dictionary[self.model]["Ethernet Chipset"] == "Broadcom": + 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) + 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) + 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) + 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) + 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) \ No newline at end of file From b448a4b6ddda7d339e795750fd19f2c450c7cac5 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 16:21:46 -0700 Subject: [PATCH 09/19] wireless.py: Refactor --- resources/build/networking/wired.py | 3 + resources/build/networking/wireless.py | 146 ++++++++++++++----------- 2 files changed, 85 insertions(+), 64 deletions(-) diff --git a/resources/build/networking/wired.py b/resources/build/networking/wired.py index 8dbf1a7f7..f9aabe1ec 100644 --- a/resources/build/networking/wired.py +++ b/resources/build/networking/wired.py @@ -10,6 +10,7 @@ class build_wired: self.config = config self.computer = self.constants.computer + def build(self): # 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: @@ -17,6 +18,7 @@ class build_wired: else: self.prebuilt_assumption() + def on_model(self): # On-model hardware detection for controller in self.constants.computer.ethernet: @@ -44,6 +46,7 @@ class build_wired: 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) + def prebuilt_assumption(self): # Stock hardware assumptions if not self.model in smbios_data.smbios_dictionary: diff --git a/resources/build/networking/wireless.py b/resources/build/networking/wireless.py index 88b335a23..32a9b0d91 100644 --- a/resources/build/networking/wireless.py +++ b/resources/build/networking/wireless.py @@ -12,82 +12,103 @@ class build_wireless: def build(self): - # WiFi patches - if not self.constants.custom_model: - if self.computer.wifi: - print(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 not self.constants.custom_model and self.constants.computer.wifi: + self.on_model() else: - print("- Unable to run Wireless hardware detection") + self.prebuilt_assumption() + self.wowl_handling() - if not self.constants.custom_model: - if self.computer.wifi: - 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) - print(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 - print(f"- Found ARPT device at {arpt_path}") - self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} - else: - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" brcmfx-country={self.computer.wifi.country_code}" - if self.constants.enable_wake_on_wlan is True: - print("- 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() - 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 - 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 - 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 - else: - if smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4360: - print("- Enabling BCM943224 and BCM94331 Networking Support") - self.wifi_fake_id() - elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4331: - print("- 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 - elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm43224: - print("- 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 - elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Atheros.Chipsets.AirPortAtheros40: - print("- 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 - elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirportBrcmNIC: + + def on_model(self): + print(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) + print(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 + print(f"- Found ARPT device at {arpt_path}") + self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} + else: + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" brcmfx-country={self.computer.wifi.country_code}" if self.constants.enable_wake_on_wlan is True: print("- 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() + 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 + 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 + 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 + + + def prebuilt_assumption(self): + 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: + print("- Enabling BCM943224 and BCM94331 Networking Support") + self.wifi_fake_id() + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm4331: + print("- 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 + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Broadcom.Chipsets.AirPortBrcm43224: + print("- 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 + elif smbios_data.smbios_dictionary[self.model]["Wireless Model"] == device_probe.Atheros.Chipsets.AirPortAtheros40: + print("- 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 + 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) + + + 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. + 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: + return + + print("- 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 if not self.constants.custom_model and self.computer.wifi and self.computer.wifi.pci_path: arpt_path = self.computer.wifi.pci_path print(f"- Found ARPT device at {arpt_path}") else: - try: - smbios_data.smbios_dictionary[self.model]["nForce Chipset"] + if not self.model in smbios_data.smbios_dictionary: + print("No known PCI pathing for this model") + return + if "nForce Chipset" in smbios_data.smbios_dictionary[self.model]: # Nvidia chipsets all have the same path to ARPT arpt_path = "PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)" - except KeyError: + else: if self.model in ("iMac7,1", "iMac8,1", "MacPro3,1", "MacBookPro4,1"): arpt_path = "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)" elif self.model in ("iMac13,1", "iMac13,2"): @@ -98,11 +119,8 @@ class build_wireless: # Assumes we have a laptop with Intel chipset # iMac11,x-12,x also apply arpt_path = "PciRoot(0x0)/Pci(0x1C,0x1)/Pci(0x0,0x0)" - print(f"- Using known DevicePath {arpt_path}") + print(f"- Using known ARPT Path: {arpt_path}") if not self.constants.custom_model and self.computer.wifi and self.constants.validate is False and self.computer.wifi.country_code: print(f"- Applying fake ID for WiFi, setting Country Code: {self.computer.wifi.country_code}") - self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} - if self.constants.enable_wake_on_wlan is True: - print("- Enabling Wake on WLAN support") - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += f" -brcmfxwowl" \ No newline at end of file + self.config["DeviceProperties"]["Add"][arpt_path] = {"brcmfx-country": self.computer.wifi.country_code} \ No newline at end of file From 1d2a7e080b32dbbe9ed21553f14af90282f1c8ce Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 16:31:08 -0700 Subject: [PATCH 10/19] bluetooth.py: Refactor --- resources/build/bluetooth.py | 54 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/resources/build/bluetooth.py b/resources/build/bluetooth.py index 377193186..744ffe4b5 100644 --- a/resources/build/bluetooth.py +++ b/resources/build/bluetooth.py @@ -11,27 +11,41 @@ class build_bluetooth: self.computer = self.constants.computer def build(self): - # Bluetooth Detection + # Bluetooth patches if not self.constants.custom_model and self.computer.bluetooth_chipset: - if self.computer.bluetooth_chipset in ["BRCM2070 Hub", "BRCM2046 Hub"]: - print("- 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) - 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 - # Note Monterey only natively supports BRCM20702 v2 (found with BCM94360) - # Due to this, BlueToolFixup is required to resolve Firmware Uploading on legacy chipsets - if self.computer.wifi: - if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360: - print("- 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) - elif self.computer.bluetooth_chipset == "3rd Party Bluetooth 4.0 Hub": - print("- Detected 3rd Party Chipset") - support.build_support(self.model, self.constants, self.config).enable_kext("BlueToolFixup.kext", self.constants.bluetool_version, self.constants.bluetool_path) - print("- Enabling Bluetooth FeatureFlags") - self.config["Kernel"]["Quirks"]["ExtendBTFeatureFlags"] = True - elif smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM20702_v1.value: + self.on_model() + else: + self.prebuilt_assumption() + + + def on_model(self): + if self.computer.bluetooth_chipset in ["BRCM2070 Hub", "BRCM2046 Hub"]: + print("- 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) + 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 + # Note Monterey only natively supports BRCM20702 v2 (found with BCM94360) + # Due to this, BlueToolFixup is required to resolve Firmware Uploading on legacy chipsets + if self.computer.wifi: + if self.computer.wifi.chipset == device_probe.Broadcom.Chipsets.AirPortBrcm4360: + print("- 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) + elif self.computer.bluetooth_chipset == "3rd Party Bluetooth 4.0 Hub": + print("- 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) + print("- Enabling Bluetooth FeatureFlags") + self.config["Kernel"]["Quirks"]["ExtendBTFeatureFlags"] = True + + + def prebuilt_assumption(self): + if not self.model in smbios_data.smbios_dictionary: + return + if not "Bluetooth Model" in smbios_data.smbios_dictionary[self.model]: + return + + if smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM20702_v1.value: print("- 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) if smbios_data.smbios_dictionary[self.model]["Bluetooth Model"] <= bluetooth_data.bluetooth_data.BRCM2070.value: From 94b33f60292fac5f205e57b6c0491d9c6f64b00e Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 16:56:56 -0700 Subject: [PATCH 11/19] firmware.py: Refactor --- resources/build/bluetooth.py | 1 + resources/build/build.py | 8 +------ resources/build/firmware.py | 43 +++++++++++++++++++++++++++++++----- resources/build/misc.py | 5 +++++ 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/resources/build/bluetooth.py b/resources/build/bluetooth.py index 744ffe4b5..537795b1d 100644 --- a/resources/build/bluetooth.py +++ b/resources/build/bluetooth.py @@ -10,6 +10,7 @@ class build_bluetooth: self.config = config self.computer = self.constants.computer + def build(self): # Bluetooth patches if not self.constants.custom_model and self.computer.bluetooth_chipset: diff --git a/resources/build/build.py b/resources/build/build.py index 0721b4834..297a8db7f 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -82,20 +82,14 @@ class build_opencore: 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() - misc.build_misc(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() if self.constants.validate is False: print("- Adding bootmgfw.efi BlessOverride") self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"] - if support.build_support(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) - - def build_opencore(self): 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 != ""): diff --git a/resources/build/firmware.py b/resources/build/firmware.py index 5e3ebe208..0931b2874 100644 --- a/resources/build/firmware.py +++ b/resources/build/firmware.py @@ -15,17 +15,24 @@ class build_firmware: def build(self): + self.cpu_compatibility_handling() self.power_management_handling() self.acpi_handling() self.firmware_driver_handling() self.firmware_compatibility_handling() - self.cpu_compatibility_handling() + def power_management_handling(self): + if not self.model in smbios_data.smbios_dictionary: + return + if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]: + return + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.ivy_bridge.value: # In macOS Ventura, Apple dropped AppleIntelCPUPowerManagement* kexts as they're unused on Haswell+ # However re-injecting the AICPUPM kexts is not enough, as Ventura changed how 'intel_cpupm_matching' is set: - # https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/osfmk/i386/pal_routines.h#L153-L163 + # macOS 12.5: https://github.com/apple-oss-distributions/xnu/blob/xnu-8020.140.41/osfmk/i386/pal_routines.h#L153-L163 + # macOS 13.0: https://github.com/apple-oss-distributions/xnu/blob/xnu-8792.41.9/osfmk/i386/pal_routines.h#L153-L164 # # Specifically Apple has this logic for power management: # - 0: Kext Based Power Management @@ -61,9 +68,17 @@ class build_firmware: # 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) + def acpi_handling(self): + if not self.model in smbios_data.smbios_dictionary: + return + if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]: + return + + # Resolves Big Sur support for consumer Nehalem + # CPBG device in ACPI is a Co-Processor Bridge Device, which is not actually physically present + # 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")): - # Applicable for consumer Nehalem print("- 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 shutil.copy(self.constants.pci_ssdt_path, self.constants.acpi_path) @@ -76,11 +91,21 @@ class build_firmware: support.build_support(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): + if not self.model in smbios_data.smbios_dictionary: + return + if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]: + return + + # 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) + # 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: print("- 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) @@ -113,15 +138,18 @@ class build_firmware: 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) - # HID patches + # HID patches if smbios_data.smbios_dictionary[self.model]["CPU Generation"] <= cpu_data.cpu_data.penryn.value: print("- 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 - def firmware_driver_handling(self): # Firmware Drivers (Drivers/*.efi) + if not self.model in smbios_data.smbios_dictionary: + return + if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]: + return # Exfat check if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.cpu_data.sandy_bridge.value: @@ -145,6 +173,7 @@ class build_firmware: 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 + def firmware_compatibility_handling(self): self.dual_dp_handling() @@ -172,10 +201,12 @@ class build_firmware: print("- Enabling VMX Bit for non-macOS OSes") self.config["UEFI"]["Quirks"]["EnableVmx"] = True - + # Works-around Hibernation bug where connecting all firmware drivers breaks the transition from S4 + # Mainly applicable for MacBookPro9,1 if self.constants.disable_connectdrivers is True: print("- Disabling ConnectDrivers") self.config["UEFI"]["ConnectDrivers"] = False + if self.constants.nvram_write is False: print("- Disabling Hardware NVRAM Write") self.config["NVRAM"]["WriteFlash"] = False diff --git a/resources/build/misc.py b/resources/build/misc.py index 76c1253a1..9e8bed412 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -103,6 +103,11 @@ class build_misc: if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: support.build_support(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: + # 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) + 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": From 93a1d0fb11c5953149693a21e6b741a38b29315c Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 17:08:22 -0700 Subject: [PATCH 12/19] smbios.py: Drop `HW_BID` rerouting --- CHANGELOG.md | 2 ++ resources/build/smbios.py | 15 +++------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3540ebd5..6d873c03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ - Ensure Model and Board ID are set correctly before Lilu loads - Publish Application Version in UI header - Allows for easier identification of version when reporting issues +- Drop usage of `HW_BID` rerouting in boot.efi + - Patch out PlatformSupport.plist instead, allows for less maintenance overall - Increment Binaries: - AirPortBrcmFixup 2.1.6 - release - AppleALC 1.7.6 - release diff --git a/resources/build/smbios.py b/resources/build/smbios.py index 8588d7b76..ac65df698 100644 --- a/resources/build/smbios.py +++ b/resources/build/smbios.py @@ -17,28 +17,18 @@ class build_smbios: 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 - # print("- 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 + print("- 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 print("- 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 - - # Patch HW_BID to OC_BID - # Set OC_BID to iMac18,1 Board ID (Mac-F60DEB81FF30ACF6) - # Goal is to only allow OS booting through OCLP, otherwise failing - print("- Enabling HW_BID reroute") - support.build_support(self.model, self.constants, self.config).get_item_by_kv(self.config["Booter"]["Patch"], "Comment", "Reroute HW_BID to OC_BID")["Enabled"] = True - self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["OC_BID"] = "Mac-BE088AF8C5EB4FA2" - self.config["NVRAM"]["Delete"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"] += ["OC_BID"] else: print("- 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) - - if self.constants.serial_settings in ["Moderate", "Advanced"]: print("- 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 @@ -49,6 +39,7 @@ class build_smbios: print("- Adding -no_compat_check") self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -no_compat_check" + def set_smbios(self): spoofed_model = self.model if self.constants.override_smbios == "Default": From 7fcef65837be9e27c3a6d3262c576618d0c63d89 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 17:15:11 -0700 Subject: [PATCH 13/19] storage.py: Refactor --- resources/build/storage.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/resources/build/storage.py b/resources/build/storage.py index 8b445f6d0..268acfa46 100644 --- a/resources/build/storage.py +++ b/resources/build/storage.py @@ -26,10 +26,13 @@ class build_storage: print("- 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) - # ThirdPartyDrives Check if self.constants.allow_3rd_party_drives is True: for drive in ["SATA 2.5", "SATA 3.5", "mSATA"]: + if not self.model in smbios_data.smbios_dictionary: + break + if not "Stock Storage" in smbios_data.smbios_dictionary[self.model]: + break if drive in smbios_data.smbios_dictionary[self.model]["Stock Storage"]: if not self.constants.custom_model: if self.computer.third_party_sata_ssd is True: @@ -41,9 +44,17 @@ class build_storage: self.config["Kernel"]["Quirks"]["ThirdPartyDrives"] = True break + def pata_handling(self): - if "PATA" in smbios_data.smbios_dictionary[self.model]["Stock Storage"]: - support.build_support(self.model, self.constants, self.config).enable_kext("AppleIntelPIIXATA.kext", self.constants.piixata_version, self.constants.piixata_path) + if not self.model in smbios_data.smbios_dictionary: + return + if not "Stock Storage" in smbios_data.smbios_dictionary[self.model]: + return + 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) + def pcie_handling(self): if not self.constants.custom_model and (self.constants.allow_oc_everywhere is True or self.model in model_array.MacPro): @@ -55,11 +66,7 @@ class build_storage: self.config["DeviceProperties"]["Add"][controller.pci_path] = {"built-in": 1} else: print(f"- Failed to find Device path for PCIe Storage Controller {i}, falling back to Innie") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("Innie.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("Innie.kext", self.constants.innie_version, self.constants.innie_path) - if not self.computer.storage: - print("- No PCIe Storage Controllers found to fix") - + support.build_support(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)] @@ -82,11 +89,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 - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("NVMeFix.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path) - - if not nvme_devices: - print("- No 3rd Party NVMe drives found") + support.build_support(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: @@ -103,6 +106,11 @@ class build_storage: def misc_handling(self): + if not self.model in smbios_data.smbios_dictionary: + return + if not "CPU Generation" in smbios_data.smbios_dictionary[self.model]: + return + # With macOS Monterey, Apple's SDXC driver requires the system to support VT-D # 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: From 93c1983a3fa4e48dd701ed36fbdeef25f966bb5f Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 17:25:57 -0700 Subject: [PATCH 14/19] support.py: Refactor --- resources/build/support.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/resources/build/support.py b/resources/build/support.py index e5432861f..5d5c059b6 100644 --- a/resources/build/support.py +++ b/resources/build/support.py @@ -22,6 +22,7 @@ class build_support: break return item + def get_kext_by_bundle_path(self, bundle_path): kext = self.get_item_by_kv(self.config["Kernel"]["Add"], "BundlePath", bundle_path) if not kext: @@ -29,6 +30,7 @@ class build_support: 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) if not efi_binary: @@ -36,6 +38,7 @@ class build_support: 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) @@ -51,20 +54,26 @@ class build_support: shutil.copy(kext_path, self.constants.kexts_path) kext["Enabled"] = True + def sign_files(self): - if self.constants.vault is True: - if utilities.check_command_line_tools() is True: - # sign.command checks for the existence of '/usr/bin/strings' however does not verify whether it's executable - # sign.command will continue to run and create an unbootable OpenCore.efi due to the missing strings binary - # macOS has dummy binaries that just reroute to the actual binaries after you install Xcode's Command Line Tools - print("- Vaulting EFI") - subprocess.run([str(self.constants.vault_path), f"{self.constants.oc_folder}/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - else: - print("- Missing Command Line tools, skipping Vault for saftey reasons") - print("- Install via 'xcode-select --install' and rerun OCLP if you wish to vault this config") + if self.constants.vault is False: + return + + if utilities.check_command_line_tools() is False: + # sign.command checks for the existence of '/usr/bin/strings' however does not verify whether it's executable + # sign.command will continue to run and create an unbootable OpenCore.efi due to the missing strings binary + # macOS has dummy binaries that just reroute to the actual binaries after you install Xcode's Command Line Tools + print("- Missing Command Line tools, skipping Vault for saftey reasons") + print("- Install via 'xcode-select --install' and rerun OCLP if you wish to vault this config") + return + + print("- Vaulting EFI") + 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 print("- Validating generated config") if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")): print("- OpenCore config file missing!!!") @@ -73,13 +82,11 @@ class build_support: config_plist = plistlib.load(Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")).open("rb")) for acpi in config_plist["ACPI"]["Add"]: - # print(f" - Validating {acpi['Path']}") if not Path(self.constants.opencore_release_folder / Path("EFI/OC/ACPI") / Path(acpi["Path"])).exists(): print(f" - Missing ACPI Table: {acpi['Path']}") raise Exception(f"Missing ACPI Table: {acpi['Path']}") for kext in config_plist["Kernel"]["Add"]: - # print(f" - Validating {kext['BundlePath']}") kext_path = Path(self.constants.opencore_release_folder / Path("EFI/OC/Kexts") / Path(kext["BundlePath"])) kext_binary_path = Path(kext_path / Path(kext["ExecutablePath"])) kext_plist_path = Path(kext_path / Path(kext["PlistPath"])) @@ -94,19 +101,17 @@ class build_support: raise Exception(f"Missing {kext_plist_path}") for tool in config_plist["Misc"]["Tools"]: - # print(f" - Validating {tool['Path']}") if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools") / Path(tool["Path"])).exists(): print(f" - Missing tool: {tool['Path']}") raise Exception(f"Missing tool: {tool['Path']}") for driver in config_plist["UEFI"]["Drivers"]: - # print(f" - Validating {driver['Path']}") if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Drivers") / Path(driver["Path"])).exists(): print(f" - Missing driver: {driver['Path']}") raise Exception(f"Missing driver: {driver['Path']}") # Validating local files - # Validate Tools + # Report if they have no associated config.plist entry (i.e. they're not being used) for tool_files in Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools")).glob("*"): if tool_files.name not in [x["Path"] for x in config_plist["Misc"]["Tools"]]: print(f" - Missing tool from config: {tool_files.name}") @@ -117,6 +122,7 @@ class build_support: print(f"- Found extra driver: {driver_file.name}") raise Exception(f"Found extra driver: {driver_file.name}") + def cleanup(self): print("- Cleaning up files") # Remove unused entries From 9c28d778264a064ebaec06c1753a42baec7d5a8c Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 17:38:39 -0700 Subject: [PATCH 15/19] build: Adjust save handling --- resources/build/build.py | 90 +++++++++------- resources/build/misc.py | 9 +- resources/build/security.py | 2 + resources/build/smbios.py | 207 ++++++++++++++++++------------------ resources/build/support.py | 1 - 5 files changed, 162 insertions(+), 147 deletions(-) diff --git a/resources/build/build.py b/resources/build/build.py index 297a8db7f..0289de91c 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -25,8 +25,6 @@ class build_opencore: self.model = model self.config = None self.constants: constants.Constants = versions - self.computer = self.constants.computer - self.gfx0_path = None def build_efi(self): @@ -35,41 +33,9 @@ class build_opencore: print(f"Building Configuration on model: {self.model}") else: print(f"Building Configuration for external model: {self.model}") - if not Path(self.constants.build_path).exists(): - Path(self.constants.build_path).mkdir() - print("Created build folder") - else: - print("Build folder already present, skipping") - if Path(self.constants.opencore_zip_copied).exists(): - print("Deleting old copy of OpenCore zip") - Path(self.constants.opencore_zip_copied).unlink() - if Path(self.constants.opencore_release_folder).exists(): - print("Deleting old copy of OpenCore folder") - shutil.rmtree(self.constants.opencore_release_folder, onerror=rmtree_handler, ignore_errors=True) - - print(f"\n- Adding OpenCore v{self.constants.opencore_version} {self.constants.opencore_build}") - shutil.copy(self.constants.opencore_zip_source, self.constants.build_path) - zipfile.ZipFile(self.constants.opencore_zip_copied).extractall(self.constants.build_path) - - print("- Adding config.plist for OpenCore") - # Setup config.plist for editing - shutil.copy(self.constants.plist_template, self.constants.oc_folder) - self.config = plistlib.load(Path(self.constants.plist_path).open("rb")) - - # Set revision in config - 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" - computer_copy = copy.copy(self.computer) - computer_copy.ioregistry = None - self.config["#Revision"]["Hardware-Probe"] = pickle.dumps(computer_copy) - else: - self.config["#Revision"]["Build-Type"] = "OpenCore Built for External Machine" - self.config["#Revision"]["OpenCore-Version"] = f"{self.constants.opencore_version} - {self.constants.opencore_build} - {self.constants.opencore_commit}" - self.config["#Revision"]["Original-Model"] = self.model - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model + 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) @@ -86,17 +52,69 @@ class build_opencore: security.build_security(self.model, self.constants, self.config).build() misc.build_misc(self.model, self.constants, self.config).build() + # Work-around ocvalidate if self.constants.validate is False: print("- Adding bootmgfw.efi BlessOverride") self.config["Misc"]["BlessOverride"] += ["\\EFI\\Microsoft\\Boot\\bootmgfw.efi"] + + def generate_base(self): + # Generate OpenCore base folder and config + if not Path(self.constants.build_path).exists(): + print("Creating build folder") + Path(self.constants.build_path).mkdir() + else: + print("Build folder already present, skipping") + + if Path(self.constants.opencore_zip_copied).exists(): + print("Deleting old copy of OpenCore zip") + Path(self.constants.opencore_zip_copied).unlink() + if Path(self.constants.opencore_release_folder).exists(): + print("Deleting old copy of OpenCore folder") + shutil.rmtree(self.constants.opencore_release_folder, onerror=rmtree_handler, ignore_errors=True) + + print(f"\n- Adding OpenCore v{self.constants.opencore_version} {self.constants.opencore_build}") + shutil.copy(self.constants.opencore_zip_source, self.constants.build_path) + zipfile.ZipFile(self.constants.opencore_zip_copied).extractall(self.constants.build_path) + + # Setup config.plist for editing + print("- Adding config.plist for OpenCore") + shutil.copy(self.constants.plist_template, self.constants.oc_folder) + self.config = plistlib.load(Path(self.constants.plist_path).open("rb")) + + + def set_revision(self): + # Set revision in config + 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" + computer_copy = copy.copy(self.constants.computer) + computer_copy.ioregistry = None + self.config["#Revision"]["Hardware-Probe"] = pickle.dumps(computer_copy) + else: + self.config["#Revision"]["Build-Type"] = "OpenCore Built for External Machine" + self.config["#Revision"]["OpenCore-Version"] = f"{self.constants.opencore_version} - {self.constants.opencore_build} - {self.constants.opencore_commit}" + self.config["#Revision"]["Original-Model"] = self.model + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Version"] = f"{self.constants.patcher_version}" + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Model"] = self.model + + + def save_config(self): + plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True) + + def build_opencore(self): + # Generate OpenCore Configuration 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() + + # 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() + print("") print(f"Your OpenCore EFI for {self.model} has been built at:") print(f" {self.constants.opencore_release_folder}") diff --git a/resources/build/misc.py b/resources/build/misc.py index 9e8bed412..ecad6eb20 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -71,8 +71,7 @@ class build_misc: if block_args != "": print(f"- Setting RestrictEvents block arguments: {block_args}") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) + support.build_support(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 = "" @@ -89,8 +88,7 @@ class build_misc: if patch_args != "": print(f"- Setting RestrictEvents patch arguments: {patch_args}") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) + support.build_support(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,8 +98,7 @@ class build_misc: self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = self.constants.custom_cpu_model_value else: print("- Adding CPU Name Patch") - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("RestrictEvents.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("RestrictEvents.kext", self.constants.restrictevents_version, self.constants.restrictevents_path) + support.build_support(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: # Ensure this is done at the end so all previous RestrictEvents patches are applied diff --git a/resources/build/security.py b/resources/build/security.py index 0c6a1994d..628595152 100644 --- a/resources/build/security.py +++ b/resources/build/security.py @@ -19,6 +19,7 @@ class build_security: print("- 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 + 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 @@ -55,6 +56,7 @@ class build_security: # 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) + if self.constants.secure_status is False: print("- Disabling SecureBootModel") self.config["Misc"]["Security"]["SecureBootModel"] = "Disabled" diff --git a/resources/build/smbios.py b/resources/build/smbios.py index ac65df698..2250f9f61 100644 --- a/resources/build/smbios.py +++ b/resources/build/smbios.py @@ -62,116 +62,16 @@ class build_smbios: if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True: self.config["#Revision"]["Spoofed-Model"] = f"{self.spoofed_model} - {self.constants.serial_settings}" - # Setup menu - def minimal_serial_patch(self): - # Generate Firmware Features - fw_feature = generate_smbios.generate_fw_features(self.model, self.constants.custom_model) - # fw_feature = self.patch_firmware_feature() - fw_feature = hex(fw_feature).lstrip("0x").rstrip("L").strip() - print(f"- Setting Firmware Feature: {fw_feature}") - fw_feature = utilities.string_to_hex(fw_feature) - - # FirmwareFeatures - self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeatures"] = fw_feature - self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeaturesMask"] = fw_feature - self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeatures"] = fw_feature - self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeaturesMask"] = fw_feature - - # Board ID - self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board - self.config["PlatformInfo"]["PlatformNVRAM"]["BID"] = self.spoofed_board - self.config["PlatformInfo"]["SMBIOS"]["BoardProduct"] = self.spoofed_board - - # Model (ensures tables are not mismatched, even if we're not spoofing) - self.config["PlatformInfo"]["DataHub"]["SystemProductName"] = self.model - self.config["PlatformInfo"]["SMBIOS"]["SystemProductName"] = self.model - self.config["PlatformInfo"]["SMBIOS"]["BoardVersion"] = self.model - - # ProcessorType (when RestrictEvent's CPU naming is used) - if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: - self.config["PlatformInfo"]["SMBIOS"]["ProcessorType"] = 1537 - - # Avoid incorrect Firmware Updates - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["SMBIOS"]["BIOSVersion"] = "9999.999.999.999.999" - - # Update tables - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - - if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": - print("- Adding custom serial numbers") - sn = self.constants.custom_serial_number - mlb = self.constants.custom_board_serial_number - - # Serial Number - self.config["PlatformInfo"]["SMBIOS"]["ChassisSerialNumber"] = sn - self.config["PlatformInfo"]["SMBIOS"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["DataHub"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["PlatformNVRAM"]["SystemSerialNumber"] = sn - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn - - # Board Serial Number - self.config["PlatformInfo"]["SMBIOS"]["BoardSerialNumber"] = mlb - self.config["PlatformInfo"]["PlatformNVRAM"]["BoardSerialNumber"] = mlb - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb - - - - def moderate_serial_patch(self): - 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 != "": - print("- Adding custom serial numbers") - self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number - self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["Automatic"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True - self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model - - def advanced_serial_patch(self): - 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 == "": - macserial_output = subprocess.run([self.constants.macserial_path] + f"-g -m {self.spoofed_model} -n 1".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - macserial_output = macserial_output.stdout.decode().strip().split(" | ") - sn = macserial_output[0] - mlb = macserial_output[1] - else: - sn = self.constants.custom_serial_number - mlb = self.constants.custom_board_serial_number - self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" - self.config["PlatformInfo"]["Automatic"] = True - self.config["PlatformInfo"]["UpdateDataHub"] = True - self.config["PlatformInfo"]["UpdateNVRAM"] = True - self.config["PlatformInfo"]["UpdateSMBIOS"] = True - self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True - self.config["PlatformInfo"]["Generic"]["ROM"] = binascii.unhexlify("0016CB445566") - self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model - self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = sn - self.config["PlatformInfo"]["Generic"]["MLB"] = mlb - self.config["PlatformInfo"]["Generic"]["SystemUUID"] = str(uuid.uuid4()).upper() - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn - self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb - - if self.constants.serial_settings == "Moderate": print("- Using Moderate SMBIOS patching") - moderate_serial_patch(self) + self.moderate_serial_patch() elif self.constants.serial_settings == "Advanced": print("- Using Advanced SMBIOS patching") - advanced_serial_patch(self) + self.advanced_serial_patch() elif self.constants.serial_settings == "Minimal": print("- Using Minimal SMBIOS patching") self.spoofed_model = self.model - minimal_serial_patch(self) + 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, @@ -269,4 +169,103 @@ class build_smbios: for entry in list(agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"]): if not entry.startswith(self.spoofed_board): agdp_config["IOKitPersonalities"]["AppleGraphicsDevicePolicy"]["ConfigMap"].pop(entry) - plistlib.dump(agdp_config, Path(new_agdp_ls).open("wb"), sort_keys=True) \ No newline at end of file + plistlib.dump(agdp_config, Path(new_agdp_ls).open("wb"), sort_keys=True) + + + def minimal_serial_patch(self): + # Generate Firmware Features + fw_feature = generate_smbios.generate_fw_features(self.model, self.constants.custom_model) + # fw_feature = self.patch_firmware_feature() + fw_feature = hex(fw_feature).lstrip("0x").rstrip("L").strip() + print(f"- Setting Firmware Feature: {fw_feature}") + fw_feature = utilities.string_to_hex(fw_feature) + + # FirmwareFeatures + self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeatures"] = fw_feature + self.config["PlatformInfo"]["PlatformNVRAM"]["FirmwareFeaturesMask"] = fw_feature + self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeatures"] = fw_feature + self.config["PlatformInfo"]["SMBIOS"]["FirmwareFeaturesMask"] = fw_feature + + # Board ID + self.config["PlatformInfo"]["DataHub"]["BoardProduct"] = self.spoofed_board + self.config["PlatformInfo"]["PlatformNVRAM"]["BID"] = self.spoofed_board + self.config["PlatformInfo"]["SMBIOS"]["BoardProduct"] = self.spoofed_board + + # Model (ensures tables are not mismatched, even if we're not spoofing) + self.config["PlatformInfo"]["DataHub"]["SystemProductName"] = self.model + self.config["PlatformInfo"]["SMBIOS"]["SystemProductName"] = self.model + self.config["PlatformInfo"]["SMBIOS"]["BoardVersion"] = self.model + + # ProcessorType (when RestrictEvent's CPU naming is used) + if self.constants.custom_cpu_model == 0 or self.constants.custom_cpu_model == 1: + self.config["PlatformInfo"]["SMBIOS"]["ProcessorType"] = 1537 + + # Avoid incorrect Firmware Updates + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["SMBIOS"]["BIOSVersion"] = "9999.999.999.999.999" + + # Update tables + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + + if self.constants.custom_serial_number != "" and self.constants.custom_board_serial_number != "": + print("- Adding custom serial numbers") + sn = self.constants.custom_serial_number + mlb = self.constants.custom_board_serial_number + + # Serial Number + self.config["PlatformInfo"]["SMBIOS"]["ChassisSerialNumber"] = sn + self.config["PlatformInfo"]["SMBIOS"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["DataHub"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["PlatformNVRAM"]["SystemSerialNumber"] = sn + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn + + # Board Serial Number + self.config["PlatformInfo"]["SMBIOS"]["BoardSerialNumber"] = mlb + self.config["PlatformInfo"]["PlatformNVRAM"]["BoardSerialNumber"] = mlb + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb + + + def moderate_serial_patch(self): + 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 != "": + print("- Adding custom serial numbers") + self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = self.constants.custom_serial_number + self.config["PlatformInfo"]["Generic"]["MLB"] = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = self.constants.custom_serial_number + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["Automatic"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True + self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model + + + def advanced_serial_patch(self): + 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 == "": + macserial_output = subprocess.run([self.constants.macserial_path] + f"-g -m {self.spoofed_model} -n 1".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + macserial_output = macserial_output.stdout.decode().strip().split(" | ") + sn = macserial_output[0] + mlb = macserial_output[1] + else: + sn = self.constants.custom_serial_number + mlb = self.constants.custom_board_serial_number + self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["run-efi-updater"] = "No" + self.config["PlatformInfo"]["Automatic"] = True + self.config["PlatformInfo"]["UpdateDataHub"] = True + self.config["PlatformInfo"]["UpdateNVRAM"] = True + self.config["PlatformInfo"]["UpdateSMBIOS"] = True + self.config["UEFI"]["ProtocolOverrides"]["DataHub"] = True + self.config["PlatformInfo"]["Generic"]["ROM"] = binascii.unhexlify("0016CB445566") + self.config["PlatformInfo"]["Generic"]["SystemProductName"] = self.spoofed_model + self.config["PlatformInfo"]["Generic"]["SystemSerialNumber"] = sn + self.config["PlatformInfo"]["Generic"]["MLB"] = mlb + self.config["PlatformInfo"]["Generic"]["SystemUUID"] = str(uuid.uuid4()).upper() + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-SN"] = sn + self.config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["OCLP-Spoofed-MLB"] = mlb \ No newline at end of file diff --git a/resources/build/support.py b/resources/build/support.py index 5d5c059b6..e26732293 100644 --- a/resources/build/support.py +++ b/resources/build/support.py @@ -140,7 +140,6 @@ class build_support: if item["Enabled"] is False: self.config[entry][sub_entry].remove(item) - plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True) for kext in self.constants.kexts_path.rglob("*.zip"): with zipfile.ZipFile(kext) as zip_file: zip_file.extractall(self.constants.kexts_path) From 8b43727b0bf46f5f96051e839ccd723f7e4f7b39 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 18:33:52 -0700 Subject: [PATCH 16/19] Add header to restructured build family files --- resources/build/bluetooth.py | 3 +++ resources/build/build.py | 2 +- resources/build/firmware.py | 3 +++ resources/build/graphics_audio.py | 3 +++ resources/build/misc.py | 9 ++++++++- resources/build/networking/wired.py | 3 +++ resources/build/networking/wireless.py | 3 +++ resources/build/security.py | 7 ++----- resources/build/smbios.py | 2 ++ resources/build/storage.py | 2 ++ resources/build/support.py | 3 ++- 11 files changed, 32 insertions(+), 8 deletions(-) diff --git a/resources/build/bluetooth.py b/resources/build/bluetooth.py index 537795b1d..dca8b3a17 100644 --- a/resources/build/bluetooth.py +++ b/resources/build/bluetooth.py @@ -1,3 +1,6 @@ +# Class for handling Bluetooth Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + from resources import constants, device_probe from resources.build import support from data import smbios_data, bluetooth_data diff --git a/resources/build/build.py b/resources/build/build.py index 0289de91c..8924c1306 100644 --- a/resources/build/build.py +++ b/resources/build/build.py @@ -1,4 +1,4 @@ -# Commands for building the EFI and SMBIOS +# Class for generating OpenCore Configurations tailored for Macs # Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk import copy diff --git a/resources/build/firmware.py b/resources/build/firmware.py index 0931b2874..176ce2265 100644 --- a/resources/build/firmware.py +++ b/resources/build/firmware.py @@ -1,3 +1,6 @@ +# Class for handling CPU and Firmware Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + from resources import constants, generate_smbios from resources.build import support from data import smbios_data, cpu_data diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index 5d09af9d0..212eab21e 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -1,3 +1,6 @@ +# Class for handling Graphics and Audio Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + from resources import constants, device_probe, utilities from resources.build import support from data import smbios_data, model_array, os_data diff --git a/resources/build/misc.py b/resources/build/misc.py index ecad6eb20..75a5b557f 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -1,3 +1,5 @@ +# Class for handling Misc Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk from resources import constants, device_probe, generate_smbios from resources.build import support @@ -223,4 +225,9 @@ class build_misc: if self.constants.oc_timeout != 5: print(f"- Setting custom OpenCore picker timeout to {self.constants.oc_timeout} seconds") - self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout \ No newline at end of file + self.config["Misc"]["Boot"]["Timeout"] = self.constants.oc_timeout + + if self.constants.vault is True: + print("- 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 \ No newline at end of file diff --git a/resources/build/networking/wired.py b/resources/build/networking/wired.py index f9aabe1ec..5cb2eba9e 100644 --- a/resources/build/networking/wired.py +++ b/resources/build/networking/wired.py @@ -1,3 +1,6 @@ +# Class for handling Wired Networking Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + from resources import constants, device_probe from resources.build import support from data import smbios_data, cpu_data diff --git a/resources/build/networking/wireless.py b/resources/build/networking/wireless.py index 32a9b0d91..74890d3bc 100644 --- a/resources/build/networking/wireless.py +++ b/resources/build/networking/wireless.py @@ -1,3 +1,6 @@ +# Class for handling Wireless Networking Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk + from resources import constants, device_probe, utilities from resources.build import support from data import smbios_data diff --git a/resources/build/security.py b/resources/build/security.py index 628595152..fed93466d 100644 --- a/resources/build/security.py +++ b/resources/build/security.py @@ -1,3 +1,5 @@ +# Class for handling macOS Security Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk from resources import constants, utilities from resources.build import support @@ -15,11 +17,6 @@ class build_security: def build(self): - if self.constants.vault is True: - print("- 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 - 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 diff --git a/resources/build/smbios.py b/resources/build/smbios.py index 2250f9f61..978ba6491 100644 --- a/resources/build/smbios.py +++ b/resources/build/smbios.py @@ -1,3 +1,5 @@ +# Class for handling SMBIOS Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk from resources import constants, utilities, generate_smbios from resources.build import support diff --git a/resources/build/storage.py b/resources/build/storage.py index 268acfa46..ddffd0805 100644 --- a/resources/build/storage.py +++ b/resources/build/storage.py @@ -1,3 +1,5 @@ +# Class for handling Storage Controller Patches, invocation from build.py +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk from resources import constants, device_probe, utilities from resources.build import support diff --git a/resources/build/support.py b/resources/build/support.py index e26732293..770b99442 100644 --- a/resources/build/support.py +++ b/resources/build/support.py @@ -1,4 +1,5 @@ -# Support files for build +# Utility class for build functions +# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk from resources import constants, utilities From e7e2b0dcad762f8e6b51814fb093f4e64073e645 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 18:55:35 -0700 Subject: [PATCH 17/19] graphics_audio.py: Refactor --- resources/build/graphics_audio.py | 185 ++++++++++++++++-------------- 1 file changed, 97 insertions(+), 88 deletions(-) diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index 212eab21e..9254167ff 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -24,36 +24,15 @@ class build_graphics_audio: self.graphics_handling() self.audio_handling() self.firmware_handling() + self.spoof_handling() + self.imac_mxm_patching() + def graphics_handling(self): if self.constants.allow_oc_everywhere is False and self.constants.serial_settings != "None": support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) - # Check GPU Vendor - if self.constants.metal_build is True: - self.backlight_path_detection() - print("- Adding Metal GPU patches on request") - if self.constants.imac_vendor == "AMD": - self.amd_patch(self.gfx0_path) - elif self.constants.imac_vendor == "Nvidia": - self.nvidia_patch(self.gfx0_path) - else: - print("- Failed to find vendor") - elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: - print(f"- Detected dGPU: {utilities.friendly_hex(self.computer.dgpu.vendor_id)}:{utilities.friendly_hex(self.computer.dgpu.device_id)}") - if self.computer.dgpu.arch in [ - device_probe.AMD.Archs.Legacy_GCN_7000, - device_probe.AMD.Archs.Legacy_GCN_8000, - device_probe.AMD.Archs.Legacy_GCN_9000, - device_probe.AMD.Archs.Polaris, - device_probe.AMD.Archs.Vega, - device_probe.AMD.Archs.Navi, - ]: - self.backlight_path_detection() - self.amd_patch(self.gfx0_path) - elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: - self.backlight_path_detection() - self.nvidia_patch(self.gfx0_path) + # Mac Pro handling if self.model in model_array.MacPro: if not self.constants.custom_model: for i, device in enumerate(self.computer.gpus): @@ -98,6 +77,7 @@ class build_graphics_audio: 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) + # Web Driver specific if not self.constants.custom_model: for i, device in enumerate(self.computer.gpus): if isinstance(device, device_probe.NVIDIA): @@ -111,72 +91,18 @@ 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} - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) + support.build_support(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" - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("WhateverGreen.kext")["Enabled"] is False: - support.build_support(self.model, self.constants, self.config).enable_kext("WhateverGreen.kext", self.constants.whatevergreen_version, self.constants.whatevergreen_path) + support.build_support(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"] - if self.constants.allow_oc_everywhere is False: - if self.constants.serial_settings != "None": - if self.model == "MacBookPro9,1": - print("- Adding AppleMuxControl Override") - amc_map_path = Path(self.constants.plist_folder_path) / Path("AppleMuxControl/Info.plist") - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"agdpmod": "vit9696"} - 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 - if self.model not in model_array.NoAGPMSupport: - print("- Adding AppleGraphicsPowerManagement Override") - agpm_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsPowerManagement/Info.plist") - 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 - - if self.model in model_array.AGDPSupport: - print("- Adding AppleGraphicsDevicePolicy Override") - agdp_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsDevicePolicy/Info.plist") - 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 - - if self.constants.serial_settings != "None": - # AGPM Patch - if self.model in model_array.DualGPUPatch: - print("- Adding dual GPU patch") - if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: - self.gfx0_path = self.computer.dgpu.pci_path - print(f"- Found GFX0 Device Path: {self.gfx0_path}") - else: - if not self.constants.custom_model: - print("- Failed to find GFX0 Device path, falling back on known logic") - self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" - - if self.model in model_array.IntelNvidiaDRM and self.constants.drm_support is True: - print("- Prioritizing DRM support over Intel QuickSync") - self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696", "shikigva": 256} - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { - "name": binascii.unhexlify("23646973706C6179"), - "IOName": "#display", - "class-code": binascii.unhexlify("FFFFFFFF"), - } - elif self.constants.serial_settings != "None": - self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696"} - if self.model.startswith("iMac14,"): - if self.computer.igpu and not self.computer.dgpu: - # Ensure that agdpmod is applied to iMac14,x with iGPU only - self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"} def backlight_path_detection(self): if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: @@ -192,7 +118,8 @@ class build_graphics_audio: else: self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" - def nvidia_patch(self, backlight_path): + + 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: # 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_version, self.constants.whatevergreen_path) @@ -235,7 +162,8 @@ class build_graphics_audio: self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True - def amd_patch(self, backlight_path): + + def amd_mxm_patch(self, backlight_path): print("- 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: # Ensure WEG is enabled as we need if for Backlight patching @@ -253,8 +181,7 @@ class build_graphics_audio: "class-code": binascii.unhexlify("FFFFFFFF"), } elif self.model == "iMac10,1": - if support.build_support(self.model, self.constants, self.config).get_kext_by_bundle_path("AAAMouSSE.kext")["Enabled"] is False: - 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("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: print("- Adding Legacy GCN Power Gate Patches") @@ -316,8 +243,6 @@ class build_graphics_audio: support.build_support(self.model, self.constants, self.config).enable_kext("AppleALC.kext", self.constants.applealc_version, self.constants.applealc_path) - - def firmware_handling(self): # Add UGA to GOP layer if "UGA Graphics" in smbios_data.smbios_dictionary[self.model]: @@ -351,4 +276,88 @@ class build_graphics_audio: if self.constants.force_output_support is True: print("- Forcing GOP Support") self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True - self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True \ No newline at end of file + self.config["UEFI"]["Quirks"]["ReloadOptionRoms"] = True + + def spoof_handling(self): + if self.constants.serial_settings == "None": + return + + # AppleMuxControl Override + if self.model == "MacBookPro9,1": + print("- Adding AppleMuxControl Override") + amc_map_path = Path(self.constants.plist_folder_path) / Path("AppleMuxControl/Info.plist") + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"agdpmod": "vit9696"} + 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 + + if self.model not in model_array.NoAGPMSupport: + print("- Adding AppleGraphicsPowerManagement Override") + agpm_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsPowerManagement/Info.plist") + 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 + + if self.model in model_array.AGDPSupport: + print("- Adding AppleGraphicsDevicePolicy Override") + agdp_map_path = Path(self.constants.plist_folder_path) / Path("AppleGraphicsDevicePolicy/Info.plist") + 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 + + # AGPM Patch + if self.model in model_array.DualGPUPatch: + print("- Adding dual GPU patch") + if not self.constants.custom_model and self.computer.dgpu and self.computer.dgpu.pci_path: + self.gfx0_path = self.computer.dgpu.pci_path + print(f"- Found GFX0 Device Path: {self.gfx0_path}") + else: + if not self.constants.custom_model: + print("- Failed to find GFX0 Device path, falling back on known logic") + self.gfx0_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)" + + if self.model in model_array.IntelNvidiaDRM and self.constants.drm_support is True: + print("- Prioritizing DRM support over Intel QuickSync") + self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696", "shikigva": 256} + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = { + "name": binascii.unhexlify("23646973706C6179"), + "IOName": "#display", + "class-code": binascii.unhexlify("FFFFFFFF"), + } + elif self.constants.serial_settings != "None": + self.config["DeviceProperties"]["Add"][self.gfx0_path] = {"agdpmod": "vit9696"} + + if self.model.startswith("iMac14,1"): + # Ensure that agdpmod is applied to iMac14,x with iGPU only + self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"agdpmod": "vit9696"} + + + def imac_mxm_patching(self): + # Check GPU Vendor + if self.constants.metal_build is True: + self.backlight_path_detection() + print("- Adding Metal GPU patches on request") + if self.constants.imac_vendor == "AMD": + self.amd_mxm_patch(self.gfx0_path) + elif self.constants.imac_vendor == "Nvidia": + self.nvidia_mxm_patch(self.gfx0_path) + else: + print("- Failed to find vendor") + elif not self.constants.custom_model and self.model in model_array.LegacyGPU and self.computer.dgpu: + print(f"- Detected dGPU: {utilities.friendly_hex(self.computer.dgpu.vendor_id)}:{utilities.friendly_hex(self.computer.dgpu.device_id)}") + if self.computer.dgpu.arch in [ + device_probe.AMD.Archs.Legacy_GCN_7000, + device_probe.AMD.Archs.Legacy_GCN_8000, + device_probe.AMD.Archs.Legacy_GCN_9000, + device_probe.AMD.Archs.Polaris, + device_probe.AMD.Archs.Vega, + device_probe.AMD.Archs.Navi, + ]: + self.backlight_path_detection() + self.amd_mxm_patch(self.gfx0_path) + elif self.computer.dgpu.arch == device_probe.NVIDIA.Archs.Kepler: + self.backlight_path_detection() + self.nvidia_mxm_patch(self.gfx0_path) \ No newline at end of file From 48de65dd308d5798a2ad9578a3785481fdf5b6d3 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 19:12:49 -0700 Subject: [PATCH 18/19] graphics_audio: avoid excessive try except usage --- resources/build/graphics_audio.py | 5 ++--- resources/build/smbios.py | 14 +++++++++----- resources/build/support.py | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/resources/build/graphics_audio.py b/resources/build/graphics_audio.py index 9254167ff..c50f4c960 100644 --- a/resources/build/graphics_audio.py +++ b/resources/build/graphics_audio.py @@ -219,10 +219,9 @@ class build_graphics_audio: # Xserves and MacPro4,1 are exceptions # iMac7,1 and iMac8,1 require AppleHDA/IOAudioFamily downgrade if not (self.model.startswith("Xserve") or self.model in ["MacPro4,1", "iMac7,1", "iMac8,1"]): - try: - smbios_data.smbios_dictionary[self.model]["nForce Chipset"] + if "nForce Chipset" in smbios_data.smbios_dictionary[self.model]: hdef_path = "PciRoot(0x0)/Pci(0x8,0x0)" - except KeyError: + else: hdef_path = "PciRoot(0x0)/Pci(0x1b,0x0)" # In AppleALC, MacPro3,1's original layout is already in use, forcing layout 13 instead if self.model == "MacPro3,1": diff --git a/resources/build/smbios.py b/resources/build/smbios.py index 978ba6491..f583276ee 100644 --- a/resources/build/smbios.py +++ b/resources/build/smbios.py @@ -44,6 +44,7 @@ class build_smbios: def set_smbios(self): spoofed_model = self.model + if self.constants.override_smbios == "Default": if self.constants.serial_settings != "None": print("- Setting macOS Monterey Supported SMBIOS") @@ -54,13 +55,16 @@ class build_smbios: else: spoofed_model = self.constants.override_smbios print(f"- Using Model ID: {spoofed_model}") - try: - spoofed_board = smbios_data.smbios_dictionary[spoofed_model]["Board ID"] - print(f"- Using Board ID: {spoofed_board}") - except KeyError: - spoofed_board = "" + + spoofed_board = "" + if spoofed_model in smbios_data.smbios_dictionary: + if "Board ID" in smbios_data.smbios_dictionary[spoofed_model]: + spoofed_board = smbios_data.smbios_dictionary[spoofed_model]["Board ID"] + print(f"- Using Board ID: {spoofed_board}") + self.spoofed_model = spoofed_model self.spoofed_board = spoofed_board + if self.constants.allow_oc_everywhere is False or self.constants.allow_native_spoofs is True: self.config["#Revision"]["Spoofed-Model"] = f"{self.spoofed_model} - {self.constants.serial_settings}" diff --git a/resources/build/support.py b/resources/build/support.py index 770b99442..8cb30ba11 100644 --- a/resources/build/support.py +++ b/resources/build/support.py @@ -47,7 +47,6 @@ class build_support: # Check failed return - # Is the kext already enabled? if kext["Enabled"] is True: return From 7543606a1eaaebba8b98531f73e99a31847714b5 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 13 Nov 2022 19:25:55 -0700 Subject: [PATCH 19/19] Nest sys_patch libraries --- gui/gui_main.py | 3 ++- resources/arguments.py | 3 ++- resources/cli_menu.py | 3 ++- resources/{ => sys_patch}/sys_patch.py | 4 +++- resources/{ => sys_patch}/sys_patch_auto.py | 3 ++- resources/{ => sys_patch}/sys_patch_detect.py | 4 ++-- resources/{ => sys_patch}/sys_patch_download.py | 0 resources/{ => sys_patch}/sys_patch_helpers.py | 0 resources/validation.py | 2 +- 9 files changed, 14 insertions(+), 8 deletions(-) rename resources/{ => sys_patch}/sys_patch.py (99%) rename resources/{ => sys_patch}/sys_patch_auto.py (99%) rename resources/{ => sys_patch}/sys_patch_detect.py (99%) rename resources/{ => sys_patch}/sys_patch_download.py (100%) rename resources/{ => sys_patch}/sys_patch_helpers.py (100%) diff --git a/gui/gui_main.py b/gui/gui_main.py index 0df811e0b..cdef089ad 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -16,7 +16,8 @@ from pathlib import Path import binascii import hashlib -from resources import constants, defaults, install, installer, sys_patch_download, utilities, sys_patch_detect, sys_patch, run, generate_smbios, updates, integrity_verification, global_settings, kdk_handler +from resources import constants, defaults, install, installer, utilities, run, generate_smbios, updates, integrity_verification, global_settings, kdk_handler +from resources.sys_patch import sys_patch_download, sys_patch_detect, sys_patch from resources.build import build from data import model_array, os_data, smbios_data, sip_data from gui import menu_redirect, gui_help diff --git a/resources/arguments.py b/resources/arguments.py index ddddc2167..d31308830 100644 --- a/resources/arguments.py +++ b/resources/arguments.py @@ -1,5 +1,6 @@ import sys -from resources import defaults, utilities, validation, sys_patch, sys_patch_auto +from resources import defaults, utilities, validation +from resources.sys_patch import sys_patch, sys_patch_auto from resources.build import build from data import model_array import threading diff --git a/resources/cli_menu.py b/resources/cli_menu.py index ff91cc916..81e90fcde 100644 --- a/resources/cli_menu.py +++ b/resources/cli_menu.py @@ -2,7 +2,8 @@ # Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk import sys -from resources import constants, install, utilities, defaults, sys_patch, installer, tui_helpers, global_settings +from resources import constants, install, utilities, defaults, installer, tui_helpers, global_settings +from resources.sys_patch import sys_patch from data import cpu_data, smbios_data, model_array, os_data, mirror_data diff --git a/resources/sys_patch.py b/resources/sys_patch/sys_patch.py similarity index 99% rename from resources/sys_patch.py rename to resources/sys_patch/sys_patch.py index c04c90f54..87709ea5d 100644 --- a/resources/sys_patch.py +++ b/resources/sys_patch/sys_patch.py @@ -38,7 +38,9 @@ import subprocess from pathlib import Path from datetime import datetime -from resources import constants, utilities, sys_patch_download, sys_patch_detect, sys_patch_auto, sys_patch_helpers, kdk_handler +from resources import constants, utilities, kdk_handler +from resources.sys_patch import sys_patch_download, sys_patch_detect, sys_patch_auto, sys_patch_helpers + from data import os_data diff --git a/resources/sys_patch_auto.py b/resources/sys_patch/sys_patch_auto.py similarity index 99% rename from resources/sys_patch_auto.py rename to resources/sys_patch/sys_patch_auto.py index 78365bc73..95debd60d 100644 --- a/resources/sys_patch_auto.py +++ b/resources/sys_patch/sys_patch_auto.py @@ -12,7 +12,8 @@ from pathlib import Path import plistlib import subprocess import webbrowser -from resources import sys_patch_detect, utilities, sys_patch_detect, updates, global_settings +from resources import utilities, updates, global_settings +from resources.sys_patch import sys_patch_detect from gui import gui_main class AutomaticSysPatch: diff --git a/resources/sys_patch_detect.py b/resources/sys_patch/sys_patch_detect.py similarity index 99% rename from resources/sys_patch_detect.py rename to resources/sys_patch/sys_patch_detect.py index 01fc6086d..9146e0f1a 100644 --- a/resources/sys_patch_detect.py +++ b/resources/sys_patch/sys_patch_detect.py @@ -3,8 +3,8 @@ # Used when supplying data to sys_patch.py # Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk -import subprocess -from resources import constants, device_probe, utilities, sys_patch_helpers, amfi_detect +from resources import constants, device_probe, utilities, amfi_detect +from resources.sys_patch import sys_patch_helpers from data import model_array, os_data, sip_data, sys_patch_dict class detect_root_patch: diff --git a/resources/sys_patch_download.py b/resources/sys_patch/sys_patch_download.py similarity index 100% rename from resources/sys_patch_download.py rename to resources/sys_patch/sys_patch_download.py diff --git a/resources/sys_patch_helpers.py b/resources/sys_patch/sys_patch_helpers.py similarity index 100% rename from resources/sys_patch_helpers.py rename to resources/sys_patch/sys_patch_helpers.py diff --git a/resources/validation.py b/resources/validation.py index 4c3829f94..7ad736ce3 100644 --- a/resources/validation.py +++ b/resources/validation.py @@ -1,5 +1,5 @@ import subprocess -from resources import sys_patch_helpers +from resources.sys_patch import sys_patch_helpers from resources.build import build from data import example_data, model_array, sys_patch_dict, os_data from pathlib import Path