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
drivers/README.md, licences, CI: the drivers' place is said where the code is and where the licence is
shimoku6cb5415d6971
diff --git a/COMPLIANCE.md b/COMPLIANCE.mdindex c04c725..5f2ccf0 100644--- a/COMPLIANCE.md+++ b/COMPLIANCE.md@@ -6,7 +6,7 @@ legal opinion, and it does not assert that the project is free of all risk. See## Apple Public Source License 2.0 (the kernel)-`xnu/hakios.patch` and everything under `xnu/files/` are modifications of Apple's XNU, which Apple+`xnu/hakios.patch` and everything under `xnu/files/` and `drivers/` are modifications of Apple's XNU, which Applepublishes under the APSL 2.0. The full text is in `LICENSE.APSL`. The obligations we track:- **Source availability (APSL 2.3).** Our modifications are published here as source. The exactdiff --git a/LICENSE b/LICENSEindex 93b2ea5..23abce4 100644--- a/LICENSE+++ b/LICENSE@@ -2,7 +2,7 @@ HakiOSTwo licenses apply, by directory:-1. The kernel: xnu/hakios.patch and everything under xnu/files/ are a derivative work of+1. The kernel: xnu/hakios.patch and everything under xnu/files/ and drivers/ are a derivative work ofApple's XNU and are licensed under the Apple Public Source License, Version 2.0, whose fulltext is in LICENSE.APSL. Per its terms the modifications are published here as source andApple's notices are kept in the files they belong to.diff --git a/README.md b/README.mdindex 83358ed..a4775cd 100644--- a/README.md+++ b/README.md@@ -21,7 +21,7 @@ device tree and its own Android, so a port to another Qualcomm phone is a new diOnly my code and my data:- the kernel: a patch to Apple's open-source XNU (`xnu/hakios.patch`, APSL 2.0) and my driver- files (`xnu/files/`), laid over a fresh clone by `xnu/apply.sh`;+ files (`xnu/files/`, `drivers/`), laid over a fresh clone by `xnu/apply.sh`;- the boot loader (`xnuloader/`), my programs and libraries (`userland/src/`), tools (`tools/`),build and run scripts;- `prebuilt/`: the kernel, loader and libraries built from this repository;@@ -125,7 +125,7 @@ module, or the open lzfse library gets built). User space and the images: `REST=| Directory | Contents ||---|---|| `xnu/` | the kernel patch and files; `apply.sh`, `export.sh`; a README about the kernel |-| `xnu/files/bsd/dev/hakios.*.c` | my drivers: display, touch, UFS, GPU, Wi-Fi, audio, modem (`hakios.mpss.c`), its packets (`hakios.ipa.c`, `hakios.cell.c`), SIM/NAS, haptics, cameras |+| `drivers/*/hakios.*` | my drivers: display, touch, UFS, GPU, Wi-Fi, audio, modem (`hakios.mpss.c`), its packets (`hakios.ipa.c`, `hakios.cell.c`), SIM/NAS, haptics, cameras || `xnuloader/` | the boot loader (a UEFI application) || `userland/` | my programs and libraries (`src/`), the image build, launchd jobs || `sysimage/` | scripts that fetch and unpack the OS files from the IPSW (none of the files themselves) |@@ -140,7 +140,7 @@ module, or the open lzfse library gets built). User space and the images: `REST=The kernel, loader and user space are shared. Everything about one phone lives in`devices/<name>/`: its UEFI, device tree, firmware list and tools. Today there is one,`devices/redwood/`, and its README is the map of what a port to another Qualcomm phone must bring.-The phone's drivers are the files `xnu/files/bsd/dev/hakios.*.c`; the head of each says where its+The phone's drivers are the files `drivers/*/hakios.*` (by subsystem: `drivers/README.md`); the head of each says where itsnumbers came from.## Cellulardiff --git a/README.uk.md b/README.uk.mdindex fd28ec1..1c4b030 100644--- a/README.uk.md+++ b/README.uk.md@@ -21,7 +21,7 @@ iOS 16.5: launchd, backboardd, SpringBoard, застосунки. Те самеЛише мій код і мої дані:- ядро: патч до відкритого XNU від Apple (`xnu/hakios.patch`, APSL 2.0) і мої файли драйверів- (`xnu/files/`), які `xnu/apply.sh` накладає на свіжий клон;+ (`xnu/files/`, `drivers/`), які `xnu/apply.sh` накладає на свіжий клон;- завантажувач (`xnuloader/`), мої програми й бібліотеки (`userland/src/`), інструменти(`tools/`), скрипти збірки та запуску;- `prebuilt/`: ядро, завантажувач і бібліотеки, зібрані з цього репозиторію;@@ -108,7 +108,7 @@ make images # користувацький простір і образи| Каталог | Вміст ||---|---|| `xnu/` | патч і файли ядра; `apply.sh`, `export.sh`; README про ядро |-| `xnu/files/bsd/dev/hakios.*.c` | мої драйвери: екран, тач, UFS, GPU, Wi-Fi, звук, модем, SIM/NAS, вібро, камери |+| `drivers/*/hakios.*` | мої драйвери: екран, тач, UFS, GPU, Wi-Fi, звук, модем, SIM/NAS, вібро, камери || `xnuloader/` | завантажувач (застосунок UEFI) || `userland/` | мої програми й бібліотеки (`src/`), збірка образів, завдання launchd || `sysimage/` | скрипти, що беруть і розпаковують файли ОС з IPSW (самих файлів немає) |diff --git a/README.zh.md b/README.zh.mdindex e2addf3..c26f374 100644--- a/README.zh.md+++ b/README.zh.md@@ -17,7 +17,7 @@ HakiOS 在搭载高通 SoC 的 Android 手机上运行开源的 XNU 内核(xnu只有我的代码和我的数据:-- 内核:对 Apple 开源 XNU 的补丁(`xnu/hakios.patch`,APSL 2.0)和我的驱动文件(`xnu/files/`),+- 内核:对 Apple 开源 XNU 的补丁(`xnu/hakios.patch`,APSL 2.0)和我的驱动文件(`xnu/files/`、`drivers/`),由 `xnu/apply.sh` 叠加到一份新克隆上;- 引导程序(`xnuloader/`)、我的程序和库(`userland/src/`)、工具(`tools/`)、构建和运行脚本;- `prebuilt/`:用本仓库构建出的内核、引导程序和库;@@ -102,7 +102,7 @@ make images # 用户空间和镜像| 目录 | 内容 ||---|---|| `xnu/` | 内核补丁和文件;`apply.sh`、`export.sh`;内核 README |-| `xnu/files/bsd/dev/hakios.*.c` | 我的驱动:显示、触摸、UFS、GPU、Wi-Fi、音频、调制解调器、SIM/NAS、振动、摄像头 |+| `drivers/*/hakios.*` | 我的驱动:显示、触摸、UFS、GPU、Wi-Fi、音频、调制解调器、SIM/NAS、振动、摄像头 || `xnuloader/` | 引导程序(UEFI 应用) || `userland/` | 我的程序和库(`src/`)、镜像构建、launchd 任务 || `sysimage/` | 从 IPSW 取得并解包系统文件的脚本(不含文件本身) |diff --git a/THIRD_PARTY_LICENSES.md b/THIRD_PARTY_LICENSES.mdindex fab8d03..f723705 100644--- a/THIRD_PARTY_LICENSES.md+++ b/THIRD_PARTY_LICENSES.md@@ -10,7 +10,7 @@ This supersedes the summary in `NOTICE`, which stays as the short, canonical lis| Component | Path | Origin | License | Notes ||---|---|---|---|---|-| XNU modifications | `xnu/hakios.patch`, `xnu/files/` | derivative of Apple XNU | APSL 2.0 (`LICENSE.APSL`) | base tag `xnu-8796.121.2`, fetched by `xnu/apply.sh` |+| XNU modifications | `xnu/hakios.patch`, `xnu/files/`, `drivers/` | derivative of Apple XNU | APSL 2.0 (`LICENSE.APSL`) | base tag `xnu-8796.121.2`, fetched by `xnu/apply.sh` || libdeflate | `xnu/files/bsd/miscfs/apfs/libdeflate/` | Eric Biggers | MIT | see its `COPYING` || libzbitmap | `xnu/files/bsd/miscfs/apfs/libzbitmap/`, `xnu-deps/build/lzbitmap/` | Corellium LLC (port of eafer/libzbitmap) | GPL-2.0+ OR MIT | used under MIT || LinuxKPI / Linux headers | `wifi/lx/include/linux/`, `wifi/lx/include/net/` | Linux / FreeBSD LinuxKPI | GPL-2.0 (Linux) / BSD-2-Clause (FreeBSD) | small compatibility headers; see each file's notice |diff --git a/ci/github-check.yml b/ci/github-check.ymlindex 94b7c08..7a7054e 100644--- a/ci/github-check.yml+++ b/ci/github-check.yml@@ -37,6 +37,8 @@ jobs:run: |python3 tools/boot-args-test.pypython3 tools/boot-args.py --check+ - name: The drivers are kept by subsystem and every one is in drivers/map+ run: python3 tools/drivers-check.py- name: The kernel patch applies to Apple's treerun: |git clone -q --depth 1 --branch xnu-8796.121.2 https://github.com/apple-oss-distributions/xnu.git /tmp/xnudiff --git a/devices/redwood/README.md b/devices/redwood/README.mdindex 411899b..410ef66 100644--- a/devices/redwood/README.md+++ b/devices/redwood/README.md@@ -12,7 +12,7 @@ tree and its Android. A port to another Qualcomm phone is another directory like| The phone's firmware | **not in the repository**: `pull-firmware.sh` pulls it off your phone over `adb` into `fw-*/` at the top || Tools | `tools/modem_firmware.py` (the modem image by the device tree), `tools/cellular_probe.py` (the modem's nodes in the device tree) |-What the kernel does for this phone in particular is the drivers `xnu/files/bsd/dev/hakios_*.c`+What the kernel does for this phone in particular is the drivers `drivers/*/hakios.*`(display, Goodix touch, UFS, Adreno 642L, WCN6750 Wi-Fi, the audio DSP, the modem, the Awinichaptics, the cameras); the head of each file says where its numbers come from. That is the map ofwhat to rewrite for another phone.diff --git a/drivers/README.md b/drivers/README.mdnew file mode 100644index 0000000..9bdf1fc--- /dev/null+++ b/drivers/README.md@@ -0,0 +1,40 @@+# Drivers++The kernel's own drivers, by subsystem, the way Linux keeps `drivers/`. They are files of Apple's XNU tree+(`bsd/dev/`, `iokit/Kernel/`), kept here so that they can be found and reviewed by what they do.++| Where | Is |+|---|---|+| `drivers/map` | the list: for each file, its subsystem and the path it has in Apple's tree |+| `xnu/apply.sh` | lays Apple's tag, `xnu/hakios.patch`, `xnu/files/` and these drivers into one tree |+| `xnu/export.sh` | the reverse, run before committing; refuses a new `hakios.*` file that `drivers/map` does not list |+| `tools/drivers-check.py` | CI: the map and the directories agree, nothing is listed twice, nothing is kept in two places |++Adding a driver: put it in `drivers/<subsystem>/`, add a line to `drivers/map`, add its `bsd/conf/files` line to+the patch (as the others have), `python3 tools/drivers-check.py`. A driver that is started by a boot argument+has to be in `docs/boot-args.md` (`python3 tools/boot-args.py --check`).++## Subsystems++| Directory | Drivers | Boot arguments | What it is |+|---|---|---|---|+| `input/` | `hakios.goodix.c`, `hakios.input.c`, `hakios.buttons.c`, `hakios.virtio_input.c` | `touchscreen=` | the touch controller, the event queue behind `/dev/hakios-touch`, the buttons, QEMU's virtio input |+| `storage/` | `hakios.ufs.c`, `hakios.ufshc.c/.h`, `hakios.sparse.c`, `hakios.image.c`, `hakios.guard.c`, `hakios.apfs_check.c`, `hakios.virtio_blk.c` | `ufs=`, `ufs_write=`, `ufs_native=` | the phone's flash (UFS), the sparse and image devices, the checks of the APFS read path, QEMU's virtio-blk. **The only code of the kernel that may write to the phone**: see `tools/provenance.allow` |+| `gpu/` | `hakios.adreno.c`, `hakios.gpu.cpp` | `gpu=`, `adreno=` | the Adreno GPU bring-up and the IOKit object user space talks to |+| `camera/` | `hakios.camera.c`, `hakios.torch.c` | `cam=`, `torch=` | the camera sensors and ISP interface, the flashlight LED |+| `haptic/` | `hakios.haptic.c` | `haptic=` | the vibration motor |+| `audio/` | `hakios.adsp.c`, `hakios.audio.c`, `hakios.sound.c`, `hakios.speaker.c`, `hakios.mic.c`, `hakios.virtio_sound.c` | `adsp=`, `sound=`, `mic=` | the audio DSP loader, `/dev/hakios-audio`, the speaker amplifiers and their guard, the microphone, QEMU's virtio sound |+| `power/` | `hakios.battery.c/.cpp`, `hakios.cpufreq.c` | `cpufreq=`, `battmgr=` | battery readings (through the DSP), CPU frequency |+| `wifi/` | `hakios.wifi.c`, `hakios.wlfw.c`, `hakios.lx.c`, `hakios.sta.c`, `hakios.apple80211.c`, `hakios.wlan.cpp` | `wifi=`, `wifi_step=` | the Wi-Fi subsystem's bring-up, the WLAN firmware service, the Linux-driver layer (`wifi/lx/`) and the surface the iOS Wi-Fi service expects |+| `modem/` | `hakios.mpss.c`, `hakios.cell.c`, `hakios.qmi.c`, `hakios.nas.c`, `hakios.ipa.c` | `modem=` | the cellular modem path (research; not reviewed in `docs/driver-review/`) |+| `net/` | `hakios.net.c`, `hakios.virtio_net.c` | | the `enN` network interface and QEMU's virtio-net |+| `core/` | `hakios.version.c` | `hakios_kver=` | `kern.hakios.version` |++## Reviews++`docs/driver-review/` has one read-only audit per group (what was checked, what was found, how sure). They are+findings to verify, not a certificate: read the report before relying on a driver, and fix findings in the driver,+not in the report.++The kernel is built from the C and C++ files only; the drivers need no files that are not in this repository,+except the touch firmware header (`input/hakios.focaltech_fw.h`), which `tools/provenance.allow` marks as pending.diff --git a/xnu/README.md b/xnu/README.mdindex e2662be..e7f96bf 100644--- a/xnu/README.md+++ b/xnu/README.md@@ -4,6 +4,7 @@ Our changes to XNU `xnu-8796.121.2` (the kernel of iOS 16.5, Darwin 22.5.0):- `hakios.patch`: changes to Apple's files;- `files/`: new files at their paths in the XNU tree;+- `../drivers/`: the drivers, by subsystem (`drivers/README.md`); `apply.sh` puts them at their paths in the tree;- `apply.sh`: fetches the sources from Apple's GitHub and lays all of this over them;`export.sh`: the reverse, run before committing.