Skip to content

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.

  1. 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.zip

    tools/triage.py inspects ANDROID! (v0–v4), VNDRBOOT (v3–v4 + ramdisk fragments + bootconfig), DTBO, and AVB0 headers, classifies the partition layout (header-v4-5part, header-v4-init-boot, header-v4-classic, header-v2-legacy), infers KERNEL_BACKEND (grapheneos-6.1, grapheneos-6.18, or mainline), and writes triage-summary.json plus a ready-to-review device.env.draft (safely keeping BOOTCTRL_BACKEND="none" and BOOTCTRL_ALLOW_BOOTLOADERS="" until hardware-verified).

  2. Create devices/<codename>/device.env and modules.boot

    Copy device.env.draft (or an existing sibling like devices/raven/device.env) to devices/<codename>/device.env, review all partition sizes, kernel offsets, cmdline, and deferred vendor modules, and author devices/<codename>/modules.boot listing the Stage 1 modules needed to reach UFS/eMMC storage, USB-C/TCPCI, thermal, and the hardware watchdog.

  3. 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 touching userdata:

    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
  4. 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).

  5. Verify A/B boot control last (anti-rollback safety)

    Keep BOOTCTRL_BACKEND="none" and BOOTCTRL_ALLOW_BOOTLOADERS="" while iterating. Only after confirming clean multi-reboot stability and matching bootloaders on both slots should you enable devinfo, gpt-ab, or bcb and pin BOOTCTRL_ALLOW_BOOTLOADERS.

Every profile is a bash-sourceable KEY="VALUE" file validated in CI (source kernel/VERSIONS.env && source devices/<codename>/device.env):

devices/raven/device.env (key fields)
DEVICE_CODENAME="raven"
DEVICE_NAME="Google Pixel 6 Pro"
DEVICE_ARCH="arm64"
DEVICE_SOC="gs101"
# Kernel backend: grapheneos-6.1 | grapheneos-6.18 | mainline
KERNEL_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_boot
RAMDISK_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 bootctrl
KERNEL_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 SELinux
KERNEL_CMDLINE="... systemd.unified_cgroup_hierarchy=1 selinux=0 bootconfig"
# Vendor modules deferred until after /vendor mounts read-only
WIFI_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:

  1. Backend scoping: grapheneos-6.1 applies kernel/patches/*.patch plus optional kernel/patches/grapheneos-6.1/*.patch. Newer Kleaf backends (grapheneos-6.18, etc.) apply only kernel/patches/<backend>/*.patch so 6.1 patches never collide with newer trees.
  2. 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 HEAD across both repos, and routes the patch to whichever repo owns 100% of its paths (failing closed on untracked, ambiguous, or cross-repo patches).
  3. Write-ahead state & clean rollback: Tracks managed paths per repo in <git-dir>/headless-phone-managed-paths.json so removing a patch or switching to BUILD_MODE=baseline cleanly resets previously patched files to HEAD, and rolls back both repos automatically if any patch fails to apply.
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:

Terminal window
cd web
pnpm run sync-devices
pnpm run typecheck
pnpm run test
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).