Add customizable SMBIOS model selection for user configuration

This commit is contained in:
Hoang Hong Quan
2024-09-28 09:02:54 +07:00
parent ab190f5f4e
commit 1efe59a82a
4 changed files with 170 additions and 105 deletions

View File

@@ -330,7 +330,7 @@ class ConfigProdigy:
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(efi_option.get("SMBIOS")))
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"]["ROM"] = self.utils.hex_to_bytes(config["PlatformInfo"]["Generic"]["ROM"])

View File

@@ -257,85 +257,6 @@ class builder:
igpu_properties["framebuffer-patch-enable"] = "01000000"
return igpu_properties
def system_product_info(self, platform, cpu_manufacturer, processor_name, cpu_codename, cpu_cores, discrete_gpu, igpu_props, macos_version):
product_name = "iMacPro1,1" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("20.0.0") or self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=12) else "MacPro7,1"
if "AMD" in cpu_manufacturer and not discrete_gpu:
product_name = "MacBookPro16,3" if "Laptop" in platform else "iMacPro1,1"
if igpu_props:
if "Kaby Lake-R".lower() in cpu_codename.lower() and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"):
cpu_codename = "Coffee Lake"
if "Sandy Bridge" in cpu_codename:
if "Desktop" in platform:
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("18.0.0"):
product_name = "iMac12,2"
else:
product_name = "MacPro6,1"
elif "NUC" in platform:
product_name = "Macmini5,1" if int(cpu_cores) < 4 else "Macmini5,3"
else:
product_name = "MacBookPro8,1" if int(cpu_cores) < 4 else "MacBookPro8,2"
elif "Ivy Bridge" in cpu_codename:
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("21.0.0"):
if "Desktop" in platform:
product_name = "iMac14,4" if not discrete_gpu else "iMac15,1"
elif "NUC" in platform:
product_name = "Macmini7,1"
else:
product_name = "MacBookPro11,1" if int(cpu_cores) < 4 else "MacBookPro11,5"
elif self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("20.0.0"):
if "Desktop" in platform:
product_name = "iMac13,1" if not discrete_gpu else "iMac13,2"
elif "NUC" in platform:
product_name = "Macmini6,1" if int(cpu_cores) < 4 else "Macmini6,2"
else:
product_name = "MacBookPro10,2" if int(cpu_cores) < 4 else "MacBookPro10,1"
else:
product_name = "MacPro6,1"
elif "Haswell" in cpu_codename:
if "Desktop" in platform:
product_name = "iMac14,4" if not discrete_gpu else "iMac15,1"
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("22.0.0"):
product_name = "iMac16,2" if not discrete_gpu else "iMac17,1"
elif "NUC" in platform:
product_name = "Macmini7,1"
else:
product_name = "MacBookPro11,1" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("21.0.0") and int(cpu_cores) < 4 else "MacBookPro11,5"
elif "Broadwell" in cpu_codename:
if "Desktop" in platform:
product_name = "iMac16,2" if not discrete_gpu else "iMac17,1"
elif "NUC" in platform:
product_name = "iMac16,1"
else:
product_name = "MacBookPro12,1" if int(cpu_cores) < 4 else "MacBookPro11,5"
elif "Skylake" in cpu_codename:
product_name = "iMac17,1"
if "Laptop" in platform:
product_name = "MacBookPro13,1" if int(cpu_cores) < 4 else "MacBookPro13,3"
elif self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=8, end=11):
product_name = "Macmini8,1"
if "Desktop" in platform:
product_name = "iMac18,3" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("18.0.0") else "iMac19,1"
if "Comet Lake" in cpu_codename:
product_name = "iMac20,1" if int(cpu_cores) < 10 else "iMac20,2"
elif "Laptop" in platform:
if "-8" in processor_name:
product_name = "MacBookPro15,2" if int(cpu_cores) < 6 else "MacBookPro15,3"
else:
product_name = "MacBookPro16,3" if int(cpu_cores) < 6 else "MacBookPro16,1"
elif "Kaby Lake" in cpu_codename:
product_name = "iMac18,1" if not discrete_gpu else "iMac18,3"
if "Laptop" in platform:
product_name = "MacBookPro14,1" if int(cpu_cores) < 4 else "MacBookPro14,3"
elif "Amber Lake" in cpu_codename:
product_name = "MacBookAir8,1"
elif "Ice Lake" in cpu_codename:
product_name = "MacBookAir9,1" if int(cpu_cores) < 4 else "MacBookPro16,2"
return product_name
def clean_up(self, config, efi_directory):
files_to_remove = []
@@ -376,7 +297,7 @@ class builder:
print("")
self.utils.request_input()
def build_efi(self, hardware, unsupported_devices, macos_version):
def build_efi(self, hardware, unsupported_devices, smbios_model, macos_version):
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)
@@ -427,15 +348,7 @@ class builder:
hardware_shorc["Integrated GPU"].get("Manufacturer", ""),
hardware_shorc["Integrated GPU Name"],
efi_option.get("macOS Version"))
efi_option["SMBIOS"] = self.system_product_info(
hardware_shorc["Platform"],
hardware_shorc["CPU Manufacturer"],
hardware_shorc.get("Processor Name"),
hardware_shorc["CPU Codename"],
hardware_shorc["CPU Cores"],
hardware_shorc["Discrete GPU"],
efi_option["iGPU Properties"],
efi_option.get("macOS Version"))
efi_option["SMBIOS"] = smbios_model
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"

View File

@@ -1,8 +1,9 @@
from Scripts.datasets import cpu_data
from Scripts.datasets.mac_model_data import mac_devices
from Scripts import gathering_files
from Scripts import run
from Scripts import utils
import os
import subprocess
import uuid
import random
@@ -35,13 +36,13 @@ class SMBIOS:
random_mac = ''.join([format(random.randint(0, 255), '02X') for _ in range(6)])
return random_mac
def generate(self, product_name):
def generate_smbios(self, smbios_model):
macserial = self.check_macserial()
random_mac_address = self.generate_random_mac()
output = self.run({
"args":[macserial, "-g", "--model", product_name]
"args":[macserial, "-g", "--model", smbios_model]
})
if output[-1] != 0 or not " | " in output[0]:
@@ -52,7 +53,150 @@ class SMBIOS:
return {
"MLB": "A" + "0"*15 + "Z" if not serial else serial[-1],
"ROM": random_mac_address,
"SystemProductName": product_name,
"SystemProductName": smbios_model,
"SystemSerialNumber": "A" + "0"*10 + "9" if not serial else serial[0],
"SystemUUID": str(uuid.uuid4()).upper(),
}
}
def select_smbios_model(self, hardware_report, macos_version):
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("20.0.0") or \
self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=12):
smbios_model = "iMacPro1,1"
else:
smbios_model = "MacPro7,1"
if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") and \
"Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type"):
smbios_model = "MacBookPro16,3" if "Laptop" in hardware_report.get("Motherboard").get("Platform") else "iMacPro1,1"
if "Intel" in list(hardware_report.get("GPU").items())[0][-1].get("Manufacturer") and \
"Integrated GPU" in list(hardware_report.get("GPU").items())[0][-1].get("Device Type"):
if "Kaby Lake-R".lower() in hardware_report.get("CPU").get("CPU Codename").lower() and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"):
hardware_report["CPU"]["CPU Codename"] = "Coffee Lake"
if "Sandy Bridge" in hardware_report.get("CPU").get("CPU Codename"):
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("18.0.0"):
smbios_model = "iMac12,2"
else:
smbios_model = "MacPro6,1"
elif "NUC" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "Macmini5,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "Macmini5,3"
else:
smbios_model = "MacBookPro8,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro8,2"
elif "Ivy Bridge" in hardware_report.get("CPU").get("CPU Codename"):
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("21.0.0"):
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac14,4" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac15,1"
elif "NUC" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "Macmini7,1"
else:
smbios_model = "MacBookPro11,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro11,5"
elif self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("20.0.0"):
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac13,1" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac13,2"
elif "NUC" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "Macmini6,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "Macmini6,2"
else:
smbios_model = "MacBookPro10,2" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro10,1"
else:
smbios_model = "MacPro6,1"
elif "Haswell" in hardware_report.get("CPU").get("CPU Codename"):
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac14,4" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac15,1"
if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("22.0.0"):
smbios_model = "iMac16,2" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac17,1"
elif "NUC" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "Macmini7,1"
else:
smbios_model = "MacBookPro11,1" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("21.0.0") and int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro11,5"
elif "Broadwell" in hardware_report.get("CPU").get("CPU Codename"):
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac16,2" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac17,1"
elif "NUC" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac16,1"
else:
smbios_model = "MacBookPro12,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro11,5"
elif "Skylake" in hardware_report.get("CPU").get("CPU Codename"):
smbios_model = "iMac17,1"
if "Laptop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "MacBookPro13,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro13,3"
elif self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=8, end=11):
smbios_model = "Macmini8,1"
if "Desktop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "iMac18,3" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("18.0.0") else "iMac19,1"
if "Comet Lake" in hardware_report.get("CPU").get("CPU Codename"):
smbios_model = "iMac20,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 10 else "iMac20,2"
elif "Laptop" in hardware_report.get("Motherboard").get("Platform"):
if "-8" in hardware_report.get("CPU").get("Processor Name"):
smbios_model = "MacBookPro15,2" if int(hardware_report.get("CPU").get("CPU Cores")) < 6 else "MacBookPro15,3"
else:
smbios_model = "MacBookPro16,3" if int(hardware_report.get("CPU").get("CPU Cores")) < 6 else "MacBookPro16,1"
elif "Kaby Lake" in hardware_report.get("CPU").get("CPU Codename"):
smbios_model = "iMac18,1" if "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type") else "iMac18,3"
if "Laptop" in hardware_report.get("Motherboard").get("Platform"):
smbios_model = "MacBookPro14,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro14,3"
elif "Amber Lake" in hardware_report.get("CPU").get("CPU Codename"):
smbios_model = "MacBookAir8,1"
elif "Ice Lake" in hardware_report.get("CPU").get("CPU Codename"):
smbios_model = "MacBookAir9,1" if int(hardware_report.get("CPU").get("CPU Cores")) < 4 else "MacBookPro16,2"
return smbios_model
def customize_smbios_model(self, hardware_report, selected_smbios_model, macos_version):
current_category = None
default_smbios_model = self.select_smbios_model(hardware_report, macos_version)
while True:
contents = []
contents.append("")
contents.append("List of available SMBIOS:")
for index, device in enumerate(mac_devices, start=1):
category = ""
for char in device.name:
if char.isdigit():
break
category += char
if category != current_category:
current_category = category
category_header = f"Category: {current_category if current_category else "Uncategorized"}"
contents.append(f"\n{category_header}\n" + "=" * len(category_header))
line = "{:2}. {:15} - {:10} {:20}{}".format(index, device.name, device.cpu, "({})".format(device.cpu_generation), "" if not device.discrete_gpu else " - {}".format(device.discrete_gpu))
if not self.utils.parse_darwin_version(device.initial_support) <= self.utils.parse_darwin_version(macos_version) <= self.utils.parse_darwin_version(device.last_supported_version):
line = "\033[90m{}\033[0m".format(line)
contents.append(line)
contents.append("")
contents.append("Current SMBIOS: {}".format(selected_smbios_model))
contents.append("\033[1;36m")
contents.append("Note:")
contents.append("- Lines in gray indicate mac models that are not supported by the current macOS version ({}).".format(macos_version))
contents.append("- You can select mac model by entering their index or name.")
contents.append("\033[0m")
if selected_smbios_model != default_smbios_model:
contents.append("R. Restore default SMBIOS model ({})".format(default_smbios_model))
contents.append("")
contents.append("B. Back")
contents.append("Q. Quit")
contents.append("")
content = "\n".join(contents)
self.utils.adjust_window_size(content)
self.utils.head("Customize SMBIOS Model", resize=False)
print(content)
option = self.utils.request_input("Select your option: ")
if option.lower() == "q":
self.utils.exit_program()
if option.lower() == "b":
return selected_smbios_model
if option.lower() == "r" and selected_smbios_model != default_smbios_model:
return default_smbios_model
if option.strip().isdigit():
index = int(option) - 1
if index >= 0 and index < len(mac_devices):
return mac_devices[index].name
else:
for device in mac_devices:
if option.lower() == device.name.lower():
return device.name