From 8884897dff0f4393b984be7dda18fbb246574e89 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 10:22:32 -0400 Subject: [PATCH 1/7] Add probing for topcase --- resources/build/misc.py | 52 ++++++++++++++++++++++++++------------- resources/device_probe.py | 27 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/resources/build/misc.py b/resources/build/misc.py index 917bc4409..9c7225ffb 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -36,7 +36,7 @@ class BuildMiscellaneous: self._feature_unlock_handling() self._restrict_events_handling() self._firewire_handling() - self._trackpad_handling() + self._topcase_handling() self._thunderbolt_handling() self._webcam_handling() self._usb_handling() @@ -170,25 +170,43 @@ class BuildMiscellaneous: support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("IOFireWireFamily.kext/Contents/PlugIns/AppleFWOHCI.kext")["Enabled"] = True - def _trackpad_handling(self) -> None: + def _topcase_handling(self) -> None: """ - Trackpad Handler + USB Top Case Handler """ - # Pre-Force Touch trackpad & keyboard support for macOS Ventura - if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.CPUGen.skylake.value: - if self.model.startswith("MacBook"): - # These units got force touch & the new keyboard mapping early, so ignore them - if self.model not in ["MacBookPro11,4", "MacBookPro11,5", "MacBookPro12,1", "MacBook8,1"]: - support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path) - support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True - support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True - support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True - support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path) - # Legacy Trackpad & Keyboard support - if self.model in ["MacBook4,1", "MacBook5,2"]: - support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path) - support.BuildSupport(self.model, self.constants, self.config).enable_kext("LegacyKeyboardInjector.kext", self.constants.legacy_keyboard, self.constants.legacy_keyboard_path) # Inject legacy personalities into AppleUSBTCKeyboard and AppleUSBTCKeyEventDriver + #On-device probing + if not self.constants.custom_model and self.computer.keyboard_type and self.computer.trackpad_type: + + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path) + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True + + if self.computer.keyboard_type == "Legacy": + support.BuildSupport(self.model, self.constants, self.config).enable_kext("LegacyKeyboardInjector.kext", self.constants.legacy_keyboard, self.constants.legacy_keyboard_path) + if self.computer.trackpad_type == "Legacy": + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path) + elif self.computer.trackpad_type == "Modern": + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path) + + #Predefined fallback + else: + # Multi Touch Top Case support for macOS Ventura+ + if smbios_data.smbios_dictionary[self.model]["CPU Generation"] < cpu_data.CPUGen.skylake.value: + if self.model.startswith("MacBook"): + # These units got the Force Touch top case, so ignore them + if self.model not in ["MacBookPro11,4", "MacBookPro11,5", "MacBookPro12,1", "MacBook8,1"]: + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path) + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True + support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBMultitouch.kext", self.constants.multitouch_version, self.constants.multitouch_path) + + # Two-finger Top Case support for macOS High Sierra+ + if self.model in ["MacBook4,1", "MacBook5,2"]: + support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path) # Also requires AppleUSBTopCase.kext + support.BuildSupport(self.model, self.constants, self.config).enable_kext("LegacyKeyboardInjector.kext", self.constants.legacy_keyboard, self.constants.legacy_keyboard_path) # Inject legacy personalities into AppleUSBTCKeyboard and AppleUSBTCKeyEventDriver def _thunderbolt_handling(self) -> None: diff --git a/resources/device_probe.py b/resources/device_probe.py index f82bd0977..0aad4059a 100644 --- a/resources/device_probe.py +++ b/resources/device_probe.py @@ -595,6 +595,8 @@ class Computer: opencore_version: Optional[str] = None opencore_path: Optional[str] = None bluetooth_chipset: Optional[str] = None + keyboard_type: Optional[str] = None + trackpad_type: Optional[str] = None ambient_light_sensor: Optional[bool] = False third_party_sata_ssd: Optional[bool] = False secure_boot_model: Optional[str] = None @@ -880,6 +882,31 @@ class Computer: elif any("Bluetooth" in usb_device.product_name for usb_device in self.usb_devices): self.bluetooth_chipset = "Generic" + def keyboard_probe(self): + if not self.usb_devices: + return + + legacy_ids = ["526","527","528","532","533","534","525","536","537","538","539","540","553","554","555"] # These keyboards were stripped of their personalities after being dropped + modern_ids = ["547","548","549","560","561","562","566","567","568","575","576","577","578","579","580","581","582","583","585","586","587","601","602","603","610","611","612","588","589","590","594","595","596"] #These keyboards remained in AppleUSBTCKeyboard until the kext was removed + + if any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in legacy_ids for usb_device in self.usb_devices): + self.keyboard_type = "Legacy" + elif any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in modern_ids for usb_device in self.usb_devices): + self.keyboard_type = "Modern" + + def trackpad_probe(self): + if not self.usb_devices: + return + + legacy_ids = ["526","527","528","778","779","532","533","534","535","536","537","538","539","540","553","554","555"] # Overlap with keyboard IDs as some units have unified USB topcase devices + modern_ids = ["547","548","549","560","561","562","566","567","568","575","576","577","578","579","580","581","582","583","585","586","587","601","602","603","610","611","612","588","589","590","594","595","596"] + + if any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in legacy_ids for usb_device in self.usb_devices): + self.trackpad_type = "Legacy" + elif any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in modern_ids for usb_device in self.usb_devices): + self.trackpad_type = "Modern" + + def sata_disk_probe(self): # Get all SATA Controllers/Disks from 'system_profiler SPSerialATADataType' # Determine whether SATA SSD is present and Apple-made From 5f3437c88e9bee38507174451c21adb60294bb02 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 10:52:01 -0400 Subject: [PATCH 2/7] Fix --- resources/device_probe.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/resources/device_probe.py b/resources/device_probe.py index 0aad4059a..99a87c65c 100644 --- a/resources/device_probe.py +++ b/resources/device_probe.py @@ -622,6 +622,8 @@ class Computer: computer.usb_device_probe() computer.cpu_probe() computer.bluetooth_probe() + computer.keyboard_probe() + computer.trackpad_probe() computer.ambient_light_sensor_probe() computer.sata_disk_probe() computer.oclp_sys_patch_probe() @@ -886,25 +888,27 @@ class Computer: if not self.usb_devices: return - legacy_ids = ["526","527","528","532","533","534","525","536","537","538","539","540","553","554","555"] # These keyboards were stripped of their personalities after being dropped - modern_ids = ["547","548","549","560","561","562","566","567","568","575","576","577","578","579","580","581","582","583","585","586","587","601","602","603","610","611","612","588","589","590","594","595","596"] #These keyboards remained in AppleUSBTCKeyboard until the kext was removed + legacy_ids = [526,527,528,532,533,534,525,536,537,538,539,540,553,554,555] # These keyboards were stripped of their personalities after being dropped + modern_ids = [547,548,549,560,561,562,566,567,568,575,576,577,578,579,580,581,582,583,585,586,587,601,602,603,610,611,612,588,589,590,594,595,596] #These keyboards remained in AppleUSBTCKeyboard until the kext was removed - if any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in legacy_ids for usb_device in self.usb_devices): - self.keyboard_type = "Legacy" - elif any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in modern_ids for usb_device in self.usb_devices): - self.keyboard_type = "Modern" + for usb_device in self.usb_devices: + if usb_device.device_id in legacy_ids and usb_device.vendor_id == 1452: + self.keyboard_type = "Legacy" + elif usb_device.device_id in modern_ids and usb_device.vendor_id == 1452: + self.keyboard_type = "Modern" def trackpad_probe(self): if not self.usb_devices: return - legacy_ids = ["526","527","528","778","779","532","533","534","535","536","537","538","539","540","553","554","555"] # Overlap with keyboard IDs as some units have unified USB topcase devices - modern_ids = ["547","548","549","560","561","562","566","567","568","575","576","577","578","579","580","581","582","583","585","586","587","601","602","603","610","611","612","588","589","590","594","595","596"] + legacy_ids = [526,527,528,778,779,532,533,534,535,536,537,538,539,540,553,554,555] # Overlap with keyboard IDs as some units have unified USB topcase devices + modern_ids = [547,548,549,560,561,562,566,567,568,575,576,577,578,579,580,581,582,583,585,586,587,601,602,603,610,611,612,588,589,590,594,595,596] - if any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in legacy_ids for usb_device in self.usb_devices): - self.trackpad_type = "Legacy" - elif any(value in usb_device.product_name and usb_device.vendor_id == "1452" for value in modern_ids for usb_device in self.usb_devices): - self.trackpad_type = "Modern" + for usb_device in self.usb_devices: + if usb_device.device_id in legacy_ids and usb_device.vendor_id == 1452: + self.trackpad_type = "Legacy" + elif usb_device.device_id in modern_ids and usb_device.vendor_id == 1452: + self.trackpad_type = "Modern" def sata_disk_probe(self): From 090167efb2724384d9e59078b99fa1158a2241c0 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 10:56:27 -0400 Subject: [PATCH 3/7] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3836f30f0..19b50fb70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ - device_probe.py: - Add USB device parsing via `IOUSBDevice` class - Streamline Bluetooth device detection + - Add Probing for Top Case hardware + - Improves handling for edge-case altered hardware scenarios (i.e. MacBookPro4,1 with MacBookPro3,1 topcase) - Increment Binaries: - PatcherSupportPkg 1.1.4 - release From 2905f88c91e67b84d8cd7a46e83dd46748a5f069 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 10:56:38 -0400 Subject: [PATCH 4/7] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19b50fb70..0b47f4e22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - Add USB device parsing via `IOUSBDevice` class - Streamline Bluetooth device detection - Add Probing for Top Case hardware - - Improves handling for edge-case altered hardware scenarios (i.e. MacBookPro4,1 with MacBookPro3,1 topcase) + - Improves handling for altered hardware scenarios (i.e. MacBookPro4,1 with MacBookPro3,1 topcase) - Increment Binaries: - PatcherSupportPkg 1.1.4 - release From 62cb8edd885d524b4bfbd65f4612d7c6020f57a2 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 10:57:07 -0400 Subject: [PATCH 5/7] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b47f4e22..3b0bd0133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - device_probe.py: - Add USB device parsing via `IOUSBDevice` class - Streamline Bluetooth device detection - - Add Probing for Top Case hardware + - Add Probing for Top Case hardware (Jazzzny) - Improves handling for altered hardware scenarios (i.e. MacBookPro4,1 with MacBookPro3,1 topcase) - Increment Binaries: - PatcherSupportPkg 1.1.4 - release From c476f8e9370e480d06f91381bdb957e2cef4333d Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 12:44:29 -0400 Subject: [PATCH 6/7] Requested changes --- data/usb_data.py | 111 ++++++++++++++++++++++++++++++++++++++ resources/device_probe.py | 36 +++++-------- 2 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 data/usb_data.py diff --git a/data/usb_data.py b/data/usb_data.py new file mode 100644 index 000000000..2ffb7f194 --- /dev/null +++ b/data/usb_data.py @@ -0,0 +1,111 @@ +class AppleIDs: + # All top case devices use Vendor ID 05ac + Modern_AppleUSBTCKeyboard = [ + 0x223, + 0x224, + 0x225, + 0x230, + 0x231, + 0x232, + 0x236, + 0x237, + 0x238, + 0x23f, + 0x240, + 0x241, + 0x242, + 0x243, + 0x244, + 0x245, + 0x246, + 0x247, + 0x249, + 0x24a, + 0x24b, + 0x259, + 0x25a, + 0x25b, + 0x262, + 0x263, + 0x264, + 0x24c, + 0x24d, + 0x24e, + 0x252, + 0x253, + 0x254 + ] + + Legacy_AppleUSBTCKeyboard = [ + 0x20e, + 0x20f, + 0x210, + 0x214, + 0x215, + 0x216, + 0x20d, + 0x218, + 0x219, + 0x21a, + 0x21b, + 0x21c, + 0x229, + 0x22a, + 0x22b + ] + + AppleUSBTrackpad = [ + 0x20e, + 0x20f, + 0x210, + 0x30a, + 0x30b, + 0x214, + 0x215, + 0x216, + 0x217, + 0x218, + 0x219, + 0x21a, + 0x21b, + 0x21c, + 0x229, + 0x22a, + 0x22b + ] + + AppleUSBMultiTouch = [ + 0x223, + 0x224, + 0x225, + 0x230, + 0x231, + 0x232, + 0x236, + 0x237, + 0x238, + 0x23f, + 0x240, + 0x241, + 0x242, + 0x243, + 0x244, + 0x245, + 0x246, + 0x247, + 0x249, + 0x24a, + 0x24b, + 0x259, + 0x25a, + 0x25b, + 0x262, + 0x263, + 0x264, + 0x24c, + 0x24d, + 0x24e, + 0x252, + 0x253, + 0x254 + ] \ No newline at end of file diff --git a/resources/device_probe.py b/resources/device_probe.py index 99a87c65c..f21479d92 100644 --- a/resources/device_probe.py +++ b/resources/device_probe.py @@ -12,7 +12,7 @@ from dataclasses import dataclass, field from typing import Any, ClassVar, Optional, Type, Union from resources import utilities, ioreg -from data import pci_data +from data import pci_data, usb_data @dataclass @@ -595,7 +595,7 @@ class Computer: opencore_version: Optional[str] = None opencore_path: Optional[str] = None bluetooth_chipset: Optional[str] = None - keyboard_type: Optional[str] = None + internal_keyboard_type: Optional[str] = None trackpad_type: Optional[str] = None ambient_light_sensor: Optional[bool] = False third_party_sata_ssd: Optional[bool] = False @@ -622,8 +622,7 @@ class Computer: computer.usb_device_probe() computer.cpu_probe() computer.bluetooth_probe() - computer.keyboard_probe() - computer.trackpad_probe() + computer.topcase_probe() computer.ambient_light_sensor_probe() computer.sata_disk_probe() computer.oclp_sys_patch_probe() @@ -884,33 +883,26 @@ class Computer: elif any("Bluetooth" in usb_device.product_name for usb_device in self.usb_devices): self.bluetooth_chipset = "Generic" - def keyboard_probe(self): + def topcase_probe(self): if not self.usb_devices: return - legacy_ids = [526,527,528,532,533,534,525,536,537,538,539,540,553,554,555] # These keyboards were stripped of their personalities after being dropped - modern_ids = [547,548,549,560,561,562,566,567,568,575,576,577,578,579,580,581,582,583,585,586,587,601,602,603,610,611,612,588,589,590,594,595,596] #These keyboards remained in AppleUSBTCKeyboard until the kext was removed - for usb_device in self.usb_devices: - if usb_device.device_id in legacy_ids and usb_device.vendor_id == 1452: - self.keyboard_type = "Legacy" - elif usb_device.device_id in modern_ids and usb_device.vendor_id == 1452: - self.keyboard_type = "Modern" + if self.internal_keyboard_type and self.trackpad_type: + break + if usb_device.vendor_id != 0x5ac: + continue - def trackpad_probe(self): - if not self.usb_devices: - return - - legacy_ids = [526,527,528,778,779,532,533,534,535,536,537,538,539,540,553,554,555] # Overlap with keyboard IDs as some units have unified USB topcase devices - modern_ids = [547,548,549,560,561,562,566,567,568,575,576,577,578,579,580,581,582,583,585,586,587,601,602,603,610,611,612,588,589,590,594,595,596] + if usb_device.device_id in usb_data.AppleIDs.Legacy_AppleUSBTCKeyboard: + self.internal_keyboard_type = "Legacy" + elif usb_device.device_id in usb_data.AppleIDs.Modern_AppleUSBTCKeyboard: + self.internal_keyboard_type = "Modern" - for usb_device in self.usb_devices: - if usb_device.device_id in legacy_ids and usb_device.vendor_id == 1452: + if usb_device.device_id in usb_data.AppleIDs.AppleUSBTrackpad: self.trackpad_type = "Legacy" - elif usb_device.device_id in modern_ids and usb_device.vendor_id == 1452: + elif usb_device.device_id in usb_data.AppleIDs.AppleUSBMultiTouch: self.trackpad_type = "Modern" - def sata_disk_probe(self): # Get all SATA Controllers/Disks from 'system_profiler SPSerialATADataType' # Determine whether SATA SSD is present and Apple-made From 78545422c03e4a86019e14f6f4daabab02538114 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Sat, 24 Jun 2023 12:56:06 -0400 Subject: [PATCH 7/7] Fix --- resources/build/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/build/misc.py b/resources/build/misc.py index 9c7225ffb..44ef55322 100644 --- a/resources/build/misc.py +++ b/resources/build/misc.py @@ -176,14 +176,14 @@ class BuildMiscellaneous: """ #On-device probing - if not self.constants.custom_model and self.computer.keyboard_type and self.computer.trackpad_type: + if not self.constants.custom_model and self.computer.internal_keyboard_type and self.computer.trackpad_type: support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTopCase.kext", self.constants.topcase_version, self.constants.top_case_path) support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCButtons.kext")["Enabled"] = True support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext")["Enabled"] = True support.BuildSupport(self.model, self.constants, self.config).get_kext_by_bundle_path("AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyEventDriver.kext")["Enabled"] = True - if self.computer.keyboard_type == "Legacy": + if self.computer.internal_keyboard_type == "Legacy": support.BuildSupport(self.model, self.constants, self.config).enable_kext("LegacyKeyboardInjector.kext", self.constants.legacy_keyboard, self.constants.legacy_keyboard_path) if self.computer.trackpad_type == "Legacy": support.BuildSupport(self.model, self.constants, self.config).enable_kext("AppleUSBTrackpad.kext", self.constants.apple_trackpad, self.constants.apple_trackpad_path)