Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions bin/omamobile
Original file line number Diff line number Diff line change
Expand Up @@ -1363,16 +1363,22 @@ cmd_push() {
# AVB_FOOTERS image is padded to the descriptor's partition size, with its
# footer at the end, so that size must be the partition's exactly.
local -A devs=()
local sectors bytes avb e
local sectors bytes avb e sys globs="" l
# The LUNs the init guards: sda, plus the descriptor's UFS_RW_LUNS
# (load_device checked those are sdb..sdz)
for l in sda ${DEV_UFS_RW_LUNS:-}; do globs+=" /sys/block/$l/$l*"; done
for p in $DEV_BOOT_IMAGES; do
slot_b_allowed "$p" || die "${p}_b is not on device/$DEVICE's storage-guard allowlist; refusing"
[[ -f "$img/$p.img" ]] || die "missing $img/$p.img (run: omamobile images)"
# Find the partition by GPT name; the init guard leaves only these writable
dev=$("$ssh" "for s in /sys/block/sda/sda*; do grep -qx 'PARTNAME=${p}_b' \$s/uevent && echo /dev/\${s##*/}; done; true")
[[ -n "$dev" ]] || die "${p}_b not found on the phone"
[[ "$("$ssh" "cat /sys/block/sda/${dev#/dev/}/ro")" == 0 ]] || die "$dev (${p}_b) is read-only; refusing"
sys=$("$ssh" "for s in$globs; do grep -qx 'PARTNAME=${p}_b' \$s/uevent && echo \$s; done; true")
[[ -n "$sys" ]] || die "${p}_b not found on the phone (looked on:$globs)"
[[ $sys != *$'\n'* ]] || die "${p}_b is on more than one partition (${sys//$'\n'/, }); refusing"
[[ $sys =~ ^/sys/block/(sd[a-z])/(sd[a-z])[0-9]+$ && ${BASH_REMATCH[1]} == "${BASH_REMATCH[2]}" ]] || die "unexpected partition path for ${p}_b: $sys"
dev=/dev/${sys##*/}
[[ "$("$ssh" "cat $sys/ro")" == 0 ]] || die "$dev (${p}_b) is read-only; refusing"
# sysfs counts 512-byte sectors, whatever the device's block size
sectors=$("$ssh" "cat /sys/block/sda/${dev#/dev/}/size")
sectors=$("$ssh" "cat $sys/size")
[[ $sectors =~ ^[0-9]{1,15}$ ]] || die "cannot read the size of $dev (${p}_b)"
bytes=$((sectors * 512))
(($(stat -c %s "$img/$p.img") <= bytes)) || die "$p.img is larger than ${p}_b ($dev, $bytes bytes); refusing"
Expand Down
61 changes: 61 additions & 0 deletions device/enchilada/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,67 @@ tree and goes away if stock is restored.
20 s and panics, and `panic=10` reboots the phone. ABL then starts the
active slot, A, which is the rescue.

## 2026-11-11: `sde`'s GPT, and what marking `boot_b` would reach

Groundwork for this phone's [CONTRIBUTING](../../CONTRIBUTING.md) §3.1
entry, which the maintainer writes. `tools/mark-slot-b` exists, but the
descriptor sets neither `UFS_RW_LUNS` nor `SLOT_B_MARK` yet, so it refuses
this phone. Nothing here has written to the phone.

**`sde`'s GPT**, read on 2026-11-09 from the slot-A rescue (`sfdisk --dump`
and the raw sectors of both copies, read-only):

- 4096-byte sectors, 786432 of them (last LBA 786431); 96 entries of 128
bytes. The primary header is at LBA 1 with entries in LBA 2-4; the backup
entries are in LBA 786427-786429, with its header at 786431.
- `boot_b` is `sde39`, entry 38, at byte 768 of LBA 3 and of LBA 786428. So
setting its bit 54 changes LBA 1, 3, 786428 and 786431, not the
first entry sector.
- Before any install its attributes read `0x003a000000000000`: priority 2,
not active, 7 tries, not successful, not unbootable. The CRCs then were
entries `0x0a9fe94a`, primary header `0xb62ccea8`, backup header
`0x619c2dc8`. `set-active b` rewrites all three, so the tool checks the
live values, not these.

**What `sde` holds** (`PARTNAME`, 72 partitions), so what a whole-disk node
for it reaches:

- for each slot, `_a` and `_b`: `aop`, `tz`, `hyp`, `modem`, `bluetooth`,
`mdtpsecapp`, `mdtp`, `abl`, `dsp`, `keymaster`, `boot`, `cmnlib`,
`cmnlib64`, `devcfg`, `qupfw`, `vendor`, `vbmeta`, `dtbo`, `storsec`,
`LOGO`, `fw_4j1ed`, `fw_4u1ea`, `fw_ufs3` to `fw_ufs8`;
- unslotted: `minidump`, `aging`, `op1`, `sec`, `devinfo`, `dip`, `apdp`,
`msadp`, `spunvm`, `splash`, `limits`, `toolsfv`, `logfs`, `sti`,
`logdump`, `ImageFv`.

`xbl` and `xbl_config` are not on `sde`. Which LUN holds them has not been
read yet.

**If both GPT copies on `sde` became invalid**, the phone could not load
`abl` from either slot, because `abl_a` and `abl_b` are on `sde`. Then there
is no fastboot, no `fastboot boot` and no slot-A rescue. The buttons would
not help either. The only way in would be Qualcomm's emergency download mode
(EDL, USB `05c6:9008`), with a programmer that matches this phone, to write
back the two read-only copies. A copy of `sde`'s LBA 0-5 and 786426-786431
(both GPT copies whole) and its `sfdisk --dump` were taken read-only on
2026-11-09, and their SHA-256 matched the phone's. They are kept off the
repository because they hold the disk's GUIDs. `tools/mark-slot-b` writes
one pair and reads it back before it touches the other, and a pair with one
sector old and one new goes first, so from a table with a valid copy at least
one copy stays valid after every single write. It saves the four old sectors on the
laptop first (`~/android/reference/enchilada/mark-slot-b-sde/`), so after a
cut cable the next run sees the half-written table and offers to finish the
write or put the old sectors back. The owner's acceptance on #432 has to
cover the EDL case in so many words before anything writes this table.

**The bit layout** is Qualcomm's ABL (`QcomModulePkg/Include/Library/PartitionTableUpdate.h`
in the `abl/tianocore/edk2` tree): `PART_ATT_PRIORITY_BIT` 48 (two bits),
`PART_ATT_ACTIVE_BIT` 50, `PART_ATT_MAX_RETRY_CNT_BIT` 51 (three bits),
`PART_ATT_SUCCESS_BIT` 54, `PART_ATT_UNBOOTABLE_BIT` 55. This phone's `abl`
is OnePlus's build of it, and bits 54 and 55 have never been seen set
here. Only `fastboot getvar slot-successful:b` reading `yes` after a write
would prove that bit 54 means "successful" to this bootloader.

## 2026-11-08: the LUN-aware guard, booted RAM-only

`fastboot boot` of an initramfs built from commit 2331a85 (the
Expand Down
3 changes: 2 additions & 1 deletion docs/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Bring-up tools (`*-stage`, `display-hz`, `usbc-deadman`) stay per plan: they pok
| `BOOT_IMAGES` | `boot init_boot vendor_boot vendor_kernel_boot dtbo` | The images written to slot B (the `_b` suffix is added by the tools and is not configurable). `boot`, `vendor_boot` and `dtbo` are always there. Without `init_boot`, `boot` carries the empty generic ramdisk and the OS version; without `vendor_kernel_boot`, `vendor_boot` carries the DTB and the initramfs (the Pixel 6: `boot vendor_boot dtbo`) |
| `BOOT_UPDATE_AUTO_WRITE` | (unset; defaults to `yes`) | Optional: `yes` or `no`. The installer records it as `AUTO_WRITE` in `/etc/omamobile/boot-update.conf`; `no` keeps an installed development root from writing slot B through package updates. It does not change the installer's own allowed writes |
| `UFS_RW` | `boot_b … dtbo_b userdata` | The storage guard's allowlist, packed into the initramfs as `/etc/omamobile-ufs-rw`. Only slot B's boot images (`boot_b`, `init_boot_b`, `vendor_boot_b`, `vendor_kernel_boot_b`, `dtbo_b`) and `userdata` are accepted, `userdata` and every `BOOT_IMAGES` entry must be on it, and each name only once. The init fails closed: a missing, empty or malformed file, or any other name in it, leaves every partition read-only |
| `UFS_RW_LUNS` | (unset) | Optional. The LUNs besides `sda` that hold `UFS_RW` partitions, as disk names `sdb` to `sdz`, packed as `/etc/omamobile-ufs-rw-luns`. The init guards each as it guards `sda`: the whole-disk node removed, the disk left writable, and only its `UFS_RW` partitions left writable. Absent (every descriptor so far), malformed, or with a closed allowlist: every LUN but `sda` stays read-only at the disk level. Boot-image writers on the phone (`omamobile-boot-update`) still look only on `sda` |
| `UFS_RW_LUNS` | (unset) | Optional. The LUNs besides `sda` that hold `UFS_RW` partitions, as disk names `sdb` to `sdz`, packed as `/etc/omamobile-ufs-rw-luns`. The init guards each as it guards `sda`: the whole-disk node removed, the disk left writable, and only its `UFS_RW` partitions left writable. Absent (every descriptor so far), malformed, or with a closed allowlist: every LUN but `sda` stays read-only at the disk level. `omamobile push` looks for slot B's images on these LUNs too; boot-image writers on the phone (`omamobile-boot-update`) still look only on `sda` |
| `SLOT_B_MARK` | (unset) | Optional, Qualcomm A/B only, and set only once the device has its [CONTRIBUTING](../CONTRIBUTING.md) §3.1 entry (none does yet): that entry as `LUN PART P_HDR P_ENT B_ENT B_HDR`, the LUN, slot B's boot partition and the four LBAs (primary header, primary entry sector holding it, backup entry sector, backup header). Only `tools/mark-slot-b` reads it: by hand, once per install of slot B's boot image, it sets attribute bit 54 (successful) on that partition and rewrites the entry-array CRC and both header CRCs, and refuses a GPT whose sectors differ from these. Nothing else ever writes a partition table |
| `INITRAMFS_INIT` | `/initramfs/init` | The init script. A leading `/` is relative to the repo root, so devices share one script. Any other value is relative to the descriptor |
| `INITRAMFS_ROOT_LABEL` | (unset) | Optional: `omamobile-root` enables read-only label/header checks before ext4 repair or mounting; only `e2fsck -p` statuses 0 and 1 proceed. Omitted: existing root handling, including unlabelled hand-installed roots, is unchanged |
| `INITRAMFS_ROOT_MODE` | (unset) | Optional: `persistent-development` or `ram-rescue`, requiring `INITRAMFS_ROOT_LABEL=omamobile-root`. The former skips growth and writes `/var/lib/omamobile/root-boot-pending` before handover; an installed, enabled SSH-ready helper must clear it after USB SSH is ready, or subsequent boots stay in RAM until the marker is cleared. The latter always stays in RAM. Omitted: existing handover behavior |
Expand Down
2 changes: 2 additions & 0 deletions tests/all
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ echo "# tests/build-packages-deps" # a package's dependencies into the build c
tests/build-packages-deps
echo "# tests/build-packages-cache" # a forced same-version rebuild drops the stale cached package
tests/build-packages-cache
echo "# tests/mark-slot-b"
tests/mark-slot-b
32 changes: 25 additions & 7 deletions tests/images-layout
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,14 @@ case $cmd in
state=$(sed -n "${n}p" "$P/script"); [[ -n $state ]] || state=$(tail -n 1 "$P/script")
case $state in old) echo old-boot ;; new) echo new-boot ;; *) exit 255 ;; esac ;;
*.omamobile-tarball*) cat "$P/modules-sum" ;;
*PARTNAME=*) [[ $cmd =~ PARTNAME=([a-z_]+) ]] && echo "/dev/sda_${BASH_REMATCH[1]}" ;;
cat\ /sys/block/sda/*/ro) echo 0 ;;
cat\ /sys/block/sda/*/size) echo "${SECTORS:-131072}" ;;
# Each partition sits on $FAKE_LUN (default sda) and is found only when
# push looks there; FAKE_DUP adds a second partition of the same name.
*PARTNAME=*) L=${FAKE_LUN:-sda}
[[ $cmd == *" /sys/block/$L/$L*"* && $cmd =~ PARTNAME=([a-z_]+) ]] || exit 0
echo "/sys/block/$L/$L$(( $(printf %s "${BASH_REMATCH[1]}" | cksum | cut -d' ' -f1) % 90 + 1 ))"
[[ -z ${FAKE_DUP:-} ]] || echo "/sys/block/$L/${L}99" ;;
cat\ /sys/block/sd?/sd*/ro) echo 0 ;;
cat\ /sys/block/sd?/sd*/size) echo "${SECTORS:-131072}" ;;
dd\ of=*) dev=${cmd#dd of=/dev/}; cat > "$P/${dev%% *}" ;;
head\ -c*) read -r _ _ n dev _ <<<"$cmd"; head -c "$n" "$P/${dev#/dev/}" | sha256sum ;;
sync\;*) echo rebooted >> "$P/log" ;;
Expand All @@ -238,12 +243,12 @@ esac
PHONE
chmod +x "$R/tools/phone-ssh"
push() { # the boot_id answers, one per argument
rm -f "$P/reads" "$P/log" "$P"/sda_*
rm -f "$P/reads" "$P/log" "$P"/sd[a-z][0-9]*
printf '%s\n' "$@" > "$P/script"
om six push
}
push old down new || { cat "$t/log"; fail "push succeeds when the phone comes back with a new boot id"; }
[[ $(find "$P" -name 'sda_*' | wc -l) == 3 && $(cat "$P/log") == rebooted ]] || fail "push writes the three images and reboots once"
[[ $(find "$P" -name 'sd[a-z][0-9]*' | wc -l) == 3 && $(cat "$P/log") == rebooted ]] || fail "push writes the three images and reboots once"
pass "push writes and verifies the images, then sees the new boot id"
for slot in 'androidboot.slot_suffix = "_a' 'androidboot.slot_suffix=_a'; do
if PHONE_SLOT=$slot push old new; then fail "push refuses a phone running from slot A ($slot)"; fi
Expand All @@ -269,17 +274,30 @@ pass "push reports no SSH when the phone never answers after the reboot"
# 16 KiB partitions: every image is too big, and nothing is written
if SECTORS=32 push old new; then fail "push refuses an image larger than its partition"; fi
grep -q 'larger than boot_b' "$t/log" || { cat "$t/log"; fail "push names the image too big for its partition"; }
[[ $(find "$P" -name 'sda_*' | wc -l) == 0 && ! -s $P/log ]] || fail "push writes nothing, and does not reboot, when an image does not fit"
[[ $(find "$P" -name 'sd[a-z][0-9]*' | wc -l) == 0 && ! -s $P/log ]] || fail "push writes nothing, and does not reboot, when an image does not fit"
pass "push checks every image against its partition's size before writing any"
# An AVB_FOOTERS image's partition must be exactly the descriptor's size
cp "$R/device/six/device.conf" "$t/six.conf"
printf 'AVB_FOOTERS="boot:0x4000000"\nAVB_ROLLBACK_INDEX=1\nAVB_SECURITY_PATCH=2026-10-05\n' >> "$R/device/six/device.conf"
push old new || { cat "$t/log"; fail "push writes an AVB_FOOTERS image to a partition of its size"; }
if SECTORS=262144 push old new; then fail "push refuses an AVB_FOOTERS size that is not the partition's"; fi
grep -q 'AVB_FOOTERS pads boot to 67108864 bytes, but boot_b' "$t/log" || { cat "$t/log"; fail "push names the AVB size and the partition's"; }
[[ $(find "$P" -name 'sda_*' | wc -l) == 0 ]] || fail "push writes nothing when an AVB size is wrong"
[[ $(find "$P" -name 'sd[a-z][0-9]*' | wc -l) == 0 ]] || fail "push writes nothing when an AVB size is wrong"
cp "$t/six.conf" "$R/device/six/device.conf"
pass "push refuses an AVB_FOOTERS image whose partition is not the descriptor's size"
# A second LUN: push looks for slot B's images only on sda and the
# descriptor's UFS_RW_LUNS, the LUNs the init guards
if FAKE_LUN=sde push old new; then fail "push finds no image on a LUN the descriptor does not name"; fi
grep -q 'boot_b not found on the phone (looked on: /sys/block/sda/sda\*)' "$t/log" || { cat "$t/log"; fail "push names the LUNs it looked on"; }
echo 'UFS_RW_LUNS=sde' >> "$R/device/six/device.conf"
FAKE_LUN=sde push old new || { cat "$t/log"; fail "push writes images on a UFS_RW_LUNS LUN"; }
[[ $(find "$P" -name 'sde[0-9]*' | wc -l) == 3 ]] || fail "push writes the three images on sde"
grep -q 'boot_b (/dev/sde24) written and verified' "$t/log" || { cat "$t/log"; fail "push names the sde partition it wrote"; }
if FAKE_LUN=sde FAKE_DUP=1 push old new; then fail "push refuses a name on two partitions"; fi
grep -q 'boot_b is on more than one partition' "$t/log" || { cat "$t/log"; fail "push names the duplicate"; }
[[ $(find "$P" -name 'sd[a-z][0-9]*' | wc -l) == 0 ]] || fail "push writes nothing when a name is on two partitions"
cp "$t/six.conf" "$R/device/six/device.conf"
pass "push finds slot B's images on the descriptor's UFS_RW_LUNS, only there and sda, and refuses a duplicate name"

# Building the images needs AOSP's mkbootimg and mkdtboimg, lz4 and a dtc;
# without them only this part skips.
Expand Down
Loading