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
boot-args: the Metal plug-in's helper is read too; the catalogue and the common defconfig made again
yehorkaa53c12fafa30e
diff --git a/configs/boot-args.lst b/configs/boot-args.lstindex 7af859d..1c81983 100644--- a/configs/boot-args.lst+++ b/configs/boot-args.lst@@ -100,6 +100,7 @@ fb_queue kfb_threads kfbheight kfbscale k+fbsubtype kfbtrace kfbwidth kgamut l@@ -149,15 +150,19 @@ haptic khaptic_effect khv_wdt_pet kloader_return_after kl+m2v_utrace umachine_name kmembench kmetal kumetal_all u+metal_defer umetal_dump umetal_fps umetal_gmem umetal_gmem_draws umetal_gmem_off u+metal_luma_boost u+metal_m2v umetal_skip umetal_trace umetal_watch u@@ -277,6 +282,7 @@ touch_poll_us ktouch_rate ktouch_spi_hz ktouchscreen k+tu_debug uufs lufs_bench kufs_check k@@ -291,6 +297,7 @@ ufs_native_spin kufs_probe lufs_shared_pa kufs_write kl+ui_lite uustacks kustacks_at kustacks_count k@@ -305,6 +312,8 @@ virtio_blk kvirtio_input kvirtio_net kvirtio_sound k+wallpaper_cache u+wallpaper_freeze uwifi kwifi_again kwifi_ask kdiff --git a/configs/common_defconfig b/configs/common_defconfigindex 08ae448..6f43afa 100644--- a/configs/common_defconfig+++ b/configs/common_defconfig@@ -2,7 +2,7 @@# HakiOS common defconfig: every setting there is, with what it does.# Made by tools/hakios-config.py listing common -o <this file>; the values are the ones that file sets, and tests/CI check that it names every symbol.#-# 350 symbols in 18 groups; 34 are set, 25 of them drivers built in.+# 370 symbols in 18 groups; 34 are set, 25 of them drivers built in.##@@ -49,7 +49,7 @@ CONFIG_HAKIOS_TORCH=y# the chip's identity from the firmware's shared memory: kern.hakios.soc_* (socinfo=1). Any Qualcomm SoC that keeps ... [hakios.socinfo.c]CONFIG_HAKIOS_SOCINFO=y-# the Adreno 642L of the SC7280 woken step by step (adreno=N), and HakiosGPU, the IOKit service Mesa and the window ... [hakios.adreno.c, hakios.gpu.cpp]+# the Adreno 642L of the SC7280 woken step by step (adreno=N), and HakiosGPU, the IOKit service Mesa, Metal and the ... [hakios.adreno.c, hakios.gpu.cpp]CONFIG_HAKIOS_ADRENO=y# the vibration motor: an Awinic AW86927 driving a linear resonant actuator (haptic=N), its waveforms from fw-haptic/ [hakios.haptic.c]@@ -335,7 +335,7 @@ CONFIG_TOUCHSCREEN=y# CONFIG_VIRTIO_INPUT is not set#-# GPU and display (74)+# GPU and display (75)## rendering on Adreno (an image built with GL=1; the GPU's firmware from your phone) [needs fw-gpu/ from the phone]@@ -413,6 +413,9 @@ CONFIG_GPU=y# the same 375 x 812 points drawn at two pixels a point instead of three# CONFIG_FBSCALE is not set+# read by MiniIOMobileFramebuffer.cpp (kernel)+# CONFIG_FBSUBTYPE is not set+# log the first N calls of every selector (default 3)# CONFIG_FBTRACE is not set@@ -1075,7 +1078,7 @@ CONFIG_MODEM_AGAIN=y# CONFIG_UFS_PROBE is not set#-# User space (14)+# User space (33)## read by inject_sb.c (user space)@@ -1087,6 +1090,12 @@ CONFIG_MODEM_AGAIN=y# the second look this many seconds later (0: no second look; 30)# CONFIG_BT_AGAIN is not set+# read by inject.c (user space)+# CONFIG_CA_METALLIB is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_CA_PROF is not set+# CoreAnimation's frame clock from the display driver's refresh notifications# CONFIG_CA_VBL is not set@@ -1111,15 +1120,66 @@ CONFIG_MODEM_AGAIN=y# the renderer is made to answer that it has those functions after all# CONFIG_GLYES is not set+# Turnip's GPU trace of every render pass (u_trace) into a file, printed during the run+# CONFIG_M2V_UTRACE is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_ALL is not set++# this queue's command buffers recorded by a thread of hakios-metal's own (deferred recording), so that the window ...+# CONFIG_METAL_DEFER is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_DUMP is not set++# each draw of a sysmem pass timed alone, by program (only sysmem passes are: without metal_gmem=1)+# CONFIG_METAL_FPS is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_GMEM is not set++# GMEM for a pass whose like had at least N draws in the frame before (hakios_metal_cb_set_gmem_min_draws), sysmem for ...+# CONFIG_METAL_GMEM_DRAWS is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_GMEM_OFF is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_LUMA_BOOST is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_M2V is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_SKIP is not set++# read by HakiosMetalCA.m (user space)+# CONFIG_METAL_TRACE is not set++# read by inject.c (user space)+# CONFIG_METAL_WATCH is not set+# the root is to be the Darwin root volume on /dev/DEV -- the phone's flash, read only# CONFIG_ROOT_APFS is not set# read by inject_sb.c (user space)# CONFIG_SWITCHER_WALLPAPER is not set+# Turnip's TU_DEBUG in the window server (sysmem, gmem, forcebin, ...)+# CONFIG_TU_DEBUG is not set++# the system's own "Reduce Transparency" and "Reduce Motion" (Settings, Accessibility), for this+# CONFIG_UI_LITE is not set+# read by init.c (user space)# CONFIG_VAR_HFS is not set+# the window that shows the wallpaper rasterized by the window server (CALayer's shouldRasterize), drawn from one ...+# CONFIG_WALLPAPER_CACHE is not set++# the wallpaper as one still picture+# CONFIG_WALLPAPER_FREEZE is not set+## Extra arguments (1)#diff --git a/configs/symbols.tsv b/configs/symbols.tsvindex 31ed41b..ddb6040 100644--- a/configs/symbols.tsv+++ b/configs/symbols.tsv@@ -91,6 +91,7 @@ FB_QUEUE arg fb_queue GPU and display k MiniIOMobileFramebuffer.cppFB_THREADS arg fb_threads GPU and display k MiniIOMobileFramebuffer.cppFBHEIGHT arg fbheight GPU and display k MiniIOMobileFramebuffer.cppFBSCALE arg fbscale GPU and display k MiniIOMobileFramebuffer.cpp the same 375 x 812 points drawn at two pixels a point instead of three+FBSUBTYPE arg fbsubtype GPU and display k MiniIOMobileFramebuffer.cppFBTRACE arg fbtrace GPU and display k MiniIOMobileFramebuffer.cpp log the first N calls of every selector (default 3)FBWIDTH arg fbwidth GPU and display k MiniIOMobileFramebuffer.cppGAMUT arg gamut Loader l loader.c@@ -135,15 +136,19 @@ GPU_EXACT arg gpu_exact GPU and display k hakios.adreno.cGPU_KEEP arg gpu_keep GPU and display k hakios.gpu.cppGPU_LOG arg gpu_log GPU and display k hakios.adreno.cHAPTIC_EFFECT arg haptic_effect Haptics and torch k hakios.haptic.c+M2V_UTRACE arg m2v_utrace User space u HakiosMetalCA.m Turnip's GPU trace of every render pass (u_trace) into a file, printed during the runMACHINE_NAME arg machine_name CPU, memory and boot k GenericARMPE.cppMEMBENCH arg membench CPU, memory and boot k hakios.cpufreq.c-METAL arg metal GPU and display ku HakiosMetal.m,MiniIOMobileFramebuffer.cpp only the program metal_test (userland/src/metal_test.m): the safe level, for seeing what Metal does with the device+METAL arg metal GPU and display ku HakiosMetal.m,MiniIOMobileFramebuffer.cpp,inject_sb.c only the program metal_test (userland/src/metal_test.m): the safe level, for seeing what Metal does with the deviceMETAL_ALL arg metal_all User space u HakiosMetalCA.m+METAL_DEFER arg metal_defer User space u HakiosMetalCA.m this queue's command buffers recorded by a thread of hakios-metal's own (deferred recording), so that the window server's render thread does not waitMETAL_DUMP arg metal_dump User space u HakiosMetalCA.mMETAL_FPS arg metal_fps User space u HakiosMetalCA.m each draw of a sysmem pass timed alone, by program (only sysmem passes are: without metal_gmem=1)METAL_GMEM arg metal_gmem User space u HakiosMetalCA.mMETAL_GMEM_DRAWS arg metal_gmem_draws User space u HakiosMetalCA.m GMEM for a pass whose like had at least N draws in the frame before (hakios_metal_cb_set_gmem_min_draws), sysmem for the rest; 56 when not given, 0METAL_GMEM_OFF arg metal_gmem_off User space u HakiosMetalCA.m+METAL_LUMA_BOOST arg metal_luma_boost User space u HakiosMetalCA.m+METAL_M2V arg metal_m2v User space u HakiosMetalCA.mMETAL_SKIP arg metal_skip User space u HakiosMetalCA.mMETAL_TRACE arg metal_trace User space u HakiosMetalCA.mMETAL_WATCH arg metal_watch User space u inject.c@@ -249,6 +254,7 @@ TOUCH_LAT arg touch_lat GPU and display ku HakiosMetalCA.m,MiniIOMobileFramebuffTOUCH_POLL_US arg touch_poll_us Touch and buttons k hakios.goodix.cTOUCH_RATE arg touch_rate Touch and buttons k hakios.goodix.c the chip reports twice as often (Xiaomi's game mode; 240 otherwise)TOUCH_SPI_HZ arg touch_spi_hz Touch and buttons k hakios.goodix.c the bus at N Hz (Android's device tree gives the chip 5 MHz)+TU_DEBUG arg tu_debug User space u HakiosMetalCA.m Turnip's TU_DEBUG in the window server (sysmem, gmem, forcebin, ...)UFS_BENCH arg ufs_bench Storage and APFS k hakios.ufs.c what one request through the loader costs, by sizeUFS_CHECK arg ufs_check Storage and APFS k hakios.ufs.cUFS_NATIVE arg ufs_native Storage and APFS kl hakios.ufs.c,loader.c through this kernel's own driver instead, its own transfer list in the controller for the run, if all is as expected; 2: only look; 3: a dry run --@@ -260,6 +266,7 @@ UFS_NATIVE_LEAVE arg ufs_native_leave Storage and APFS k hakios.ufshc.cUFS_NATIVE_SLOTS arg ufs_native_slots Storage and APFS k hakios.ufshc.cUFS_NATIVE_SPIN arg ufs_native_spin Storage and APFS k hakios.ufshc.cUFS_PROBE arg ufs_probe Loader l loader.c+UI_LITE arg ui_lite User space u inject_sb.c the system's own "Reduce Transparency" and "Reduce Motion" (Settings, Accessibility), for thisUSTACKS arg ustacks Debugging k user_exception_trace.cUSTACKS_AT arg ustacks_at Debugging k user_exception_trace.cUSTACKS_COUNT arg ustacks_count Debugging k user_exception_trace.c@@ -272,6 +279,8 @@ VBLUR arg vblur GPU and display u eagl.cVIRTIO_BLK arg virtio_blk Storage and APFS k hakios.virtio_blk.cVIRTIO_INPUT arg virtio_input Touch and buttons k hakios.virtio_input.cVIRTIO_SOUND arg virtio_sound Audio and battery k hakios.virtio_sound.c+WALLPAPER_CACHE arg wallpaper_cache User space u inject_sb.c the window that shows the wallpaper rasterized by the window server (CALayer's shouldRasterize), drawn from one texture instead of composed again+WALLPAPER_FREEZE arg wallpaper_freeze User space u inject_sb.c the wallpaper as one still pictureWIFI_AGAIN arg wifi_again Wi-Fi k hakios.wifi.c start the DSP although the one before it was shut down without having acknowledged a stop: THAT HAS RESET THE PHONE, twice of twoWIFI_ASK arg wifi_ask Wi-Fi k hakios.wifi.c step 14 also asks that service a question (its capabilities) and writes down the beginning of an answerWIFI_BA arg wifi_ba Wi-Fi k lx_80211.cdiff --git a/docs/boot-args.md b/docs/boot-args.mdindex 16bc0fd..e02e75c 100644--- a/docs/boot-args.md+++ b/docs/boot-args.md@@ -2,13 +2,13 @@Made by `tools/boot-args.py --markdown`; CI fails if it is out of date with the source (`tools/boot-args.py --check`).-Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **339 arguments**: 276 read by the kernel, 14 by the loader, 59 by user space (one is read in more than one place).+Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **348 arguments**: 277 read by the kernel, 14 by the loader, 67 by user space (one is read in more than one place).-This is a catalogue of what exists and who reads it, not a manual. What an argument means is in the head of the file that reads it. The stable switches have a symbol in the configuration (`tools/hakios-config.py help SYMBOL`, `docs/configs.md`); the rest are the knobs of bring-up (a driver's steps, pauses, traces, test modes) and can change with the driver. Any of them can be given in a configuration with `CONFIG_BOOTARGS="name=value ..."`, which checks that each name is in this list.+This is a catalogue of what exists and who reads it, not a manual. What an argument means is in the head of the file that reads it. The stable switches have a symbol in the configuration (`tools/hakios-config.py help SYMBOL`, `docs/configs.md`); the rest are the knobs of bring-up (a driver's steps, pauses, traces, test modes) and can change with the driver. Any of them can be given in a configuration with `CONFIG_BOOTARGS="name=value ..."`, which checks that each name is in this list. What the arguments of the two Metal paths do: [Metal on the Adreno](reference/metal.md#boot-arguments).Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl kern.bootargs`).-## GPU and display (74)+## GPU and display (75)| Argument | Layer | Read by | Configuration | Set by ||---|---|---|---|---|@@ -36,6 +36,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `fb_threads` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_THREADS` | || `fbheight` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBHEIGHT` | || `fbscale` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBSCALE` | |+| `fbsubtype` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBSUBTYPE` | || `fbtrace` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBTRACE` | || `fbwidth` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBWIDTH` | || `glblit` | U | `eagl.c` | `CONFIG_GLBLIT` | |@@ -74,7 +75,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `gpu_exact` | K | `hakios.adreno.c` | `CONFIG_GPU_EXACT` | || `gpu_keep` | K | `hakios.gpu.cpp` | `CONFIG_GPU_KEEP` | || `gpu_log` | K | `hakios.adreno.c` | `CONFIG_GPU_LOG` | |-| `metal` | KU | `HakiosMetal.m`, `MiniIOMobileFramebuffer.cpp` | `CONFIG_METAL` | |+| `metal` | KU | `HakiosMetal.m`, `MiniIOMobileFramebuffer.cpp`, `inject_sb.c` | `CONFIG_METAL` | || `rec_mb` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_REC_MB` | || `rec_ring` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_REC_RING` | || `rec_secs` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_REC_SECS` | |@@ -395,7 +396,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `ufs` | L | `loader.c` | `CONFIG_UFS` | || `ufs_probe` | L | `loader.c` | `CONFIG_UFS_PROBE` | |-## User space (27)+## User space (35)| Argument | Layer | Read by | Configuration | Set by ||---|---|---|---|---|@@ -412,17 +413,25 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `glno` | U | `inject.c` | `CONFIG_GLNO` | || `glsb3` | U | `inject.c` | `CONFIG_GLSB3` | || `glyes` | U | `inject.c` | `CONFIG_GLYES` | |+| `m2v_utrace` | U | `HakiosMetalCA.m` | `CONFIG_M2V_UTRACE` | || `metal_all` | U | `HakiosMetalCA.m` | `CONFIG_METAL_ALL` | |+| `metal_defer` | U | `HakiosMetalCA.m` | `CONFIG_METAL_DEFER` | || `metal_dump` | U | `HakiosMetalCA.m` | `CONFIG_METAL_DUMP` | || `metal_fps` | U | `HakiosMetalCA.m` | `CONFIG_METAL_FPS` | || `metal_gmem` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM` | || `metal_gmem_draws` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM_DRAWS` | || `metal_gmem_off` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM_OFF` | |+| `metal_luma_boost` | U | `HakiosMetalCA.m` | `CONFIG_METAL_LUMA_BOOST` | |+| `metal_m2v` | U | `HakiosMetalCA.m` | `CONFIG_METAL_M2V` | || `metal_skip` | U | `HakiosMetalCA.m` | `CONFIG_METAL_SKIP` | || `metal_trace` | U | `HakiosMetalCA.m` | `CONFIG_METAL_TRACE` | || `metal_watch` | U | `inject.c` | `CONFIG_METAL_WATCH` | || `root_apfs` | U | `init.c` | `CONFIG_ROOT_APFS` | || `sb_delay` | U | `inject_sb.c` | | xl (XL_SB_DELAY) || `switcher_wallpaper` | U | `inject_sb.c` | `CONFIG_SWITCHER_WALLPAPER` | |+| `tu_debug` | U | `HakiosMetalCA.m` | `CONFIG_TU_DEBUG` | |+| `ui_lite` | U | `inject_sb.c` | `CONFIG_UI_LITE` | || `var_hfs` | U | `init.c` | `CONFIG_VAR_HFS` | || `var_store` | U | `init.c` | `CONFIG_VAR_STORE` | |+| `wallpaper_cache` | U | `inject_sb.c` | `CONFIG_WALLPAPER_CACHE` | |+| `wallpaper_freeze` | U | `inject_sb.c` | `CONFIG_WALLPAPER_FREEZE` | |diff --git a/tools/boot-args-test.py b/tools/boot-args-test.pyindex d4cd463..52b4971 100755--- a/tools/boot-args-test.py+++ b/tools/boot-args-test.py@@ -64,6 +64,7 @@ FILES = {# user space: strstr on the kern.bootargs buffer, and its own boot_arg() helper"userland/src/eagl.c": 'void k(char *arguments) { strstr(arguments, "u_strstr=1"); strstr(arguments, "ku_both="); }\n',"userland/src/init.c": 'static const char *\nboot_arg(const char *name)\n{ return 0; }\nvoid m(void) { boot_arg("u_helper"); }\n',+ "userland/src/HakiosMetalCA.m": 'void hm(void) { if (hm_boot_arg_set("u_hm_helper=1")) {} }\n',# the kernel also reads ku_both"drivers/net/hakios.net.c": 'void n(void) { PE_parse_boot_argn("ku_both", &v, 4); }\n',# NOT arguments: must not be found@@ -77,7 +78,7 @@ d = repo(FILES)try:got = found(d)for name, layers in (("k_direct", "k"), ("k_string", "k"), ("k_tunable", "k"), ("k_writeable", "k"), ("k_wrapped", "k"),- ("k_wifi_helper", "k"), ("k_wifi_lx", "k"), ("l_arg", "l"), ("u_strstr", "u"), ("u_helper", "u"),+ ("k_wifi_helper", "k"), ("k_wifi_lx", "k"), ("l_arg", "l"), ("u_strstr", "u"), ("u_helper", "u"), ("u_hm_helper", "u"),("ku_both", "klu")):check("found: %-14s layers %s" % (name, layers), got.get(name) == layers, "got %r" % got.get(name))for name in ("not_k_no_definition", "adreno_zap", "metadata", "not_u_other", "not_k_dt", "name", "arguments"):diff --git a/tools/boot-args.py b/tools/boot-args.pyindex 3b7906e..0bb311b 100755--- a/tools/boot-args.py+++ b/tools/boot-args.py@@ -23,7 +23,7 @@ What is looked for:xnu/hakios.patch adds to Apple's filesthe loader starts_with(c, "name=...") on the payload's command line, in xnuloader/user space a name given to strstr()/strncmp() on sysctl kern.bootargs, in userland/src/ (seen: sb_delay=, touch_lat=1,- ca_vbl=1 ...)+ ca_vbl=1 ...), or to the Metal plug-in's helper hm_boot_arg_set("metal_m2v=1")"""import argparseimport collections@@ -55,6 +55,8 @@ LOADER = re.compile(r'starts_with\((?:c|cmd|p|a|s), "([a-z][a-z0-9_.]*)=')# user space reads sysctl kern.bootargs into a buffer called arguments, args or argument, and looks in it with strstr:# strstr(arguments, "gltrace_at="), strstr(args, "touch_lat=1"): the name is what stands before the =USER = re.compile(r'strstr\(\s*(?:arguments|args|argument)\s*,\s*"([a-z][a-z0-9_]*)=')+# ... and the Metal plug-in has a helper that is given the whole word: hm_boot_arg_set("metal_m2v=1") in HakiosMetalCA.m+HM_ARG = re.compile(r'\bhm_boot_arg_set\(\s*"([a-z][a-z0-9_]*)=')# the group an argument is listed under: by the file that reads it (the first match decides)GROUPS = [@@ -138,6 +140,8 @@ def scan(root, keep=None):if f.startswith("userland/src/"):for m in USER.finditer(text):found[m.group(1)]["user"].add(base)+ for m in HM_ARG.finditer(text):+ found[m.group(1)]["user"].add(base)if BOOT_ARG_DEF.search(text):for m in BOOT_ARG_CALL.finditer(text):found[m.group(1)]["user"].add(base)@@ -266,7 +270,8 @@ def markdown(found, config):"that reads it. The stable switches have a symbol in the configuration (`tools/hakios-config.py help SYMBOL`, ""`docs/configs.md`); the rest are the knobs of bring-up (a driver's steps, pauses, traces, test modes) and can change ""with the driver. Any of them can be given in a configuration with `CONFIG_BOOTARGS=\"name=value ...\"`, which checks "- "that each name is in this list.",+ "that each name is in this list. What the arguments of the two Metal paths do: "+ "[Metal on the Adreno](reference/metal.md#boot-arguments).","","Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl kern.bootargs`).","",