Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

fw patcher: guest-system patch set and X1 bootstrap updates

Jackyebed07c3e445
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift
index 3f637d33..e551763f 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwarePostRestoreDeviceTree.swift
@@ -494,6 +494,12 @@ public enum CustomFirmwarePostRestoreDeviceTree {
/// ("Restore pose on VM") instead of waiting for hinge hardware.
public static let foldableVMSubtypes = ["V68AP": "V68VM2025"]
+ /// Every sub-type that marks a tree a foldable board's: the board's own
+ /// values and their VM replacements.
+ public static var foldableSubtypes: Set<String> {
+ Set(foldableVMSubtypes.keys).union(foldableVMSubtypes.values)
+ }
+
/// `blob` with its root `target-sub-type` replaced by the board's VM
/// sub-type. A tree whose sub-type has none, or already has it, comes back
/// unchanged.
@@ -525,6 +531,44 @@ public enum CustomFirmwarePostRestoreDeviceTree {
}
}
+ /// `blob` with `/product/product-id` taken from the foldable board's own
+ /// flat tree `board`, through `DeviceTreePatcher.presentFoldableProductID`.
+ /// Returns the size change with the changes, as `withHomePodAudioProduct`
+ /// does. A tree that is not a foldable guest, or already carries the
+ /// board's token, comes back unchanged.
+ public static func withFoldableProductId(_ blob: Data, board: Data) throws -> (Data, [Change], Int) {
+ let root = try parseTree(blob, label: "DT")
+ let source = try parseTree(board, label: "foldable board DT")
+ guard let change = try DeviceTreePatcher.presentFoldableProductID(in: root, from: source) else {
+ return (blob, [], 0)
+ }
+ let record = Change(property: "product/product-id", before: change.before?.hex ?? "absent", after: change.after.hex)
+ let delta = align4(change.after.count) - (change.before.map { align4($0.count) } ?? -36)
+ return (serializeNode(root), [record], delta)
+ }
+
+ /// Give a foldable guest's `devicetree.img4` (or bare `.im4p`) the board's
+ /// own product token, in place. See `withFoldableProductId`.
+ @discardableResult
+ public static func presentFoldableProductId(
+ at url: URL,
+ board boardURL: URL,
+ dryRun: Bool = false,
+ verbose: Bool = true,
+ ) throws -> Outcome {
+ let boardData: Data
+ do {
+ boardData = try Data(contentsOf: boardURL)
+ } catch {
+ throw PatcherError.fileNotFound(boardURL.path)
+ }
+ let board = try openDeviceTree(boardData, path: boardURL.path).blob
+ return try rewrite(at: url, dryRun: dryRun, verbose: verbose) { blob in
+ let (newBlob, changes, delta) = try withFoldableProductId(blob, board: board)
+ return (newBlob, changes, blob.count + delta)
+ }
+ }
+
/// The root of a flat tree that must fill `blob` exactly.
private static func parseTree(_ blob: Data, label: String) throws -> DeviceTreePatcher.DTNode {
let (root, end) = try parseNode(blob, at: 0)
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
index d3c386df..73b12db1 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
@@ -392,6 +392,79 @@ extension DeviceTreePatcher {
return (nil, value)
}
+ // MARK: - Foldable product identity
+
+ /// The 20-byte product token of a foldable board's own tree. CoreMotion
+ /// selects its motion capabilities from this token — the hinge-angle
+ /// manager among them — and the frameworks' `isV68` checks key on it; the
+ /// VM platform's token selects none. Accept a retained donor IM4P or its
+ /// decoded flat payload, never a token invented from the product name.
+ public static func foldableProductID(from data: Data) throws -> Data {
+ let payload: Data
+ if let im4p = try? IM4P(data) {
+ guard im4p.fourcc == "dtre", !im4p.isEncrypted else {
+ throw PatcherError.invalidFormat("Foldable product: expected an unencrypted dtre IM4P")
+ }
+ payload = try im4p.payload()
+ } else {
+ payload = data
+ }
+ let parser = DeviceTreePatcher(data: payload, verbose: false)
+ return try foldableProductID(from: parser.parsePayload(payload))
+ }
+
+ static func foldableProductID(from source: DTNode) throws -> Data {
+ let subtypes = rootSubtypes(of: source)
+ guard subtypes.count == 1,
+ CustomFirmwarePostRestoreDeviceTree.foldableVMSubtypes.keys.contains(subtypes[0])
+ else {
+ throw PatcherError.invalidFormat(
+ "Foldable product: expected a foldable board tree, not \(subtypes.isEmpty ? "no sub-type" : subtypes.joined(separator: ", "))",
+ )
+ }
+ let product = try child(of: source, named: "product")
+ let properties = product.properties.filter { $0.name == "product-id" }
+ guard properties.count == 1, let property = properties.first,
+ property.flags == 0, property.value.count == 20
+ else {
+ throw PatcherError.invalidFormat("Foldable product: donor product-id must be one concrete 20-byte value")
+ }
+ return property.value
+ }
+
+ /// Replace the installed tree's product token with the foldable board's
+ /// own. The installed tree must itself be a foldable guest — the board's
+ /// own sub-type or the VM value the sub-type repair writes — so a
+ /// foldable board's token never reaches another guest. A tree that
+ /// already carries the token, or is not a foldable guest, comes back
+ /// unchanged.
+ static func presentFoldableProductID(in root: DTNode, from source: DTNode) throws -> (before: Data?, after: Data)? {
+ let subtypes = rootSubtypes(of: root)
+ guard subtypes.count == 1,
+ CustomFirmwarePostRestoreDeviceTree.foldableSubtypes.contains(subtypes[0])
+ else { return nil }
+ let value = try foldableProductID(from: source)
+ let product = try child(of: root, named: "product")
+ guard product.properties.filter({ $0.name == "product-id" }).count <= 1 else {
+ throw PatcherError.invalidFormat("Foldable product: installed product-id is duplicated")
+ }
+ if let existing = product.properties.first(where: { $0.name == "product-id" }) {
+ guard existing.value != value || existing.flags != 0 else { return nil }
+ let before = existing.value
+ existing.value = value
+ existing.flags = 0
+ return (before, value)
+ }
+ product.properties.append(DTProperty(name: "product-id", flags: 0, value: value, valueOffset: 0))
+ return (nil, value)
+ }
+
+ private static func rootSubtypes(of node: DTNode) -> [String] {
+ node.properties
+ .filter { $0.name == "target-sub-type" }
+ .compactMap { String(data: $0.value.prefix { $0 != 0 }, encoding: .utf8) }
+ }
+
/// What `presentBoardAudio` changed: the audio node's serialized bytes
/// before and after, empty when there was no node.
struct BoardAudioChange {
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index 0c3150ea..bb10da46 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -28,6 +28,9 @@ public enum FirmwareGuestSystemPatchSet {
public static let metalCacheReuseMarker = "/usr/lib/vphone-metal-cache-reuse"
public static let gyroscope = "system-backboardd-cfw-gyroscope"
public static let accelerometer = "system-backboardd-cfw-accelerometer"
+ public static let hinge = "system-backboardd-cfw-hinge"
+ public static let foldGuard = "system-springboard-cfw-fold_guard"
+ public static let foldDisplay = "system-springboard-cfw-fold_display"
public static let attitude = "system-apps-cfw-attitude"
public static let arm64eX1DyldBootstrap = "system-dyld-boot-arm64e_x1_bootstrap"
public static let arm64eX1CacheBootstrap = "dyld-boot-arm64e_x1_bootstrap"
@@ -449,6 +452,48 @@ public enum FirmwareGuestSystemPatchSet {
applicability: VPhonePatchApplicability(iOSBase: .atLeast(major: 18, minor: 0)),
),
+ VPhonePatchDeclaration(
+ identifier: hinge,
+ title: "Virtual hinge angle sensor",
+ summary: """
+ Installs libvphonehinge.dylib, loaded by SystemHook into backboardd. Publishes the \
+ foldable's virtual hinge HID service (usage page 0xFF0C, usage 0x21) and reports \
+ the hinge angle chosen by display.posture, so CoreMotion's angle manager — and \
+ through it CoreDevice's hingeAngle stream — reads the fold state instead of \
+ finding no sensor. With the foldable product identity patch, which is what makes \
+ CoreMotion look for the service. Foldable guests only.
+ """,
+ target: .guestFile(path: "/usr/lib/libvphonehinge.dylib"),
+ applicability: VPhonePatchApplicability(iOSBase: .atLeast(major: 18, minor: 0)),
+ ),
+
+ VPhonePatchDeclaration(
+ identifier: foldGuard,
+ title: "Foldable secure-indicator guard",
+ summary: """
+ Installs libvphonefoldguard.dylib, loaded by SystemHook into SpringBoard. With \
+ the foldable product identity, SpringBoard's first CA transaction reaches \
+ CASecureIndicatorLayer, which raises about indicator geometry a single-display \
+ guest cannot supply — the raise crash-loops SpringBoard into device-recovery \
+ (SIGABRT, measured twice on 27.1 24A94425). The guard catches that one exception \
+ and answers no layer copy, so the system app boots with the Duo identity and its \
+ fold layouts; the secure indicator is the casualty. Inert on any guest without \
+ the identity. Foldable guests only.
+ """,
+ target: .guestFile(path: "/usr/lib/libvphonefoldguard.dylib"),
+ applicability: VPhonePatchApplicability(iOSBase: .major(27)),
+ ),
+
+ VPhonePatchDeclaration(
+ identifier: foldDisplay,
+ title: "Foldable second-display identity",
+ summary: """
+ Installs libvphonefolddisplay.dylib, loaded by SystemHook into SpringBoard. SpringBoard sizes its home grid from the display topology: with one always-connected display the grid keeps the outer panel's fit whatever the panel's pixel size, because the fold layouts key on +[FBDisplayManager alwaysConnectedIdentities].count >= 2 and the guest's paravirt GPU binds a single connector. The library pads a single answer with a copy of the real identity, so the count gates pass without inventing a display. Experimental: whether the grid then follows the posture is what this observes, and identity-keyed consumers may dedupe the copy. Foldable guests only.
+ """,
+ target: .guestFile(path: "/usr/lib/libvphonefolddisplay.dylib"),
+ applicability: VPhonePatchApplicability(iOSBase: .major(27)),
+ ),
+
VPhonePatchDeclaration(
identifier: attitude,
title: "Device attitude simulation",
@@ -617,6 +662,21 @@ public enum FirmwareGuestSystemPatchSet {
""",
target: .prebootDeviceTree,
),
+ VPhonePatchDeclaration(
+ identifier: prebootFoldableProductId,
+ title: "Foldable product identity",
+ summary: """
+ Research only, off in every preset. Replaces /product/product-id in a foldable \
+ guest's restored Preboot device tree with the board's own token, taken from the \
+ Duo's DeviceTree.v68ap. Measured on duotest-m5 (27.1, 24A94425): with the Duo \
+ token and one display, SpringBoard crash-loops and launchd reboots the guest into \
+ device-recovery — the Duo branches the token opens expect the second panel. \
+ CoreMotion's hinge capability therefore needs a narrower route than the device-tree \
+ token; Apple's Duo simulator satisfies it by registering two displays in its device \
+ type, not by the token alone.
+ """,
+ target: .prebootDeviceTree,
+ ),
VPhonePatchDeclaration(
identifier: prebootHaptics,
title: "Haptics node",
@@ -719,6 +779,7 @@ public enum FirmwareGuestSystemPatchSet {
/// Apple's VM sub-type for a foldable board in the restored Preboot
/// device tree.
public static let prebootFoldableVMSubtype = "preboot-cfw-devicetree_foldable_vm_subtype"
+ public static let prebootFoldableProductId = "preboot-exp-devicetree_foldable_product_id"
/// The haptics node removal in the restored Preboot device tree, for any
/// VM patched before `fw patch` removed it from every guest's tree.
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
index 255f0273..10138eaa 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
@@ -70,6 +70,7 @@ public enum FirmwarePatchSetCatalog {
.union(experimentalIdentityPatches)
.union([FirmwareGuestSystemPatchSet.otaUserland, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow, FirmwareGuestSystemPatchSet.homePodCryptexStaging, FirmwareGuestSystemPatchSet.homePodCryptexClass, FirmwareGuestSystemPatchSet.homePodAdHocInstall])
.union([FirmwareKernelCustomFirmwarePatchSet.tvTPROPagers, misTrustAuthPatch, FirmwareGuestSystemPatchSet.settingsRootRows, FirmwareGuestSystemPatchSet.settingsSoftwareUpdate, FirmwareGuestSystemPatchSet.tvTPRO, FirmwareGuestSystemPatchSet.tvOTAUserland])
+ .union([FirmwareGuestSystemPatchSet.prebootFoldableProductId])
/// ProMotion: the 120 Hz timing for the paravirtual display.
///
@@ -250,11 +251,14 @@ public enum FirmwarePatchSetCatalog {
"preboot-cfw-devicetree_haptics",
"preboot-cfw-devicetree_iphone_product",
"preboot-cfw-devicetree_foldable_vm_subtype",
+ "preboot-exp-devicetree_foldable_product_id",
"preboot-cfw-devicetree_microphone_array",
RestoreRamDiskSealPatcher.patchIdentifier,
"system-apps-cfw-attitude",
"system-backboardd-cfw-gyroscope",
"system-backboardd-cfw-accelerometer",
+ "system-backboardd-cfw-hinge",
+ "system-springboard-cfw-fold_guard",
"system-campo-cfw-entitlements",
"system-debugserver-cfw-install",
FirmwareGuestSystemPatchSet.arm64eX1DyldBootstrap,
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareIPhoneProductTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareIPhoneProductTests.swift
index 7039cf75..000dd321 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareIPhoneProductTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareIPhoneProductTests.swift
@@ -141,3 +141,72 @@ struct CustomFirmwareFoldableVMSubtypeTests {
}
}
}
+
+@Suite("Foldable product identity")
+struct CustomFirmwareFoldableProductIdTests {
+ private typealias Node = FlatDeviceTreeNode
+
+ private static let boardToken = Data((0 ... 19).map { UInt8(0xa0 + $0) })
+ private static let vmToken = Data(repeating: 0x5a, count: 20)
+
+ private static func tree(subtype: String, productID: Data?) -> Data {
+ var properties: [(String, Data)] = [("product-name", Data("iPhone\0".utf8))]
+ if let productID {
+ properties.append(("product-id", productID))
+ }
+ return Node("device-tree", [
+ ("model", Data("iPhone19,4\0".utf8)),
+ ("target-sub-type", Data("\(subtype)\0".utf8)),
+ ("target-type", Data("v68\0".utf8)),
+ ], children: [Node("product", properties)]).serialized
+ }
+
+ @Test func `a foldable guest takes the board's product token`() throws {
+ // Both sub-types the guest can carry: the board's own, and the VM
+ // value the sub-type repair writes before this one runs.
+ for subtype in ["V68AP", "V68VM2025"] {
+ let original = Self.tree(subtype: subtype, productID: Self.vmToken)
+ let board = Self.tree(subtype: "V68AP", productID: Self.boardToken)
+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withFoldableProductId(original, board: board)
+ #expect(changes.map(\.property) == ["product/product-id"])
+ #expect(changes.first?.before == Self.vmToken.hex)
+ #expect(changes.first?.after == Self.boardToken.hex)
+ #expect(delta == 0)
+ #expect(patched == Self.tree(subtype: subtype, productID: Self.boardToken))
+ }
+ }
+
+ @Test func `a tree without the property gains it`() throws {
+ let original = Self.tree(subtype: "V68VM2025", productID: nil)
+ let board = Self.tree(subtype: "V68AP", productID: Self.boardToken)
+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withFoldableProductId(original, board: board)
+ #expect(changes.map(\.property) == ["product/product-id"])
+ #expect(changes.first?.before == "absent")
+ #expect(delta == 36 + 20)
+ #expect(patched == Self.tree(subtype: "V68VM2025", productID: Self.boardToken))
+ }
+
+ @Test func `other guests and a second run are left alone`() throws {
+ let board = Self.tree(subtype: "V68AP", productID: Self.boardToken)
+ for subtype in ["D47AP", "V63AP"] {
+ let original = Self.tree(subtype: subtype, productID: Self.vmToken)
+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withFoldableProductId(original, board: board)
+ #expect(changes.isEmpty)
+ #expect(delta == 0)
+ #expect(patched == original)
+ }
+ let settled = Self.tree(subtype: "V68VM2025", productID: Self.boardToken)
+ let (patched, changes, delta) = try CustomFirmwarePostRestoreDeviceTree.withFoldableProductId(settled, board: board)
+ #expect(changes.isEmpty)
+ #expect(delta == 0)
+ #expect(patched == settled)
+ }
+
+ @Test func `a non-foldable donor is refused`() throws {
+ let original = Self.tree(subtype: "V68VM2025", productID: Self.vmToken)
+ let donor = Self.tree(subtype: "D47AP", productID: Self.boardToken)
+ #expect(throws: (any Error).self) {
+ _ = try CustomFirmwarePostRestoreDeviceTree.withFoldableProductId(original, board: donor)
+ }
+ }
+}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
index bb7a6cb1..4991ccb2 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
@@ -474,7 +474,15 @@ struct FirmwarePatchSetCatalogTests {
#expect(shipped.count == FirmwarePatchSetCatalog.builtInPresets.count)
for builtIn in FirmwarePatchSetCatalog.builtInPresets {
let match = shipped.first { $0.identifier == builtIn.identifier }
- #expect(match == builtIn, "\(builtIn.identifier).plist differs from the built-in copy")
+ if match != builtIn, let match,
+ case let .block(shippedBlocked) = match.selection,
+ case let .block(builtInBlocked) = builtIn.selection {
+ let missing = builtInBlocked.subtracting(shippedBlocked).sorted()
+ let extra = shippedBlocked.subtracting(builtInBlocked).sorted()
+ #expect(match == builtIn, "\(builtIn.identifier).plist differs from the built-in copy — plist missing: \(missing), plist extra: \(extra)")
+ } else {
+ #expect(match == builtIn, "\(builtIn.identifier).plist differs from the built-in copy")
+ }
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index c82b4bc5..de682fc7 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -569,6 +569,9 @@ struct VPhoneCustomFirmwareInstaller {
}
if !Self.isFoldable(device) {
notApplicableGuest.insert(FirmwareGuestSystemPatchSet.prebootFoldableVMSubtype)
+ notApplicableGuest.insert(FirmwareGuestSystemPatchSet.prebootFoldableProductId)
+ notApplicableGuest.insert(FirmwareGuestSystemPatchSet.hinge)
+ notApplicableGuest.insert(FirmwareGuestSystemPatchSet.foldGuard)
}
if !device.usesTVOS {
notApplicableGuest.insert(FirmwareGuestSystemPatchSet.tvTPRO)
@@ -1266,6 +1269,8 @@ struct VPhoneCustomFirmwareInstaller {
&& identifier != FirmwareGuestSystemPatchSet.gyroscope
&& identifier != FirmwareGuestSystemPatchSet.accelerometer
&& identifier != FirmwareGuestSystemPatchSet.attitude
+ && identifier != FirmwareGuestSystemPatchSet.hinge
+ && identifier != FirmwareGuestSystemPatchSet.foldGuard
}
guard plan.isEnabled(identifier) else {
print(" [·] \(identifier): off in preset \(plan.presetIdentifier)")
@@ -1408,7 +1413,10 @@ struct VPhoneCustomFirmwareInstaller {
} catch let overflow as DyldSharedCacheMaxSlidePatcher.RegionOverflow {
throw overflow
} catch {
- print(" [!] shared region check skipped: \(error)")
+ // Expected: the preflight looks for the plain arm64e cache file,
+ // and every iOS 27 guest ships a chunked X1 cache the later cache
+ // stage measures directly. Nothing to report.
+ print(" [·] shared region check skipped: the cache is not a plain \(cacheArchitecture) file")
}
if guestDevice.hasPlainArm64Userland {
@@ -1554,10 +1562,23 @@ struct VPhoneCustomFirmwareInstaller {
(FirmwareGuestSystemPatchSet.gyroscope, "libvphonegyro.dylib"),
(FirmwareGuestSystemPatchSet.accelerometer, "libvphoneaccelerometer.dylib"),
(FirmwareGuestSystemPatchSet.attitude, "libvphoneattitude.dylib"),
+ (FirmwareGuestSystemPatchSet.hinge, "libvphonehinge.dylib"),
+ (FirmwareGuestSystemPatchSet.foldGuard, "libvphonefoldguard.dylib"),
+ (FirmwareGuestSystemPatchSet.foldDisplay, "libvphonefolddisplay.dylib"),
] {
isolate([identifier]) {
let path = "usr/lib/" + library
- if on(identifier) {
+ // The hinge serves a foldable guest's CoreMotion, the guard
+ // exists only beside the foldable identity, and the display
+ // pad answers the fold layouts' two-display gate; on any other
+ // guest they would publish hooks nobody reads or a no-op that
+ // is not installed at all.
+ let foldOnly = identifier == FirmwareGuestSystemPatchSet.hinge
+ || identifier == FirmwareGuestSystemPatchSet.foldGuard
+ || identifier == FirmwareGuestSystemPatchSet.foldDisplay
+ let wanted = on(identifier)
+ && (!foldOnly || Self.isFoldable(guestDevice))
+ if wanted {
try system.replaceFile(path, fromFileAt: VPhoneGuestBinaries.resolve(library),
mode: 0o755, owner: Self.guestOwner)
live.insert(identifier)
@@ -3054,7 +3075,14 @@ struct VPhoneCustomFirmwareInstaller {
boardDeviceTree.map { [$0.path] } ?? []))
}
if Self.isFoldable(guestDevice) {
+ // Keep the repair in the inverse composition even with no donor
+ // when it is off: restoring the clean backup needs no source tree.
+ if enabled(FirmwareGuestSystemPatchSet.prebootFoldableProductId), boardDeviceTree == nil {
+ throw ValidationError("Foldable product identity needs the board's own device tree.")
+ }
repairGroup.append((FirmwareGuestSystemPatchSet.prebootFoldableVMSubtype, "patch-dt-foldable-vm-subtype", []))
+ repairGroup.append((FirmwareGuestSystemPatchSet.prebootFoldableProductId, "patch-dt-foldable-product-id",
+ boardDeviceTree.map { [$0.path] } ?? []))
}
repairGroup.append((FirmwareGuestSystemPatchSet.prebootHaptics, "patch-dt-haptics", []))
repairGroup.append((FirmwareGuestSystemPatchSet.prebootMicrophoneArray, "patch-dt-microphone-array", []))
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
index 7fe9ca43..d17db687 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
@@ -618,6 +618,41 @@ struct VPhoneCustomFirmwarePatchFoldableVMSubtypeCommand: ParsableCommand {
}
}
+// MARK: - patch-dt-foldable-product-id
+
+struct VPhoneCustomFirmwarePatchFoldableProductIdCommand: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "patch-dt-foldable-product-id",
+ abstract: "Give a foldable guest's device tree the board's own product identity",
+ discussion: """
+ Replaces /product/product-id of a foldable guest's device tree with the
+ foldable board's own 20-byte token, taken from the board's tree, in
+ place, preserving the container's compression, manifest and restore
+ info. CoreMotion selects its motion capabilities from that token — the
+ hinge-angle manager among them — and the frameworks' isV68 checks key
+ on it, so UIKit and Photos open their Duo branches too. Any other
+ tree, or one that already carries the token, is left as it is.
+
+ Takes a devicetree.img4 (preferred) or bare .im4p, and the foldable
+ board's DeviceTree.<board>.im4p.
+ """,
+ )
+
+ @Argument(help: "Path to devicetree.img4 or devicetree.im4p", transform: URL.init(fileURLWithPath:))
+ var deviceTree: URL
+
+ @Argument(help: "Path to the foldable board'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 = false
+
+ func run() throws {
+ try CustomFirmwarePostRestoreDeviceTree.presentFoldableProductId(
+ at: deviceTree, board: board, dryRun: dryRun, verbose: true)
+ }
+}
+
// MARK: - patch-dt-haptics
struct VPhoneCustomFirmwarePatchHapticsCommand: ParsableCommand {
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
index c3dd46d4..d61dd110 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
@@ -258,6 +258,7 @@ struct VPhoneCustomFirmwareCommand: ParsableCommand {
VPhoneCustomFirmwarePatchHomePodCryptexClassCommand.self,
VPhoneCustomFirmwarePatchIPhoneProductCommand.self,
VPhoneCustomFirmwarePatchFoldableVMSubtypeCommand.self,
+ VPhoneCustomFirmwarePatchFoldableProductIdCommand.self,
VPhoneCustomFirmwarePatchHapticsCommand.self,
VPhoneCustomFirmwarePatchMicrophoneArrayCommand.self,
] + VPhoneCustomFirmwareMachOVerbs.all + VPhoneCustomFirmwareDyldSharedCacheVerbs.all,