Run a virtual iPhone on an Apple Silicon Mac.
Swift
Remove the haptics node from every guest, not only iPads
Jackyfa50d48a1826
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 60dfb872..d0587379 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -28,10 +28,12 @@> M-series board keeps Stage Manager (no `disable-chamois`) and the iPad (A16)> has no `medusa-overlay-app-capability`: `devicetree-cfw-ipad_artwork`,> `devicetree-cfw-ipad_product`, `devicetree-cfw-ipad_buttons`,-> `devicetree-cfw-ipad_identity`, (2026-10-02) `devicetree-cfw-ipad_audio`,-> which takes the board's `/product/audio` node, and (2026-10-03)-> `devicetree-cfw-ipad_haptics`, which removes `/product/haptics` where the-> board has none. They are written to a second device tree,+> `devicetree-cfw-ipad_identity` and (2026-10-02) `devicetree-cfw-ipad_audio`,+> which takes the board's `/product/audio` node. (`/product/haptics`, which no+> iPad tree has, is not one of them: since 2026-10-03+> `devicetree-cfw-product_haptics_node` removes it from every guest's tree,+> iPhone and iPad alike — see "Why the haptics node goes" below.) They are+> written to a second device tree,> `Firmware/all_flash/DeviceTree.vphone600ap.guest.im4p`, which `fw prepare`> copies from the vphone600 one and the hybrid manifest names as `DeviceTree`;> `RestoreDeviceTree` keeps pointing at the original, so restore still boots@@ -2225,30 +2227,40 @@ virtio sound device with a host output sink. Two faults; the full reveal is| `system-virtiosound-cfw-hal_plugin` (new) | `/System/Library/Audio/Plug-Ins/HAL/VPhoneVirtIOSound.driver`, `cfw install` and `cfw update-environment` | Installs the CoreAudio HAL plugin for `AppleVirtIOSound`, built from `VPhoneGuestComponents/VirtIOSound`. || `devicetree-cfw-ipad_audio` (new) | An iPad guest's installed DeviceTree, `fw patch` | Replaces `/product/audio` with the board tree's node (`DeviceTreePatcher.presentBoardAudio`), all properties as the board has them except its `AAPL,phandle`. || `preboot-cfw-devicetree_board_audio` (new) | Restored Preboot `devicetree.img4`, `cfw install` and `cfw update-environment` | The same replacement for an iPad VM patched before it (`vphone-cli cfw patch-dt-board-audio`), from the board tree in `FirmwareOriginals`. |-| `devicetree-cfw-ipad_haptics` (new, 2026-10-03) | An iPad guest's installed DeviceTree, `fw patch` | Makes `/product/haptics` what the board tree has (`DeviceTreePatcher.presentBoardHaptics`): removed for every iPad so far, none of which has the node. |-| `preboot-cfw-devicetree_board_haptics` (new, 2026-10-03) | Restored Preboot `devicetree.img4`, `cfw install` and `cfw update-environment` | The same change for an iPad VM patched before it (`vphone-cli cfw patch-dt-board-haptics`), from the board tree in `FirmwareOriginals`. When it changes the tree, the installer also removes the guest's cached MobileGestalt answers, see below. |+| `devicetree-cfw-product_haptics_node` (new, 2026-10-03) | Every guest's DeviceTree, `fw patch`: an iPhone guest's one tree, an iPad guest's installed tree and its `RestoreDeviceTree` | Removes `/product/haptics` (`DeviceTreePatcher.removeHaptics(from:)`), whatever the variant and the board. |+| `preboot-cfw-devicetree_haptics` (new, 2026-10-03) | Restored Preboot `devicetree.img4`, `cfw install` and `cfw update-environment`, every guest | The same removal for a VM patched before it (`vphone-cli cfw patch-dt-haptics`); it needs no board tree. When it changes the tree, the installer also removes the guest's cached MobileGestalt answers, see below. |`fw patch` now reads an iPad's board tree through the `FirmwareOriginals` stash,so `DeviceTree.<board>.im4p` stays in the VM folder after the restore tree goes.**Why the haptics node goes.** vphone600 carries `/product/haptics`-(`closed-loop`, `supports-3rd-party-haptics`); `DeviceTree.j410ap` and-`.j820ap` have no such node. With it MobileGestalt answers yes to-`DeviceSupportsHaptics` and `DeviceSupportsClosedLoopHaptics`, ToneLibrary sets-`playHapticTracks` on every tone, and mediaplaybackd builds a `CHHapticEngine`-whose server, `com.apple.audio.hapticd` in audiomxd, never answers on a VM:-six one-second XPC timeouts, `FigHapticEngineCreate` fails 4099, and-`itemfig_rebuildRenderPipelinesAndBoss` fails the item — the ringtone never-starts although its route and audio queue are built. Without the node the-guest answers as the iPad does and tones play. The answers are cached in+(`closed-loop`, `supports-3rd-party-haptics`). With it MobileGestalt answers+yes to `DeviceSupportsHaptics` and `DeviceSupportsClosedLoopHaptics`,+ToneLibrary sets `playHapticTracks` on every tone, and mediaplaybackd builds a+`CHHapticEngine` whose server, `com.apple.audio.hapticd` in audiomxd, never+answers on a VM: six one-second XPC timeouts, `FigHapticEngineCreate` fails+4099, and `itemfig_rebuildRenderPipelinesAndBoss` fails the item — the+ringtone never starts although its route and audio queue are built. It was+first seen on iPad guests, whose own trees (`DeviceTree.j410ap`, `.j820ap`)+have no such node, and fixed there by making the node follow the board. An+iPhone guest (iPhone99,11, iOS 27.0) then failed the same way — the same+hapticd timeouts, the same 4099, the tone dropped — and a real iPhone's tree+does have the node, so following the board cannot fix it. What is missing is+the actuator and the haptic server, and no VM has either; every guest's tree+loses the node, and the board-following patch and its Preboot repair were+replaced by these two. The restore tree loses it as well: an iPad guest's+`RestoreDeviceTree` is patched exactly as an iPhone guest's tree is, and+restore reads nothing from the node. Without it the guest answers as a device+with no Taptic Engine does and tones play. The answers are cached in`/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist`,written at first boot, so a guest that has already booted keeps the old onesuntil that file is removed and the guest restarted; a guest created with thepatch never has them. `cfw install` and `cfw update-environment` remove the-file from the mounted Data volume whenever a Preboot board repair (haptics or-audio) changed the tree, and log `[+] MobileGestalt cache removed`; a repair-that found the tree already matching removes nothing. This is part of those-two repairs rather than a declaration of its own: it writes no patch, runs+file from the mounted Data volume whenever a Preboot device tree repair (the+haptics removal, or the board audio node) changed the tree, and log+`[+] MobileGestalt cache removed`; a repair that found the tree already right+removes nothing. This is part of those two repairs rather than a declaration+of its own: it writes no patch, runsonly when one of them changed the tree, and turning a repair off alreadyturns it off. Removing it by hand (`files.remove`, then `system.reboot`)remains the fallback for a tree changed any other way. Detail and thediff --git a/Research/Guest/virtio_sound.md b/Research/Guest/virtio_sound.mdindex ee53cf25..544f543e 100644--- a/Research/Guest/virtio_sound.md+++ b/Research/Guest/virtio_sound.md@@ -508,9 +508,23 @@ come from the device tree:| `DeviceTree.j820ap` (iPad17,3) | camera, facetime, maps, audio | none |So the guest says it has a Taptic Engine and the iPad it presents does not.-`devicetree-cfw-ipad_haptics` makes the node follow the board — removed, for-an iPad — and `preboot-cfw-devicetree_board_haptics` does the same to a guest-that is already installed.+The first fix made the node follow the board, which removed it on an iPad.++**An iPhone guest fails the same way.** On an iPhone99,11 guest running iOS+27.0, a tone preview logged the same six hapticd timeouts, the same+`FigHapticEngineCreate` 4099, and the item failed and was dropped. That guest+boots the shared vphone600 tree, has no board tree of its own to follow, and a+real iPhone's tree does have `/product/haptics`; following the board can never+remove it there. What decides it is not the device the guest presents but the+hardware behind it: no VM has a haptic actuator, and nothing serves+`com.apple.audio.hapticd`. So the removal is now unconditional.+`devicetree-cfw-product_haptics_node` takes the node out of every tree+`fw patch` writes — an iPhone guest's one tree, an iPad guest's installed tree,+and its `RestoreDeviceTree`, which is patched exactly as an iPhone guest's+tree is and from which restore reads nothing of the node — and+`preboot-cfw-devicetree_haptics` (`vphone-cli cfw patch-dt-haptics <dt>`)+does the same to a guest that is already installed, with no board tree+needed. `cfw install` and `cfw update-environment` run it for every guest.**The answers are cached.** libMobileGestalt writes`/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist`@@ -526,8 +540,8 @@ vphone-launchpad-cli guest rpc <machine> system.reboot '{"force":true}'```A guest created with the patch never caches the wrong answers. For an existing-one the installer now does the removal: when a Preboot board repair-(`preboot-cfw-devicetree_board_haptics` or+one the installer now does the removal: when a Preboot device tree repair+(`preboot-cfw-devicetree_haptics` or`preboot-cfw-devicetree_board_audio`) changes the devicetree during `cfw install` or `cfw update-environment`, it deletes that filefrom the mounted Data volume (`CustomFirmwareMobileGestaltCache`, through the@@ -538,7 +552,7 @@ same descriptor-relative access as every other guest write) and prints```The guest's next boot is then enough. A repair that finds the tree already-matching the board removes nothing, and a guest that never booted has no file+right removes nothing, and a guest that never booted has no fileand gets no line. The two commands above remain the way to do it by hand, fora guest whose tree was changed some other way.@@ -547,8 +561,9 @@ has no Haptics row, mediaplaybackd makes no hapticd connection, and a tonepreview plays on the Mac — heard, and in `vpquery.log` a 20 s stream with 237writes and none starved.-iPhone guests are not changed: an iPhone's own tree has the node, and what a-tone does there with no haptic server has not been measured.+Not yet verified on an iPhone guest: that, with the node removed and the+cache rebuilt, a tone there plays as it does on `audiotest-ipad`. The failure+it removes is the same one, measured above.## Reveal and validationdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMobileGestaltCache.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMobileGestaltCache.swiftindex d305b0aa..b7beb3a2 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMobileGestaltCache.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMobileGestaltCache.swift@@ -3,13 +3,14 @@// libMobileGestalt answers most device questions from the device tree, and at// first boot it writes those answers to a cache on the Data volume. It reads// the cache from then on, so a guest whose Preboot device tree is repaired-// later keeps answering as the old tree did: after the board haptics repair-// removed `/product/haptics`, Settings still showed the Haptics row and tones-// stayed silent until the file was removed and the guest rebooted. Without the-// file, libMobileGestalt computes the answers again from the tree it booted.+// later keeps answering as the old tree did: after the haptics repair removed+// `/product/haptics`, Settings still showed the Haptics row and tones stayed+// silent until the file was removed and the guest rebooted. Without the file,+// libMobileGestalt computes the answers again from the tree it booted.//-// `cfw install` and `cfw update-environment` remove it when a board repair-// changed the tree, and only then. See `Research/Guest/virtio_sound.md` §7.+// `cfw install` and `cfw update-environment` remove it when a Preboot device+// tree repair (the haptics removal or the board audio node) changed the tree,+// and only then. See `Research/Guest/virtio_sound.md` §7.import Foundationimport VPhoneCoreKitdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swiftindex 1c79a9d8..5ffb9d55 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift@@ -89,31 +89,6 @@ public enum CustomFirmwarePostRestoreDeviceTree {board boardURL: URL,dryRun: Bool = false,verbose: Bool = true,- ) throws -> Outcome {- try rewrite(at: url, board: boardURL, dryRun: dryRun, verbose: verbose, edit: withBoardAudio)- }-- /// Make an iPad guest's `devicetree.img4` (or bare `.im4p`) carry the- /// haptics node of the iPad's own tree at `boardURL` — none, on every iPad- /// so far — in place. See `DeviceTreePatcher.presentBoardHaptics`.- @discardableResult- public static func presentBoardHaptics(- at url: URL,- board boardURL: URL,- dryRun: Bool = false,- verbose: Bool = true,- ) throws -> Outcome {- try rewrite(at: url, board: boardURL, dryRun: dryRun, verbose: verbose, edit: withBoardHaptics)- }-- /// `rewrite(at:)` with an edit that also takes the flat tree of the board's- /// device tree file and returns the size change it made.- private static func rewrite(- at url: URL,- board boardURL: URL,- dryRun: Bool,- verbose: Bool,- edit: (Data, Data) throws -> (Data, [Change], Int),) throws -> Outcome {let boardData: Datado {@@ -123,7 +98,21 @@ public enum CustomFirmwarePostRestoreDeviceTree {}let board = try openDeviceTree(boardData, path: boardURL.path).blobreturn try rewrite(at: url, dryRun: dryRun, verbose: verbose) { blob in- let (newBlob, changes, delta) = try edit(blob, board)+ let (newBlob, changes, delta) = try withBoardAudio(blob, board: board)+ return (newBlob, changes, blob.count + delta)+ }+ }++ /// Remove `/product/haptics` from a guest's `devicetree.img4` (or bare+ /// `.im4p`), in place. See `DeviceTreePatcher.removeHaptics(from:)`.+ @discardableResult+ public static func removeHaptics(+ at url: URL,+ dryRun: Bool = false,+ verbose: Bool = true,+ ) throws -> Outcome {+ try rewrite(at: url, dryRun: dryRun, verbose: verbose) { blob in+ let (newBlob, changes, delta) = try withoutHaptics(blob)return (newBlob, changes, blob.count + delta)}}@@ -301,42 +290,31 @@ public enum CustomFirmwarePostRestoreDeviceTree {else { return "none" }return String(id.value.loadLE(UInt32.self, at: 0))}- return try withBoardNode(blob, board: board, property: "product/audio", DeviceTreePatcher.presentBoardAudio) {- ("acoustic-id \(acousticID($0.before))", "acoustic-id \(acousticID($0.after)), \($0.after.count)B")- }- }-- /// `blob` with `/product/haptics` as the board's flat tree `board` has it,- /// through `DeviceTreePatcher.presentBoardHaptics`: removed where the board- /// has none. Returns the size change with the changes, as `withBoardAudio`- /// does. A tree that already matches comes back unchanged.- public static func withBoardHaptics(_ blob: Data, board: Data) throws -> (Data, [Change], Int) {- func describe(_ node: Data) -> String {- node.isEmpty ? "absent" : "present, \(node.count)B"- }- return try withBoardNode(blob, board: board, property: "product/haptics", DeviceTreePatcher.presentBoardHaptics) {- (describe($0.before), describe($0.after))+ let root = try parseTree(blob, label: "DT")+ let source = try parseTree(board, label: "board DT")+ guard let change = DeviceTreePatcher.presentBoardAudio(in: root, from: source) else {+ return (blob, [], 0)}+ let record = Change(+ property: "product/audio",+ before: "acoustic-id \(acousticID(change.before))",+ after: "acoustic-id \(acousticID(change.after)), \(change.after.count)B",+ )+ return (serializeNode(root), [record], change.after.count - change.before.count)}- /// Parses both flat trees, applies `present` to them, and returns the- /// serialized result with one change, described by `describe`, and the- /// size it added.- private static func withBoardNode(- _ blob: Data,- board: Data,- property: String,- _ present: (DeviceTreePatcher.DTNode, DeviceTreePatcher.DTNode) -> DeviceTreePatcher.BoardNodeChange?,- describe: (DeviceTreePatcher.BoardNodeChange) -> (before: String, after: String),- ) throws -> (Data, [Change], Int) {+ /// `blob` without `/product/haptics`, through+ /// `DeviceTreePatcher.removeHaptics(from:)`, which fw patch uses for every+ /// new guest. Returns the size change with the changes, as `withBoardAudio`+ /// does: the node's bytes out. A tree with no haptics node comes back+ /// unchanged.+ public static func withoutHaptics(_ blob: Data) throws -> (Data, [Change], Int) {let root = try parseTree(blob, label: "DT")- let source = try parseTree(board, label: "board DT")- guard let change = present(root, source) else {+ guard let removed = DeviceTreePatcher.removeHaptics(from: root) else {return (blob, [], 0)}- let described = describe(change)- let record = Change(property: property, before: described.before, after: described.after)- return (serializeNode(root), [record], change.after.count - change.before.count)+ let record = Change(property: "product/haptics", before: "present, \(removed.count)B", after: "absent")+ return (serializeNode(root), [record], -removed.count)}/// The root of a flat tree that must fill `blob` exactly.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swiftindex ccce8e7a..5fcfd3b7 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift@@ -26,6 +26,10 @@// Only the installed tree carries these. Restore boots `RestoreDeviceTree`,// which keeps the iPhone99,11 identity `restored_external` checks against the// manifest; see `FirmwareManifest.separateGuestDeviceTree`.+//+// One edit here is every guest's, not only an iPad's: `/product/haptics` goes+// from every tree of every role, because no VM has the actuator or the haptic+// server the node promises. See `removeHaptics(from:)`.import Foundationimport VPhoneCoreKit@@ -52,7 +56,7 @@ extension DeviceTreePatcher {static let iPadButtonsPatch = "devicetree-cfw-ipad_buttons"static let iPadIdentityPatch = "devicetree-cfw-ipad_identity"static let iPadAudioPatch = "devicetree-cfw-ipad_audio"- static let iPadHapticsPatch = "devicetree-cfw-ipad_haptics"+ static let hapticsPatch = "devicetree-cfw-product_haptics_node"// MARK: - What Is Copied@@ -202,44 +206,43 @@ extension DeviceTreePatcher {}}- // MARK: - Board Nodes+ // MARK: - Audio- /// What `presentBoardNode` changed: the node's serialized bytes before and- /// after, empty where there was, or now is, no node.- struct BoardNodeChange {+ /// What `presentBoardAudio` changed: the audio node's serialized bytes+ /// before and after, empty when there was no node.+ struct BoardAudioChange {let before: Datalet after: Data}- /// Give `root`'s `/product/<name>` the properties of the board's.+ /// Give `root`'s `/product/audio` the properties of the board's.+ ///+ /// The tree's audio node, when there is one, came from+ /// `devicetree-cfw-product_audio_node`, which copies the D47 iPhone's. Its+ /// `acoustic-id` (8018) names `/Library/Audio/Tunings/AID8018`, which an iPad+ /// image does not ship; VirtualAudio then builds no microphone sub-ports, and+ /// on an iPad, whose board answers yes to stereo and webcam recording, it+ /// throws `PRECONDITION FAILURE` in `RoutingSettings_J98` and never+ /// initializes, so the guest has no audio route at all. The board's own node+ /// names the tunings its image carries (AID2029 on J820).////// Every property is copied as the board has it, placeholders included,/// except `AAPL,phandle`, which is the board tree's and could collide in/// this one; a property the board's node lacks is removed. The node is- /// added under `/product` when the tree has none. Where the board has no- /// such node the tree's is removed if `removeWhenAbsent`, and otherwise- /// left. Returns nil when nothing changes.- private static func presentBoardNode(- _ name: String,- in root: DTNode,- from source: DTNode,- removeWhenAbsent: Bool,- ) -> BoardNodeChange? {+ /// added under `/product` when the tree has none. Returns nil when the+ /// board has no audio node or the tree already matches it.+ static func presentBoardAudio(in root: DTNode, from source: DTNode) -> BoardAudioChange? {guardlet sourceProduct = optionalChild(of: source, named: "product"),+ let sourceAudio = optionalChild(of: sourceProduct, named: "audio"),let product = optionalChild(of: root, named: "product")else { return nil }- let existing = optionalChild(of: product, named: name)- guard let sourceNode = optionalChild(of: sourceProduct, named: name) else {- guard removeWhenAbsent, let existing else { return nil }- product.children.removeAll { $0 === existing }- return BoardNodeChange(before: serialize(existing), after: Data())- }- let copied = sourceNode.properties.filter { $0.name != "AAPL,phandle" }+ let copied = sourceAudio.properties.filter { $0.name != "AAPL,phandle" }func describe(_ properties: [DTProperty]) -> [String: (UInt16, Data)] {Dictionary(properties.map { ($0.name, ($0.flags, $0.value)) }, uniquingKeysWith: { first, _ in first })}+ let existing = optionalChild(of: product, named: "audio")if let existing {let lhs = describe(existing.properties.filter { $0.name != "AAPL,phandle" })let rhs = describe(copied)@@ -259,27 +262,13 @@ extension DeviceTreePatcher {if existing == nil {product.children.append(node)}- return BoardNodeChange(before: before, after: serialize(node))+ return BoardAudioChange(before: before, after: serialize(node))}- /// Give `root`'s `/product/audio` the properties of the board's.- ///- /// The tree's audio node, when there is one, came from- /// `devicetree-cfw-product_audio_node`, which copies the D47 iPhone's. Its- /// `acoustic-id` (8018) names `/Library/Audio/Tunings/AID8018`, which an iPad- /// image does not ship; VirtualAudio then builds no microphone sub-ports, and- /// on an iPad, whose board answers yes to stereo and webcam recording, it- /// throws `PRECONDITION FAILURE` in `RoutingSettings_J98` and never- /// initializes, so the guest has no audio route at all. The board's own node- /// names the tunings its image carries (AID2029 on J820).- ///- /// Returns nil when the board has no audio node or the tree already matches it.- static func presentBoardAudio(in root: DTNode, from source: DTNode) -> BoardNodeChange? {- presentBoardNode("audio", in: root, from: source, removeWhenAbsent: false)- }+ // MARK: - Haptics- /// Make `root`'s `/product/haptics` what the board's tree has — which for- /// an iPad is nothing.+ /// Remove `root`'s `/product/haptics`. Returns the node's serialized bytes,+ /// or nil when the tree has none.////// vphone600 carries the node (`closed-loop`, `supports-3rd-party-haptics`),/// so MobileGestalt answers yes to `DeviceSupportsHaptics` and@@ -289,12 +278,18 @@ extension DeviceTreePatcher {/// queue. A VM has no haptic server behind `com.apple.audio.hapticd`: the/// engine's XPC setup times out six times, `FigHapticEngineCreate` fails/// with 4099, and `itemfig_rebuildRenderPipelinesAndBoss` fails the whole- /// item with it — the tone's audio never starts. An iPad's tree has no- /// haptics node at all, so the real device never asks.- ///- /// Returns nil when the tree already matches the board.- static func presentBoardHaptics(in root: DTNode, from source: DTNode) -> BoardNodeChange? {- presentBoardNode("haptics", in: root, from: source, removeWhenAbsent: true)+ /// item with it — the tone's audio never starts. That was measured on an+ /// iPad guest and on an iPhone guest alike. An iPad's own tree has no+ /// haptics node and an iPhone's has one, so what the guest's board carries+ /// does not decide it: no VM has the actuator or the server, so no guest+ /// tree keeps the node, whatever its role.+ static func removeHaptics(from root: DTNode) -> Data? {+ guard+ let product = optionalChild(of: root, named: "product"),+ let haptics = optionalChild(of: product, named: "haptics")+ else { return nil }+ product.children.removeAll { $0 === haptics }+ return serialize(haptics)}/// The flat encoding of one node and its children, for the patch record.@@ -330,29 +325,18 @@ extension DeviceTreePatcher {)}let source = try parsePayload(sourceTree)- let boardNodes = [- ("audio", Self.iPadAudioPatch, Self.presentBoardAudio),- ("haptics", Self.iPadHapticsPatch, Self.presentBoardHaptics),- ]- for (name, patchID, present) in boardNodes {- guard gateAllows(patchID), let change = present(root, source) else { continue }- let removed = change.after.isEmpty+ if gateAllows(Self.iPadAudioPatch), let change = Self.presentBoardAudio(in: root, from: source) {patches.append(PatchRecord(- patchID: patchID,+ patchID: Self.iPadAudioPatch,component: component,fileOffset: 0,virtualAddress: nil,originalBytes: change.before,patchedBytes: change.after,- description: removed- ? "Remove /device-tree/product/\(name), which \(device.productType) does not have"- : "Set /device-tree/product/\(name) as on \(device.productType)",+ description: "Set /device-tree/product/audio as on \(device.productType)",))if verbose {- let what = removed- ? "-node : /product/\(name), absent on \(device.productType)"- : "=node : /product/\(name) as on \(device.productType) (\(change.after.count)B)"- print(" \(what) [\(patchID)]")+ print(" =node : /product/audio as on \(device.productType) (\(change.after.count)B) [\(Self.iPadAudioPatch)]")}}for edit in try Self.guestEdits(from: source) {@@ -398,4 +382,22 @@ extension DeviceTreePatcher {}}}++ /// Applies `removeHaptics(from:)` to the parsed tree, whichever guest and+ /// role it is for, and records the removal.+ func applyHapticsRemoval(root: DTNode) {+ guard gateAllows(Self.hapticsPatch), let removed = Self.removeHaptics(from: root) else { return }+ patches.append(PatchRecord(+ patchID: Self.hapticsPatch,+ component: component,+ fileOffset: 0,+ virtualAddress: nil,+ originalBytes: removed,+ patchedBytes: Data(),+ description: "Remove /device-tree/product/haptics, which no VM has the hardware for",+ ))+ if verbose {+ print(" -node : /product/haptics, no actuator or haptic server on a VM (\(removed.count)B) [\(Self.hapticsPatch)]")+ }+ }}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swiftindex 68ce00b5..7a282994 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift@@ -319,6 +319,7 @@ public final class DeviceTreePatcher: BufferedPatcher {/// `identityPropertyPatches` + `experimentalNodeAdditions` when/// `includeIdentityPatches` is true (the `.exp` firmware variant) —/// other variants leave the device's identity properties untouched.+ /// `/product/haptics` is removed from every tree, whatever the variant.private func applyPatches(root: DTNode) throws {var patchesToApply = Self.basePropertyPatchesif includeIdentityPatches {@@ -384,6 +385,9 @@ public final class DeviceTreePatcher: BufferedPatcher {if presentsGuest {try applyGuestEdits(root: root)}++ // Every guest, every tree: no VM has the haptics the node promises.+ applyHapticsRemoval(root: root)}/// Property patches that describe the virtual board rather than a phone,diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swiftindex 8987305b..72673351 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift@@ -6,7 +6,8 @@// Two kinds of entry. The first four properties make the research board present// as a phone the guest's own UI can lay out. The rest give it the iPhone17,3// identity and the camera, audio and SMC nodes that identity implies, which is-// what lets a stock app see a plausible device.+// what lets a stock app see a plausible device. One node goes instead of+// coming: the haptics node, whose hardware no VM has.//// None is boot-essential: a VM with a stock device tree boots, it just looks like// a research board and has no camera.@@ -166,6 +167,16 @@ public enum FirmwareDeviceTreePatchSet {"Sets the ISP round-trip buffer flags for the camera pipeline.",),+ // MARK: Removed Nodes+ //+ // Written to every guest's tree, iPhone and iPad, whatever the variant.++ property(+ "devicetree-cfw-product_haptics_node",+ "Haptics node",+ "Removes the Taptic Engine no VM has, so tones play without the haptic track it cannot drive.",+ ),+// MARK: iPad Guest//// Written only to an iPad guest's installed tree (an iPhone guest@@ -196,11 +207,6 @@ public enum FirmwareDeviceTreePatchSet {"iPad audio configuration","Takes the audio node from the iPad's tree, so its acoustic ID names tunings the iPad image ships.",),- property(- "devicetree-cfw-ipad_haptics",- "iPad haptics",- "Removes the Taptic Engine an iPad does not have, so tones play without the haptic track a VM cannot drive.",- ),],provides: ["vphone.devicetree"],)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swiftindex 3d1b57aa..65a38e03 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift@@ -264,13 +264,13 @@ public enum FirmwareGuestSystemPatchSet {target: .prebootDeviceTree,),VPhonePatchDeclaration(- identifier: prebootBoardHaptics,- title: "iPad haptics",+ identifier: prebootHaptics,+ title: "Haptics node",summary: """- Removes the haptics node from an iPad guest's restored Preboot device tree, as fw \- patch now does. With it iOS believes the guest has a Taptic Engine, plays every \- tone with its haptic track, and drops the tone when the haptic engine a VM does \- not have fails to start. Needs the iPad's device tree in the VM's FirmwareOriginals.+ Removes the haptics node from a guest's restored Preboot device tree, iPhone or \+ iPad, as fw patch now does. With it iOS believes the guest has a Taptic Engine, \+ plays every tone with its haptic track, and drops the tone when the haptic engine \+ a VM does not have fails to start.""",target: .prebootDeviceTree,),@@ -321,7 +321,10 @@ public enum FirmwareGuestSystemPatchSet {/// The iPad audio node repair in the restored Preboot device tree, for an/// iPad VM patched before `fw patch` copied the board's node.public static let prebootBoardAudio = "preboot-cfw-devicetree_board_audio"- public static let prebootBoardHaptics = "preboot-cfw-devicetree_board_haptics"++ /// The haptics node removal in the restored Preboot device tree, for any+ /// VM patched before `fw patch` removed it from every guest's tree.+ public static let prebootHaptics = "preboot-cfw-devicetree_haptics"/// The preset parameter `system-systemversion-cfw-build_version` reads.public static let buildVersionParameter = "BuildVersion"diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swiftindex 0d4030c3..c5d0cd17 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift@@ -93,7 +93,7 @@ struct DeviceTreeGuestDeviceTests {],)- /// vphone600's `/product/haptics`, which no iPad tree has.+ /// vphone600's `/product/haptics`, which no VM can back.static let haptics = Node(properties: [.string("name", "haptics"),@@ -216,14 +216,35 @@ struct DeviceTreeGuestDeviceTests {return read(patcher.patchedData)}- /// Run the patcher on an iPad's installed tree, returning the tree it- /// writes and its records.- static func installed(- _ guest: Data,+ /// The trees a guest is patched in: an iPhone guest's one shared tree, and+ /// an iPad guest's installed tree and restore tree.+ enum Guest: CaseIterable, Sendable {+ case iPhone+ case iPad+ case iPadRestore++ var device: VPhoneGuestDevice {+ self == .iPhone ? .default : .iPad16_1+ }++ var role: DeviceTreePatcher.TreeRole {+ switch self {+ case .iPhone: .shared+ case .iPad: .installed+ case .iPadRestore: .restore+ }+ }+ }++ /// Run the patcher on `guest`'s tree, returning the tree it writes and its+ /// records.+ static func patched(+ _ tree: Data,+ as guest: Guest,gate: VPhonePatchGate = .unrestricted,) throws -> (data: Data, records: [PatchRecord]) {let patcher = DeviceTreePatcher(- data: guest, verbose: false, device: .iPad16_1, role: .installed,+ data: tree, verbose: false, device: guest.device, role: guest.role,sourceTree: board().serialized(),)patcher.gate = gate@@ -343,9 +364,10 @@ struct DeviceTreeGuestDeviceTests {// MARK: - Haptics- @Test func `an iPad's installed tree loses the haptics node its board does not have`() throws {- let guest = Self.guestTree(haptics: Self.haptics).serialized()- let (patched, records) = try Self.installed(guest)+ @Test(arguments: Guest.allCases)+ func `every guest's tree loses the haptics node`(guest: Guest) throws {+ let tree = Self.guestTree(haptics: Self.haptics).serialized()+ let (patched, records) = try Self.patched(tree, as: guest)#expect(Self.read(patched)["device-tree/product/haptics"] == nil)let parser = DeviceTreePatcher(data: Data(), verbose: false)@@ -355,35 +377,36 @@ struct DeviceTreeGuestDeviceTests {// The same tree without the node patches to the same bytes: nothing// around it moved, and the length is the node's shorter.- let (without, _) = try Self.installed(Self.guestTree(haptics: nil).serialized())+ let (without, _) = try Self.patched(Self.guestTree(haptics: nil).serialized(), as: guest)#expect(patched == without)- #expect(guest.count - Self.guestTree(haptics: nil).serialized().count == Self.haptics.serialized().count)+ #expect(tree.count - Self.guestTree(haptics: nil).serialized().count == Self.haptics.serialized().count)- let haptics = records.filter { $0.patchID == "devicetree-cfw-ipad_haptics" }+ let haptics = records.filter { $0.patchID == "devicetree-cfw-product_haptics_node" }#expect(haptics.count == 1)#expect(haptics.first?.originalBytes == Self.haptics.serialized())#expect(haptics.first?.patchedBytes.isEmpty == true)}- @Test func `the haptics node stays when its patch is off`() throws {+ @Test(arguments: Guest.allCases)+ func `the haptics node stays when its patch is off`(guest: Guest) throws {let declared = Set(FirmwareDeviceTreePatchSet.manifest.patches.map(\.identifier))- #expect(declared.contains("devicetree-cfw-ipad_haptics"))- let gate = VPhonePatchGate(declared: declared, enabled: declared.subtracting(["devicetree-cfw-ipad_haptics"]))- let (patched, records) = try Self.installed(Self.guestTree(haptics: Self.haptics).serialized(), gate: gate)+ #expect(declared.contains("devicetree-cfw-product_haptics_node"))+ let gate = VPhonePatchGate(declared: declared, enabled: declared.subtracting(["devicetree-cfw-product_haptics_node"]))+ let (patched, records) = try Self.patched(Self.guestTree(haptics: Self.haptics).serialized(), as: guest, gate: gate)- #expect(!records.contains { $0.patchID == "devicetree-cfw-ipad_haptics" })- let product = try #require(Self.read(patched)["device-tree/product"])- #expect(Self.string(product["artwork-device-idiom"]) == "pad", "the other iPad edits still apply")+ #expect(!records.contains { $0.patchID == "devicetree-cfw-product_haptics_node" })+ #expect(!records.isEmpty, "the other edits still apply")let root = try DeviceTreePatcher(data: Data(), verbose: false).parsePayload(patched)#expect(Self.childNames(root, at: ["product"]) == ["maps", "haptics", "util"])#expect(Self.integer(Self.read(patched)["device-tree/product/haptics"]?["closed-loop"]) == 1)}- @Test func `removing the haptics node a second time changes nothing`() throws {- let (once, _) = try Self.installed(Self.guestTree(haptics: Self.haptics).serialized())- let (twice, records) = try Self.installed(once)+ @Test(arguments: Guest.allCases)+ func `removing the haptics node a second time changes nothing`(guest: Guest) throws {+ let (once, _) = try Self.patched(Self.guestTree(haptics: Self.haptics).serialized(), as: guest)+ let (twice, records) = try Self.patched(once, as: guest)#expect(twice == once)- #expect(!records.contains { $0.patchID == "devicetree-cfw-ipad_haptics" })+ #expect(!records.contains { $0.patchID == "devicetree-cfw-product_haptics_node" })}}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBoardHapticsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBoardHapticsTests.swiftdeleted file mode 100644index 881dd1c6..00000000--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBoardHapticsTests.swift+++ /dev/null@@ -1,118 +0,0 @@-// CustomFirmwareBoardHapticsTests.swift — an iPad guest has the board's haptics node, or none.-//-// `withBoardHaptics` (the Preboot repair) and-// `DeviceTreePatcher.presentBoardHaptics` (what `fw patch` runs for an iPad's-// installed tree) make `/product/haptics` what the board tree has: removed for-// an iPad, which has no Taptic Engine. The trees here are built in the flat-// format the restored tree uses, so the parse, the edit and the serialization-// all run.--@testable import FirmwarePatcher-import Foundation-import Testing--@Suite("iPad haptics node from the board tree")-struct CustomFirmwareBoardHapticsTests {- private typealias Node = FlatDeviceTreeNode-- /// A tree whose `/product` holds `maps`, then `haptics` when given, then- /// `util` — the node sits between siblings, as it does on vphone600.- private static func tree(haptics: Node?) -> Data {- let product = Node(- "product",- [("product-name", Data("iPad\0".utf8))],- children: [Node("maps", [("regulatory", Node.uint32(1))])]- + (haptics.map { [$0] } ?? [])- + [Node("util", [("ramdisk", Node.uint32(0))])],- )- return Node("device-tree", [("model", Data("iPad16,1\0".utf8))], children: [product]).serialized- }-- /// What vphone600 carries.- private static let guestHaptics = Node("haptics", [- ("closed-loop", Node.uint32(1)),- ("supports-3rd-party-haptics", Node.uint32(1)),- ("AAPL,phandle", Node.uint32(100)),- ])-- /// A board that does have an actuator.- private static let boardHaptics = Node("haptics", [- ("closed-loop", Node.uint32(1)),- ("supports-3rd-party-haptics", Node.uint32(0)),- ("AAPL,phandle", Node.uint32(7)),- ])-- // MARK: - Tests-- @Test func `removes the node an iPad's tree does not have`() throws {- let original = Self.tree(haptics: Self.guestHaptics)- let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- original,- board: Self.tree(haptics: nil),- )- #expect(changes.map(\.property) == ["product/haptics"])- #expect(changes.first?.after == "absent")- #expect(delta < 0)- #expect(patched.count == original.count + delta)- // The siblings on either side survive, in order.- #expect(patched == Self.tree(haptics: nil))- }-- @Test func `a tree with no node is left alone`() throws {- let original = Self.tree(haptics: nil)- let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- original,- board: Self.tree(haptics: nil),- )- #expect(changes.isEmpty)- #expect(delta == 0)- #expect(patched == original)- }-- @Test func `removing twice changes nothing the second time`() throws {- let board = Self.tree(haptics: nil)- let (once, _, _) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- Self.tree(haptics: Self.guestHaptics),- board: board,- )- let (twice, changes, _) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(once, board: board)- #expect(changes.isEmpty)- #expect(twice == once)- }-- @Test func `a board with a node gives its properties and keeps the guest's phandle`() throws {- let (patched, changes, _) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- Self.tree(haptics: Self.guestHaptics),- board: Self.tree(haptics: Self.boardHaptics),- )- #expect(changes.first?.after.hasPrefix("present") == true)- let expected = Node("haptics", [- ("closed-loop", Node.uint32(1)),- ("supports-3rd-party-haptics", Node.uint32(0)),- ("AAPL,phandle", Node.uint32(100)),- ])- #expect(patched == Self.tree(haptics: expected))- }-- @Test func `a tree that already matches the board's node is left alone`() throws {- var matching = Self.boardHaptics- matching.properties[3].value = Node.uint32(100)- let original = Self.tree(haptics: matching)- let (patched, changes, _) = try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- original,- board: Self.tree(haptics: Self.boardHaptics),- )- #expect(changes.isEmpty)- #expect(patched == original)- }-- @Test func `a truncated tree is refused`() {- let original = Self.tree(haptics: Self.guestHaptics)- #expect(throws: (any Error).self) {- try CustomFirmwarePostRestoreDeviceTree.withBoardHaptics(- original.prefix(original.count - 4),- board: Self.tree(haptics: nil),- )- }- }-}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareHapticsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareHapticsTests.swiftnew file mode 100644index 00000000..7350d197--- /dev/null+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareHapticsTests.swift@@ -0,0 +1,83 @@+// CustomFirmwareHapticsTests.swift — no guest keeps the haptics node.+//+// `withoutHaptics` (the Preboot repair) and `DeviceTreePatcher.removeHaptics`+// (what `fw patch` runs for every guest's tree) remove `/product/haptics`: no+// VM has the actuator or the haptic server it promises, iPhone or iPad. The+// trees here are built in the flat format the restored tree uses, so the+// parse, the edit and the serialization all run.++@testable import FirmwarePatcher+import Foundation+import Testing++@Suite("Haptics node removal")+struct CustomFirmwareHapticsTests {+ private typealias Node = FlatDeviceTreeNode++ /// A tree whose `/product` holds `maps`, then `haptics` when given, then+ /// `util` — the node sits between siblings, as it does on vphone600.+ private static func tree(haptics: Node?) -> Data {+ let product = Node(+ "product",+ [("product-name", Data("iPhone\0".utf8))],+ children: [Node("maps", [("regulatory", Node.uint32(1))])]+ + (haptics.map { [$0] } ?? [])+ + [Node("util", [("ramdisk", Node.uint32(0))])],+ )+ return Node("device-tree", [("model", Data("iPhone99,11\0".utf8))], children: [product]).serialized+ }++ /// What vphone600 carries.+ private static let haptics = Node("haptics", [+ ("closed-loop", Node.uint32(1)),+ ("supports-3rd-party-haptics", Node.uint32(1)),+ ("AAPL,phandle", Node.uint32(100)),+ ])++ // MARK: - Tests++ @Test func `removes the node`() throws {+ let original = Self.tree(haptics: Self.haptics)+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(original)+ #expect(changes.map(\.property) == ["product/haptics"])+ #expect(changes.first?.before == "present, \(Self.haptics.serialized.count)B")+ #expect(changes.first?.after == "absent")+ #expect(delta == -Self.haptics.serialized.count)+ #expect(patched.count == original.count + delta)+ // The siblings on either side survive, in order.+ #expect(patched == Self.tree(haptics: nil))+ }++ @Test func `a tree with no node is left alone`() throws {+ let original = Self.tree(haptics: nil)+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(original)+ #expect(changes.isEmpty)+ #expect(delta == 0)+ #expect(patched == original)+ }++ @Test func `removing twice changes nothing the second time`() throws {+ let (once, _, _) = try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(Self.tree(haptics: Self.haptics))+ let (twice, changes, _) = try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(once)+ #expect(changes.isEmpty)+ #expect(twice == once)+ }++ @Test func `a haptics node outside product is not touched`() throws {+ let original = Node(+ "device-tree",+ [("model", Data("iPhone99,11\0".utf8))],+ children: [Node("product"), Node("arm-io", children: [Self.haptics])],+ ).serialized+ let (patched, changes, _) = try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(original)+ #expect(changes.isEmpty)+ #expect(patched == original)+ }++ @Test func `a truncated tree is refused`() {+ let original = Self.tree(haptics: Self.haptics)+ #expect(throws: (any Error).self) {+ try CustomFirmwarePostRestoreDeviceTree.withoutHaptics(original.prefix(original.count - 4))+ }+ }+}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareMobileGestaltCacheTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareMobileGestaltCacheTests.swiftindex 0f0d049b..9ecda4e8 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareMobileGestaltCacheTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareMobileGestaltCacheTests.swift@@ -1,7 +1,7 @@// CustomFirmwareMobileGestaltCacheTests.swift — the installer drops the guest's cached answers.//// `cfw install` and `cfw update-environment` remove the MobileGestalt cache-// from the mounted Data volume after a board repair changed the device tree.+// from the mounted Data volume after a Preboot repair changed the device tree.// These run the removal against a scratch folder standing in for that volume.import Darwindiff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex a52e4cee..c07b43f3 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -273,10 +273,10 @@ struct VPhoneCustomFirmwareInstaller {}}// The Preboot identity patches go with the boot chain and belong to a- // full install only. The board audio repair is the exception: an iPad VM- // restored before it has no other way to get its audio back, since its- // restore tree is gone and `fw patch` does not run again.- let boardTreeChanged = try patchPreboot(+ // full install only. The device tree repairs are the exception: a VM+ // restored before the board audio repair or the haptics removal has no+ // other way to get them, since `fw patch` does not run again.+ let treeRepaired = try patchPreboot(volumes: volumes,work: work,plan: plan,@@ -287,7 +287,7 @@ struct VPhoneCustomFirmwareInstaller {// A guest that has booted keeps the MobileGestalt answers it cached// from the old tree, so a repair that changed the tree drops them; one// that found the tree already right leaves them be.- if boardTreeChanged {+ if treeRepaired {let dataRoot = try openGuestVolume("data", device: "\(container)s3", in: work)if try CustomFirmwareMobileGestaltCache.remove(fromDataVolume: dataRoot) {print(" [+] MobileGestalt cache removed; the guest rebuilds it from the new device tree at next boot")@@ -780,7 +780,7 @@ struct VPhoneCustomFirmwareInstaller {private static let lateGuestPatches = [FirmwareGuestSystemPatchSet.virtioSoundDriver,FirmwareGuestSystemPatchSet.prebootBoardAudio,- FirmwareGuestSystemPatchSet.prebootBoardHaptics,+ FirmwareGuestSystemPatchSet.prebootHaptics,FirmwareGuestSystemPatchSet.virtualAudioSpeakerRouteThrows,FirmwareGuestSystemPatchSet.virtualAudioMuteSetThrow,FirmwareGuestSystemPatchSet.virtualAudioSpeakerProtectionGate,@@ -1160,12 +1160,14 @@ struct VPhoneCustomFirmwareInstaller {}/// `includeIdentity` is false for an environment update, which carries- /// only the board audio and haptics repairs. `boardDeviceTree` is the- /// iPad's own device tree, staged from the VM's `FirmwareOriginals`, or nil- /// for an iPhone guest or a VM patched before `fw patch` kept it.+ /// only the device tree repairs: the board audio repair, which needs+ /// `boardDeviceTree`, and the haptics removal, which every guest gets.+ /// `boardDeviceTree` is the iPad's own device tree, staged from the VM's+ /// `FirmwareOriginals`, or nil for an iPhone guest or a VM patched before+ /// `fw patch` kept it.///- /// Returns whether a board repair changed the device tree, which leaves- /// the guest's cached MobileGestalt answers stale.+ /// Returns whether a repair changed the device tree, which leaves the+ /// guest's cached MobileGestalt answers stale.private func patchPreboot(volumes: [[String: Any]],work: WorkDirectory,@@ -1195,11 +1197,14 @@ struct VPhoneCustomFirmwareInstaller {}}let spoofBuild = includeIdentity ? self.spoofBuild : nil- let boardVerbs = boardDeviceTree == nil ? [] : [- (FirmwareGuestSystemPatchSet.prebootBoardAudio, "patch-dt-board-audio"),- (FirmwareGuestSystemPatchSet.prebootBoardHaptics, "patch-dt-board-haptics"),- ].filter { on($0.0) }.map(\.1)- guard rewriteIdentity || !boardVerbs.isEmpty || !(spoofBuild ?? "").isEmpty else { return false }+ var repairs: [(verb: String, arguments: [String])] = []+ if let boardDeviceTree, on(FirmwareGuestSystemPatchSet.prebootBoardAudio) {+ repairs.append(("patch-dt-board-audio", [boardDeviceTree.path]))+ }+ if on(FirmwareGuestSystemPatchSet.prebootHaptics) {+ repairs.append(("patch-dt-haptics", []))+ }+ guard rewriteIdentity || !repairs.isEmpty || !(spoofBuild ?? "").isEmpty else { return false }guardlet preboot = volumes.first(where: { ($0["Roles"] as? [String])?.contains("Preboot") == true }),let device = preboot["DeviceIdentifier"] as? String@@ -1227,12 +1232,10 @@ struct VPhoneCustomFirmwareInstaller {if rewriteIdentity {try patchCopy(of: deviceTree, in: root, work: work, verb: "patch-post-restore-dt")}- var boardTreeChanged = false- if let boardDeviceTree {- for verb in boardVerbs {- if try patchCopy(of: deviceTree, in: root, work: work, verb: verb, arguments: [boardDeviceTree.path]) {- boardTreeChanged = true- }+ var treeRepaired = false+ for repair in repairs {+ if try patchCopy(of: deviceTree, in: root, work: work, verb: repair.verb, arguments: repair.arguments) {+ treeRepaired = true}}if let build = spoofBuild {@@ -1241,7 +1244,7 @@ struct VPhoneCustomFirmwareInstaller {try patchCopy(of: version, in: root, work: work, verb: "patch-build-version", arguments: [build])}}- return boardTreeChanged+ return treeRepaired}}diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swiftindex e6c77b69..bd17df93 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift@@ -354,41 +354,32 @@ struct VPhoneCustomFirmwarePatchBoardAudioCommand: ParsableCommand {}}-// MARK: - patch-dt-board-haptics+// MARK: - patch-dt-haptics-struct VPhoneCustomFirmwarePatchBoardHapticsCommand: ParsableCommand {+struct VPhoneCustomFirmwarePatchHapticsCommand: ParsableCommand {static let configuration = CommandConfiguration(- commandName: "patch-dt-board-haptics",- abstract: "Make an iPad guest's device tree carry the iPad's own haptics node, or none",+ commandName: "patch-dt-haptics",+ abstract: "Remove the haptics node from a guest's device tree",discussion: """- Sets /product/haptics in a restored device tree to what the iPad's own- tree has (DeviceTree.<board>.im4p from its IPSW), in place, preserving- the container's compression, manifest and restore info. An iPad has no- haptics node, so the vphone600 one is removed: with it, iOS believes the- guest has a Taptic Engine, plays every tone with its haptic track, and- drops the tone when the haptic engine a VM does not have fails to start.- A tree that already matches is left as it is.-- Takes a devicetree.img4 (preferred) or a bare .im4p, and the board's- DeviceTree .im4p.+ Removes /product/haptics from a restored device tree, in place,+ preserving the container's compression, manifest and restore info. No+ VM has a haptic actuator or the haptic server behind it: with the node,+ iOS believes the guest has a Taptic Engine, plays every tone with its+ haptic track, and drops the tone when the haptic engine fails to start.+ That holds for an iPhone guest and an iPad guest alike. A tree without+ the node is left as it is.++ Takes a devicetree.img4 (preferred) or a bare .im4p.""",)@Argument(help: "Path to devicetree.img4 or devicetree.im4p", transform: URL.init(fileURLWithPath:))var deviceTree: URL- @Argument(help: "Path to the iPad's DeviceTree.<board>.im4p", transform: URL.init(fileURLWithPath:))- var board: URL-@Flag(name: .customLong("dry-run"), help: "Report what would change and exit")var dryRun = falsefunc run() throws {- try CustomFirmwarePostRestoreDeviceTree.presentBoardHaptics(- at: deviceTree,- board: board,- dryRun: dryRun,- verbose: true,- )+ try CustomFirmwarePostRestoreDeviceTree.removeHaptics(at: deviceTree, dryRun: dryRun, verbose: true)}}diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swiftindex c04b34f9..eba742f5 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift@@ -185,7 +185,7 @@ struct VPhoneCustomFirmwareCommand: ParsableCommand {VPhoneCustomFirmwarePatchCampoEntitlementsCommand.self,VPhoneCustomFirmwarePatchPostRestoreDeviceTreeCommand.self,VPhoneCustomFirmwarePatchBoardAudioCommand.self,- VPhoneCustomFirmwarePatchBoardHapticsCommand.self,+ VPhoneCustomFirmwarePatchHapticsCommand.self,] + VPhoneCustomFirmwareMachOVerbs.all + VPhoneCustomFirmwareDyldSharedCacheVerbs.all,)}