Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
tools, docs: doctor, a Windows guide and a legal review
shimokuaf258d2b6b91
diff --git a/Makefile b/Makefileindex 1bf135f..ff6814a 100644--- a/Makefile+++ b/Makefile@@ -13,6 +13,7 @@# make phone a session on the phone, then back to Android (tools/modem-cycle.sh)# make prebuilt refresh prebuilt/ from what was built (tools/update-prebuilt.sh)# make clean build output of the kernel, loader and images+# make doctor check this machine and a phone on adb for what HakiOS needs (tools/doctor.sh)## DEVICE=poco-x5-pro the device directory under devices/ (default poco-x5-pro)# ARGS="..." kernel arguments for make phone (default: everything the phone has)@@ -26,10 +27,13 @@ ARGS_OPEN ?= cpus=1ARGS ?= touchscreen=1 gpu=1 adsp=1 sound=4 wifi=1 haptic=5 modem=1 modem_again=1 modem_buffer=0xa8000000IMAGE_OPTS ?= REST=1-.PHONY: help fetch images kernel loader loader-open hello qemu qemu-open phone prebuilt clean all+.PHONY: help fetch images kernel loader loader-open hello qemu qemu-open phone prebuilt clean all doctorhelp:- @sed -n '2,23p' Makefile | sed 's/^# \{0,1\}//'+ @awk '{ if (!/^#/) exit; sub(/^# ?/, ""); print }' Makefile++doctor:+ tools/doctor.shall: kernel loader imagesdiff --git a/docs/legal-review.md b/docs/legal-review.mdnew file mode 100644index 0000000..98e4ed0--- /dev/null+++ b/docs/legal-review.md@@ -0,0 +1,183 @@+# Legal review of HakiOS (and of funding it with a token)++Date: 2026-10-26. Author: an AI assistant reading the repository and public sources. **This is not+legal advice and not a lawyer's opinion.** It is a risk map with evidence, meant to tell you what to+fix first and what to ask a real lawyer. Every claim about the repository was checked against the+files named; every claim about law or cases is linked to the source it came from. Where I could not+verify something, it says so.++## Verdict++"Is it legal?" has no single answer, because the project is four different things:++| Layer | Verdict | Why |+|---|---|---|+| The open code (kernel patch under APSL 2.0, our loader/tools/userland under MIT) | **Fine, with homework done well.** | `COMPLIANCE.md` is a solid checklist: source published, Apple's notices kept, XNU-derived code not relabelled MIT. |+| **Running iOS on non-Apple hardware** | **Grey, and a breach of Apple's licence for whoever does it.** | The licence grants use "on a single Apple-branded Device" and forbids copying/decrypting/modifying/deriving ([iOS 16 licence](https://www.apple.com/legal/sla/docs/iOS16_iPadOS16.pdf), §2(a), §2(d)). Not distributing iOS is the right mitigation and you do it. Courts split on the rest (below). |+| **Four things in the repo that contradict its own legal statements** | **Fix before anything else.** | Vendor blobs tracked in git, iOS screenshots still in history, App Store/FairPlay experiments plus an iPhone identity, "iOS" emphasised in the brand. Details below. |+| **The $HackiOS token** | **Separate, and the biggest risk of the whole thing.** | A token licenses nothing and cannot make the project "legal"; it can only fund it. But it turns a research project into one with a revenue stream, which changes how courts, Apple, platforms and regulators see it. |++The single most useful sentence: **keep the token and the code completely apart, and never sell or+gate anything that contains Apple's code behind it.**++## 1. Apple: what the cases actually say++- **[Apple v. Psystar](https://jolt.law.harvard.edu/digest/apple-inc-v-psystar-corp) (9th Cir., 2011):**+ Apple won. Psystar sold computers running Mac OS X, which its licence limits to Apple hardware; the+ court affirmed infringement and rejected "copyright misuse", so a licence restriction to Apple+ hardware was enforceable. Psystar was a commercial hardware seller, and the district court also+ found a DMCA violation (I could not confirm what the appeal said about the DMCA part).+- **[Apple v. Corellium](https://9to5mac.com/2023/05/08/us-court-corellium-apple-ios/) (11th Cir., May+ 2023, unpublished):** Corellium won on fair use for its iOS virtualisation, reasoning that it+ advanced security research and that iOS is largely functional. Three limits matter to you: the+ opinion is unpublished and fact-specific; the court **sent back Apple's claims about icons and+ wallpapers** unresolved; and the parties [settled in December 2023](https://www.theregister.com/2023/12/18/apple_corellium_case_settles/)+ on confidential terms. Corellium was a research tool, not a consumer port.+- **What follows for HakiOS:** you sit between the two. You do not sell iOS or hardware (good, unlike+ Psystar), but you are a hardware port that lets people run iOS on a phone, not a research+ virtualiser, and Corellium's facts are about research. Do not rely on Corellium as a safe harbour.+- **Jurisdiction decides a lot.** Apple's licence is governed by California law (§12), but the+ maintainers and users live elsewhere. In the EU, rules on lawful acquirers and interoperability+ differ from US copyright law; in Ukraine I have not checked. This is the first question for a lawyer.++### What the build does that touches Apple's code (the exposure that is yours, not the user's)++- `sysimage/fetch.sh` downloads parts of the IPSW from Apple's public CDN and `userland/build.sh`+ assembles a modified root image: it selects parts of iOS, replaces launchd with `stage0`, injects+ our dylibs into SpringBoard and other Apple processes (`userland/src/inject*.c`), and+ `xnuloader/mkidentity.py` copies the iPhone's device-tree identity so the system "believes it is+ the iPhone its files were built for". Licence §2(d) forbids to "modify, or create derivative works".+ That is the clause someone would point at. It is a licence/contract problem for the person+ running it first, and a "you are inducing it" argument against the project second.+- The kernel replaces Apple's code-signing policy with a stub (`libkern/amfi/miniamfi.c`,+ `bsd/kern/kern_minimac.c`; the patch says "nothing is signed here ... AMFI is a stub"). That is+ *implementing nothing* rather than *breaking* a protection, which likely sits on the safer side of+ the DMCA's anti-circumvention rule, but it is untested. Make the sentence "without decrypting or+ circumventing anything" in the README precise ("the IPSW is downloaded unmodified; no encryption is+ broken") instead of absolute.++## 2. Four places where the repo contradicts its own legal text — fix first++### P0-a. Vendor binaries are in git (and the docs say they are not)++`README.md` and `LEGAL.md` say the phone's firmware is "never" in the repository. But the tree tracks:+`devices/poco-x5-pro/uefi/files/Binaries/redwood/**` (Qualcomm/Xiaomi UEFI drivers extracted from+`xbl.img`, e.g. `DisplayDxe.efi`, `DALSYSDxe.efi`, `XBLCore.te`), the **built image+`devices/poco-x5-pro/prebuilt/SILICIUM_UEFI.fd` (2 MB, contains those drivers)**, and+`xnu/files/bsd/dev/hakios.focaltech_fw.h` (713 KB, a touch-controller firmware turned into a header).+`COMPLIANCE.md` itself marks all of this "to verify, not cleared". The upstream [Mu-Silicium](https://github.com/Project-Silicium/Mu-Silicium)+licenses its *code* BSD-2-Clause (GPL for some dirs) and states **no terms** for the vendor-binaries+folder, so "Project Silicium does it too" is not a licence.++Note: deleting `Binaries/` is not enough, because `SILICIUM_UEFI.fd` carries the same drivers.++**Fix:** move all three to the pull-from-device model the rest of the firmware already uses (the+`pull-firmware-root.sh` and UEFIReader flow), build `SILICIUM_UEFI.fd` locally, and drop the tracked+copies. Then fix the sentences in README/LEGAL so they are true.++### P0-b. iOS screenshots are still in the history++Commit `3849ceb` (2026-10-25) removed `docs/homescreen.jpg`, `lockscreen`, `settings`, `messages`,+`maps`, `wallet`, `appstore-*`, and more, but they remain retrievable from history and from any clone+or fork made before. They show Apple's UI, icons and wallpapers, which is exactly what Apple's+remanded claims in *Corellium* were about.++**Fix:** purge them with `git filter-repo` and force-push (coordinate with the team: every clone and+fork must re-sync), then ask GitHub support to drop cached views of the old commits. Decide this+consciously: the alternative is to accept the risk and say so.++### P0-c. App Store / FairPlay experiments and the iPhone identity vs "not an iPhone to Apple's services"++`README.md:37` and `LEGAL.md:37` promise nothing "that would make the phone pass as an iPhone to+Apple's services". Yet: the loader presents the device as an iPhone (`identity.h`), and+`userland/src/inject_store.c` (opt-in `STOREFRONT=1`) injects into `appstored`, makes it answer with+the storefront `143469-2,8`, and notes that it fetched Apple's bag from `bag.itunes.apple.com` and+`init.itunes.apple.com` "by hand". `inject_fairplay.c` studies Apple's **FairPlay** daemon. iOS itself,+believing it is an iPhone X, also contacts Apple's servers on its own.++Whether any of that is unlawful depends on law I have not verified (terms of service, computer-misuse+statutes, DRM rules), but it plainly contradicts the stated promise, and touching FairPlay and the+store is what draws attention. **Fix:** keep these experiments out of the public repository (a private+branch), make outbound traffic to Apple's service hosts blocked by default in the image with a documented+switch, and rewrite the sentence to say what is true.++### P1. The name and the logo emphasise "iOS"++The project is "HakiOS" in the repo, "HackiOS" in the token and site, and the brand rules write "HACK in+white, iOS in red". "iOS" is Apple's mark; descriptive use ("works with iOS") is fine, but a product name+that embeds and highlights it is where confusion claims start, and `hackios.org` repeats it. This is a+branding decision, not a legal emergency: at least stop highlighting "iOS" in the logo, and use one+spelling everywhere. A rename is the clean fix if you expect to grow.++## 3. Copyright hygiene in your own code (low effort, high value)++- **Contributions:** `CONTRIBUTING.md` says contributions come under the same terms. Add a DCO+ sign-off requirement (`Signed-off-by:`) so each contributor states they have the right to submit.+- **APSL files:** the `xnu/files/` drivers are under APSL 2.0 (a conservative, correct choice). Keep the+ per-file headers; APSL has termination and patent provisions, so every maintainer should read it once.+- **The stray XNU build:** `prebuilt/mach.development.bcm2837` is a binary of APSL code, so APSL 2.3 needs+ corresponding source to be available. It is, in this repo plus Apple's tag; keep `apply.sh` pinned.++## 4. The token++What I know comes from your earlier notes and may be out of date; correct me. $HackiOS on BNB Chain+via [flap.sh](https://flap.sh), contract `0x5be8dca3…7777`, 1B supply, a 1% buy / 1% sell tax that funds+the team; a community site with three holder tiers, Snapshot voting on devices and roadmap, and a stated+fee split of 50% development / 30% growth / 20% community pot.++**I could not verify flap.sh's own terms or exactly how its creator-fee wallet works**: the sources I+found are secondary. Read its official docs and terms, and check whether your tax wallet, "dividend"+features and any token-gating are allowed.++### Can a token fund the project? Yes, and here is where it bites++1. **Securities risk (US).** The SEC staff's [February 2025 statement](https://www.winston.com/en/blogs-and-podcasts/non-fungible-insights-blockchain-decrypted/sec-staff-under-new-administration-issues-statement-declaring-that-meme-coins-are-not-securities)+ said *typical* meme coins are not securities. It is non-binding, and it excludes coins designed to+ evade the rules and projects whose economics point to profit from the team's efforts. A token whose+ tax is earmarked for a development team, with holder governance over the roadmap and a pot paid to+ holders, is closer to that line than a joke coin. **The "20% community pot" is the riskiest item:+ if it is paid to holders in proportion to what they hold, it looks like profit-sharing.** Make it a+ grant/bounty budget decided by vote, not a distribution to holders.+2. **EU (MiCA).** ESMA's [Q&A](https://www.esma.europa.eu/node/222469) says the white-paper exemptions+ can be lost depending on where the token is admitted to trading and that offers can still be public+ offers; a DEX launch does not make the question go away. Whether you are an "offeror" at all, when a+ bonding-curve contract sells the token, is for an EU lawyer.+3. **Ukraine.** The 2022 law "On Virtual Assets" ([No. 2074-IX](https://aub.org.ua/en/virtualni-aktyvy-novyi-etap-rehuliuvannia-ta-opodatkuvannia-v-ukraini-2/))+ is not yet in force because it waits for Tax Code amendments, and the tax bill (No. 10225-d) had+ passed only a [first reading](https://www.ey.com/en_ua/it-tax-law-digest/the-draft-law-on-the-taxation-of-income-from-virtual-assets-approved-by-the-parliamentary-committee)+ in what I found; check the Rada's site for the current state. "Not yet regulated" is not "approved".+ Fee income that reaches the team is income wherever it is tax-resident: keep records now.+4. **Consumer-protection and fraud exposure.** Statements like "revenue", "supports the price", "roadmap+ will deliver" are the usual source of liability. Your own brand rule ("honest, no price promises") is+ the right rule; put it in a published policy and hold every channel to it.+5. **Apple exposure grows with money.** Commercial exploitation weighs against fair use. If holders can+ obtain system images or Apple-derived artefacts through the token, you stop being a source project+ and start looking like Psystar. **Rule: the token gates community perks and votes, never a file that+ contains Apple code.**++### Structure that lowers the risk (cheap to do now)++- A legal entity (association/foundation, or a lawyer-advised wrapper) that owns the fee wallet, not+ individuals; a multisig with at least two signers; a public treasury and a published budget.+- Team vesting and a public statement of how fees are spent; no promise of returns, ever.+- No revenue distribution to holders; tiers give access and a vote, not money.+- Keep the token off the code repository entirely (it already is) and off the legal files.+- Geo-fence marketing away from US persons until counsel signs off; no "investment" language.+- A one-page disclaimer on the site: not affiliated with Apple; the token is not a licence; no+ expectation of profit; no access to Apple software.++## 5. What I could not check++flap.sh's official terms and creator-fee mechanics; the legal system you live in; Apple's current+enforcement posture; whether the vendors would object to the UEFI binaries; the current text of the+Ukrainian bills; what the website `hackios.org` says. A lawyer with crypto and IP experience should+review §2 and §4 before the team acts on this.++## 6. Decisions I need from you (ranked)++1. Remove the vendor blobs and the built UEFI image from the tree (P0-a)? I can prepare the change.+2. Purge the iOS screenshots from history (P0-b)? This rewrites history; it needs the whole team.+3. Move the App Store / FairPlay experiments off the public repository (P0-c)?+4. Keep the "HackiOS" name, or rename before it grows (P1)?+5. Change the community pot so it is never paid to holders pro rata (§4.1)?+6. Hire a lawyer for one hour on §1 (jurisdiction) and §4 (the token).diff --git a/docs/windows.md b/docs/windows.mdnew file mode 100644index 0000000..e026264--- /dev/null+++ b/docs/windows.md@@ -0,0 +1,66 @@+# HakiOS on a Windows machine++How to build and run HakiOS with a Windows PC and a phone. It works, with each tool where it fits.+Everything here was done on a real machine and phone; `tools/doctor.sh` checks the same things for you.++## What runs where++| Job | Where | Why |+|---|---|---|+| Build the images (`sysimage/fetch.sh`, `userland/build.sh`) | **WSL 2, in its own filesystem** (`~/hakios`) | `fetch.sh` makes files named `NAME:com.apple.decmpfs`; NTFS forbids `:`. The Windows drive is also slow for tens of thousands of small files. |+| Drive the phone (`./xl`, `tools/modem-cycle-win.sh`) | **Git Bash**, in your Windows checkout | `fastboot` and `adb` are Windows programs that see the phone's USB; WSL 2 does not, without usbipd. |++So: build in WSL, copy `userland/root.apfs` and `userland/system.apfs` to the Windows checkout, run `xl`+from Git Bash.++## Setup++1. **Platform-tools:** unpack Google's Android platform-tools to `C:\platform-tools` (adb, fastboot).+ fastboot worked here without a separate USB driver.+2. **WSL 2 Ubuntu:** `sudo apt install 7zip clang lld lz4 python3 git make` (7-Zip must be 23 or newer).+3. **Git Bash** (Git for Windows). Check your Windows checkout and WSL both with:+ ```sh+ tools/doctor.sh # in Git Bash (host checks for the xl side, and the phone)+ tools/doctor.sh # in WSL, in ~/hakios (host checks for the build side)+ ```+4. **In Git Bash**, before using `xl`: `export PATH="$PWD/tools/win-bin:/c/platform-tools:$PATH"`.+ `tools/win-bin/flock` replaces util-linux's `flock`, which Git Bash does not have and `xl` needs.++## The phone++- Turn on USB debugging. Unlock the bootloader (yours to do; it wipes the phone).+- **Trust the device tree, not the product name.** Some units report a different brand and model than+ the board they really are (root-hiding modules fake the identity and even the bootloader's+ "locked" state). `tools/doctor.sh` prints both. The supported platform is `redwood` / SM7325.+- **Firmware needs root on some ROMs.** If `devices/poco-x5-pro/pull-firmware.sh` reports every file+ "not on the phone" but `doctor` says the firmware is readable only by root, use+ `devices/poco-x5-pro/pull-firmware-root.sh`. It copies under `su` to a staging directory, pulls, and+ removes the staging directory; nothing on the phone is changed.++## Build and run++```sh+# WSL, in ~/hakios (a clone in WSL's own filesystem, with fw-*/ copied in):+sysimage/fetch.sh # iOS 16.5 from Apple's servers, ~9 min+PREBUILT=1 REST=1 MODEM=1 SYSTEM=1 userland/build.sh # root.apfs + system.apfs, ~4 min, no theos needed+cp userland/root.apfs userland/system.apfs /mnt/d/.../hackios-xnu-kernel/userland/++# Git Bash, in the Windows checkout:+./xl enter # Android -> fastboot -> the loader in RAM (also the unlock test)+./xl screenshot logs/s.png # what the loader put on the screen+./xl log # the loader's log+./xl reload # restart the phone and enter the loader again+./xl reboot # back to Android+```++Nothing is flashed: everything is booted from RAM, and a reboot brings Android back.++## When something goes wrong++- **`xl state` says `absent`** for more than three minutes: the phone is not on USB at all. Check the+ cable and the screen; hold power about 15 seconds to restart it into Android. `doctor` shows whether+ Windows sees any device.+- **`Failed to mount root device`** from a run: it was started without a root image. A run needs+ `system.apfs` built with `MODEM=1` if it uses the modem (`tools/modem-cycle-win.sh`).+- **`tools/modem-cycle.sh` fails under Git Bash:** use `tools/modem-cycle-win.sh`; the original puts the+ macOS helpers in `tools/macos-bin` first on `PATH`, and they do not run on Windows.diff --git a/tools/doctor.sh b/tools/doctor.shnew file mode 100644index 0000000..026b39b--- /dev/null+++ b/tools/doctor.sh@@ -0,0 +1,142 @@+#!/bin/bash+# tools/doctor.sh: check this machine, and a phone on adb if there is one, for what HakiOS needs, and say+# what to do about every problem. Read-only: it changes nothing on the host or on the phone.+#+# tools/doctor.sh (or: make doctor)+#+# Exit status: 1 if something that is needed is missing, 0 otherwise (warnings are not failures).+# What it knows comes from bringing the project up on a Windows machine with a phone behind a spoofed+# identity: see docs/windows.md.+cd "$(dirname "$0")/.." || exit 1+export MSYS_NO_PATHCONV=1 # Git Bash must not rewrite /proc/... into C:/... for adb++npass=0; nwarn=0; nfail=0+if [ -t 1 ]; then G=$'\e[32m'; Y=$'\e[33m'; R=$'\e[31m'; B=$'\e[1m'; N=$'\e[0m'; else G=; Y=; R=; B=; N=; fi+ok() { printf ' %sok%s %s\n' "$G" "$N" "$1"; npass=$((npass + 1)); }+warn() { printf ' %swarn%s %s\n -> %s\n' "$Y" "$N" "$1" "$2"; nwarn=$((nwarn + 1)); }+bad() { printf ' %sFAIL%s %s\n -> %s\n' "$R" "$N" "$1" "$2"; nfail=$((nfail + 1)); }+note() { printf ' %s\n' "$1"; }+head1() { printf '\n%s%s%s\n' "$B" "$1" "$N"; }+have() { command -v "$1" >/dev/null 2>&1; }+# a build tool: a failure where the images are built, only a warning in Git Bash (they are built in WSL there)+need() { if [ "$host" = gitbash ]; then warn "$1" "$2 -- in WSL, where the images are built (docs/windows.md)"; else bad "$1" "$2"; fi; }++case "$(uname -s)" in+Linux) if grep -qi microsoft /proc/version 2>/dev/null; then host=wsl; else host=linux; fi ;;+Darwin) host=macos ;;+MINGW* | MSYS* | CYGWIN*) host=gitbash ;;+*) host=other ;;+esac++head1 "This machine ($host)"++# python3 (the build scripts need 3.8+); on Windows `python3` can be a Store stub that does not run+if have python3 && v=$(python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>/dev/null) && [ -n "$v" ]; then+ if [ "${v%%.*}" -ge 3 ] && [ "${v##*.}" -ge 8 ]; then ok "python3 $v"; else bad "python3 $v is too old" "install Python 3.8 or newer"; fi+else+ bad "python3 does not run" "install Python 3 (on Windows: python.org, not the Microsoft Store stub)"+fi++# 7-Zip 23 or newer: sysimage/fetch.sh unpacks APFS with it+z=""; for t in 7zz 7z 7za; do have $t && { z=$t; break; }; done+if [ -n "$z" ]; then+ zv=$($z 2>&1 | head -3 | grep -oE '[0-9]+\.[0-9]+' | head -1)+ if [ -n "$zv" ] && [ "${zv%%.*}" -ge 23 ]; then ok "7-Zip $zv ($z)"; else need "7-Zip ${zv:-?} is older than 23 (cannot read APFS)" "install 7-Zip 23 or newer (apt: 7zip, brew: sevenzip)"; fi+else+ need "7-Zip not found" "install 7-Zip 23 or newer (apt: 7zip, brew: sevenzip)"+fi++if have cc || have clang; then ok "C compiler ($(have cc && echo cc || echo clang)): builds unzbm for sysimage/fetch.sh"; else need "no C compiler" "install clang or gcc"; fi+have git && ok "git" || bad "git not found" "install git"+if have lld-link; then ok "lld-link: the boot loader can be built (xnuloader/build.sh)"; else warn "lld-link not found" "needed only to build the loader (apt: lld; brew: lld); prebuilt/loader.efi works without"; fi+have lz4 && ok "lz4" || warn "lz4 not found" "needed by some image steps (apt: lz4)"++if have flock; then+ ok "flock (xl needs it)"+elif [ "$host" = gitbash ]; then+ warn "no flock in Git Bash" "export PATH=\"\$PWD/tools/win-bin:\$PATH\" (tools/win-bin/flock is a shim for it)"+else+ bad "flock not found" "install util-linux (macOS: see tools/macos-bin/README.md)"+fi++# room for the IPSW parts and the images: about 8 GB while fetching, 5.3 GB afterwards, 2.5 GB system image+kb=$(df -Pk . 2>/dev/null | awk 'NR == 2 { print $4 }')+if [ -n "$kb" ] && [ "$kb" -ge 12582912 ]; then ok "disk: $((kb / 1048576)) GB free here"; else warn "disk: ${kb:+$((kb / 1048576)) GB }free here, 12 GB wanted" "free some space, or work in another directory"; fi++# the trap: fetch.sh makes files named NAME:com.apple.decmpfs, and ':' is not a legal NTFS name character+case "$host:$PWD" in+wsl:/mnt/*) warn "this checkout is on a Windows drive (/mnt/...)" "build in WSL's own filesystem: git clone it to ~/hakios and copy fw-* there (docs/windows.md)" ;;+gitbash:*) warn "Git Bash cannot run sysimage/fetch.sh (NTFS forbids ':' in file names)" "build the images in WSL, copy them back; run xl from here (docs/windows.md)" ;;+esac++# rebuilding the kernel or userland needs theos's SDK and its Linux toolchain's cctools linker (xnu-deps/setup.sh)+theos=${THEOS:-$HOME/theos}+if [ -d "$theos/sdks/iPhoneOS16.5.sdk" ] && [ -x "$theos/toolchain/linux/iphone/bin/ld" ]; then+ ok "theos with the iPhoneOS 16.5 SDK and the cctools linker: the kernel and userland can be rebuilt"+elif [ -d "$theos/sdks/iPhoneOS16.5.sdk" ]; then+ warn "theos has the SDK but not its Linux toolchain (no cctools linker: $theos/toolchain/linux/iphone/bin/ld)" "optional, only to rebuild the kernel or userland: install theos's Linux toolchain, then xnu-deps/setup.sh; PREBUILT=1 and prebuilt/ work without"+else+ warn "no theos SDK ($theos/sdks/iPhoneOS16.5.sdk)" "optional, only to rebuild the kernel or userland (theos + xnu-deps/setup.sh); PREBUILT=1 and prebuilt/ work without"+fi+have qemu-system-aarch64 && ok "qemu-system-aarch64: make qemu-open works" || warn "no qemu-system-aarch64" "optional: only for the QEMU targets"++head1 "What is already built here"+if [ -f fw-modem/modem.mdt ]; then ok "phone firmware pulled (fw-*/)"; else warn "no fw-modem/ yet" "with the phone on adb: devices/poco-x5-pro/pull-firmware.sh, or pull-firmware-root.sh if that gets nothing"; fi+if [ -f userland/system.apfs ] && [ -f userland/root.apfs ]; then ok "userland/system.apfs and root.apfs"; else warn "no iOS images yet" "make fetch, then PREBUILT=1 REST=1 MODEM=1 SYSTEM=1 userland/build.sh (needs iOS 16.5 from Apple's servers, ~8 GB)"; fi++head1 "Phone"+adb=""+for c in adb adb.exe /mnt/c/platform-tools/adb.exe /c/platform-tools/adb.exe tools/macos-bin/platform-tools/adb; do+ if have "$c" || [ -x "$c" ]; then adb=$c; break; fi+done+if [ -z "$adb" ]; then+ warn "adb not found" "install Android platform-tools (docs/windows.md); skipping the phone checks"+else+ fb=""; for c in fastboot fastboot.exe /mnt/c/platform-tools/fastboot.exe /c/platform-tools/fastboot.exe; do { have "$c" || [ -x "$c" ]; } && { fb=$c; break; }; done+ devs=$("$adb" devices 2>/dev/null | tr -d '\r' | awk 'NR > 1 && $2 == "device" { print $1 }')+ if [ -z "$devs" ]; then+ if "$adb" devices 2>/dev/null | grep -q unauthorized; then+ warn "a phone is attached but has not authorised this computer" "unlock it and accept the USB debugging prompt"+ elif [ -n "$fb" ] && "$fb" devices 2>/dev/null | grep -q fastboot; then+ ok "a phone is in fastboot (./xl state tells loader from fastboot)"+ else+ warn "no phone on adb or fastboot" "plug it in with USB debugging on; if it was left in the HakiOS loader and is gone, hold power ~15 s to restart it into Android"+ fi+ else+ A() { "$adb" shell "$1" 2>/dev/null | tr -d '\r'; }+ model=$(A 'getprop ro.product.model'); board=$(A 'getprop ro.product.board'); soc=$(A 'getprop ro.soc.model')+ dtm=$(A 'cat /proc/device-tree/model 2>/dev/null'); dtc=$(A 'cat /proc/device-tree/compatible 2>/dev/null | tr "\\0" " "')+ note "reports: model='$model' board='$board' soc='$soc'"+ note "device tree: model='$dtm' compatible='$dtc'"+ if echo "$dtm $board" | grep -qi redwood && [ "$soc" = SM7325 ]; then+ ok "redwood / SM7325: the reference platform (devices/poco-x5-pro)"+ if ! echo "$model" | grep -qiE 'poco|redwood|2210132'; then+ note "the reported model '$model' is not a POCO X5 Pro name: it is probably spoofed; the device tree is what counts"+ fi+ elif [ -n "$dtm$soc" ]; then+ warn "not the reference platform ($soc)" "a port is a new devices/<name>/: devices/poco-x5-pro/README.md; adb pull /sys/firmware/fdt and run tools/soc-args.py on it"+ else+ warn "could not read the device tree" "an adb shell may be restricted; try with root"+ fi+ if A 'su -c id' | grep -q 'uid=0'; then+ ok "root answers (su)"; root=1+ else+ warn "no root" "some ROMs keep the modem, GPU and DSP firmware unreadable to the adb shell"; root=0+ fi+ plain=$(A 'ls /vendor/firmware_mnt/image/modem.mdt 2>&1')+ if echo "$plain" | grep -q '^/vendor/firmware_mnt/image/modem.mdt$'; then+ ok "modem firmware is readable without root: devices/poco-x5-pro/pull-firmware.sh works"+ elif [ "$root" = 1 ] && A 'su -c "ls /vendor/firmware_mnt/image/modem.mdt"' | grep -q modem.mdt; then+ warn "the firmware is there but only root can read it" "use devices/poco-x5-pro/pull-firmware-root.sh instead of pull-firmware.sh"+ else+ warn "modem firmware not found under /vendor/firmware_mnt/image" "check the ROM's firmware layout (docs/windows.md)"+ fi+ lk=$(A 'getprop ro.boot.flash.locked'); vb=$(A 'getprop ro.boot.verifiedbootstate')+ note "bootloader as reported: locked=$lk verifiedboot=$vb (root-hiding modules can fake this; the real test is ./xl enter)"+ bat=$(A 'cat /sys/class/power_supply/battery/capacity')+ if [ -n "$bat" ] && [ "$bat" -lt 30 ] 2>/dev/null; then warn "battery $bat%" "charge it: HakiOS does not charge the phone while it runs"; else ok "battery ${bat:-?}%"; fi+ fi+fi++printf '\n%s%d ok, %d warnings, %d failures%s\n' "$B" "$npass" "$nwarn" "$nfail" "$N"+[ "$nfail" -eq 0 ]