Add custom kext selection for user configuration

This commit is contained in:
Hoang Hong Quan
2024-10-07 22:54:37 +07:00
parent f47552acc8
commit d6423e77fc
4 changed files with 432 additions and 1094 deletions

View File

@@ -4,6 +4,7 @@ from Scripts import aida64
from Scripts import compatibility_checker
from Scripts import efi_builder
from Scripts import gathering_files
from Scripts import kext_maestro
from Scripts import smbios
from Scripts import utils
import updater
@@ -19,6 +20,7 @@ class OCPE:
self.a = aida64.AIDA64()
self.c = compatibility_checker.CompatibilityChecker()
self.b = efi_builder.builder()
self.k = kext_maestro.KextMaestro()
self.s = smbios.SMBIOS()
self.u = utils.Utils()
self.result_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Results")
@@ -181,8 +183,9 @@ class OCPE:
print("1. Select Hardware Report")
print("2. Select macOS Version")
print("3. Customize ACPI Patch")
print("4. Customize SMBIOS Model")
print("5. Build OpenCore EFI")
print("4. Customize Kexts")
print("5. Customize SMBIOS Model")
print("6. Build OpenCore EFI")
print("")
print("Q. Quit")
print("")
@@ -205,7 +208,8 @@ class OCPE:
smbios_model = self.s.select_smbios_model(hardware_report, macos_version)
self.ac.select_acpi_tables()
self.ac.select_acpi_patches(hardware_report, unsupported_devices, smbios_model)
elif option < 6:
self.k.select_required_kexts(hardware_report, smbios_model, macos_version, self.ac.patches)
elif option < 7:
try:
hardware_report
except:
@@ -215,13 +219,17 @@ class OCPE:
if option == 2:
macos_version = self.select_macos_version(supported_macos_version)
smbios_model = self.s.select_smbios_model(hardware_report, macos_version)
self.k.select_required_kexts(hardware_report, smbios_model, macos_version, self.ac.patches)
elif option == 3:
self.ac.customize_patch_selection(hardware_report, unsupported_devices, smbios_model)
elif option == 4:
smbios_model = self.s.customize_smbios_model(hardware_report, smbios_model, macos_version)
self.k.kext_configuration_menu(hardware_report, smbios_model, macos_version, self.ac.patches)
elif option == 5:
smbios_model = self.s.customize_smbios_model(hardware_report, smbios_model, macos_version)
self.k.kext_configuration_menu(hardware_report, smbios_model, macos_version, self.ac.patches)
elif option == 6:
self.gathering_files()
self.b.build_efi(hardware_report, unsupported_devices, smbios_model, macos_version, self.ac)
self.b.build_efi(hardware_report, unsupported_devices, smbios_model, macos_version, self.ac, self.k)
self.show_result(hardware_report)
if __name__ == '__main__':
@@ -233,4 +241,4 @@ if __name__ == '__main__':
else:
o.main()
except Exception as e:
o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e)))
o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e)))

View File

@@ -69,8 +69,8 @@ class ConfigProdigy:
return not self.utils.contains_any(chipset_data.AMDChipsets, motherboard_chipset) is None or not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=10) is None
def is_low_end_intel_cpu(self, processor_name):
return any(brand in processor_name for brand in ["Celeron", "Pentium"])
return any(cpu_branding in processor_name for cpu_branding in ["Celeron", "Pentium"])
def deviceproperties(self, cpu_codename, intel_mei, igpu_properties):
deviceproperties_add = {}
@@ -133,31 +133,33 @@ class ConfigProdigy:
return None
def load_kernel_patch(self, motherboard_chipset, cpu_manufacturer, cpu_codename, cpu_cores, gpu_manufacturer, tsc_sync):
def load_kernel_patch(self, motherboard_chipset, cpu_manufacturer, cpu_cores, gpu_manufacturer, kexts):
kernel_patch = []
if "AMD" in cpu_manufacturer:
kernel_patch.extend(self.g.get_amd_kernel_patches())
elif tsc_sync:
kernel_patch.extend(self.g.get_amd_kernel_patches()[-6:-4])
if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6:
kernel_patch.append({
"Arch": "Any",
"Base": "_cpu_thread_alloc",
"Comment": "Force enable Hyper Threading for macOS Mojave or later",
"Count": 1,
"Enabled": True,
"Find": self.utils.hex_to_bytes("8B8894010000"),
"Identifier": "kernel",
"Limit": 0,
"Mask": self.utils.hex_to_bytes(""),
"MaxKernel": "",
"MinKernel": "18.0.0",
"Replace": self.utils.hex_to_bytes("B9FF00000090"),
"ReplaceMask": self.utils.hex_to_bytes(""),
"Skip": 0
})
for kext in kexts:
if kext.checked:
if kext.name == "CpuTopologyRebuild":
kernel_patch.append({
"Arch": "Any",
"Base": "_cpu_thread_alloc",
"Comment": "Force enable Hyper Threading for macOS Mojave or later",
"Count": 1,
"Enabled": True,
"Find": self.utils.hex_to_bytes("8B8894010000"),
"Identifier": "kernel",
"Limit": 0,
"Mask": self.utils.hex_to_bytes(""),
"MaxKernel": "",
"MinKernel": "18.0.0",
"Replace": self.utils.hex_to_bytes("B9FF00000090"),
"ReplaceMask": self.utils.hex_to_bytes(""),
"Skip": 0
})
elif kext.name == "ForgedInvariant":
kernel_patch.extend(self.g.get_amd_kernel_patches()[-6:-4])
for patch in kernel_patch:
if "cpuid_cores_per_package" in patch["Comment"]:
@@ -177,57 +179,62 @@ class ConfigProdigy:
return kernel_patch
def boot_args(self, motherboard_name, platform, cpu_manufacturer, cpu_codename, cpu_cores, discrete_gpu_codename, discrete_gpu_id, integrated_gpu_name, codec_id, touchpad_communication, unsupported_devices, custom_cpu_name, macos_version):
def boot_args(self, hardware_report, unsupported_devices, macos_version):
boot_args = [
"-v",
"debug=0x100",
"keepsyms=1"
]
codec_id = list(hardware_report.get("Audio").items())[0][-1].get("Codec ID")
if codec_id in codec_layouts.data:
boot_args.append("alcid={}".format(random.choice(codec_layouts.data.get(codec_id))))
if "AMD" in cpu_manufacturer or self.is_intel_hedt_cpu(cpu_codename):
if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")):
boot_args.append("npci=0x2000")
if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"):
boot_args.append("revpatch=sbvmm{}".format(",cpuname" if custom_cpu_name else ""))
boot_args.append("revpatch=sbvmm{}".format(",cpuname" if not (" Core" in hardware_report.get("CPU").get("Processor Name") and \
self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=12)) else ""))
if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6:
if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=13) and int(hardware_report.get("CPU").get("CPU Cores")) > 6:
boot_args.append("-ctrsmt")
if "Intel" in cpu_manufacturer:
if "UHD" in integrated_gpu_name and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"):
if "Intel" in hardware_report.get("CPU").get("CPU Manufacturer"):
if "UHD" in list(hardware_report.get("GPU").keys())[0] and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"):
boot_args.append("igfxonln=1")
if "Ice Lake" in cpu_codename:
if "Ice Lake" in list(hardware_report.get("GPU").items())[0][-1].get("GPU Codename"):
boot_args.extend(["-noDC9", "-igfxcdc", "-igfxdvmt", "-igfxdbeo"])
if "Laptop" in platform:
if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=6):
if "Laptop" in hardware_report.get("Motherboard").get("Platform"):
if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=6):
boot_args.append("-igfxbl{}".format("t" if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0") else "r"))
if "Navi" in discrete_gpu_codename and not "Navi 2" in discrete_gpu_codename:
if "Navi 1" in list(hardware_report.get("GPU").items())[-1][-1].get("GPU Codename"):
boot_args.append("agdpmod=pikera")
if not "SURFACE" in motherboard_name and "I2C" in touchpad_communication:
boot_args.append("-vi2c-force-polling")
if not "SURFACE" in hardware_report.get("Motherboard").get("Motherboard Name"):
for input in hardware_report.get("Input").keys():
if "I2C" in input:
boot_args.append("-vi2c-force-polling")
break
if "Beta" in os_data.get_macos_name_by_darwin(macos_version):
boot_args.append("-lilubetaall")
if "Discrete GPU" in unsupported_devices:
boot_args.append("-wegnoegpu")
if "Integrated GPU" in unsupported_devices:
boot_args.append("-wegnoigpu")
if discrete_gpu_id in ["1002-6610", "1002-682B", "1002-6837", "1002-683D", "1002-683F"]:
if list(hardware_report.get("GPU").items())[-1][-1].get("Device ID") in ("1002-6610", "1002-682B", "1002-6837", "1002-683D", "1002-683F"):
boot_args.append("radpg=15")
if discrete_gpu_id in ["1002-67B0", "1002-67B1", "1002-67B8", "1002-6810", "1002-6811"]:
if list(hardware_report.get("GPU").items())[-1][-1].get("Device ID") in ("1002-67B0", "1002-67B1", "1002-67B8", "1002-6810", "1002-6811"):
boot_args.append("-raddvi")
if any("Discrete GPU" in device_name for device_name in unsupported_devices):
boot_args.append("-wegnoegpu")
if any("Integrated GPU" in device_name for device_name in unsupported_devices):
boot_args.append("-wegnoigpu")
return " ".join(boot_args)
def csr_active_config(self, macos_version):
@@ -252,66 +259,67 @@ class ConfigProdigy:
return uefi_drivers
def genarate(self, hardware, efi_option, config):
def genarate(self, hardware_report, unsupported_devices, smbios_model, macos_version, kexts, config):
del config["#WARNING - 1"]
del config["#WARNING - 2"]
del config["#WARNING - 3"]
del config["#WARNING - 4"]
config["ACPI"]["Add"] = []
config["ACPI"]["Delete"] = []
config["ACPI"]["Patch"] = []
config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware.get("Motherboard Chipset"))
config["Booter"]["Patch"] = self.add_booter_patch(efi_option.get("SMBIOS"), efi_option.get("macOS Version"))
config["Booter"]["Quirks"]["DevirtualiseMmio"] = self.check_mats_support(hardware.get("CPU Manufacturer"), hardware.get("Motherboard Chipset"))
if "AMD" in hardware.get("CPU Manufacturer") and not "TRX40" in hardware.get("Motherboard Chipset"):
config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware_report.get("Motherboard").get("Motherboard Chipset"))
config["Booter"]["Patch"] = self.add_booter_patch(smbios_model, macos_version)
config["Booter"]["Quirks"]["DevirtualiseMmio"] = self.check_mats_support(hardware_report.get("CPU").get("CPU Manufacturer"), hardware_report.get("Motherboard").get("Motherboard Chipset"))
if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") and not "TRX40" in hardware_report.get("Motherboard").get("Motherboard Chipset"):
config["Booter"]["Quirks"]["DevirtualiseMmio"] = False
config["Booter"]["Quirks"]["EnableWriteUnprotector"] = False if "AMD" in hardware.get("CPU Manufacturer") else not config["Booter"]["Quirks"]["DevirtualiseMmio"]
config["Booter"]["Quirks"]["ProtectUefiServices"] = "Z390" in hardware.get("Motherboard Chipset") or \
not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), start=10) is None
config["Booter"]["Quirks"]["EnableWriteUnprotector"] = False if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") else not config["Booter"]["Quirks"]["DevirtualiseMmio"]
config["Booter"]["Quirks"]["ProtectUefiServices"] = "Z390" in hardware_report.get("Motherboard").get("Motherboard Chipset") or \
not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=10) is None
config["Booter"]["Quirks"]["RebuildAppleMemoryMap"] = not config["Booter"]["Quirks"]["EnableWriteUnprotector"]
config["Booter"]["Quirks"]["ResizeAppleGpuBars"] = 0 if self.check_resizable_bar_support(
hardware.get("Motherboard Chipset"),
hardware.get("CPU Codename")
hardware_report.get("Motherboard").get("Motherboard Chipset"),
hardware_report.get("CPU").get("CPU Codename")
) else -1
config["Booter"]["Quirks"]["SetupVirtualMap"] = not (not self.utils.contains_any(chipset_data.AMDChipsets, hardware.get("Motherboard Chipset"), end=5) is None or \
"ASUS" in hardware.get("Motherboard Name") and self.is_intel_hedt_cpu(hardware.get("CPU Codename")) and config["Booter"]["Quirks"]["DevirtualiseMmio"])
config["Booter"]["Quirks"]["SetupVirtualMap"] = not (not self.utils.contains_any(chipset_data.AMDChipsets, hardware_report.get("Motherboard").get("Motherboard Chipset"), end=5) is None or \
"ASUS" in hardware_report.get("Motherboard").get("Motherboard Name") and self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")) and config["Booter"]["Quirks"]["DevirtualiseMmio"])
config["Booter"]["Quirks"]["SyncRuntimePermissions"] = config["Booter"]["Quirks"]["RebuildAppleMemoryMap"]
config["DeviceProperties"]["Add"] = self.deviceproperties(hardware.get("CPU Codename"), hardware.get("Intel MEI"), efi_option.get("iGPU Properties"))
config["DeviceProperties"]["Add"] = self.deviceproperties(
hardware_report.get("CPU").get("CPU Codename"),
next((device_props for device_name, device_props in hardware_report.get("System Devices").items() if "HECI" in device_name or "Management Engine Interface" in device_name), None), {})
config["Kernel"]["Add"] = []
config["Kernel"]["Block"] = self.block_kext_bundle(hardware.get("Network"), efi_option.get("macOS Version"))
config["Kernel"]["Block"] = self.block_kext_bundle(hardware_report.get("Network"), macos_version)
spoof_cpuid = self.spoof_cpuid(
hardware.get("Processor Name"),
hardware.get("CPU Codename"),
efi_option.get("macOS Version")
hardware_report.get("CPU").get("Processor Name"),
hardware_report.get("CPU").get("CPU Codename"),
macos_version
)
if spoof_cpuid:
config["Kernel"]["Emulate"]["Cpuid1Data"] = self.utils.hex_to_bytes("{}{}".format(spoof_cpuid, "0"*8*3))
config["Kernel"]["Emulate"]["Cpuid1Mask"] = self.utils.hex_to_bytes("{}{}".format("F"*8, "0"*8*3))
config["Kernel"]["Emulate"]["DummyPowerManagement"] = "AMD" in hardware.get("CPU Manufacturer") or \
self.is_low_end_intel_cpu(hardware.get("Processor Name"))
config["Kernel"]["Emulate"]["DummyPowerManagement"] = "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or \
self.is_low_end_intel_cpu(hardware_report.get("CPU").get("Processor Name"))
config["Kernel"]["Force"] = []
config["Kernel"]["Patch"] = self.load_kernel_patch(
hardware.get("Motherboard Chipset"),
hardware.get("CPU Manufacturer"),
hardware.get("CPU Codename"),
hardware["CPU Cores"],
hardware["Discrete GPU"].get("Manufacturer", "") or hardware["Integrated GPU"].get("Manufacturer", ""),
efi_option.get("Synchronize the TSC")
hardware_report.get("Motherboard").get("Motherboard Chipset"),
hardware_report.get("CPU").get("CPU Manufacturer"),
hardware_report.get("CPU").get("CPU Cores"),
list(hardware_report.get("GPU").items())[-1][-1].get("Manufacturer"),
kexts
)
config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=2) is None
config["Kernel"]["Quirks"]["AppleXcpmCfgLock"] = False if "AMD" in hardware.get("CPU Manufacturer") else not config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"]
config["Kernel"]["Quirks"]["AppleXcpmExtraMsrs"] = self.is_intel_hedt_cpu(hardware.get("CPU Codename")) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=4) is None
config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=2) is None
config["Kernel"]["Quirks"]["AppleXcpmCfgLock"] = False if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") else not config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"]
config["Kernel"]["Quirks"]["AppleXcpmExtraMsrs"] = self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=4) is None
config["Kernel"]["Quirks"]["CustomSMBIOSGuid"] = True
config["Kernel"]["Quirks"]["DisableIoMapper"] = not "AMD" in hardware.get("CPU Manufacturer")
config["Kernel"]["Quirks"]["DisableRtcChecksum"] = "ASUS" in hardware.get("Motherboard Name") or "HP" in hardware.get("Motherboard Name")
config["Kernel"]["Quirks"]["LapicKernelPanic"] = "HP" in hardware.get("Motherboard Name")
config["Kernel"]["Quirks"]["DisableIoMapper"] = not "AMD" in hardware_report.get("CPU").get("CPU Manufacturer")
config["Kernel"]["Quirks"]["DisableRtcChecksum"] = "ASUS" in hardware_report.get("Motherboard").get("Motherboard Name") or "HP" in hardware_report.get("Motherboard").get("Motherboard Name")
config["Kernel"]["Quirks"]["LapicKernelPanic"] = "HP" in hardware_report.get("Motherboard").get("Motherboard Name")
config["Kernel"]["Quirks"]["PanicNoKextDump"] = config["Kernel"]["Quirks"]["PowerTimeoutKernelPanic"] = True
config["Kernel"]["Quirks"]["ProvideCurrentCpuInfo"] = "AMD" in hardware.get("CPU Manufacturer") or \
not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), start=13) is None
config["Kernel"]["Quirks"]["ProvideCurrentCpuInfo"] = "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or \
not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=13) is None
config["Misc"]["BlessOverride"] = []
config["Misc"]["Boot"]["HideAuxiliary"] = False
@@ -324,46 +332,32 @@ class ConfigProdigy:
config["Misc"]["Entries"] = []
config["Misc"]["Security"]["AllowSetDefault"] = True
config["Misc"]["Security"]["ScanPolicy"] = 0
config["Misc"]["Security"]["SecureBootModel"] = "Default" if self.utils.parse_darwin_version("20.0.0") <= self.utils.parse_darwin_version(efi_option.get("macOS Version")) < self.utils.parse_darwin_version("23.0.0") else "Disabled"
config["Misc"]["Security"]["SecureBootModel"] = "Default" if self.utils.parse_darwin_version("20.0.0") <= self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("23.0.0") else "Disabled"
config["Misc"]["Security"]["Vault"] = "Optional"
config["Misc"]["Tools"] = []
if efi_option.get("Custom CPU Name"):
config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = 1
config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = hardware.get("Processor Name")
del config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["#INFO (prev-lang:kbd)"]
config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] = self.boot_args(
hardware.get("Motherboard Name"),
hardware.get("Platform"),
hardware.get("CPU Manufacturer"),
hardware.get("CPU Codename"),
hardware.get("CPU Cores"),
hardware.get("Discrete GPU").get("GPU Codename", ""),
hardware.get("Discrete GPU").get("Device ID", ""),
hardware.get("Integrated GPU Name"),
hardware.get("Codec ID"),
hardware.get("Touchpad Communication"),
", ".join(list(hardware.get("Unsupported Devices").keys())),
efi_option.get("Custom CPU Name"),
efi_option.get("macOS Version")
)
config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = self.utils.hex_to_bytes(self.csr_active_config(efi_option.get("macOS Version")))
config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] = self.boot_args(hardware_report, unsupported_devices, macos_version)
config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = self.utils.hex_to_bytes(self.csr_active_config(macos_version))
config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["prev-lang:kbd"] = "en:252"
if efi_option.get("Custom CPU Name"):
config["NVRAM"]["Delete"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"].extend(["revcpu", "revcpuname"])
config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"].append("csr-active-config")
config["PlatformInfo"]["Generic"].update(self.smbios.generate_smbios(efi_option.get("SMBIOS")))
if efi_option.get("Custom CPU Name"):
config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537 if int(hardware["CPU Cores"]) < 8 else 3841
config["PlatformInfo"]["Generic"].update(self.smbios.generate_smbios(smbios_model))
config["PlatformInfo"]["Generic"]["ROM"] = self.utils.hex_to_bytes(config["PlatformInfo"]["Generic"]["ROM"])
config["PlatformInfo"]["UpdateSMBIOSMode"] = "Custom"
config["UEFI"]["APFS"]["MinDate"] = config["UEFI"]["APFS"]["MinVersion"] = -1
config["UEFI"]["Drivers"] = self.load_drivers()
config["UEFI"]["Quirks"]["IgnoreInvalidFlexRatio"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=4) is None
config["UEFI"]["Quirks"]["IgnoreInvalidFlexRatio"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=4) is None
config["UEFI"]["Quirks"]["ReleaseUsbOwnership"] = True
config["UEFI"]["Quirks"]["UnblockFsConnect"] = "HP" in hardware.get("Motherboard Name")
config["UEFI"]["Quirks"]["UnblockFsConnect"] = "HP" in hardware_report.get("Motherboard").get("Motherboard Name")
config["UEFI"]["ReservedMemory"] = []
if not (" Core" in hardware_report.get("CPU").get("Processor Name") and \
self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=12)):
config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = 1
config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = hardware_report.get("CPU").get("Processor Name")
config["NVRAM"]["Delete"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"].extend(["revcpu", "revcpuname"])
config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537 if int(hardware_report.get("CPU").get("CPU Cores")) < 8 else 3841
return config

View File

@@ -1,4 +1,3 @@
from Scripts.datasets import cpu_data
from Scripts import config_prodigy
from Scripts import kext_maestro
from Scripts import utils
@@ -11,249 +10,7 @@ class builder:
self.config = config_prodigy.ConfigProdigy()
self.kext = kext_maestro.KextMaestro()
self.utils = utils.Utils()
self.intel_igpu_properties = {
"Ice Lake": {
"Laptop": {
"AAPL,ig-platform-id": "0000528A",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Comet Lake": {
"Desktop": {
"AAPL,ig-platform-idEx": "0300C89B",
"AAPL,ig-platform-id": "07009B3E",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"NUC": {
"AAPL,ig-platform-id": "07009B3E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "00009B3E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Coffee Lake": {
"Desktop": {
"AAPL,ig-platform-idEx": "0300913E",
"AAPL,ig-platform-id": "07009B3E"
},
"NUC": {
"AAPL,ig-platform-id": "07009B3E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "0900A53E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Whiskey Lake": {
"NUC": {
"AAPL,ig-platform-id": "07009B3E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "0900A53E",
"device-id": "9B3E0000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Amber Lake": {
"Laptop": {
"AAPL,ig-platform-id": "0000C087",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Kaby Lake": {
"Desktop": {
"AAPL,ig-platform-idEx": "03001259",
"AAPL,ig-platform-id": "00001259",
"device-id": "12590000"
},
"NUC": {
"AAPL,ig-platform-id": "00001659",
"device-id": "16590000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "00001B59",
"device-id": "1B590000",
"framebuffer-con1-alldata": "01050A00 00080000 87010000 02040A00 00080000 87010000 FF000000 01000000 20000000",
"framebuffer-con1-enable": "01000000",
"#framebuffer-con2-alldata": "01050A00 00080000 87010000 03060A00 00040000 87010000 FF000000 01000000 20000000",
"#framebuffer-con2-enable": "01000000",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Skylake": {
"Desktop": {
"AAPL,ig-platform-idEx": "01001219",
"AAPL,ig-platform-id": "00001219"
},
"NUC": {
"AAPL,ig-platform-id": "05003B19",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "00001619",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Broadwell": {
"Desktop": {
"AAPL,ig-platform-idEx": "07002216",
"AAPL,ig-platform-id": "07002216"
},
"NUC": {
"AAPL,ig-platform-id": "02001616",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
},
"Laptop": {
"AAPL,ig-platform-id": "06002616",
"framebuffer-fbmem": "00009000",
"framebuffer-stolenmem": "00003001"
}
},
"Haswell": {
"Desktop": {
"AAPL,ig-platform-idEx": "04001204",
"AAPL,ig-platform-id": "0300220D"
},
"NUC": {
"AAPL,ig-platform-id": "0300220D",
"device-id": "12040000",
"framebuffer-cursormem": "00009000"
},
"Laptop": {
"AAPL,ig-platform-id": "0600260A",
"device-id": "12040000",
"framebuffer-cursormem": "00009000"
}
},
"Ivy Bridge": {
"Desktop": {
"AAPL,ig-platform-idEx": "07006201",
"AAPL,ig-platform-id": "0A006601"
},
"Laptop": {
"AAPL,ig-platform-id": "03006601"
}
},
"Sandy Bridge": {
"Desktop": {
"AAPL,snb-platform-idEx": "00000500",
"AAPL,snb-platform-id": "10000300",
"device-id": "26010000"
},
"Laptop": {
"AAPL,snb-platform-id": "00000100"
}
}
}
def is_low_end_intel_cpu(self, processor_name):
return any(cpu_branding in processor_name for cpu_branding in ["Celeron", "Pentium"])
def check_igpu_compatibility(self, cpu_codename, macos_version):
return not (("Sandy Bridge" in cpu_codename and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("18.0.0")) or \
("Ivy Bridge" in cpu_codename and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.0.0")) or \
(("Haswell" in cpu_codename or "Broadwell" in cpu_codename) and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0")) or \
(("Skylake" in cpu_codename or "Kaby Lake" in cpu_codename) and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0")) or \
(("Amber Lake" in cpu_codename or "Whiskey Lake" in cpu_codename) and self.utils.parse_darwin_version(macos_version) == self.utils.parse_darwin_version("17.0.0")) or \
("Ice Lake" in cpu_codename and self.utils.parse_darwin_version("19.4.0") >= self.utils.parse_darwin_version(macos_version)))
def igpu_properties(self, platform, processor_name, gpu_codename, discrete_gpu, integrated_gpu_manufacturer, integrated_gpu_name, macos_version):
if "Skylake".lower() in gpu_codename.lower() and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0"):
gpu_codename = "Kaby Lake"
if "Kaby Lake-R".upper() in gpu_codename.upper() and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"):
gpu_codename = "Coffee Lake"
gpu_codename = self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename)
if not "Intel" in integrated_gpu_manufacturer or not integrated_gpu_name or self.is_low_end_intel_cpu(processor_name) or not self.check_igpu_compatibility(gpu_codename, macos_version) or not self.intel_igpu_properties.get(gpu_codename, True):
return {}
igpu_properties = self.intel_igpu_properties[gpu_codename][platform]
if "Desktop" in platform:
if discrete_gpu:
if "Sandy Bridge" in gpu_codename:
return {
"AAPL,snb-platform-id": igpu_properties["AAPL,snb-platform-idEx"],
"device-id": "02010000",
}
else:
return {
"AAPL,ig-platform-id": igpu_properties["AAPL,ig-platform-idEx"]
}
del igpu_properties["AAPL,ig-platform-idEx"]
if "Haswell" in gpu_codename and not "440" in integrated_gpu_name:
igpu_properties["device-id"] = "12040000"
elif "Skylake" in gpu_codename and "P530" in integrated_gpu_name:
igpu_properties["device-id"] = "12040000"
else:
if "Haswell" in gpu_codename and "5" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "0500260A"
del igpu_properties["device-id"]
elif "Broadwell" in gpu_codename and "56" in integrated_gpu_name:
igpu_properties["device-id"] = "26160000"
elif "Skylake" in gpu_codename:
if "NUC" in platform:
if "51" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "00001E19"
elif "52" in integrated_gpu_name or "53" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "02001619"
elif "54" in integrated_gpu_name or "55" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "02002619"
if "510" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "00001B19"
igpu_properties["device-id"] = "02190000"
elif "550" in integrated_gpu_name or "P530" in integrated_gpu_name:
igpu_properties["device-id"] = "16190000"
elif "Kaby Lake" in gpu_codename:
if "NUC" in platform:
if "15" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "00001E59"
elif "63" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "00001B59"
elif "40" in integrated_gpu_name or "65" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "02002659"
else:
if "UHD" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "0000C087"
igpu_properties["device-id"] = "16590000"
elif self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename, start=8, end=11):
if "NUC" in platform:
if "55" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "0000A53E"
del igpu_properties["device-id"]
else:
if "3" in integrated_gpu_name:
igpu_properties["AAPL,ig-platform-id"] = "0900A53E"
igpu_properties["hda-gfx"] = "onboard-1"
igpu_properties["framebuffer-patch-enable"] = "01000000"
return igpu_properties
def clean_up(self, config, efi_directory):
files_to_remove = []
@@ -264,13 +21,6 @@ class builder:
if not driver_path in driver_loaded:
files_to_remove.append(os.path.join(drivers_directory, driver_path))
kexts_directory = os.path.join(efi_directory, "EFI", "OC", "Kexts")
kext_list = self.utils.find_matching_paths(kexts_directory, extension_filter=".kext")
kext_loaded = [os.path.basename(kext.get("BundlePath")) for kext in config.get("Kernel").get("Add")]
for kext_path, type in kext_list:
if not os.path.basename(kext_path) in kext_loaded:
files_to_remove.append(os.path.join(kexts_directory, kext_path))
tools_directory = os.path.join(efi_directory, "EFI", "OC", "Tools")
tool_list = self.utils.find_matching_paths(tools_directory, extension_filter=".efi")
tool_loaded = [tool.get("Path") for tool in config.get("Misc").get("Tools")]
@@ -294,59 +44,19 @@ class builder:
print("")
self.utils.request_input()
def build_efi(self, hardware, unsupported_devices, smbios_model, macos_version, acpi_guru):
def build_efi(self, hardware_report, unsupported_devices, smbios_model, macos_version, acpi_guru, kext_maestro):
efi_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "Results")
self.utils.create_folder(efi_directory, remove_content=True)
forbidden_chars = r'[<>:"/\\|?*]'
self.utils.write_file(os.path.join(efi_directory, re.sub(forbidden_chars, '_', hardware.get("Motherboard").get("Motherboard Name")) + ".json"), hardware)
self.utils.write_file(os.path.join(efi_directory, re.sub(forbidden_chars, '_', hardware_report.get("Motherboard").get("Motherboard Name")) + ".json"), hardware_report)
if not os.path.exists(self.kext.ock_files_dir):
raise Exception("Directory '{}' does not exist.".format(self.kext.ock_files_dir))
source_efi_dir = os.path.join(self.kext.ock_files_dir, "OpenCore")
shutil.copytree(source_efi_dir, efi_directory, dirs_exist_ok=True)
hardware_shorc = {}
hardware_shorc["Motherboard Name"] = hardware["Motherboard"].get("Motherboard Name").upper()
hardware_shorc["Motherboard Chipset"] = hardware["Motherboard"].get("Motherboard Chipset").upper()
hardware_shorc["Platform"] = hardware["Motherboard"].get("Platform")
hardware_shorc["CPU Configuration"] = hardware["CPU"].get("CPU Configuration")
hardware_shorc["CPU Manufacturer"] = hardware["CPU"].get("CPU Manufacturer")
hardware_shorc["Processor Name"] = hardware["CPU"].get("Processor Name")
hardware_shorc["CPU Cores"] = hardware["CPU"].get("CPU Cores")
hardware_shorc["CPU Codename"] = hardware["CPU"].get("CPU Codename")
hardware_shorc["Instruction Set"] = hardware["CPU"].get("Instruction Set")
hardware_shorc["Integrated GPU"] = list(hardware.get("GPU").items())[-1][1] if "Integrated GPU" in list(hardware.get("GPU").items())[-1][1]["Device Type"] else {}
hardware_shorc["Integrated GPU Name"] = list(hardware.get("GPU").keys())[-1] if hardware_shorc["Integrated GPU"] else ""
hardware_shorc["Discrete GPU"] = list(hardware.get("GPU").items())[0][1].copy() if "Discrete GPU" in list(hardware.get("GPU").items())[0][1]["Device Type"] else {}
if hardware_shorc["Discrete GPU"]:
hardware_shorc["Discrete GPU"]["GPU Name"] = list(hardware.get("GPU").keys())[0]
hardware_shorc["Network"] = hardware.get("Network")
hardware_shorc["Bluetooth"] = [device_props.get("Device ID") for device_name, device_props in hardware.get("Bluetooth", {}).items()]
hardware_shorc["Codec ID"] = next((device_props.get("Codec ID") for device_name, device_props in hardware.get("Audio").items()), None)
hardware_shorc["SD Controller"] = hardware.get("SD Controller")
hardware_shorc["Input"] = hardware.get("Input")
input_devices = ", ".join(list(hardware_shorc.get("Input", {}).keys()))
hardware_shorc["Touchpad Communication"] = "None" if not "Laptop" in hardware_shorc.get("Platform") else "I2C" if "I2C" in input_devices else "PS2" if "PS2" in input_devices else "None"
hardware_shorc["Storage Controllers"] = hardware.get("Storage Controllers")
hardware_shorc["Intel MEI"] = hardware.get("Intel MEI")
hardware_shorc["Unsupported Devices"] = unsupported_devices
efi_option = {}
efi_option["macOS Version"] = macos_version
efi_option["Custom CPU Name"] = not (" Core" in hardware_shorc.get("Processor Name") and self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_shorc.get("CPU Codename"), end=12))
efi_option["Synchronize the TSC"] = "Laptop" in hardware_shorc["Platform"] and "ASUS" in hardware_shorc["Motherboard Name"] or "AMD" in hardware_shorc["Integrated GPU"].get("Manufacturer", "") or self.config.is_intel_hedt_cpu(hardware_shorc["CPU Codename"])
efi_option["iGPU Properties"] = self.igpu_properties(
hardware_shorc["Platform"],
hardware_shorc.get("Processor Name"),
hardware_shorc["Integrated GPU"].get("GPU Codename", ""),
hardware_shorc["Discrete GPU"],
hardware_shorc["Integrated GPU"].get("Manufacturer", ""),
hardware_shorc["Integrated GPU Name"],
efi_option.get("macOS Version"))
efi_option["SMBIOS"] = smbios_model
config_file = os.path.join(efi_directory, "EFI", "OC", "config.plist")
config_data = self.utils.read_file(config_file)
@@ -354,9 +64,9 @@ class builder:
if not config_data:
raise Exception("Error: The file {} does not exist.".format(config_file))
self.config.genarate(hardware_shorc, efi_option, config_data)
self.config.genarate(hardware_report, unsupported_devices, smbios_model, macos_version, kext_maestro.kexts, config_data)
acpi_guru.hardware_report = hardware
acpi_guru.hardware_report = hardware_report
acpi_guru.unsupported_devices = unsupported_devices
acpi_guru.acpi_directory = os.path.join(efi_directory, "EFI", "OC", "ACPI")
acpi_guru.smbios_model = smbios_model
@@ -379,40 +89,9 @@ class builder:
config_data["ACPI"]["Patch"] = acpi_guru.apply_acpi_patches(config_data["ACPI"]["Patch"])
kexts = self.kext.gathering_kexts(
hardware_shorc["Motherboard Name"],
hardware_shorc["Platform"],
hardware_shorc["CPU Configuration"],
hardware_shorc["CPU Manufacturer"],
hardware_shorc["CPU Codename"],
hardware_shorc["CPU Cores"],
hardware_shorc["Instruction Set"],
hardware_shorc["Discrete GPU"].get("GPU Codename", ""),
hardware_shorc["Integrated GPU"],
hardware_shorc.get("Network"),
hardware_shorc.get("Bluetooth"),
hardware_shorc.get("Codec ID"),
hardware_shorc["Input"],
hardware_shorc.get("SD Controller"),
hardware_shorc.get("Storage Controllers"),
hardware.get("USB Controllers"),
efi_option.get("SMBIOS"),
efi_option.get("Custom CPU Name"),
efi_option.get("Synchronize the TSC"),
acpi_guru.patches,
efi_option.get("macOS Version")
)
kexts_directory = os.path.join(efi_directory, "EFI", "OC", "Kexts")
self.kext.install_kexts_to_efi(kexts, efi_option.get("macOS Version"), kexts_directory)
config_data["Kernel"]["Add"] = self.kext.load_kexts(
kexts,
hardware_shorc["Motherboard Name"],
hardware_shorc["Platform"],
hardware_shorc["CPU Manufacturer"],
hardware_shorc["Discrete GPU"].get("GPU Codename", ""),
efi_option["macOS Version"]
)
kext_maestro.install_kexts_to_efi(macos_version, kexts_directory)
config_data["Kernel"]["Add"] = kext_maestro.load_kexts(macos_version, kexts_directory)
self.utils.write_file(config_file, config_data)

File diff suppressed because it is too large Load Diff