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: find the AOSS mailbox in either kind of device tree; no carriage returns in boot-args
shimoku0a0287255c1d
diff --git a/.gitattributes b/.gitattributesnew file mode 100644index 0000000..a71f73d--- /dev/null+++ b/.gitattributes@@ -0,0 +1,11 @@+# Text is LF in the working tree on every platform. Git for Windows (core.autocrlf=true) otherwise+# turns it into CRLF, which breaks things quietly: a shell script with CRs ("bash\r: No such file"),+# and files of boot-arguments (devices/*/soc.args) whose lines are joined into the kernel's command+# line with a CR left inside every value. Git tells text from binary by content, so nothing here has+# to list the binaries.+* text=auto eol=lf++# A patch is not converted at all: the Mu-Silicium files it patches have CRLF line endings upstream, and+# the context lines of its hunks carry them (BootManager.c, BootManagerLib.inf). Turning them into LF+# would make the patch fail to apply.+*.patch -textdiff --git a/.gitignore b/.gitignoreindex f952048..7138285 100644--- a/.gitignore+++ b/.gitignore@@ -3,6 +3,7 @@# is named here./*!/.gitignore+!/.gitattributes!/README.md!/CONTRIBUTING.md!/ci/diff --git a/tools/modem-cycle-win.sh b/tools/modem-cycle-win.shindex 0dbac5e..260dda7 100644--- a/tools/modem-cycle-win.sh+++ b/tools/modem-cycle-win.sh@@ -13,7 +13,7 @@ ARGS=$1; SECS=${2:-300}# kernel command line so hakios.mpss.c / hakios.ipa.c map that phone's blocks. SOC_ARGS names the file;# default is the one device there is. The POCO's values equal the kernel defaults, so this is a no-op there.SOC_ARGS=${SOC_ARGS-$(ls devices/*/soc.args 2>/dev/null | head -1)}-SOC=""; [ -n "$SOC_ARGS" ] && [ -f "$SOC_ARGS" ] && SOC=$(tr '\n' ' ' < "$SOC_ARGS")+SOC=""; [ -n "$SOC_ARGS" ] && [ -f "$SOC_ARGS" ] && SOC=$(tr -d '\r' < "$SOC_ARGS" | tr '\n' ' ')for i in $(seq 1 2160); do s=$(./xl state); [ "$s" != absent ] && break; sleep 10; doneecho "$(date +%T) phone: $s"; [ "$s" = absent ] && { echo "NO PHONE"; exit 1; }./xl enter 2>&1 | tail -1diff --git a/tools/modem-cycle.sh b/tools/modem-cycle.shindex 4907abe..9da74cb 100755--- a/tools/modem-cycle.sh+++ b/tools/modem-cycle.sh@@ -10,7 +10,7 @@ ARGS=$1; SECS=${2:-300}# kernel command line so hakios.mpss.c / hakios.ipa.c map that phone's blocks. SOC_ARGS names the file;# default is the one device there is. The POCO's values equal the kernel defaults, so this is a no-op there.SOC_ARGS=${SOC_ARGS-$(ls devices/*/soc.args 2>/dev/null | head -1)}-SOC=""; [ -n "$SOC_ARGS" ] && [ -f "$SOC_ARGS" ] && SOC=$(tr '\n' ' ' < "$SOC_ARGS")+SOC=""; [ -n "$SOC_ARGS" ] && [ -f "$SOC_ARGS" ] && SOC=$(tr -d '\r' < "$SOC_ARGS" | tr '\n' ' ')for i in $(seq 1 2160); do s=$(./xl state); [ "$s" != absent ] && break; sleep 10; doneecho "$(date +%T) phone: $s"; [ "$s" = absent ] && { echo "NO PHONE"; exit 1; }./xl enter 2>&1 | tail -1diff --git a/tools/soc-args-test-aoss.py b/tools/soc-args-test-aoss.pynew file mode 100644index 0000000..9b018ad--- /dev/null+++ b/tools/soc-args-test-aoss.py@@ -0,0 +1,112 @@+#!/usr/bin/env python3+"""The generator must find the AOSS mailbox however a phone's device tree describes it.++The same SM7325 phone gave soc_aoss from the repository's reference tree and none from the tree the+running phone itself exports (/sys/firmware/fdt): the reference calls the node+qcom,sm8350-aoss-qmp, the phone's Android kernel calls it qcom,qmp-mbox on /soc/qcom,qmp-aop. This test+builds small device trees of its own (no part of a real phone's tree is committed) and checks+tools/soc-args.py on each:++ mainline form -> soc_aoss found+ vendor-kernel form -> soc_aoss found+ both, and a reg-less decoy -> the one with a reg, and only one line+ neither -> no soc_aoss, and no failure+"""+import os+import struct+import subprocess+import sys+import tempfile++HERE = os.path.dirname(os.path.abspath(__file__))+SOC_ARGS = os.path.join(HERE, "soc-args.py")+++def fdt(tree):+ """A flattened device tree for {name: (props, children)}; props is {prop: bytes}."""+ strings, offsets, body = bytearray(), {}, bytearray()++ def string_off(name):+ if name not in offsets:+ offsets[name] = len(strings)+ strings.extend(name.encode() + b"\0")+ return offsets[name]++ def pad(b):+ b.extend(b"\0" * (-len(b) % 4))++ def node(name, props, children):+ body.extend(struct.pack(">I", 1))+ body.extend(name.encode() + b"\0")+ pad(body)+ for pname, value in props.items():+ body.extend(struct.pack(">III", 3, len(value), string_off(pname)))+ body.extend(value)+ pad(body)+ for cname, (cprops, cchildren) in children.items():+ node(cname, cprops, cchildren)+ body.extend(struct.pack(">I", 2))++ node("", *tree[""])+ body.extend(struct.pack(">I", 9))+ header_size, rsvmap = 40, 16+ off_struct = header_size + rsvmap+ off_strings = off_struct + len(body)+ total = off_strings + len(strings)+ header = struct.pack(">IIIIIIIIII", 0xD00DFEED, total, off_struct, off_strings, header_size, 17, 16, 0,+ len(strings), len(body))+ return header + b"\0" * rsvmap + bytes(body) + bytes(strings)+++def cells(*values):+ return b"".join(struct.pack(">I", v) for v in values)+++def compat(*names):+ return b"".join(n.encode() + b"\0" for n in names)+++def soc_with(**nodes):+ return {"": ({}, {"soc": ({}, nodes)})}+++def run(tree):+ with tempfile.NamedTemporaryFile(suffix=".dtb", delete=False) as f:+ f.write(fdt(tree))+ path = f.name+ try:+ # an IPCC node is there in every tree, so that the generator has something to print+ return subprocess.run([sys.executable, SOC_ARGS, path], capture_output=True, text=True)+ finally:+ os.unlink(path)+++IPCC = ("qcom,ipcc@408000", ({"compatible": compat("qcom,ipcc"), "reg": cells(0x408000, 0x1000)}, {}))+failures = []+++def check(label, tree, want):+ got = run(tree)+ lines = [l for l in got.stdout.splitlines() if l.startswith("soc_aoss=")]+ ok = got.returncode == 0 and lines == want+ print("%s %s" % ("ok " if ok else "FAIL", label))+ if not ok:+ failures.append(label)+ print(" want %r, got %r (exit %d) %s" % (want, lines, got.returncode, got.stderr.strip()[:120]))+++mainline = ("power-controller@c300000", ({"compatible": compat("qcom,sm8350-aoss-qmp"), "reg": cells(0xC300000, 0x400)}, {}))+vendor = ("qcom,qmp-aop@c300000", ({"compatible": compat("qcom,qmp-mbox"), "reg": cells(0xC300000, 0x400)}, {}))+decoy = ("qcom,qmp-aop@dead000", ({"compatible": compat("qcom,qmp-mbox")}, {})) # no reg: must be ignored+other_soc = ("power-controller@1000000", ({"compatible": compat("qcom,sc7280-aoss-qmp"), "reg": cells(0x1000000, 0x400)}, {}))++check("mainline form", soc_with(**dict([IPCC, mainline])), ["soc_aoss=0xc300000"])+check("vendor-kernel form", soc_with(**dict([IPCC, vendor])), ["soc_aoss=0xc300000"])+check("a reg-less decoy beside the mainline node", soc_with(**dict([IPCC, decoy, mainline])), ["soc_aoss=0xc300000"])+check("a reg-less decoy only", soc_with(**dict([IPCC, decoy])), [])+check("another SoC's compatible (qcom,sc7280-aoss-qmp)", soc_with(**dict([IPCC, other_soc])), ["soc_aoss=0x1000000"])+check("neither: no soc_aoss, no failure", soc_with(**dict([IPCC])), [])++if failures:+ sys.exit("soc-args-test-aoss: %d FAILED" % len(failures))+print("soc-args-test-aoss: all passed")diff --git a/tools/soc-args.py b/tools/soc-args.pyindex 51da9cb..54af460 100755--- a/tools/soc-args.py+++ b/tools/soc-args.py@@ -61,7 +61,27 @@ def u32(value, index=0):return struct.unpack_from('>I', value, index * 4)[0]+def aoss_mailbox(nodes):+ """The address of the AOSS QMP mailbox, which one phone's device tree describes in two ways.++ A tree from a mainline-style kernel has a node whose compatible is qcom,<soc>-aoss-qmp (the+ reference tree here: qcom,sm8350-aoss-qmp on /soc/power-controller@c300000). A tree from the+ phone's own Android (vendor) kernel, which is what /sys/firmware/fdt gives on the phone, calls the+ same hardware /soc/qcom,qmp-aop@c300000 with the compatible qcom,qmp-mbox; the reference tree+ even has such a node as well, but without a reg. Both carry the same address. Only a node that+ has a reg counts, and the mainline form is preferred when both are there."""+ for path, props in nodes.items():+ kinds = props.get('compatible', b'').split(b'\0')+ if any(k.startswith(b'qcom,') and k.endswith(b'-aoss-qmp') for k in kinds) and len(props.get('reg', b'')) >= 4:+ return u32(props['reg'], 0)+ for path, props in nodes.items():+ if path.rsplit('/', 1)[-1].split('@', 1)[0] == 'qcom,qmp-aop' and len(props.get('reg', b'')) >= 4:+ return u32(props['reg'], 0)+ return None++def main():+ sys.stdout.reconfigure(newline="\n") # LF on Windows too: the output becomes a file of boot-argsif len(sys.argv) != 2:sys.exit(__doc__)nodes = nodes_of(open(sys.argv[1], 'rb').read())@@ -80,7 +100,9 @@ def main():args.append((arg, u32(props['reg'], cell)))block('qcom,ipcc', 'soc_ipcc') # cell 0: the address- block('qcom,sm8350-aoss-qmp', 'soc_aoss') # the AOSS mailbox (its compatible varies by SoC)+ aoss = aoss_mailbox(nodes) # the AOSS mailbox: see aoss_mailbox() for the two ways it is described+ if aoss is not None:+ args.append(('soc_aoss', aoss))block('qcom,rpmh-rsc', 'soc_rsc', cell=4) # drv-2 (the application processors') is the third addr/size pair (reg-names drv-0/1/2)_, smmu = find_named(nodes, 'apps-smmu') # not by compatible: the GPU's SMMU shares qcom,qsmmu-v500if smmu and 'reg' in smmu: