Fix GPU vendor user-configuration

Closes https://github.com/dortania/Opencore-Legacy-Patcher/issues/89
This commit is contained in:
Mykola Grymalyuk
2021-03-09 23:19:37 -07:00
parent d605e33a72
commit 951c2b3a2a
4 changed files with 71 additions and 27 deletions

View File

@@ -13,6 +13,7 @@
- Add user-configurable Vaulting, enabled by default
- Add user-configurable SIP and SecureBootModel
- Fix USB Maps not working on "Minimal" SMBIOS
- Fix GPU vendor user-configuration
## 0.0.15
- Add user-configurable OpenCore DEBUG builds

View File

@@ -101,14 +101,25 @@ Current target:\t{self.constants.os_support}
print("""This is for iMacs that have upgraded Metal GPUs, otherwise
Patcher assumes based on stock configuration (ie. iMac10,x-12,x)
Valid Options:
1. None(stock GPU)
2. Nvidia GPU
3. AMD GPU
Note: Patcher will detect whether hardware has been upgraded regardless, this
option is for those patching on a different machine.
option is for those patching on a different machine or OCLP cannot detect.
""")
change_kext_menu = input("Enable Metal GPU build algorithm?(y/n): ")
if change_kext_menu in {"y", "Y", "yes", "Yes"}:
self.constants.metal_build = True
elif change_kext_menu in {"n", "N", "no", "No"}:
change_kext_menu = input("Set GPU Patch type(ie. 1): ")
if change_kext_menu == "1":
self.constants.metal_build = False
self.constants.imac_vendor = "None"
elif change_kext_menu == "2":
self.constants.metal_build = True
self.constants.imac_vendor = "Nvidia"
elif change_kext_menu == "3":
self.constants.metal_build = True
self.constants.imac_vendor = "AMD"
else:
print("Invalid option")
@@ -118,7 +129,7 @@ option is for those patching on a different machine.
print("""This is for Macs with upgraded wifi cards(ie. BCM94360/2)
Note: Patcher will detect whether hardware has been upgraded regardless, this
option is for those patching on a different machine.
option is for those patching on a different machine or cannot detect.
""")
change_kext_menu = input("Enable Upgraded Wifi build algorithm?(y/n): ")
if change_kext_menu in {"y", "Y", "yes", "Yes"}:
@@ -216,6 +227,21 @@ Valid options:
self.constants.secure_status = False
else:
print("Invalid option")
def change_imac_nvidia(self):
utilities.cls()
utilities.header(["Force iMac Nvidia Patches"])
print("""Specifically for iMac10,x-12,x with Metal Nvidia GPU upgrades
By default the patcher will try to detect what hardware is
running, however this will enforce iMac Nvidia Build Patches.
""")
change_kext_menu = input("Assume iMac Nvidia patches(y/n): ")
if change_kext_menu in {"y", "Y", "yes", "Yes"}:
self.constants.imac_nvidia_build = True
elif change_kext_menu in {"n", "N", "no", "No"}:
self.constants.imac_nvidia_build = False
else:
print("Invalid option")
def patcher_settings(self):
response = None
@@ -230,8 +256,8 @@ Valid options:
[f"Enable Verbose Mode:\t\tCurrently {self.constants.verbose_debug}", self.change_verbose],
[f"Enable OpenCore DEBUG:\t\tCurrently {self.constants.opencore_debug}", self.change_oc],
[f"Enable Kext DEBUG:\t\t\tCurrently {self.constants.kext_debug}", self.change_kext],
[f"Assume Metal GPU Always:\t\tCurrently {self.constants.kext_debug}", self.change_metal],
[f"Assume Upgraded Wifi Always:\tCurrently {self.constants.kext_debug}", self.change_wifi],
[f"Force iMac Metal Patch:\t\tCurrently {self.constants.imac_vendor}", self.change_metal],
[f"Assume Upgraded Wifi Always:\tCurrently {self.constants.wifi_build}", self.change_wifi],
[f"Set ShowPicker Mode:\t\tCurrently {self.constants.showpicker}", self.change_showpicker],
[f"Set Vault Mode:\t\t\tCurrently {self.constants.vault}", self.change_vault],
[f"Set SIP and SecureBootModel:\tSIP: {self.constants.sip_status} SBM: {self.constants.secure_status}", self.change_sip],

View File

@@ -47,6 +47,7 @@ class Constants:
self.min_os_support = 11.0
self.max_os_support = 11.0
self.metal_build = False
self.imac_vendor = "None"
self.wifi_build = False
self.gui_mode = False
self.serial_settings = "Minimal"

View File

@@ -162,36 +162,52 @@ class BuildOpenCore:
if self.model in ModelArray.HiDPIpicker:
print("- Setting HiDPI picker")
self.config["NVRAM"]["Add"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["UIScale"] = binascii.unhexlify("02")
def nvidia_patch(self):
self.constants.custom_mxm_gpu = True
print("- Adding Nvidia Brightness Control patches")
if self.model in ["iMac11,1", "iMac11,2", "iMac11,3"]:
backlight_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"
self.config["DeviceProperties"]["Add"][backlight_path] = {"@0,backlight-control": binascii.unhexlify("01000000"), "@0,built-in": binascii.unhexlify("01000000")}
shutil.copy(self.constants.backlight_path, self.constants.kexts_path)
self.get_kext_by_bundle_path("AppleBacklightFixup.kext")["Enabled"] = True
elif self.model in ["iMac12,1", "iMac12,2"]:
backlight_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"
self.config["DeviceProperties"]["Add"][backlight_path] = {"@0,backlight-control": binascii.unhexlify("01000000"), "@0,built-in": binascii.unhexlify("01000000")}
print("- Disabling unsupported iGPU")
self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"name": binascii.unhexlify("23646973706C6179"), "IOName": "#display", "class-code": binascii.unhexlify("FFFFFFFF")}
else:
print("- Failed to determine model")
def amd_patch(self):
self.constants.custom_mxm_gpu = True
print("- Adding AMD DRM patches")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=80 unfairgva=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")}
# Check GPU Vendor
if self.constants.metal_build is True:
print("- Adding Metal GPU patches on request")
if self.constants.imac_vendor == "AMD":
amd_patch(self)
elif self.constants.imac_vendor == "Nvidia":
nvidia_patch(self)
else:
print("- Failed to find vendor")
elif self.constants.custom_model == "None":
current_gpu: str = subprocess.run("system_profiler SPDisplaysDataType".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
self.constants.current_gpuv = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Vendor"))][0]
self.constants.current_gpud = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Device ID"))][0]
print(f"- Detected GPU: {self.constants.current_gpuv} {self.constants.current_gpud}")
if (self.constants.current_gpuv == "AMD (0x1002)") & (self.constants.current_gpud in ModelArray.AMDMXMGPUs):
self.constants.custom_mxm_gpu = True
print("- Adding AMD DRM patches")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=80 unfairgva=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")}
amd_patch(self)
elif (self.constants.current_gpuv == "NVIDIA (0x10de)") & (self.constants.current_gpud in ModelArray.NVIDIAMXMGPUs):
self.constants.custom_mxm_gpu = True
print("- Adding Brightness Control patches")
if self.model in ["iMac11,1", "iMac11,2", "iMac11,3"]:
backlight_path = "PciRoot(0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)"
self.config["DeviceProperties"]["Add"][backlight_path] = {"@0,backlight-control": binascii.unhexlify("01000000"), "@0,built-in": binascii.unhexlify("01000000")}
shutil.copy(self.constants.backlight_path, self.constants.kexts_path)
self.get_kext_by_bundle_path("AppleBacklightFixup.kext")["Enabled"] = True
elif self.model in ["iMac12,1", "iMac12,2"]:
backlight_path = "PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"
self.config["DeviceProperties"]["Add"][backlight_path] = {"@0,backlight-control": binascii.unhexlify("01000000"), "@0,built-in": binascii.unhexlify("01000000")}
print("- Disabling unsupported iGPU")
self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x2,0x0)"] = {"name": binascii.unhexlify("23646973706C6179"), "IOName": "#display", "class-code": binascii.unhexlify("FFFFFFFF")}
nvidia_patch(self)
# Add OpenCanopy
print("- Adding OpenCanopy GUI")
shutil.rmtree(self.constants.resources_path, onerror=rmtree_handler)