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
xnu/sync-drivers.sh: make kernel builds what is in drivers/
shimoku863a6d57f55f
diff --git a/tools/make-kernel.sh b/tools/make-kernel.shindex 02f6c62..dbe5296 100755--- a/tools/make-kernel.sh+++ b/tools/make-kernel.sh@@ -39,6 +39,8 @@ if [ "$1" = --judge ]; thenexitfi+# what was edited in drivers/ goes into the kernel tree first (only what is newer than the tree's copy)+[ ! -d xnu-src/xnu-8796.121.2 ] || xnu/sync-drivers.sh xnu-src/xnu-8796.121.2 || exit 1log=${KERNEL_LOG:-xnu-build.log}./xnu-build.sh -k "$@" 2>&1 | tee "$log"status=${PIPESTATUS[0]}diff --git a/xnu/README.md b/xnu/README.mdindex e7f96bf..500a874 100644--- a/xnu/README.md+++ b/xnu/README.md@@ -34,6 +34,9 @@ Things to know:- After changing kernel headers that the two external libraries see: `xnu-deps/setup.sh --rebuild-libs`.- Apple's DriverKit generator (`iig`) is closed; `xnu-deps/iig-impl/` holds stubs generated fromthe linker's undefined symbols (`xnu-deps/gen-iig-stubs.py`).+- A driver can be edited in `drivers/<subsystem>/`: `make kernel` runs `xnu/sync-drivers.sh`, which copies it into+ the tree when it is newer than the tree's copy (never the other way round). Everything else, and drivers edited+ in the tree, go back with `xnu/export.sh`.- Edit `xnu-src/xnu-8796.121.2` directly (a git tree on branch `redwood`); `xnu/export.sh`regenerates the patch and `files/` from the whole tree, so bring the tree up to the current patchfirst if somebody else changed the kernel meanwhile.diff --git a/xnu/sync-drivers.sh b/xnu/sync-drivers.shnew file mode 100644index 0000000..46bf3c5--- /dev/null+++ b/xnu/sync-drivers.sh@@ -0,0 +1,24 @@+#!/bin/bash+# Copy the drivers that were edited in drivers/ into the kernel tree, so that `make kernel` builds what is in+# the repository. A driver is copied only when the file in drivers/ is NEWER than the one in the tree: a driver+# that was edited in the tree (and not yet exported with xnu/export.sh) is never overwritten by an old copy.+# usage: xnu/sync-drivers.sh [KERNEL-TREE] (default: $XNU_SRC, else xnu-src/xnu-8796.121.2)+# prints one line per file it copied, and "drivers: in step" when there was nothing to do.+set -e+HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)+TREE=${1:-${XNU_SRC:-$HERE/../xnu-src/xnu-8796.121.2}}+[ -d "$TREE" ] || { echo "sync-drivers: no kernel tree at $TREE (xnu/apply.sh makes it)" >&2; exit 1; }+[ -f "$HERE/../drivers/map" ] || { echo "sync-drivers: no drivers/map" >&2; exit 1; }+copied=0+while read -r sub tree _; do+ case "$sub" in ''|'#'*) continue ;; esac+ src="$HERE/../drivers/$sub/$(basename "$tree")"+ [ -f "$src" ] || { echo "sync-drivers: drivers/$sub/$(basename "$tree") is in drivers/map but missing" >&2; exit 1; }+ if [ ! -e "$TREE/$tree" ] || { [ "$src" -nt "$TREE/$tree" ] && ! cmp -s "$src" "$TREE/$tree"; }; then+ mkdir -p "$(dirname "$TREE/$tree")"+ cp -p "$src" "$TREE/$tree"+ echo "sync-drivers: drivers/$sub/$(basename "$tree") -> $tree"+ copied=$((copied + 1))+ fi+done < "$HERE/../drivers/map"+[ "$copied" -gt 0 ] || echo "sync-drivers: drivers in step with the kernel tree"