Skip to content

omamobile-device-husky 0.1.19, omamobile-device-tegu 0.2.22: omamobile-bootctl marks slot B by hand (#252) - #483

Open
derekross wants to merge 4 commits into
mainfrom
bootctl-husky-tegu
Open

derekross wants to merge 4 commits into
mainfrom
bootctl-husky-tegu

Conversation

@derekross

@derekross derekross commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Never run on a phone. It writes devinfo, so it needs the maintainer's review. It must not merge before the maintainer rules on the window below (#252). Offline tests only. The 9a's hold in AGENTS.md stands; this PR adds only a pointer to the tool, to use once that hold is lifted.

This is the tool behind #252's decision: a device-aware omamobile-bootctl for the Pixel 8 Pro (husky) and the Pixel 9a (tegu). The phone's owner runs it by hand from the device plan's runbook, once per install of slot B's images, after tools/phone-smoke passes. No unit, hook or installer calls it, and both packages' tests check that.

The read-write window exposes the whole boot LUN while it is open

The kernel won't write a partition of a read-only disk. In include/linux/blkdev.h, bdev_read_only() is the partition's own BD_READ_ONLY flag OR the disk's (part0's). That OR is what blkdev_write_iter() checks before it returns -EPERM, and it is also what BLKROGET and sysfs ro report. BLKROSET changes only the node it is called on. So devinfo can't be made writable while sdd stays read-only, and the tool has to clear the LUN's flag too.

While that flag is clear, the whole-disk node /dev/sdd is writable. Raw writes through it reach every byte of the LUN, including the other partitions on it: pinfo, blenv and mfg_data on husky; tegu's sdd holds mfg_data, and the rest isn't recorded. Those partitions' own flags guard only their own nodes.

The tool keeps the window as short as it can (it opens and closes it itself, no blockdev from a shell):

  1. Refuse if devinfo, the LUN or a sibling is mounted or held, or open for writing by any other process. These checks run again right before the window, after the codename prompt.
  2. Clear the disk's flag, and check that it really cleared.
  3. Check each sibling's and devinfo's own flag. This is the only moment a partition's own flag can be read; any flag that is clear or unreadable closes the window.
  4. Clear devinfo's flag. Read the partition again and compare it with what the checks saw.
  5. Write 0x35 |= 0x02 with O_DSYNC.
  6. Read the partition back with O_DIRECT. On a mismatch, write the original back, read it back, and exit 3 (or 4 if that read-back fails).
  7. Set devinfo read-only and check it, then the disk.

^C, SIGTERM and SIGHUP are blocked during the window. A relock child waits, without a timeout, until the tool says the window is opening. From then on it sets both flags back every 10 s for as long as the tool lives (so a stopped or hung tool can't leave the window open), and once more the moment the tool exits or is killed. The tool also checks that the child is alive before each step that opens anything further.

Recommendation to the maintainer: guard the boot LUNs the way the main LUN is guarded (whole-disk node removed, each partition's own flag set) in a separate PR tested on the 7 Pro, because it changes the shared initramfs/init and udev rule. With that in place, this tool's window becomes devinfo's flag alone, the disk flag never changes, and the code here simplifies to that. Other options: (a) accept the disk-level window as is; (c) a raw SCSI write through SG_IO; (d) a kernel change. Please rule on #252 before this merges.

What the tool checks

  • The board's first compatible string, and the devinfo version recorded for that phone in bootctl/bootctl-device.h: 3.15 on both (husky BATTERY-NOTES and Marking slot B successful: the plan after #125's hold, and for the Pixel 8 Pro #252; tegu NOTES 2026-10-22). Any other major or minor is refused.
  • Slot B booted, active and not unbootable.
  • devinfo found exactly once by PARTNAME, on a boot LUN.
  • The storage guard holding.
  • Dry run by default. --write needs --expect "<the dry run's eight bytes>" and the codename, passed or typed.
  • Output: only the version and the slot bytes 0x30-0x37, decoded, before and after.

Structure

  • bootctl/omamobile-bootctl.c, bootctl/bootctl-device.h and test/bootctl. The source and the test are byte-identical in the two packages (test/all checks), and the header is checked against device.conf. The license is Apache-2.0, with LICENSE.Apache-2.0.
  • Not under src/: bin/omamobile initramfs compiles any device package's src/omamobile-bootctl.c into the boot image against musl (bin/omamobile:703-716). This PR's first head did that, and it broke both phones' builds on <linux/fs.h>.
    • Now both packages' test/all fail on any file where the builder or tools/stage-boot-files would look.
    • The ioctls come from <sys/mount.h>; the file also compiles against the Alpine musl sysroot.
    • Statically: the builder's probe is if [[ -f $ROOT/packages/$DEV_PACKAGE/src/omamobile-bootctl.c ]]; then (bin/omamobile:703). The source is now at packages/omamobile-device-{husky,tegu}/bootctl/omamobile-bootctl.c, so the probe is false for both phones, and the builder takes the same no-bootctl branch as on main.
    • The initramfs byte-identity check is still to do on the build machine, for husky and tegu. One husky comparison already ran on the laptop before the instruction to stop building: this branch and main were byte-identical (sha256 b8fe1b34…, same Android clang on PATH). tegu's descriptor doesn't build an initramfs on main either (SOC_IDS is missing).
  • Cheetah is untouched: no diff in its package, initramfs/, bin/ or tools/. Cheetah's binary is unchanged.

Tests (offline, no phone)

test/bootctl builds a -DBOOTCTL_TEST variant against a fake /sys, /proc and /dev. The read-only flags are files that follow the kernel's own-or-disk rule, and every flag change is logged, so recovery cases can show the window really opened before they check that it closed. The production build is compiled too, and checked to contain no test hooks. 53 cases:

  • Refusals before any flag changes: versions 3.11, 3.16 and 4.15, magic, board, slot, --expect, codename, no tty, an unbootable or inactive B, mounted devinfo, holders on devinfo, the LUN or a sibling, writers on the LUN, devinfo or a sibling, a duplicate or missing devinfo, the guard not holding, an unreadable sibling flag.
  • Inside the window: each sibling with its own flag clear (all three, in turn), a sibling flag that becomes unreadable, a disk flag that won't clear, devinfo already clear, devinfo changed between the checks and the write.
  • The write: exactly bit 0x02 of byte 0x35. A second run is a no-op. The tool relocks on its own even without the child.
  • Failures: read-back mismatch restores (3); a restore that doesn't read back (4); a failed write (3); a devinfo flag that won't set again (5); a failed relock child (5); no relock child, in which case no flag changes at all.
  • Process trouble: SIGKILL before and after the write; a hung tool; a stop longer than the timeout before the window opens, then a kill inside it (relocked within 1 s); a stop right after the child is armed, then a hang (the child keeps relocking); a writer or a guard change while the prompt waits; ^C, SIGTERM and SIGHUP ignored inside the window.

35 mutations of the guards are each caught. These include every one the review found surviving: the version major ignored, a newer minor accepted, the first or last sibling skipped, an unreadable sibling accepted, the disk flag left unchecked, the step-4 compare removed, writers on devinfo or a sibling missed, holders checked on devinfo only, the re-check after the prompt removed, the relock read-back, the restore read-back, the child's status or start failure ignored, the child never armed, a one-shot child, and a child that times out from the fork.

Run:

  • packages/omamobile-device-husky/test/all (which runs test/bootctl --mutations, about 3 minutes) and packages/omamobile-device-tegu/test/all (the cases only): both pass.
  • tools/pr-check origin/main: passes.

Docs

  • A runbook in husky BRINGUP-M1.md ("Slot B marked successful by hand") and tegu BRINGUP-M1.md §6. Each step has a risk, Expect/Pass, Stop and Rollback, and the fastboot lines pin the serial.
  • One pointer sentence added to AGENTS.md's 9a paragraph; the hold wording is unchanged.
  • The CONTRIBUTING §3.2 bullet from the first head is withdrawn, pending the ruling.
  • Note, not changed here: CONTRIBUTING §3.2's existing sentence that cheetah's omamobile-boot-success "opens exactly devinfo" isn't accurate. It runs blockdev --setrw on the whole boot LUN, then on the partition (lines 30-31), so it opens the same disk-level window.

Versions

husky 0.1.10 and tegu 0.2.13. Open PRs claim husky 0.1.8 and 0.1.9, and tegu 0.2.9, 0.2.10 and 0.2.12. Set them at merge.

Open questions

  • The window ruling above.
  • Husky's devinfo size isn't recorded anywhere, so the tool doesn't check it.
  • The guard check refuses if any other sd* disk is writable, a USB stick included. Is that intended?

🤖 Generated with Claude Code

derekross and others added 2 commits November 7, 2026 09:51
…e-bootctl marks slot B by hand (#252)

The maintainer's decision on #252: on the Pixel 8 Pro and the Pixel 9a,
slot B is marked successful by hand, attended, once per install of slot
B's images and only after they pass tools/phone-smoke, with a
device-aware omamobile-bootctl whose read-write window is reviewed first.
This is that tool. Nothing runs it: no unit, hook or installer calls it,
and both packages' tests check that.

The source is new, one file shared byte for byte by the two packages
(test/all compares them); the per-phone values are in
src/bootctl-device.h: codename, board compatible and the devinfo layout
recorded for that phone (3.15 on both: husky BATTERY-NOTES and #252,
tegu NOTES 2026-10-22). The 7 Pro's omamobile-bootctl and
omamobile-boot-success are untouched.

It finds devinfo by PARTNAME, refuses another board or layout, a boot
from slot A, an inactive or unbootable slot B, a mounted or held
devinfo, another process with the LUN open for writing, and a storage
guard that isn't holding. Dry run by default; --write needs the dry
run's eight slot bytes (--expect) and the codename. It writes one byte
(0x35, OR 0x02), reads the whole partition back past the page cache,
restores the original on a mismatch, and prints only the version and
the slot bytes 0x30-0x37.

The window can't be devinfo alone: bdev_read_only() is the partition's
own flag OR its disk's (include/linux/blkdev.h), and the write path,
BLKROGET and sysfs ro all use it, so the boot LUN's flag has to be
cleared too. The tool clears it only for the one byte, checks right
after that every sibling partition keeps its own flag (the only moment
that can be read), blocks ^C, SIGTERM and SIGHUP, and forks a relock
child that sets both flags back if the tool dies, stops or hangs.

Tested offline only, never on a phone: test/bootctl builds a test
variant that reads a fake /sys, /proc and /dev with file-backed flags
following the kernel's rule, and covers the refusals, a dry run that
writes nothing, a write that flips bit 0x02 of 0x35 alone, a read-back
mismatch that restores and fails, a failed write, kills before and
after the write, a hung tool and ignored signals; 18 mutations of the
key guards are each caught. Runbooks: husky and tegu BRINGUP-M1. The
9a's hold in AGENTS.md stands until the maintainer lifts it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…review round 1 (#483)

The review of #483 found that bin/omamobile's initramfs builder compiles
any device package's src/omamobile-bootctl.c into the boot image against
Alpine's musl sysroot. With the first head that broke husky's and tegu's
initramfs builds (<linux/fs.h> isn't in that sysroot) and would have put
the devinfo tool into every boot image. The source and its header move
to bootctl/, the ioctls come from <sys/mount.h>, and test/all now fails
on any file where the builder or tools/stage-boot-files look. husky's
initramfs built from this tree and from main is byte-identical; tegu's
descriptor doesn't build an initramfs on main either (SOC_IDS), and the
builder's probe no longer matches there.

The relock child timed out once, from the fork: a tool stopped for 10 s
before the window opened would then open it unwatched. It now waits
untimed until the tool says the window is opening, then relocks every
10 s for as long as the tool lives, and once more when the pipe closes.
The tool checks the child is alive before each step that opens more.

The guard, writer and holder checks run again after the codename
prompt, right before the window; holders are checked on the disk and
every sibling as well as devinfo; and step 1 checks that the disk flag
actually cleared.

Tests: new cases for versions 3.16 and 4.15, each sibling clear in
turn, a sibling flag that can't be read, a disk flag that won't clear,
devinfo changing inside the window, writers and holders on devinfo, a
sibling or the disk, a restore that doesn't read back, a devinfo flag
that won't set again, a failed or missing relock child, a stop longer
than the timeout before and after the child is armed, and changes made
while the prompt waits. Every recovery case asserts the window opened
before it asserts the flags came back. 35 mutations are each caught.

The CONTRIBUTING bullet describing the disk-level window is withdrawn
until the maintainer rules on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner Author

Ruling on the window, from #252: this waits for a separate PR that guards the boot LUNs the way the main LUN is guarded (whole-disk node removed, each partition's own flag set). That PR gets a Pixel 7 Pro boot first. Then this tool is rebased so its window clears devinfo's flag alone, and it gets its own review again. Keeping it open until then.

Somnius added a commit to Somnius/omarchy-mobile that referenced this pull request Nov 7, 2026
… slot B

Line 55 and the open question now say what you decided on derekross#252: marking is a
manual, attended step, and nothing marks slot B on the 8 Pro until the boot
LUN guard change and derekross#483 are in. Line 55 also carries the same dated record
as line 16 and the DEVICES Boot cell, as you asked.

Signed-off-by: Lef <me@lefteros.com>
@W4HO-ham

Copy link
Copy Markdown
Contributor

Following your ruling above ("this tool is rebased so its window clears devinfo's flag alone"): I had the hours overnight, so I did that rebase as a branch you can take or leave, on top of the #484 merge I offered there. It is bootctl-on-guard on my fork: #484's two commits and its merge with main, your two commits here untouched, a merge commit that holds only the conflicts, and one commit with the change to the tool. Offline only, as before: nothing in it has run on a phone, and the 9a's hold stands. It still needs your review from the first line; I only wanted it to cost you less.

What the last commit changes in omamobile-bootctl.c (one file, copied to both packages):

  • The window is devinfo's own flag and nothing else. relock(), the parent's close and the relock child set that one flag; no code path sets or clears a disk flag any more. The sibling loop inside the window is gone: with the disk flag clear a sibling's flag is readable before the window, so check_guard() sees it.
  • check_guard() wants initramfs, device-cheetah, device-raven, device-lynx (versions at merge): guard the boot LUNs as the main LUN (#252) #484's guard: no whole-disk node for a boot LUN (not even at mode 0000; the main LUN keeps its mode-0000 allowance for the udev rule), the boot LUN's own flag clear, and every partition outside the allowlist read-only, the allowlist counting on the main LUN only. The disk's flag is read from sysfs ro, there being no node to ask. Under an initramfs from before initramfs, device-cheetah, device-raven, device-lynx (versions at merge): guard the boot LUNs as the main LUN (#252) #484, which sets the disk flag, the tool refuses and says why.
  • The disk's flag and devinfo's are read once more at the window, after the child is armed: a disk flag set meanwhile, or devinfo found already open, stops with exit 3.
  • The checks for holders and writers on the LUN and its siblings are as you wrote them. A writer on the boot LUN is matched by device number, since there is no node; the test build stands in for that with a file under elsewhere/.

test/bootctl: the fake phone is guarded the new way, and every case asserts that no disk flag is ever written. New cases: a boot LUN read-only at the disk level, one whose flag can't be read, a whole-disk node (or a symlink) on a boot LUN, a writable dtbo_b on a boot LUN, and the two last-moment changes. The mutation list follows the code (twelve new or changed, among them "the tool clears the disk flag" and "the tool sets the disk flag when it relocks"). The runbooks in both BRINGUP-M1 files and both READMEs describe the new window.

Run here: test/bootctl --mutations in both packages, 59 cases and 41 mutations caught; both packages' test/all; tests/all and tools/pr-check. Two lines of yours in the packages' test/all piped into grep -q under pipefail, which main's newer tests/grep-q-pipes refuses; I changed them to grep -c … >/dev/null in a separate commit. Versions are main's plus one: device-husky 0.1.13, device-tegu 0.2.19.

One thing I was unsure of and decided the strict way: a whole-disk node at mode 0000 on a boot LUN is refused, although the udev rule would leave /dev/sda like that. The rule names only sda, so on a boot LUN such a node means someone made it.

W4HO-ham added a commit to W4HO-ham/omarchy-mobile that referenced this pull request Nov 15, 2026
Calls, texts and mobile data work from the device package's boot unit once the owner enables it; the cell already says why it is not on by default (marking slot B is on hold, derekross#483) and names the two gaps (the far end's echo on the speakerphone, no earpiece route). That is the state the 9a's fingerprint cell calls works (opt-in).
derekross and others added 2 commits November 18, 2026 13:16
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@derekross derekross changed the title omamobile-device-husky 0.1.10, omamobile-device-tegu 0.2.13: omamobile-bootctl marks slot B by hand (#252) omamobile-device-husky 0.1.19, omamobile-device-tegu 0.2.22: omamobile-bootctl marks slot B successful, by hand Nov 18, 2026
@derekross derekross changed the title omamobile-device-husky 0.1.19, omamobile-device-tegu 0.2.22: omamobile-bootctl marks slot B successful, by hand omamobile-device-husky 0.1.19, omamobile-device-tegu 0.2.22: omamobile-bootctl marks slot B by hand (#252) Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants