Run a virtual iPhone on an Apple Silicon Mac.
Swift
Pin OpenAVB to upstream 3c7e7f6 and drop the carried patch
Jackyd9f2f1edbc54
diff --git a/AGENTS.md b/AGENTS.mdindex 766c0b59..4bbedc3c 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -56,7 +56,7 @@ The `VPhone` scheme puts host programs in `VPhone.bundle/Contents/MacOS` and eve### Key Patterns-- New machines boot **OpenAVB**, not Apple's AVPBooter: `VPhone.bundle/Contents/Resources/OpenAVB/OpenAVB.bin`, checked in prebuilt under `VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/` from a pinned OpenAVB commit plus the patches in `patches/` beside it. Rebuild or check it only with `Build/UpdateOpenAVB.sh` (Homebrew LLVM/LLD, outside the repo). `fw patch` skips AVPBooter on an OpenAVB machine; `vphone-cli restore` uploads the iBSS identity first (`MobileRestoreCore/Recovery/openavb.c`); `vm config --rom` switches ROM. See `Research/Firmware/openavb_boot_rom.md`.+- New machines boot **OpenAVB**, not Apple's AVPBooter: `VPhone.bundle/Contents/Resources/OpenAVB/OpenAVB.bin`, checked in prebuilt under `VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/` from a pinned OpenAVB commit plus any patches in `patches/` beside it (none at present). Rebuild or check it only with `Build/UpdateOpenAVB.sh` (Homebrew LLVM/LLD, outside the repo). `fw patch` skips AVPBooter on an OpenAVB machine; `vphone-cli restore` uploads the iBSS identity first (`MobileRestoreCore/Recovery/openavb.c`); `vm config --rom` switches ROM. See `Research/Firmware/openavb_boot_rom.md`.- `vphone-cli` is the unentitled entry point. `VPhoneGuestLaunchPlanner` resolves `vphone-vm` beside the running executable, checks its entitlements, probes AMFI, and reports the exact allowlist command on refusal. It never obtains root itself.- `vphone-escalator` manages AMFI cdhash admission only. It writes amfid heap state, not executable code. Root authorization belongs to the user or to `vphone-launchpad`; neither `vphone-cli` nor the bundle has an SMJobBless or sudo password flow.diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex b806844a..2bd5f621 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -3185,9 +3185,9 @@ they are.## OpenAVB replaces AVPBooter on new machines (2026-10-18)New machines boot OpenAVB (`Resources/OpenAVB/OpenAVB.bin`, built from-`owngoal-dev/OpenAVB` at `115169e`, which includes vphone's five-Virtualization.framework fixes, plus one carried patch that lets a guest-reboot: the ROM waits for a SEP restarted by the reset) instead of+`owngoal-dev/OpenAVB` at `3c7e7f6`, with no carried patches; upstream+includes vphone's six Virtualization.framework fixes, the last of which lets a+guest reboot: the ROM waits for a SEP restarted by the reset) instead ofVirtualization.framework's `AVPBooter.vresearch1.bin`. OpenAVB checks no imagedigest, so `avpbooter-boot-dgst_bypass` has nothing to patch on such a machine:`fw patch` drops the AVPBooter component when `romImages.avpBooter` names an@@ -3205,6 +3205,7 @@ Two boot-chain files change form, not content:No patch site moved and no patch was added or removed. The OpenAVB-sidechanges (read-only ROM aperture, chip ID 0, DFU suffix CRC, remote-boot bit,-USB device left running) were carried as patches at first and are now-upstream (owngoal-dev/OpenAVB#1). `Firmware/openavb_boot_rom.md` describes+USB device left running, SEP not ready after a warm reset) were carried as+patches at first and are now upstream (owngoal-dev/OpenAVB#1 and #2).+`Firmware/openavb_boot_rom.md` describeseach one and how it was found.diff --git a/Research/Firmware/openavb_boot_rom.md b/Research/Firmware/openavb_boot_rom.mdindex c0814428..be579fd8 100644--- a/Research/Firmware/openavb_boot_rom.md+++ b/Research/Firmware/openavb_boot_rom.md@@ -78,8 +78,10 @@ Virtualization.framework it did not start. Five changes made it boot andrestore. vphone carried them as patches until upstream took them in[owngoal-dev/OpenAVB#1](https://github.com/owngoal-dev/OpenAVB/pull/1),merged as `02ca2e5`. Upstream then rewrote `main` into one commit, `115169e`,-which keeps those changes, is the pin, and builds the same image the patched-`54b67bf` did, and OpenAVB's `make verify` passes on it. Each change+which keeps those changes and builds the same image the patched `54b67bf`+did. A sixth change, found later, went upstream in+[owngoal-dev/OpenAVB#2](https://github.com/owngoal-dev/OpenAVB/pull/2) as+`3c7e7f6`, which is the pin; OpenAVB's `make verify` passes on it. Each changewas found on a live machine by the first thing that stopped, in this order:1. **ROM aperture is read-only.** `_start` stores `avp_el2_present` at@@ -109,9 +111,8 @@ was found on a live machine by the first thing that stopped, in this order:(`4d682d940d6c950:514`: an event record whose type byte is not 1, 2 or 3).The handoff now writes the device's two enable registers (`+0x404`,`+0x400`) back to 0, and iBSS initializes it itself.-6. **SEP not ready after a warm reset** (carried as- `patches/0001-Wait-for-the-SEP-before-the-first-request-after-a-wa.patch`,- not upstream yet). A guest reboot is a PSCI `SYSTEM_RESET`, which restarts+6. **SEP not ready after a warm reset** (owngoal-dev/OpenAVB#2, carried as a+ patch until it was merged). A guest reboot is a PSCI `SYSTEM_RESET`, which restartsthe SEP together with the AP. Cold boots and restores worked, but everyguest reboot hung: the console filled with `SEP RX timeout`, andLaunchpad's setup boot failed at "the guest did not come back from the@@ -155,7 +156,7 @@ reach the VM's serial log.accepted`, iBSS and iBEC print `Remote boot`, and the restore ends `RestoreFinished` with 86 boot-chain patches in the receipt.With CFW installed it boots to iOS on OpenAVB and vphoned answers.-- Guest reboot (2026-10-18, with patch 0001): `system.reboot` on that machine+- Guest reboot (2026-10-18, with change 6): `system.reboot` on that machinecomes back in 10 s, three times out of three, with no `SEP RX timeout`.`vm template setup` (Launchpad's setup boot, which failed at its rebootstep without the patch) passes, the reboot taking 9 s. A second full DFU@@ -173,8 +174,14 @@ log show `OpenBootROM:` for OpenAVB.## Upstream-Changes 1 to 5 are upstream (owngoal-dev/OpenAVB#1; `main` at `115169e`-carries them). Change 6 is carried in `Resources/OpenAVB/patches/` as a-`git format-patch` file until upstream takes it; delete it when the pin moves-past it.+All six changes are upstream: 1 to 5 in owngoal-dev/OpenAVB#1 (folded into+`115169e`), 6 in owngoal-dev/OpenAVB#2. vphone carries no patch. The pin is+#2's own commit, `3c7e7f6`, not its merge `63c1ead`: both have the same tree+and `main` reaches both, but upstream has rewritten `main` once, and GitHub+keeps a PR's head commit reachable (`refs/pull/2/head`) after a rewrite. If+upstream rewrites `main` again, `UpdateOpenAVB.sh` fails at checkout; move the+pin to the rewritten commit that builds the same image.++A change upstream has not taken yet goes in `Resources/OpenAVB/patches/` as a+`git format-patch` file; delete it when the pin moves past it.`UpdateOpenAVB.sh` refuses a patch that no longer applies.diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/UpdateOpenAVB.sh b/VPhoneExecutable/VPhoneVirtualization/Build/UpdateOpenAVB.shindex 924a7965..3dd9dfdc 100755--- a/VPhoneExecutable/VPhoneVirtualization/Build/UpdateOpenAVB.sh+++ b/VPhoneExecutable/VPhoneVirtualization/Build/UpdateOpenAVB.sh@@ -20,7 +20,7 @@set -euo pipefailrepository="https://github.com/owngoal-dev/OpenAVB.git"-pinned="115169e61a206a967bb2299e5c3145888741bba3"+pinned="3c7e7f602d2d35af67f50454a8216337f35b11bb"root="$(cd "${0:a:h}/../../.." && pwd)"destination="$root/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB"diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/README.md b/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/README.mdindex 45618260..9f68e0f8 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/README.md+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/README.md@@ -10,8 +10,8 @@ the image into each new machine folder.| | || --- | --- || Source | `https://github.com/owngoal-dev/OpenAVB` |-| Commit | `115169e61a206a967bb2299e5c3145888741bba3` |-| Patches | `patches/*.patch`, applied in order (one) |+| Commit | `3c7e7f602d2d35af67f50454a8216337f35b11bb` |+| Patches | none (`patches/*.patch`, applied in order, when there are any) || Target | `make build/OpenAVB.bin` || Toolchain | Homebrew LLVM 23.1.3 (`clang`, `llvm-objcopy`), Homebrew LLD 23.1.3 || SHA-256 | `d63ea62226d4383288a5a36c440aa2d1df8cccabe0118cac0ab2e0c23ba4c3d2` |@@ -26,19 +26,18 @@ header). It clones and builds outside the repository and needs## Patches-One, not upstream yet:-`0001-Wait-for-the-SEP-before-the-first-request-after-a-wa.patch`. After a-guest reboot the SEP restarts together with the ROM, and a request sent-before it is up was dropped, so every guest reboot hung. The ROM now waits-for the SEP's first message before sending.--OpenAVB's first commit, `54b67bf`, did not run under+None. OpenAVB's first commit, `54b67bf`, did not run underVirtualization.framework. Five changes found on live machines made it boot andrestore, and upstream took them in-[owngoal-dev/OpenAVB#1](https://github.com/owngoal-dev/OpenAVB/pull/1). Upstream `main`-(`115169e`) carries them and, without the patch above, builds the same image the patched-`54b67bf` did. `Research/Firmware/openavb_boot_rom.md` has the evidence for-each change.+[owngoal-dev/OpenAVB#1](https://github.com/owngoal-dev/OpenAVB/pull/1), now+part of `115169e`. A sixth let a guest reboot: after a reboot the SEP restarts+together with the ROM, a request sent before it was up was dropped, and every+reboot hung, so the ROM now waits for the SEP's first message before sending.+Upstream took it in+[owngoal-dev/OpenAVB#2](https://github.com/owngoal-dev/OpenAVB/pull/2). The pin+is that PR's commit, `3c7e7f6`, which `main` reaches through the merge+`63c1ead` (same tree), rather than the merge itself.+`Research/Firmware/openavb_boot_rom.md` has the evidence for each change.If vphone needs a change upstream has not taken yet, put it in `patches/` as a`git format-patch` file. `UpdateOpenAVB.sh` applies patches in order anddiff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/patches/0001-Wait-for-the-SEP-before-the-first-request-after-a-wa.patch b/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/patches/0001-Wait-for-the-SEP-before-the-first-request-after-a-wa.patchdeleted file mode 100644index 14b0fdb9..00000000--- a/VPhoneExecutable/VPhoneVirtualization/Resources/OpenAVB/patches/0001-Wait-for-the-SEP-before-the-first-request-after-a-wa.patch+++ /dev/null@@ -1,88 +0,0 @@-From 20ae8738b77e53cf49a3e1cba195cab449368274 Mon Sep 17 00:00:00 2001-From: Jacky <[email protected]>-Date: Sun, 18 Oct 2026 19:23:41 +0800-Subject: [PATCH] Wait for the SEP before the first request after a warm reset--On a guest reboot (PSCI SYSTEM_RESET) Virtualization.framework restarts-the SEP together with the AP. OpenAVB got to the mailbox first, took it,-and sent the bootstrap request at once. The mailbox dropped it-("coprocessor.mailbox: Failed to send a message"), the SEP's own setup-then cleared the AP's ownership, and each side waited for the other:-the console filled with "SEP RX timeout" and the guest never came back.--After a cold start the SEP is up long before the ROM gets there and its-first message is already waiting. So after taking the slot, wait for-that message, taking the slot back if the SEP's restart drops it, and-send only then. Each ownership request also sets the enable bit at-+0x10 first, as Apple's ROM and the SEP ROM do.----- src/protocol/sep/sep.c | 35 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 1 deletion(-)--diff --git a/src/protocol/sep/sep.c b/src/protocol/sep/sep.c-index 77c9cbc..6dba128 100644---- a/src/protocol/sep/sep.c-+++ b/src/protocol/sep/sep.c-@@ -15,6 +15,7 @@ enum {- SEP_TIMEOUT_RECOVERY_LIMIT = 5,- SEP_TIMEOUT_POLL_INTERVAL_US = 100,- SEP_FINALIZE_ROUNDS = 8,-+ SEP_READY_TIMEOUT_US = 5000000,- };-- static void early_console_write(const char *message) {-@@ -29,11 +30,20 @@ static uint32_t timeout_recovery_count;- static bool preflight_wait_complete;- static uint8_t last_protocol_opcode;---void sep_initialize(void) {-+/*-+ * Request the slot until it reads as owned, setting the enable bit at +0x10-+ * before each request as Apple's ROM does, and as the SEP ROM does on its-+ * side.-+ */-+static void sep_acquire(void) {- uint32_t active_control = mmio_read32(SEP_MAILBOX_BASE + 0x14);- while ((active_control & SEP_MAILBOX_OWNED) == 0) {- /* The ownership register acknowledges writes, so an owned slot is- * observed and preserved without issuing another ownership request. */-+ mmio_write32(-+ SEP_MAILBOX_BASE + 0x10,-+ mmio_read32(SEP_MAILBOX_BASE + 0x10) | 1-+ );- mmio_write32(- SEP_MAILBOX_BASE + 0x14,- active_control | SEP_MAILBOX_OWNED-@@ -47,6 +57,29 @@ void sep_initialize(void) {- avp_memory_barrier();- }--+void sep_initialize(void) {-+ sep_acquire();-+ /*-+ * Do not send before the SEP has announced itself. After a cold start it-+ * is up long before this ROM gets here, and its first message is already-+ * waiting. After a warm reset (a guest reboot) it restarts together with-+ * this ROM and is slower: a request sent now is dropped by the mailbox,-+ * and the SEP's own setup then clears the ownership taken above, so both-+ * sides wait for each other. Wait for its message instead, taking the-+ * slot back when its restart drops it.-+ */-+ const uint64_t start = avp_time_counter();-+ const uint64_t limit = avp_time_microseconds_to_ticks(SEP_READY_TIMEOUT_US);-+ while ((mmio_read32(SEP_MAILBOX_BASE + 0x1c) & 0x00020000) != 0) {-+ if ((mmio_read32(SEP_MAILBOX_BASE + 0x14) & SEP_MAILBOX_OWNED) == 0) {-+ sep_acquire();-+ }-+ if (avp_time_has_elapsed(start, limit)) {-+ break;-+ }-+ }-+}-+- static int32_t sep_receive(- uint32_t timeout_microseconds,- SEPMailboxMessage *message----2.56.0-