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
build: an Apple-free path -- 'make qemu-open' builds the kernel, a placeholder loader (xnuloader/mkidentity.sh --placeholder, no IPSW, no Apple device-tree data) and the raw-syscall hello RAM disk, and boots them in QEMU with nothing of Apple's; Makefile device default is poco-x5-pro
shimoku74ef0f480a6edd
diff --git a/Makefile b/Makefileindex dc81bd9..1bf135f 100644--- a/Makefile+++ b/Makefile@@ -7,26 +7,29 @@# make kernel the kernel from source (xnu/apply.sh, xnu-deps/setup.sh, xnu-build.sh)# make loader the boot loader, with identity.h made from your IPSW (xnuloader/build.sh)# make firmware the phone's firmware off the phone over adb (devices/$(DEVICE)/pull-firmware.sh)-# make qemu a 20-minute session in QEMU+# make qemu a 20-minute session in QEMU (needs the iOS images)+# make qemu-open boot the open kernel in QEMU with NO Apple software+# (kernel + the hello RAM disk + a placeholder loader)# 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#-# DEVICE=redwood the device directory under devices/ (default redwood)+# DEVICE=poco-x5-pro the device directory under devices/ (default poco-x5-pro)# ARGS="..." kernel arguments for make phone (default: everything the phone has)# SECS=600 the session's length for make phone / make qemu# JOBS=8 parallel jobs for the kernel build-DEVICE ?= redwood+DEVICE ?= poco-x5-proJOBS ?= 8SECS ?= 600+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 firmware qemu phone prebuilt clean all+.PHONY: help fetch images kernel loader loader-open hello qemu qemu-open phone prebuilt clean allhelp:- @sed -n '2,20p' Makefile | sed 's/^# \{0,1\}//'+ @sed -n '2,23p' Makefile | sed 's/^# \{0,1\}//'all: kernel loader images@@ -51,6 +54,26 @@ qemu:mkdir -p logsqemu/run-ios.sh $(SECS) -display gtk | tee logs/qemu.log+# The Apple-free path: no IPSW, no iOS user space. The loader is built with a placeholder identity+# (xnuloader/mkidentity.sh --placeholder), and the kernel boots the raw-syscall `hello` RAM disk.+# This is the configuration an outside contributor can build and run with nothing of Apple's.+loader-open:+ PLACEHOLDER=1 xnuloader/mkidentity.sh+ xnuloader/build.sh++# `hello` on its own: a static, raw-syscall program (no iOS SDK, no Apple libraries).+hello:+ . ./xnu-env.sh && xnu-clang -arch arm64 -Os -static -nostdlib -ffreestanding \+ -fno-stack-protector -fno-builtin -Wl,-e,_start -Wl,-pagezero_size,0x100000000 \+ -o userland/hello userland/src/hello.c++qemu-open: kernel loader-open hello+ mkdir -p logs+ xnuloader/mkpayload.py -o qemu/payload.bin \+ kernel=xnu-src/xnu-8796.121.2/BUILD/obj/DEVELOPMENT_ARM64_BCM2837/mach.development.bcm2837 \+ ramdisk=userland/hello --cmdline "$(ARGS_OPEN)"+ qemu/run.sh $(SECS) | tee logs/qemu-open.log+phone:XL_SB_DELAY=8 tools/modem-cycle.sh "$(ARGS)" $(SECS)diff --git a/xnuloader/mkidentity.py b/xnuloader/mkidentity.pyindex b689490..cf84cf8 100755--- a/xnuloader/mkidentity.py+++ b/xnuloader/mkidentity.py@@ -60,7 +60,33 @@ def emit(label, props, skip):print('};\n')+def emit_empty(label):+ # A one-entry table whose single property has a name no device tree uses and a zero length:+ # dt_identity copies it as an empty, harmless property; dt_identity_one never matches it. This+ # avoids a zero-length array (not standard C) while carrying no Apple-derived data.+ print(f'/* placeholder: no properties (built without an IPSW) */')+ print(f'static const struct identity_prop {label}[] = {{ {{ "hakios-placeholder", 0, 0 }} }};')+ print(f'static const unsigned char {label}_data[] = {{ 0 }};\n')+++def placeholder():+ """An identity.h with no Apple-derived data, for building the loader without an IPSW.++ The device-tree properties iOS reads to tell which iPhone it is are left empty. This is+ enough to build and boot the open kernel under QEMU with an Apple-free user space (the+ `hello` RAM disk); it is NOT enough to run the iOS 16.5 user space, which wants the real+ properties. Generate the real header from your own IPSW (mkidentity.sh) for that.+ """+ print('/* Generated by mkidentity.py --placeholder: no Apple device-tree data. */')+ print('struct identity_prop { const char *name; unsigned offset, length; };\n')+ for label in ('identity_root', 'identity_product', 'identity_haptics', 'identity_camera'):+ emit_empty(label)++def main():+ if len(sys.argv) > 1 and sys.argv[1] == '--placeholder':+ placeholder()+ returnraw = open(sys.argv[1], 'rb').read()root, _ = parse(raw)children = {name_of(c): c for c in root[1]}diff --git a/xnuloader/mkidentity.sh b/xnuloader/mkidentity.shindex 8203217..1b22100 100755--- a/xnuloader/mkidentity.sh+++ b/xnuloader/mkidentity.sh@@ -10,9 +10,18 @@# xnuloader/mkidentity.py the header from the decoded tree## usage: xnuloader/mkidentity.sh [DeviceTree.im4p] (an im4p already at hand skips the download)+# xnuloader/mkidentity.sh --placeholder (no IPSW: an identity.h with no Apple data,+# enough to build and boot the open kernel under+# QEMU with an Apple-free user space, not iOS)set -eHERE=$(cd "$(dirname "$0")" && pwd)TOP=$(cd "$HERE/.." && pwd)+if [ "$1" = --placeholder ] || [ "${PLACEHOLDER:-}" = 1 ]; then+ python3 "$HERE/mkidentity.py" --placeholder > "$HERE/identity.h.new"+ mv "$HERE/identity.h.new" "$HERE/identity.h"+ echo "mkidentity.sh: xnuloader/identity.h made WITHOUT an IPSW (placeholder; no Apple data, not for iOS)"+ exit 0+fiWORK=$(mktemp -d "${TMPDIR:-/tmp}/mkidentity.XXXXXX")trap 'rm -rf "$WORK"' EXITIM4P=${1:-$WORK/dt.im4p}