Firmware, Watchdog & A/B Safety
Running bare-metal Linux on modern Android smartphones means cooperating cleanly with the stock bootloader (ABL), A/B slot boot control, anti-rollback fuses, and hardware watchdogs. This guide explains how headless-phone keeps your device recoverable and how to update stock firmware safely.
Updating Stock Bootloader, Radio & /vendor (tools/update-firmware.py)
Section titled “Updating Stock Bootloader, Radio & /vendor (tools/update-firmware.py)”When Google or GrapheneOS releases a newer factory image (bringing updated bootloader, modem radio, or /vendor firmware blobs on super), use tools/update-firmware.py instead of flash-all.sh. It refreshes bootloader across both A/B slots, updates radio, and optionally updates super without touching Debian’s userdata, metadata, boot, vendor_boot, init_boot, or dtbo.
-
Unpack a signature-verified GrapheneOS or Google factory image
Extract the archive so
bootloader-*.img,radio-*.img,android-info.txt, andsuper*.imglive inside one directory (e.g.raven-install-2026111800/). -
Preview with
--dry-runTerminal window python tools/update-firmware.py \--firmware-dir path/to/raven-install-2026111800 \--device raven \--slot b \--dry-run--dry-runvalidates product codename, bootloader/radio version consistency acrossandroid-info.txt/flash-all.sh/script.txt, and splitsuper_1..N.imgcompleteness before printing the exact fastboot sequence. -
Run the live firmware update
Boot the phone into fastboot mode (hold Volume Down) and execute:
Terminal window # Update bootloader (both slots), radio (both slots), and superpython tools/update-firmware.py \--firmware-dir path/to/raven-install-2026111800 \--device raven \--slot b \--reboot# Or update bootloader + radio only (skip rewriting super)python tools/update-firmware.py \--firmware-dir path/to/raven-install-2026111800 \--device raven \--slot b \--only-bootloader-radio \--reboot
How Dual-Slot Bootloader Updates Stay Safe
Section titled “How Dual-Slot Bootloader Updates Stay Safe”tools/update-firmware.py never overwrites the currently running bootloader slot directly:
- Pass 1/2:
flash --slot=other bootloader <img >→--set-active=other→reboot-bootloader→ polls pinned-s <serial>→ verifiescurrent-slotswitched ANDversion-bootloadermatches the expected version. - Pass 2/2: Repeats the sequence so the original slot also gets the new bootloader and verifies both slots are identical.
- Radio:
flash --slot=all radio <img >→reboot-bootloader. super(unless--skip-super/--only-bootloader-radio): Verifies livemax-download-sizematches manifest and is large enough; for splitsuper_1..N.img, temporarily sets--set-active=a(matching GrapheneOS’s split-super layout assumption) and flashes all chunks in order.- Restore slot & optional reboot: Restores
--slot(or your pre-updatecurrent-slot).
Hard command guardrails forbid erase, format, oem, flashing, update, -w, --wipe, and every non-firmware partition (userdata, metadata, boot*, vendor_boot*, init_boot*, dtbo*, vbmeta*, misc, devinfo, persist, efs*, pvmfw*).
tools/update-firmware.py Flags
Section titled “tools/update-firmware.py Flags”| Flag | Default | Description |
|---|---|---|
--firmware-dir <PATH> |
(required) | Unpacked GrapheneOS or Google factory image directory. |
--device / --product <NAME> |
Auto from bundle | Expected device codename cross-checked against bundle and fastboot. |
--expected-bootloader <VER> |
Auto from bundle | Expected version-bootloader verified after both bootloader passes. |
--serial <SERIAL> |
Single device | Pin a specific fastboot serial across reboots. |
--slot {a,b} |
Pre-update slot | Active slot to restore when finished. |
--super-count <N> |
From manifest | Expected count of split super_1..N.img files (never guessed). |
--skip-super / --only-bootloader-radio |
Off | Skip flashing super. |
--reboot |
Off | Reboot into OS after completing all steps. |
--reboot-wait <SEC> |
5.0 |
Initial sleep after each reboot-bootloader. |
--reboot-timeout <SEC> |
60.0 |
Max wait for pinned serial to reconnect after bootloader reboot. |
--dry-run |
Off | Validate images and print plan with zero fastboot writes. |
A/B Slot-Success Marking & Tensor Anti-Rollback (mark-boot-ok)
Section titled “A/B Slot-Success Marking & Tensor Anti-Rollback (mark-boot-ok)”When you switch A/B slots via fastboot --set-active=<slot> or os-upgrade, slot-successful:<slot> resets to no and ABL decrements slot-retry-count on every reboot until userspace marks the slot healthy.
mark-boot-ok.service handles this automatically — only after verifying real remote reachability:
ssh.serviceis active, and- A carrier-up (
LOWER_UP) network uplink has a non-tentative, non-dadfailedscope globalIP (preferring the default-route interface; routerless static-IP LAN fallback ignores loopback and virtual container/tunnel interfaces likedocker*,br-*,veth*,wg*,tailscale*).
If networking isn’t up yet within --wait-seconds 30, the script exits with code 75 (EX_TEMPFAIL), which systemd retries every 15 seconds (RestartForceExitStatus=75, StartLimitIntervalSec=0). Permanent configuration or allowlist errors exit 1 (RestartPreventExitStatus=1).
Inspecting Slot Metadata Safely
Section titled “Inspecting Slot Metadata Safely”# Read-only inspection (uses O_RDONLY + LOCK_SH; never writes)sudo mark-boot-ok --inspectSupported Boot Control Backends (headless_bootctrl.py)
Section titled “Supported Boot Control Backends (headless_bootctrl.py)”Configured in /etc/headless-phone/bootctrl.conf (BOOTCTRL_BACKEND, BOOT_DEVICE, BOOTCTRL_ALLOW_BOOTLOADERS):
| Backend | Hardware Target | Mechanism |
|---|---|---|
devinfo |
Google Tensor Pixels (GS101+) | PARTNAME=devinfo (DEVI magic 0x49564544, v3.3+, slots[0] at 0x30, slots[1] at 0x34). Bootloader-allowlist gated; O_RDWR | O_DSYNC, flock, fsync, read-back verified. |
gpt-ab |
Qualcomm AOSP GPT A/B devices | boot_a/boot_b UEFI GPT attributes byte 54 (bits 48–55). Crash-safe write order: commits and read-back verifies backup GPT completely before primary GPT, with interrupted-transaction recovery. Bootloader-allowlist gated. |
bcb |
Standard AOSP misc BCB devices |
misc partition offset 2048 (0x42414342 magic + CRC32). |
none |
Unverified devices (oriole) |
Read-only / disabled (no-op exit 0). |
Manual mark-boot-ok Flags
Section titled “Manual mark-boot-ok Flags”| Flag | Description |
|---|---|
--inspect |
Read-only display of current slot and bootctrl metadata. |
--backend {none,devinfo,gpt-ab,bcb} |
Override BOOTCTRL_BACKEND. |
--boot-device <STR> |
Override BOOT_DEVICE (e.g. 14700000.ufs). |
--allow-bootloaders <CSV> |
Override BOOTCTRL_ALLOW_BOOTLOADERS. |
--allow-unverified-bootloader |
Explicitly bypass the bootloader allowlist gate (manual testing only). |
--force-offline |
Skip the SSH + global uplink readiness check. |
--wait-seconds <INT> |
Readiness polling window before exiting 75 (default 30). |
Hardware Watchdog Hand-Off
Section titled “Hardware Watchdog Hand-Off”To guarantee an unattended headless server recovers from kernel hangs or deadlocks:
- ABL → Stage 1 Initramfs: GS101 ABL arms a ~180 s hardware watchdog before jumping to Linux. Stage 1 loads
s3c2410_wdt.kofrommodules.boot, enablingCONFIG_WATCHDOG_HANDLE_BOOT_ENABLEDauto-petting during early boot. - Stage 1 → Stage 2
systemd:/etc/systemd/system.conf.d/10-watchdog.confhands watchdog ownership to PID 1 with:/etc/systemd/system.conf.d/10-watchdog.conf [Manager]RuntimeWatchdogSec=30sRebootWatchdogSec=2min
If systemd freezes for 30 seconds, the hardware watchdog resets the phone automatically.
Critical Partition Safety Reference (raven)
Section titled “Critical Partition Safety Reference (raven)”| Partition | Purpose | Rule |
|---|---|---|
boot_{a,b}, vendor_boot_{a,b}, dtbo_{a,b} |
Per-slot Linux kernel, initramfs, DTB/DTBO | Safe to flash on your Linux slot (flash.py, WebUSB, os-upgrade). |
vbmeta_{a,b} |
Per-slot AVB verification header | Flashed on first install (flash.py --vbmeta or WebUSB); inspected read-only by os-upgrade (never overwritten by OTA). |
userdata |
Shared ext4 Debian rootfs (~110+ GiB) | Shared across A/B slots; never touched by update-firmware.py or os-upgrade. |
super |
Android dynamic partitions (including /vendor) |
Mounted strictly read-only at runtime; update only via update-firmware.py. |
metadata |
Android metadata encryption keys (16 MiB) | Never erase or overwrite. |
misc |
AOSP BCB (bootonce-bootloader, 1 MiB) |
Keep intact (used for reboot bootloader and BCB backends). |
devinfo |
Tensor A/B slot state (4 MiB, sdd1) |
Only updated atomically by headless_bootctrl.py (mark-boot-ok / os-upgrade). |