Adding & Porting New Devices
headless-phone keeps all device-specific knowledge inside a small declarative directory under devices/<codename>/ so one Debian rootfs, flasher, OTA updater, and WebUSB installer work cleanly across devices.
Porting Workflow
Section titled “Porting Workflow”-
Run non-destructive hardware triage (
tools/triage.py)Connect the target phone (with ADB enabled on stock Android/GrapheneOS, in fastboot mode, and/or with a downloaded factory image zip) and generate a draft profile automatically:
Terminal window # Capture ADB probes (cmdline, bootconfig, modules, block devices, sysfs)# and fastboot partition geometry into build/triage/<serial>/python tools/triage.py --capture-profile --save# Also inspect a local factory image zip or unpacked boot images (works offline;# streams nested zips on disk without loading into RAM)python tools/triage.py --capture-profile --inspect-images path/to/factory-image.ziptools/triage.pyinspectsANDROID!(v0–v4),VNDRBOOT(v3–v4 + ramdisk fragments + bootconfig),DTBO, andAVB0headers, classifies the partition layout (header-v4-5part,header-v4-init-boot,header-v4-classic,header-v2-legacy), infersKERNEL_BACKEND(grapheneos-6.1,grapheneos-6.18, ormainline), and writestriage-summary.jsonplus a ready-to-reviewdevice.env.draft(safely keepingBOOTCTRL_BACKEND="none"andBOOTCTRL_ALLOW_BOOTLOADERS=""until hardware-verified). -
Create
devices/<codename>/device.envandmodules.bootCopy
device.env.draft(or an existing sibling likedevices/raven/device.env) todevices/<codename>/device.env, review all partition sizes, kernel offsets, cmdline, and deferred vendor modules, and authordevices/<codename>/modules.bootlisting the Stage 1 modules needed to reach UFS/eMMC storage, USB-C/TCPCI, thermal, and the hardware watchdog. -
Validate an unmodified baseline kernel first
Before applying custom Kconfig or patches, verify the upstream kernel boots cleanly with
SHELL_MODE=1(USB serial recovery shell) so you never risk touchinguserdata:Terminal window BUILD_MODE=baseline kernel/build.sh <codename>SHELL_MODE=1 initramfs/build.sh <codename>python tools/flash.py --boot-dir out/<codename>/boot --slot b --reboot -
Build custom kernel + Debian rootfs & sync WebUSB catalog
Run the full custom build (
kernel/build.sh,initramfs/build.sh,rootfs/build.sh), test live on hardware, and verify the WebUSB installer’s auto-synced device catalog (cd web && pnpm run sync-devices && pnpm run test). -
Verify A/B boot control last (anti-rollback safety)
Keep
BOOTCTRL_BACKEND="none"andBOOTCTRL_ALLOW_BOOTLOADERS=""while iterating. Only after confirming clean multi-reboot stability and matching bootloaders on both slots should you enabledevinfo,gpt-ab, orbcband pinBOOTCTRL_ALLOW_BOOTLOADERS.
Anatomy of devices/<codename>/device.env
Section titled “Anatomy of devices/<codename>/device.env”Every profile is a bash-sourceable KEY="VALUE" file validated in CI (source kernel/VERSIONS.env && source devices/<codename>/device.env):
DEVICE_CODENAME="raven"DEVICE_NAME="Google Pixel 6 Pro"DEVICE_ARCH="arm64"DEVICE_SOC="gs101"
# Kernel backend: grapheneos-6.1 | grapheneos-6.18 | mainlineKERNEL_BACKEND="grapheneos-6.1"KLEAF_TARGET="raviole"KLEAF_BUILD_SCRIPT="build_raviole.sh"
# Android boot header layout (Header v4 classic vs v4 init_boot vs v3 vs v2)BOOT_HEADER_VERSION="4"HAS_INIT_BOOT="0" # Set "1" for Pixel 7+ (separate init_boot partition)HAS_VENDOR_BOOT="1"HAS_VENDOR_KERNEL_BOOT="0" # Set "1" for devices with vendor_kernel_bootRAMDISK_COMPRESSION="lz4"BOOT_PARTITION_SIZE="67108864"VENDOR_BOOT_PARTITION_SIZE="67108864"DTBO_PARTITION_SIZE="16777216"VENDOR_BOOT_PAGESIZE="2048"KERNEL_BASE="0x10000000"KERNEL_OFFSET="0x00008000"RAMDISK_OFFSET="0x01000000"TAGS_OFFSET="0x00000100"DTB_OFFSET="0x01f00000"
# Artifacts, storage, and A/B bootctrlKERNEL_IMAGE="Image.lz4"DTB_FILES="gs101-a0.dtb gs101-b0.dtb"DTBO_FILE="dtbo.img"ROOTFS_PARTITION="userdata"ROOTFS_LABEL="headless-root"BOOT_DEVICE="14700000.ufs"BOOTCTRL_BACKEND="devinfo" # Keep "none" until verified on hardware!BOOTCTRL_ALLOW_BOOTLOADERS="${RAVEN_BOOTLOADER_VERSION:-slider-17.0-15681480}"
# Cmdline: drop cgroup.memory=nokmem; enable cgroups v2 & disable SELinuxKERNEL_CMDLINE="... systemd.unified_cgroup_hierarchy=1 selinux=0 bootconfig"
# Vendor modules deferred until after /vendor mounts read-onlyWIFI_MODULE="bcmdhd4389"VENDOR_MODULES="bcmdhd4389 aoc_core aoc_usb_driver aoc_uwb_platform_drv aoc_channel_dev aoc_char_dev ..."VENDOR_BLACKLIST_MODULES="bcmdhd4389 aoc_core ..."VENDOR_MODPROBE_OPTIONS="options aoc_core aoc_autoload_firmware=1"WATCHDOG_MODULE="s3c2410_wdt"Supported Boot Image Layouts (initramfs/build.sh)
Section titled “Supported Boot Image Layouts (initramfs/build.sh)”| Layout | Devices | Partitions Built |
|---|---|---|
| Header v4 Classic | Pixel 6 (raven, oriole, bluejay) |
boot.img (kernel + generic ramdisk), vendor_boot.img (platform + dlkm + DTB + bootconfig), dtbo.img |
Header v4 Split init_boot |
Pixel 7–10 (pantah, shusky, caimito, rango, …) |
boot.img (kernel only), init_boot.img (generic ramdisk), vendor_kernel_boot.img (dlkm + DTB + bootconfig), optional vendor_boot.img, dtbo.img |
| Header v3 | Android 11–12 GKI devices | boot.img, vendor_boot.img (single vendor ramdisk), dtbo.img |
| Header v2 Legacy / Mainline | Pixel 4 (flame), upstream mainline phones |
Monolithic boot.img (merged ramdisk + --dtb), optional dtbo.img |
Multi-Repo Kernel Patch Routing (kernel/apply_patches.py)
Section titled “Multi-Repo Kernel Patch Routing (kernel/apply_patches.py)”GrapheneOS Kleaf trees split kernel code across two separate Git repositories: the common Android Common Kernel submodule (common/ack on 6.1, common on 6.18) and the top-level kernel super-repo (private/google-modules/...).
kernel/apply_patches.py handles this cleanly and fail-closed:
- Backend scoping:
grapheneos-6.1applieskernel/patches/*.patchplus optionalkernel/patches/grapheneos-6.1/*.patch. Newer Kleaf backends (grapheneos-6.18, etc.) apply onlykernel/patches/<backend>/*.patchso 6.1 patches never collide with newer trees. - Automatic exact-blob routing: Parses every patch’s touched paths in an isolated non-Git temp directory (rejecting file creations, renames, copies, and traversal paths), checks
git ls-tree HEADacross both repos, and routes the patch to whichever repo owns 100% of its paths (failing closed on untracked, ambiguous, or cross-repo patches). - Write-ahead state & clean rollback: Tracks managed paths per repo in
<git-dir>/headless-phone-managed-paths.jsonso removing a patch or switching toBUILD_MODE=baselinecleanly resets previously patched files toHEAD, and rolls back both repos automatically if any patch fails to apply.
Shipped Kernel Patches (GPL-2.0-only)
Section titled “Shipped Kernel Patches (GPL-2.0-only)”| Patch | Routed Repo | Purpose |
|---|---|---|
0001-allow-standard-linux-inet-sockets.patch |
common/ack (ACK) |
Replaces Android’s CONFIG_ANDROID_PARANOID_NETWORK AID_INET GID 3003 check in af_inet.c / af_inet6.c so non-root Linux daemons (avahi-daemon, _apt) and Docker containers can open standard IPv4/IPv6 sockets. |
0002-bcmdhd-fix-non-dhd-netdev-type-confusion.patch |
kernel_pixel_6.1 (super-repo) |
Guards dhd_ioctl_entry_local() and wl_cfg80211_dump_station() across bcm4383/4389/4390/4398 so systemd-networkd/iw querying hidden aware_nmi0/p2p0 netdevs never triggers a kernel Oops. |
Syncing Device Profiles to the WebUSB Installer
Section titled “Syncing Device Profiles to the WebUSB Installer”The WebUSB installer reads devices/*/device.env via web/scripts/sync-devices.mjs (automatically invoked during pnpm run build, typecheck, and test). Whenever you add or edit a device profile, verify:
cd webpnpm run sync-devicespnpm run typecheckpnpm run testtools/triage.py CLI Reference
Section titled “tools/triage.py CLI Reference”| Flag | Description |
|---|---|
--save |
Save full getprop / fastboot getvar all snapshots under build/triage/<serial>/. |
--capture-profile |
Run all 8 read-only ADB probes + fastboot capture, emitting merged triage-summary.json and device.env.draft. |
--inspect-images <PATH> |
Parse a standalone .img, directory, or nested factory .zip offline. |
--allow-image-mismatch |
Bypass strict product-hint verification when combining --inspect-images with a live device. |
--serial <SERIAL> |
Target a specific device when multiple ADB/fastboot devices are attached. |
--out <PATH> |
Output directory (default build/triage). |