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
mkjobs: judge a daemon's program by the recipe's root; CommCenter tried and left out
vcvkkbccff2148144
diff --git a/tools/new-workspace.sh b/tools/new-workspace.shindex ee560b4..526878a 100755--- a/tools/new-workspace.sh+++ b/tools/new-workspace.sh@@ -10,8 +10,8 @@## The kernel tree is copied as it is now, uncommitted work included, and that state is recorded# (refs/redwood/baseline in the copy's kernel tree): tools/kernel-delta.sh, run in the workspace,-# prints what was changed in the kernel since. Files below ios165/rootfs and ios165/cryptex are-# hard links to this copy's: replace them, never edit them in place.+# prints what was changed in the kernel since. Files below ios165/rootfs, ios165/cryptex and+# ios165/cryptex-app are hard links to this copy's: replace them, never edit them in place.# The phone is not part of a workspace: there is one, and ./xl belongs to the main copy.set -eROOT=$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)@@ -37,9 +37,14 @@ rm -rf $K/BUILD)# what the kernel build needs besides the treecp -a --reflink=auto "$ROOT/xnu-deps/." xnu-deps/-# the files of iOS and the system image made of them+# the files of iOS and the system image made of them. The App cryptex goes along with the rest: without it+# a workspace quietly builds images with no /System/Cryptexes/App at all, and Safari's daemons and+# AuthenticationServicesAgent -- eight jobs -- then look to mkjobs.py like programs nobody has+# (build.sh at cryptex-app, mkjobs.py present()).for d in rootfs cryptex "20F66__iPhone10,3_6"; do cp -al "$ROOT/ios165/$d" ios165/; done-for f in system.files system.manifest var.skel .done-rootfs .done-cryptex a2s.json; do+# (the App cryptex only if this copy has it: fetch.sh unpacks it, and not every copy has run that far)+[ -d "$ROOT/ios165/cryptex-app" ] && cp -al "$ROOT/ios165/cryptex-app" ios165/+for f in system.files system.manifest var.skel .done-rootfs .done-cryptex a2s.json cryptex-app.dmg; do[ -e "$ROOT/ios165/$f" ] && cp -a "$ROOT/ios165/$f" ios165/donefor f in rootfs.dmg rootfs.slt extracted; dodiff --git a/userland/build.sh b/userland/build.shindex 48b6213..efc8b88 100755--- a/userland/build.sh+++ b/userland/build.sh@@ -224,9 +224,15 @@ if [ -d $IOS/rootfs/usr/lib ]; thendone >> root/etc/var.skelcp ${RC:-rc.launchd} root/etc/rccp ${RC_JOBS:-rc.jobs} root/etc/rc.jobs- # the jobs the iOS launchd will see (/System/Library/LaunchDaemons is a symlink to this directory)+ # the jobs the iOS launchd will see (/System/Library/LaunchDaemons is a symlink to this directory).+ # With FLASHBOOT=1 the root will be Apple's whole volume on the flash, not the part of it that fits in+ # the system image, so mkjobs.py judges "is this daemon's program there" by the listing of the volume+ # and not by what select-system.py extracted here (--root-volume; seven jobs turn on the difference,+ # fairplayd among them).cp com.redwood.demo.plist com.redwood.wifi.plist root/LaunchDaemons/- [ -n "$IOS_JOBS" ] && OSLOG=${OSLOG-com.apple.backboardd} ./mkjobs.py ${REST:+--rest} $IOS/rootfs root/LaunchDaemons $IOS_JOBS+ VOLUME=""+ [ -n "$FLASHBOOT" ] && [ -f $IOS/rootfs.slt ] && VOLUME="--root-volume $IOS/rootfs.slt"+ [ -n "$IOS_JOBS" ] && OSLOG=${OSLOG-com.apple.backboardd} ./mkjobs.py ${REST:+--rest} $VOLUME $IOS/rootfs root/LaunchDaemons $IOS_JOBSfi# firmware of the phone's own hardware, where somebody has pulled it from the phone's Android into ../fw-gpu# (it is the vendor's and never in the repository): the kernel's GPU bring-up, bsd/dev/redwood_adreno.c, finds it in fw/diff --git a/userland/mkjobs.py b/userland/mkjobs.pyindex 98f10c7..cef72a3 100755--- a/userland/mkjobs.py+++ b/userland/mkjobs.py@@ -1,7 +1,7 @@#!/usr/bin/env python3"""Copy stock iOS launchd job definitions into the small image, adjusted for the bring-up.-usage: mkjobs.py [--rest] IOS_ROOTFS DEST_DIR label...+usage: mkjobs.py [--rest] [--root-volume LISTING] IOS_ROOTFS DEST_DIR label...For every label, IOS_ROOTFS/System/Library/LaunchDaemons/<label>.plist is copied to DEST_DIR withits standard error sent to the console, which is where a daemon's last words are read (there@@ -9,7 +9,17 @@ is no log viewer or crash reporter yet). For the jobs named in the environment v("all" for every one) OS_ACTIVITY_DT_MODE is set too, which makes os_log print there as well:everything the daemon has to say -- SpringBoard alone says a megabyte in half a minute, whichcosts time and pushes everybody else out of the log that comes back from the phone.-The program itself must be in the system image; a warning is printed if it was not extracted.+The program itself must be there at run time; a warning is printed if it will not be.++What "there at run time" means is the recipe, not what happens to be unpacked on this machine, and the+two recipes differ. With the system image as the root, it is what select-system.py chose, and a daemon it+left out as too big really is absent. With the iOS volume on the phone's flash as the root (build.sh+FLASHBOOT=1), the root is Apple's whole volume: --root-volume names the technical listing of its image+(ios165/rootfs.slt) and a program counts as there if Apple ships it. Seven jobs turn on that --+fairplayd, identityservicesd, passd, assistantd, callservicesd, lskdd, searchpartyd -- and were being+refused on a flash boot for a reason true only of the thinned copy here. Eight more, Safari's and+AuthenticationServicesAgent, hang on the App cryptex being unpacked beside it at all (see CRYPTEXES+below); a workspace used to lose those silently, which tools/new-workspace.sh no longer does.With --rest, the other jobs of iOS follow (their standard error on the console as well, their os_logonly when named in OSLOG), and with them the "launch angels" (System/Library/LaunchAngels: the@@ -19,7 +29,7 @@ service like a daemon), but strictly on demand: whatever starts them byitself (RunAtLoad, KeepAlive) is taken out, so that launchd runs one only when a program asksfor one of its Mach services. That is how an application finds the daemons it needs withoutall 490 of them being started at boot. Left out: jobs without Mach services (nothing could-ever start them), jobs whose program is not in the system image, and those in DENY, which+ever start them), jobs whose program will not be there at run time, and those in DENY, whichdrive hardware that is not there or do things nobody wants here."""import os@@ -34,6 +44,21 @@ import sys# It needs no hardware we have not got, and it serves its clients whether or not it reaches a push courier,# which it never will: the courier wants a device identity rooted in the Secure Enclave this phone has not# got (apsd -> mobileactivationd, "Device is probably unactivated"), so the push itself stays out of reach.)+# CommCenter stays, and this is what it cost to find out. Shipping both of its plists is the stock+# arrangement -- they carry the same label and launchd picks by the device tree, so with no "baseband" node+# it takes com.apple.CommCenter-noncellular, the variant iOS has for a device with no modem -- and it does+# pick it. It then gets a long way: it answers com.apple.commcenter.xpc and .coretelephony.xpc (148 and 36+# failed lookups in a session become none), serves geod its policy, loads the network-extension+# configurations. And then it dies, every time, on one of two IOKit drivers of the cellular path that this+# kernel has not got: "Could not find AppleIPAppender service" (matched by name, user client+# ApplePDPHelperInterface -- PDP contexts, traffic-class flows, dedicated bearers) and SIGSEGV 50 ms later,+# or "Unable to communicate with AppleBaseband driver" (com.apple.driver.AppleBasebandPCI) and SIGABRT.+# It respawns and does it again: 36 crashes in a seven-minute session where the same image without it has+# none. The boot is not held up -- it reaches the same 236 processes against 240 -- so the trade is 184+# failed lookups a session against a process dying every twelve seconds for ever, which is a bad one.+# Stubbing the first driver is the kind of work RedwoodBattery already is, but the second is an Apple+# baseband on PCIe, and this phone's modem is on the SoC and speaks QMI to a Qualcomm subsystem -- so what+# is behind the driver is missing too, not just the driver.DENY = ('watchdog', 'CommCenter', 'wifi', 'WiFi', 'bluetooth', 'BTServer', 'locationd', 'softwareupdate','datamigrator', 'backupd', 'thermalmonitord', 'keybagd', 'nfcd', 'biometrickitd', 'pearld','obliterat', 'storage_mounter', 'com.apple.fud', 'sepd', 'seputil', 'camera', 'ReportCrash',@@ -49,9 +74,13 @@ DENY = ('watchdog', 'CommCenter', 'wifi', 'WiFi', 'bluetooth', 'BTServer', 'locaDENY = tuple(word for word in DENY if word not in os.environ.get('ALLOW', '').split())args = sys.argv[1:]-rest = args[:1] == ['--rest']-if rest:- args = args[1:]+rest = '--rest' in args+root_volume = None # the listing of the whole iOS volume, when that volume is the root+if '--root-volume' in args:+ i = args.index('--root-volume')+ root_volume = args[i + 1]+ del args[i:i + 2]+args = [a for a in args if a != '--rest']src_root, dest, labels = args[0], args[1], args[2:]oslog = os.environ.get('OSLOG', '').split()src = f'{src_root}/System/Library/LaunchDaemons'@@ -61,11 +90,21 @@ src = f'{src_root}/System/Library/LaunchDaemons'CRYPTEXES = {'/System/Cryptexes/OS/': 'cryptex', '/System/Cryptexes/App/': 'cryptex-app'}+def volume_paths(listing, _cache={}):+ """Every path in a 7z technical listing of the iOS root filesystem image, without a leading slash."""+ if listing not in _cache:+ _cache[listing] = {line[len('Path = '):].strip()+ for line in open(listing, errors='replace') if line.startswith('Path = ')}+ return _cache[listing]++def present(program):for prefix, unpacked in CRYPTEXES.items():if program.startswith(prefix):return os.path.isfile(os.path.join(os.path.dirname(os.path.abspath(src_root)), unpacked,program[len(prefix):]))+ if root_volume:+ return program.lstrip('/') in volume_paths(root_volume)return os.path.isfile(f'{src_root}{program}')@@ -83,7 +122,8 @@ for label in labels:with open(f'{dest}/{label}.plist', 'wb') as f:plistlib.dump(job, f, fmt=plistlib.FMT_BINARY)program = job.get('Program') or job['ProgramArguments'][0]- missing = '' if present(program) else ' (NOT in the system image!)'+ missing = '' if present(program) else (' (NOT on the iOS volume!)' if root_volume+ else ' (NOT in the system image!)')print(f' job {label}: {program}{missing}')if rest: