Skip to content
How HakiOS Runs iOS 16.5 on Snapdragon 778G: 22-Step GPU Bring-Up & Mesa on Darwin

How HakiOS Runs iOS 16.5 on Snapdragon 778G: 22-Step GPU Bring-Up & Mesa on Darwin

This article details how the HakiOS project ports iOS 16.5 to the Snapdragon 778G-powered POCO X5 Pro, covering the custom bootloader, 22-step Adreno GPU initialization, Mesa graphics stack port to Darwin, 88 QMI service modem bring-up, a six-stage write-gating security design, and unresolved issues like missing Metal and cellular data.

Geek Labs
Geek Labs
Geek Labs

The HakiOS project demonstrates a research-grade port of iOS 16.5 to a non-Apple device — the POCO X5 Pro 5G (Snapdragon 778G / SM7325) — without writing a single byte to the phone's storage. The entire system runs from RAM via fastboot boot; a reboot restores the original Android installation.

Not a Flash: RAM-Only Execution

HakiOS is explicitly positioned as a research testbed, not a ROM. The user-space components are assembled on a host machine: sysimage/fetch.sh downloads the iOS 16.5 IPSW from Apple's public servers, extracts required parts, and builds a system image. Vendor firmware (GPU, Wi-Fi, audio DSP, modem, haptics) is pulled from the target device via adb pull and ignored by git. The repository contains zero Apple binaries, images, fonts, or screenshots.

Boot Chain: Three Custom Links

The boot sequence replaces Apple's closed iBoot with three custom components:

Android fastboot — loads the bootloader into memory.

HakiOS UEFI — a Mu-Silicium derivative that shows a boot splash, allocates framebuffer and storage.

xnuloader — a standalone UEFI application (no EDK2 dependency) that locates the XNUP payload, copies Mach-O segments into a free memory region, constructs an Apple-format device tree and boot_args structure, disables the MMU, and jumps to the kernel entry point.

The patched XNU kernel ( xnu-8796.121.2) plus 44,000 lines of new driver code in xnu/files/ and a 122 KB patch touching 73 files ( xnu/hakios.patch) then takes over, followed by the iOS 16.5 user space (launchd, backboardd, SpringBoard).

Driver Configuration: Opt-In, Dependency-Aware

Drivers are not enabled by default. Each requires an explicit boot argument (e.g., touchscreen=1, gpu=1, adsp=1 sound=4 mic=4, modem=1). Unselected drivers are excluded from compilation entirely. The project adopts XNU's native config/MASTER option mechanism: each subsystem declares a conf file listing its source files and dependencies via requires. For example, the SOUND driver requires ADSP and SPEAKER. A Linux-style Kconfig-inspired layer ( configs/defconfig, configs/<device>_defconfig, .config, savedefconfig) maps CONFIG_HAKIOS_<NAME> to driver inclusion and other CONFIG_* symbols to kernel boot arguments. A CI-verified script extracts over 300 boot arguments from source to keep documentation in sync.

GPU Bring-Up: 22 Steps Under Hypervisor Supervision

The Adreno 642L GPU initialization is documented in a 60+ line comment in the driver source. From cold silicon to a three-color test pattern, 22 carefully ordered steps are required. Key insights:

Step 1: Read, don't write. Query global clock controller state and RPMh supply names; read fuses for GPU identity. Notably, no hardware register holds the chip ID — qcom,chipid (0x06030500) exists only in the device tree.

Step 5: Verify clocks with a frequency counter. Control registers can lie — they may report enabled while the clock is not actually running.

Step 10: Write-then-read-back to GMU memory. Confirms the firmware communication path.

Steps 11-12: TrustZone interaction. The 3D core requires a signed "zap shader" ( a660_zap.mdt) to exit secure mode. TrustZone must verify the signature; the shader header is copied from the phone's small image into kernel memory for presentation.

Steps 13-15: Page tables and GMU firmware. Allocate memory for GMU firmware, build page tables and SMMU translation contexts, then load a660_gmu.bin.

Step 22: Render. Command the 3D core to produce a three-color frame.

Because the kernel runs under Qualcomm's Hypervisor, any disallowed access terminates execution — often silently and sometimes with delayed crashes. Debug switches allow stopping at step K ( adreno_only=K), skipping steps ( adreno_skip=MASK), and inserting pauses ( adreno_pause=MS, default 2200 ms) to catch delayed failures. After the test pattern, the entire GPU block is torn down in reverse order; no GPU state persists across reboots.

Graphics Stack: Porting Mesa's Freedreno to Darwin

Instead of writing a new Adreno driver for iOS's proprietary Metal stack, HakiOS ports the mature open-source freedreno Gallium driver from Mesa to Darwin. Freedreno expects libdrm/DRM-KMS; Darwin lacks libdrm. The project implements src/hakios-drm, backed by IOKit and CoreFoundation. The key difference: on Linux a buffer size is obtained via lseek(fd, 0, SEEK_END) on a real file descriptor; on Darwin the fd is an IOSurface ID, so a custom ioctl-like call hakios_drm_surface() retrieves the size. Four patches adapt freedreno ( freedreno-darwin.patch), the AIR frontend ( air-frontend.patch), the IR3 backend ( air-ir3.patch, ir3-round-default.patch), and OSMesa ES profile ( osmesa-es-profile.patch). This yields OpenGL ES support; Metal remains absent because it is Apple-exclusive. iOS's UIKit/CoreAnimation primarily uses CPU and IOSurface, so the UI functions, but Metal-dependent apps will not run.

Cellular Modem: 88 QMI Services and IPA Data Path

The modem bring-up is the largest single driver ( hakios.mpss.c, 250 KB). Qualcomm's Hexagon MPSS architecture requires TrustZone-loaded firmware, shared memory, SMP2P, GLINK, and QRTR to expose ~88 QMI services. The modem filesystem (modemst1/2, fsc, fsg) is served read-only from UFS via RMTFS; writes stay in kernel memory — the flash is never touched. TFTP over QRTR and a service registry (analogous to Android's tqftpserv and pd-mapper) are implemented from scratch. The IPA (IP Packet Accelerator) hardware packet engine is configured mirroring Linux's drivers/net/ipa: four GSI channels with event rings (command 5, LAN RX 14, modem TX 2, modem RX 7) mapped to endpoints 7/9/2/16. A design choice: rings are polled by the interface thread instead of using GSI interrupts. Modem packets are wrapped in an Ethernet-like en1 interface with a dummy router; the kernel answers ARP and DHCP (assigning a /24 gateway/DNS from the session address), letting iOS's configd treat it as a USB Ethernet adapter. A critical sequencing bug was documented: DPM Open Port → WDA Set Data Format → Bind Mux Data Port → Set IP Family → Start Network Interface . Skipping DPM Open Port causes InvalidOperation errors (discovered at iteration 38-41). Current status: modem powers up, SIM detected, NAS reads signal (UMTS -70 to -87 dBm), LTE service registration reached, but data session attach fails (packet domain not attached); no voice, SMS, or IPv6.

Security: Write-Gating as a Six-Stage Gate System

Unlike typical "one-command" flashing tools, HakiOS splits the transition from RAM-only to persistent storage into six stages with explicit gates:

Stages 0-1: Read-only pre-checks. Verify dual-slot layout, active slot, bootloader unlock status, battery level. Full backup of boot-critical partitions; each backup verified with three SHA-256 hashes (on-device, host, re-read from device).

Stage 2: Mostly read-only. Carve a darwin partition from the tail of Android's userdata; the tool only prints commands, does not execute writes.

Stage 3: First writes, guarded. A dedicated writer allows writes only to the darwin partition; all others rejected. Every write is followed by read-back verification.

Stage 4: Boot from darwin , loader still from RAM. System image lives on flash, but bootloader remains fastboot boot. A corrupted system image is recoverable by rebooting to Android.

Stage 5: Modify boot chain. Write to the inactive slot only, then fastboot set_active. The active slot is never touched.

Never written: xbl/abl/tz/hyp (bootloader chain), modem/RF calibration data, active slot. Rationale: Xiaomi bootloader chain damage requires official service tools.

Gate conditions are codified: Stage 2 requires Stage 1 manifest with verified partitions and backed-up data; Stage 3 requires new GPT read-back matching the partitioning tool and Android still bootable with data intact; Stage 5 requires Stage 4 to have booted successfully at least three times with logs written. Additionally, every write operation must be listed in tools/provenance.allow; CI fails on any undeclared writer. The loader itself enforces this whitelist at runtime.

Open Security Audit: 129 Findings, 10 Reports

The project publishes driver-review/README.md with 10 read-only audit reports totaling 129 findings, each with file, line, failure scenario, and confidence. Mechanical issues (bounds, integer widening, locking, error paths) were fixed; remaining issues are explicitly listed:

Six device nodes have 0666 permissions (touch, audio, mic, camera, haptic, flashlight) — any process can read mic/camera or inject touch events. Reason: all iOS daemons currently need access regardless of user; tightening requires deciding per-node ownership.

GPU command stream lacks validation and CP_PROTECT tables — client can write anywhere reachable by its SMMU context, effectively equating GPU access to root. Fix requires Adreno protection register hardware knowledge. posix_spawn persona entitlement check removed — any process can spawn root children. Original justification (no one uses the entitlement) is now outdated.

Touch controller firmware download lacks checksum verification and read-back.

The audit preamble states "not tested on phone" and excludes modem driver, XNU core, darwin-write.py, and var_store.c.

Comparison with Similar Projects

HakiOS compares itself (based on public info as of 2026-10-27) with three peers:

ios-sweet : Single device (Redmi Note 10 Pro, SM7150), iOS 16 bring-up, xnu-8796, MIT. Uses fastboot boot shim, HFS+ root in userdata.

UniXNU : Generic UEFI environment (OpenCore-like), Xiaomi Pad 6S Pro (SM8550), SoC code sharing, BSD-2-Clause-Patent.

Bergamota : Single device (Poco F1, SDM845), iOS 18 (ios-sweet fork), xnu-11215 "Heartwood", includes macOS control app, license unspecified.

HakiOS : Darwin kernel + custom loader/drivers + Linux-style config, POCO X5 Pro 5G (SM7325), xnu-8796.121.2, MIT + APSL 2.0 for kernel changes.

HakiOS unique features: configuration system, version string ( sysctl kern.hakios.version), 300+ auto-cataloged boot arguments, make qemu-open path requiring zero Apple software, provenance guard. Missing relative to peers: ios-sweet/Bergamota are smaller codebases; Bergamota targets iOS 18; UniXNU shares UEFI across devices; HakiOS loader currently covers one device family. All four cannot access Apple services (Apple ID, iMessage) due to missing Secure Enclave — a hard boundary.

How to Run

Three paths:

Lightweight (no Apple software):

git clone https://github.com/oosexgang/hakios-xnu-kernel.git hakios && cd hakios && make qemu-open

. Compiles kernel, runs a placeholder loader and raw-syscall hello in QEMU. No IPSW, no iOS user space, no phone firmware. Ideal for contributors.

QEMU full iOS: make fetch (downloads 7.4 GB IPSW), make images (builds APFS image), make qemu (~20 min session). Requires Linux x86-64, ~12 GB disk, 7-Zip 23+, lz4, qemu-system-aarch64, edk2-aarch64. Lock screen appears in 2-3 minutes; mouse = touch, H = home, L = power, arrows = volume.

Real hardware: Unlocked POCO X5 Pro 5G, adb/fastboot on host. make firmware pulls GPU/Wi-Fi/audio/haptic/modem/camera firmware from phone; make phone runs ~10 min session with all hardware enabled, then returns to Android. Note: documentation's clone URL ( hakios-os.git) 404s; actual repo is hakios-xnu-kernel (issue #17).

Not a daily driver: no Bluetooth, no charging support in this kernel, no Metal, no Apple ID login, cellular data not working. Only validated on POCO X5 Pro 5G.

Legal Review (AI-Assisted, Not Legal Advice)

A legal-review.md (2026-10-26) analyzes four layers:

Open-source code: Kernel patches under APSL 2.0, loader/tools under MIT — clean.

Running iOS on non-Apple hardware: Gray area; violates iOS license §2(a) (single Apple-branded device) and §2(d) (no modification/derivative works). Cites Apple v. Psystar (2011, 9th Cir.) upholding hardware restriction, and Apple v. Corellium (2023, 11th Cir., unpublished) where fair use prevailed for security research virtualization — but Corellium's facts are specific and settled; HakiOS sits between: not selling iOS/hardware (better than Psystar), but a port for on-device execution, not a research virtualization tool (weaker than Corellium).

Internal inconsistencies (P0): Vendor binaries still in git (Qualcomm UEFI driver from xbl.img, 2 MB SILICIUM_UEFI.fd, 713 KB touch firmware header) despite "never have" claim; iOS screenshots removed in commit 3849ceb but remain in git history (akin to icons/wallpapers in Corellium); experimental App Store/FairPlay code once existed; loader spoofs iPhone identity contradicting "won't impersonate to Apple services"; branding uses "iOS" in red ("HACK" white, "iOS" red) across repo, token, website.

$HackiOS token (BNB Chain, contract 0x5be8dca3…7777, 1B supply, 1% buy/sell tax, Snapshot governance, 50/30/20 split): Largest risk — turns research into revenue-generating project, altering legal/regulatory perception.

Verdict: Worth Studying, Not Worth Daily Driving

Strengths: Engineering quality is exceptional — 44k driver lines, 22-step GPU bring-up log, six-stage write-gating, 129-finding security audit with line numbers. The portable design (common/SoC/device repo split, tools/soc-args.py auto-generates kernel parameters from device tree via /sys/firmware/fdt over adb — IPA base, MPSS memory, PAS ID, SMMU stream IDs, IPA firmware names) enables new device ports by adding a directory under devices/, not rewriting. Third parties already porting to POCO X3 Pro (SM8150) and Infinix Hot 20 (MT6768).

Core difficulty: Simultaneous correctness across three layers: Hypervisor-constrained register access, Mesa-to-IOSurface graphics plumbing, and launchd-satisfying kernel responses. Any layer fails → entire stack fails. Hence the independent verification path make qemu-open.

Bottom line: If you want to learn "how to bring up hardware under a hypervisor," this codebase's comment quality makes it a textbook. If you just want iOS on your phone — only one device validated, no Bluetooth, no charging, no Metal, no Apple ID, no cellular data — don't bother. This is 2026's most readable kernel port, not the most installable OS. Its future depends on how the team resolves the P0 legal inconsistencies.

---

Project: https://github.com/oosexgang/hakios-xnu-kernel Companion repos:

hakios-sm7325      POCO X5 Pro 5G device layer (defconfig, UEFI platform, firmware scripts)
hakios-uefi        HakiOS UEFI (Mu-Silicium fork)
hakios-metal       Metal driver attempt
hakios-mt6768      Infinix Hot 20 port

Reminder: Validated on a single phone; do not use a primary device.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

kernel-developmentMesaXNU kernelDarwinAdreno GPUHakiOSiOS portingSnapdragon 778G
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.