Skip to content

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.

  1. Unpack a signature-verified GrapheneOS or Google factory image

    Extract the archive so bootloader-*.img, radio-*.img, android-info.txt, and super*.img live inside one directory (e.g. raven-install-2026111800/).

  2. Preview with --dry-run

    Terminal window
    python tools/update-firmware.py \
    --firmware-dir path/to/raven-install-2026111800 \
    --device raven \
    --slot b \
    --dry-run

    --dry-run validates product codename, bootloader/radio version consistency across android-info.txt / flash-all.sh / script.txt, and split super_1..N.img completeness before printing the exact fastboot sequence.

  3. 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 super
    python 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:

  1. Pass 1/2: flash --slot=other bootloader <img > → --set-active=other → reboot-bootloader → polls pinned -s <serial> → verifies current-slot switched AND version-bootloader matches the expected version.
  2. Pass 2/2: Repeats the sequence so the original slot also gets the new bootloader and verifies both slots are identical.
  3. Radio: flash --slot=all radio <img > → reboot-bootloader.
  4. super (unless --skip-super / --only-bootloader-radio): Verifies live max-download-size matches manifest and is large enough; for split super_1..N.img, temporarily sets --set-active=a (matching GrapheneOS’s split-super layout assumption) and flashes all chunks in order.
  5. Restore slot & optional reboot: Restores --slot (or your pre-update current-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*).

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.service is active, and
  • A carrier-up (LOWER_UP) network uplink has a non-tentative, non-dadfailed scope global IP (preferring the default-route interface; routerless static-IP LAN fallback ignores loopback and virtual container/tunnel interfaces like docker*, 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).

Terminal window
# Read-only inspection (uses O_RDONLY + LOCK_SH; never writes)
sudo mark-boot-ok --inspect

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

To guarantee an unattended headless server recovers from kernel hangs or deadlocks:

  1. ABL → Stage 1 Initramfs: GS101 ABL arms a ~180 s hardware watchdog before jumping to Linux. Stage 1 loads s3c2410_wdt.ko from modules.boot, enabling CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED auto-petting during early boot.
  2. Stage 1 → Stage 2 systemd: /etc/systemd/system.conf.d/10-watchdog.conf hands watchdog ownership to PID 1 with:
    /etc/systemd/system.conf.d/10-watchdog.conf
    [Manager]
    RuntimeWatchdogSec=30s
    RebootWatchdogSec=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).