From 30bb2261d06bc0eeea56baaf25e81e53d93de412 Mon Sep 17 00:00:00 2001 From: Matt Barr Date: Mon, 9 Nov 2026 16:22:46 -0500 Subject: [PATCH 1/5] push: find slot B's images on the descriptor's UFS_RW_LUNS; enchilada sets sde MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit push looked for _b only under /sys/block/sda. It now looks on sda and each LUN in UFS_RW_LUNS, the same LUNs the init guards, and refuses a name found on more than one partition or a path it doesn't expect. enchilada opts in with UFS_RW_LUNS=sde, where its boot_b is (#530's review). push and flash still refuse android-v0 until the slot-B install and its CONTRIBUTING §3.1 entry land in this pull request. tests/images-layout: the fake phone places partitions on one LUN; push finds them on a UFS_RW_LUNS LUN, not on a LUN the descriptor doesn't name, and refuses a duplicate name before writing anything. Co-Authored-By: Claude Opus 5.5 --- bin/omamobile | 16 +++++++++++----- device/enchilada/device.conf | 6 ++++-- tests/images-layout | 32 +++++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/bin/omamobile b/bin/omamobile index a96f3ee6e..ec88ecc25 100755 --- a/bin/omamobile +++ b/bin/omamobile @@ -1246,16 +1246,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" diff --git a/device/enchilada/device.conf b/device/enchilada/device.conf index a9e0e4d0c..87d89e933 100644 --- a/device/enchilada/device.conf +++ b/device/enchilada/device.conf @@ -10,8 +10,9 @@ # touching a phone (tests/boot-method), and keep refusing it until the # slot-B install and its CONTRIBUTING.md §3.1 entry are agreed. # -# Storage: userdata is on sda, but boot_* sit on LUN sde, so the shared -# init's sda-only guard keeps boot_b read-only (the same split as dodge). +# Storage: userdata is on sda, but boot_* sit on LUN sde. UFS_RW_LUNS=sde +# has the init guard sde as it guards sda, leaving only boot_b writable +# there, and push looks for boot_b on sde too. # Never flash xbl/abl/vbmeta/modem/persist from an image. # # FASTBOOT_PRODUCT=sdm845 is ABL's `getvar product`: the SoC's name, which @@ -38,6 +39,7 @@ TAGS_OFFSET=0x00000100 BOOT_IMAGES=boot UFS_RW="boot_b userdata" +UFS_RW_LUNS=sde OMAMOBILE_SLOT=b # The first-light kernel builds the USB gadget as modules (USB_CONFIGFS=m) INITRAMFS_MODULES="libcomposite u_ether usb_f_ncm u_serial usb_f_acm" diff --git a/tests/images-layout b/tests/images-layout index 9a70d97c4..354b95c3c 100755 --- a/tests/images-layout +++ b/tests/images-layout @@ -203,9 +203,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" ;; @@ -215,12 +220,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" if push old old; then fail "push fails when the boot id never changes"; fi grep -c 'same boot id: the reboot did not happen' "$t/log" >/dev/null || { cat "$t/log"; fail "an unchanged boot id is reported as such"; } @@ -234,7 +239,7 @@ 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" @@ -242,9 +247,22 @@ printf 'AVB_FOOTERS="boot:0x4000000"\nAVB_ROLLBACK_INDEX=1\nAVB_SECURITY_PATCH=2 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. From baf364ca2e4853c53eb91682c0997964f7d95ecc Mon Sep 17 00:00:00 2001 From: Matt Barr Date: Mon, 9 Nov 2026 22:54:25 -0500 Subject: [PATCH 2/5] install-phone: install android-v0 (enchilada) to slot B The slot-B install for enchilada goes through the installer, the same guarded path as every other phone: serial pinned, codename typed, allowlist, dry run, then boot_b, userdata, set-active b and reboot. - BOOT_METHOD=android-v0 is accepted; SOC_IDS/SOC_COMPATIBLE stay required for android-v4 only (v0 appends its one DTB). - The product check (phone and manifest.json) uses FASTBOOT_PRODUCT when the descriptor sets it: OnePlus ABL reports the SoC, sdm845, which is not unique, so the serial and typed codename identify it. - OnePlus ABL reports an empty version-bootloader. That is now refused unless the owner passes --bootloader-slots-match unreported, having compared both slots' firmware partitions from a read-only backup. - omamobile-boot-update refuses android-v0, so such an install writes AUTO_WRITE=no: kernel updates reach slot B by push. - enchilada's CMDLINE drops omamobile.initramfs and ufs-probe, so the installed boot_b hands off to the Arch root, as the hand-flashed one did (NOTES). Co-Authored-By: Claude Opus 5.5 --- device/enchilada/device.conf | 18 +++++----- tests/boot-method | 9 ++--- tests/install-phone | 42 +++++++++++++++++++++++ tools/bundle-manifest | 2 +- tools/install-phone | 66 ++++++++++++++++++++++++------------ 5 files changed, 101 insertions(+), 36 deletions(-) diff --git a/device/enchilada/device.conf b/device/enchilada/device.conf index 87d89e933..e07ac6da1 100644 --- a/device/enchilada/device.conf +++ b/device/enchilada/device.conf @@ -2,13 +2,12 @@ # Guarded SDM845 descriptor for the OnePlus 6 (enchilada). Format rules: # device/cheetah/device.conf. Notes and the state of each slot: NOTES.md. # -# RAM-only bring-up: this ABL boots an Android boot image header v0 holding -# a gzip kernel with the DTB appended (no dtbo, no vendor_boot), booted with -# `fastboot boot`, so nothing is written. `omamobile images` packs that -# boot.img from the header fields below (tests/images-layout); fastboot, -# flash, push and the installer refuse BOOT_METHOD=android-v0 before -# touching a phone (tests/boot-method), and keep refusing it until the -# slot-B install and its CONTRIBUTING.md §3.1 entry are agreed. +# This ABL boots an Android boot image header v0 holding a gzip kernel with +# the DTB appended (no dtbo, no vendor_boot). `omamobile images` packs that +# boot.img from the header fields below (tests/images-layout). The slot-B +# install is tools/install-phone (boot_b and userdata, then set-active b); +# its CONTRIBUTING.md §3.1 entry names the one GPT write that marks boot_b +# successful, by hand, once per install. # # Storage: userdata is on sda, but boot_* sit on LUN sde. UFS_RW_LUNS=sde # has the init guard sde as it guards sda, leaving only boot_b writable @@ -43,5 +42,6 @@ UFS_RW_LUNS=sde OMAMOBILE_SLOT=b # The first-light kernel builds the USB gadget as modules (USB_CONFIGFS=m) INITRAMFS_MODULES="libcomposite u_ether usb_f_ncm u_serial usb_f_acm" -# omamobile.initramfs: stay in the initramfs; RAM-only, nothing is mounted rw -CMDLINE="console=tty0 panic=10 omamobile.initramfs omamobile.ufs-probe" +# The init hands off to the Arch root on userdata. A RAM-only `fastboot boot` +# for bring-up adds omamobile.initramfs (stay in the initramfs) by hand. +CMDLINE="console=tty0 panic=10" diff --git a/tests/boot-method b/tests/boot-method index b82730452..c8b091ddf 100755 --- a/tests/boot-method +++ b/tests/boot-method @@ -45,7 +45,8 @@ echo 'ok - the shipped flame descriptor has no persistent installer path' # The shipped enchilada descriptor: android-v0 images get past the # descriptor checks (no kernel build here, so they stop at "build the # kernel first"); fastboot, flash and push refuse it as RAM-only, and the -# installer still refuses the method. None of it reaches a phone. +# installer takes the method and stops at the missing images, before the +# phone. None of it reaches a phone. mkdir -p "$t/repo/device/enchilada" cp device/enchilada/device.conf "$t/repo/device/enchilada/" if DEVICE=enchilada KERNEL_OUT="$t/no-kernel" "$t/repo/bin/omamobile" images > "$t/log" 2>&1; then fail "enchilada images succeeds without a kernel"; fi @@ -55,11 +56,11 @@ for cmd in fastboot flash push; do grep -q "$cmd refuses BOOT_METHOD=android-v0" "$t/log" || fail "enchilada $cmd fails for the wrong reason" done for dry in '' --dry-run; do - if "$t/repo/tools/install-phone" --device enchilada $dry --work "$t/work" > "$t/log" 2>&1; then fail "enchilada installs"; fi - grep -q 'unsupported BOOT_METHOD=android-v0;' "$t/log" || fail "enchilada installer fails for the wrong reason" + if "$t/repo/tools/install-phone" --device enchilada --images "$t/no-images" $dry --work "$t/work" > "$t/log" 2>&1; then fail "enchilada installs without images"; fi + grep -q "no-images holds images for 'an unknown device', not enchilada" "$t/log" || fail "enchilada installer fails for the wrong reason" done [[ ! -e $t/calls && ! -e $t/work ]] || fail "the enchilada descriptor accessed a phone or prepared an image" -echo 'ok - enchilada images reach the kernel check; fastboot/flash/push and both installer modes refuse android-v0' +echo 'ok - enchilada images reach the kernel check; fastboot/flash/push refuse android-v0; the installer takes it and stops at the images' # Header fields must be present and numeric; BOOT_IMAGES is boot only and # boot_b must be writable. diff --git a/tests/install-phone b/tests/install-phone index ac2a0d5fa..7e95755c6 100755 --- a/tests/install-phone +++ b/tests/install-phone @@ -274,6 +274,48 @@ printf '\nBOOT_METHOD=android-v4\n' >> "$R/device/testdev/device.conf" install --dry-run || { cat "$t/out"; fail "explicit android-v4 installs"; } pass "explicit android-v4 and legacy omitted BOOT_METHOD both work" +# android-v0 (enchilada's shape): one boot image, no SOC_IDS, a SoC-named +# fastboot product, and a bootloader that reports no version at all +cat > "$R/device/testdev/device.conf" <<'EOF' +CODENAME=testdev +FASTBOOT_PRODUCT=sdm845 +NAME="Test Phone" +BOOT_METHOD=android-v0 +BOOT_IMAGES=boot +UFS_RW="boot_b userdata" +EOF +v0vars() { printf 'product:%s\nunlocked:yes\ncurrent-slot:a\nversion-bootloader:\npartition-size:boot_b: 0x4000000\npartition-size:userdata: 0x1B800BB000\n' "$1" > "$t/vars"; } +v0vars testdev +refuse "an android-v0 phone whose product is not FASTBOOT_PRODUCT" --bootloader-slots-match unreported +grep -q "not sdm845" "$t/out" || fail "names the expected product" +v0vars sdm845 +refuse "a bootloader with no version, unconfirmed"; grep -q -- '--bootloader-slots-match unreported' "$t/out" || fail "says how to confirm both slots" +refuse "a version confirmed for a bootloader that reports none" --bootloader-slots-match cloudripper-17.0-15199429 +install --dry-run --bootloader-slots-match unreported || { cat "$t/out"; fail "an android-v0 dry run succeeds"; } +expected=" would run: fastboot -s FAKE123 flash boot_b $t/images/boot.img + would run: fastboot -s FAKE123 flash userdata $t/work/root.simg + would run: fastboot -s FAKE123 --set-active=b + would run: fastboot -s FAKE123 reboot" +command -v img2simg >/dev/null || expected=${expected//root.simg/root.img} +[[ $(grep 'would run:' "$t/out") == "$expected" ]] || { grep 'would run:' "$t/out"; fail "the android-v0 dry run prints exactly boot_b, userdata, set-active, reboot"; } +rm -f "$t/userdata.flashed" +install --bootloader-slots-match unreported || { cat "$t/out"; fail "an android-v0 run succeeds"; } +want="-s FAKE123 flash boot_b $t/images/boot.img +-s FAKE123 flash userdata $t/work/root.simg +-s FAKE123 --set-active=b +-s FAKE123 reboot" +command -v img2simg >/dev/null || want=${want//root.simg/root.img} +[[ $(flashing_calls) == "$want" ]] || { flashing_calls; fail "an android-v0 run sends exactly those commands"; } +v0img=$t/userdata.flashed +if command -v simg2img >/dev/null && [[ $(head -c4 "$v0img" | od -An -tx1 | tr -d ' ') == 3aff26ed ]]; then + simg2img "$v0img" "$t/v0.raw" && v0img=$t/v0.raw +fi +[[ $(debugfs -R 'cat /etc/omamobile/boot-update.conf' "$v0img" 2>/dev/null | grep -v '^#') == AUTO_WRITE=no ]] \ + || fail "an android-v0 install leaves the boot hook off (omamobile-boot-update has no android-v0 path)" +descriptor > "$R/device/testdev/device.conf" +vars "" "" $'version-bootloader-a:x\nversion-bootloader-b:x' +pass "android-v0: FASTBOOT_PRODUCT checked, an unreported bootloader version confirmed, only boot_b and userdata written, boot hook off" + # A release bundle: install beside device.conf and images/, the root image next to it BD=$t/bundle/omamobile-testdev-2026.10.13 mkdir -p "$BD/images" diff --git a/tools/bundle-manifest b/tools/bundle-manifest index 650085fb7..c7241c4a9 100755 --- a/tools/bundle-manifest +++ b/tools/bundle-manifest @@ -143,7 +143,7 @@ def main(): "compression": "zstd", "filesystem": "ext4", "label": "omamobile-root"}, "install": { "tool": "fastboot", - "product": codename, + "product": d.get("FASTBOOT_PRODUCT") or codename, "require_unlocked_bootloader": True, "require_matching_bootloader_slots": True, "storage_guard_allowlist": allow, diff --git a/tools/install-phone b/tools/install-phone index 9db28c29a..143229ef1 100755 --- a/tools/install-phone +++ b/tools/install-phone @@ -15,7 +15,7 @@ # persist, efs, modem, devinfo and vbmeta are never touched. # # Before anything it checks: the phone answers in fastboot, its product is the -# descriptor's CODENAME, the bootloader is unlocked, both bootloader slots +# descriptor's CODENAME (or FASTBOOT_PRODUCT), the bootloader is unlocked, both bootloader slots # carry the same version, and each image fits its slot B partition (an # AVB_FOOTERS image exactly). A bundle's manifest.json (tools/bundle-manifest) # states the same checks and writes as data, for this script, a web flasher @@ -26,7 +26,8 @@ # /etc/omamobile/firstboot.conf (and root's authorized_keys) into a LOCAL # COPY of the root image with debugfs (no root needed), with # /etc/omamobile/boot-update.conf (AUTO_WRITE=yes: kernel package updates -# reach slot B through omamobile-boot-update, docs/RELEASES.md §5.3; a +# reach slot B through omamobile-boot-update, docs/RELEASES.md §5.3; +# AUTO_WRITE=no for android-v0, which omamobile-boot-update can't write yet; a # development phone, set up by hand, has no such file), shows exactly what it # will run, and waits for the codename to be typed. The phone's first boot # (omamobile-firstboot) creates the user from that file and deletes it. @@ -49,7 +50,9 @@ # --bootloader-slots-match VERSION # when the bootloader reports no per-slot versions: # you checked the other slot carries VERSION too -# (it must equal the current slot's) +# (it must equal the current slot's); "unreported" +# when it reports no version at all and you checked +# both slots' firmware partitions match # --reinstall slot B is the current slot and holds Omarchy Mobile # (a reinstall); without it, a phone running from # slot B is refused, since that is where stock @@ -130,17 +133,27 @@ done < "$conf" CODENAME=${D[CODENAME]:-} [[ $CODENAME =~ ^[a-z0-9]+$ ]] || die "$conf: no CODENAME" [[ $mode == bundle || $CODENAME == "$device" ]] || die "$conf: CODENAME=$CODENAME, expected $device" -# Legacy descriptors omit BOOT_METHOD; only their Android v4 path is installable. -# Refuse before image preparation or any fastboot query/write. +# Legacy descriptors omit BOOT_METHOD (Android v4). android-v0 is a header v0 +# boot.img with the DTB appended (enchilada, CONTRIBUTING.md §3.1). +# Refuse anything else before image preparation or any fastboot query/write. BOOT_METHOD=${D[BOOT_METHOD]-android-v4} -[[ $BOOT_METHOD == android-v4 ]] || die "$conf: unsupported BOOT_METHOD=$BOOT_METHOD; install-phone supports only android-v4" -# The descriptor names how ABL picks the base DTB: SOC_IDS (/soc_id, gs101 -# and gs201) or SOC_COMPATIBLE (/soc_compatible, zuma), exactly one, as +[[ $BOOT_METHOD == android-v4 || $BOOT_METHOD == android-v0 ]] || + die "$conf: unsupported BOOT_METHOD=$BOOT_METHOD; install-phone supports android-v4 and android-v0" +# What the bootloader's "getvar product" must say: the codename, or the +# descriptor's FASTBOOT_PRODUCT (a SoC name such as sdm845, shared with other +# phones, so there the pinned serial and the typed codename identify the phone) +PRODUCT=${D[FASTBOOT_PRODUCT]:-$CODENAME} +[[ $PRODUCT =~ ^[a-z0-9_-]+$ ]] || die "$conf: FASTBOOT_PRODUCT must be a fastboot product name" +# An android-v4 descriptor names how ABL picks the base DTB: SOC_IDS (/soc_id, +# gs101 and gs201) or SOC_COMPATIBLE (/soc_compatible, zuma), exactly one, as # bin/omamobile checks. A staged descriptor names neither and is refused. -if [[ -n ${D[SOC_IDS]:-} && -n ${D[SOC_COMPATIBLE]:-} ]]; then - die "$conf: SOC_IDS and SOC_COMPATIBLE are exclusive" -elif [[ -z ${D[SOC_IDS]:-} && -z ${D[SOC_COMPATIBLE]:-} ]]; then - die "$conf: SOC_IDS is missing (or SOC_COMPATIBLE); this device can't be installed yet" +# android-v0 appends the one DTB to the kernel, so it names neither. +if [[ $BOOT_METHOD == android-v4 ]]; then + if [[ -n ${D[SOC_IDS]:-} && -n ${D[SOC_COMPATIBLE]:-} ]]; then + die "$conf: SOC_IDS and SOC_COMPATIBLE are exclusive" + elif [[ -z ${D[SOC_IDS]:-} && -z ${D[SOC_COMPATIBLE]:-} ]]; then + die "$conf: SOC_IDS is missing (or SOC_COMPATIBLE); this device can't be installed yet" + fi fi # Images record the device they were built for, as flash and push check: # out-int/images holds whichever device was built last. @@ -300,8 +313,8 @@ PY esac done <<<"$plan" [[ ${M[format]} == 1 ]] || die "manifest.json has format ${M[format]}; this installer reads format 1" - [[ ${M[codename]} == "$CODENAME" && ${M[product]} == "$CODENAME" ]] || - die "manifest.json is for ${M[codename]} (product ${M[product]}), but the descriptor is $CODENAME" + [[ ${M[codename]} == "$CODENAME" && ${M[product]} == "$PRODUCT" ]] || + die "manifest.json is for ${M[codename]} (product ${M[product]}), but the descriptor is $CODENAME (product $PRODUCT)" [[ ${M[require_unlocked_bootloader]} == true ]] || die "manifest.json must require an unlocked bootloader" [[ ${M[require_matching_bootloader_slots]} == true ]] || die "manifest.json must require both bootloader slots to match" read -ra allow <<<"$UFS_RW" @@ -390,15 +403,20 @@ fb() { "$FASTBOOT" -s "$serial" "$@"; } vars=$(fb getvar all 2>&1 | sed -E 's/^\(bootloader\) //') var() { awk -F: -v k="$1" '$1 == k { sub(/^[^:]*:[ ]*/, ""); print; exit }' <<<"$vars"; } product=$(var product) -[[ $product == "$CODENAME" ]] || die "the phone is '${product:-unknown}', not $CODENAME (${D[NAME]:-}): wrong descriptor or wrong phone" +[[ $product == "$PRODUCT" ]] || die "the phone is '${product:-unknown}', not $PRODUCT ($CODENAME, ${D[NAME]:-}): wrong descriptor or wrong phone" [[ $(var unlocked) == yes ]] || die "the bootloader is locked: unlock it first (this erases the phone; see CONTRIBUTING.md)" current_slot=$(var current-slot) current_bl=$(var version-bootloader) -[[ -n $current_bl ]] || die "the phone reports no version-bootloader" # Per-slot bootloader versions, where the bootloader reports them bl_a=$(sed -nE 's/^version-bootloader[-_:]a:[ ]*//p' <<<"$vars" | head -1) bl_b=$(sed -nE 's/^version-bootloader[-_:]b:[ ]*//p' <<<"$vars" | head -1) -if [[ -n $bl_a && -n $bl_b ]]; then +if [[ -z $current_bl ]]; then + # Some bootloaders (OnePlus ABL) report no version at all: the owner checked + # both slots' firmware partitions match (for enchilada: the read-only backup + # compared _a and _b byte for byte, device/enchilada/NOTES.md) + [[ $slots_match == unreported ]] || die "the phone reports no bootloader version, so the slots can't be compared here. Setting slot B active runs slot B's bootloader: check that every firmware partition (xbl, abl, ...) is the same on _a and _b, from a read-only backup, then rerun with --bootloader-slots-match unreported" + note "bootloader version not reported; both slots confirmed by you (--bootloader-slots-match unreported)" +elif [[ -n $bl_a && -n $bl_b ]]; then [[ $bl_a == "$bl_b" ]] || die "the bootloader slots differ (a: $bl_a, b: $bl_b). Never flash a bootloader partition by hand (CONTRIBUTING §3.1): from stock Android, sideload the full OTA for your build twice, so each slot gets the same bootloader, then rerun. If that doesn't make them match, stop and ask in an issue" note "bootloader $bl_a on both slots" elif [[ -n $slots_match ]]; then @@ -407,7 +425,7 @@ elif [[ -n $slots_match ]]; then else die "the phone only reports slot ${current_slot:-?}'s bootloader ($current_bl). Setting slot B active runs slot B's bootloader, so both must match. Check the other slot (fastboot getvar version-bootloader while it is current), then rerun with --bootloader-slots-match $current_bl" fi -note "$CODENAME, unlocked, current slot ${current_slot:-?}" +note "$CODENAME (product $product), unlocked, current slot ${current_slot:-?}" # Stock Android must be the one on slot A. An Android system update writes the # other slot and switches to it, so a phone that took one can run stock from # slot B, and writing slot B would overwrite the stock system in use. From @@ -495,6 +513,10 @@ mkdir -p "$work" chmod 700 "$work" copy=$work/root.img sparse=$work/root.simg conf_file=$work/firstboot.conf keys_file=$work/authorized_keys boot_conf=$work/boot-update.conf ramdisk_dir=$work/ramdisk +# omamobile-boot-update has no android-v0 path yet (it refuses the descriptor), +# so an android-v0 phone gets AUTO_WRITE=no: kernel updates reach slot B by push +auto_write=yes +[[ $BOOT_METHOD == android-v4 ]] || auto_write=no # The copy holds the password hash (and any Wi-Fi password): never left behind cleanup() { rm -f "$conf_file" "$keys_file" "$boot_conf" "$copy" "$sparse"; rm -rf "$ramdisk_dir"; } trap cleanup EXIT @@ -518,7 +540,7 @@ trap cleanup EXIT printf '%s\n' "$ssh_key" > "$keys_file" printf '%s\n' "# Written by install-phone: a release install takes kernel updates through" \ "# omamobile-boot-update's pacman hook (docs/RELEASES.md §5.3). AUTO_WRITE=no stops it." \ - "AUTO_WRITE=yes" > "$boot_conf" + "AUTO_WRITE=$auto_write" > "$boot_conf" ) unset wifi_psk @@ -694,9 +716,9 @@ echo " fastboot flash userdata $userdata_image" echo " fastboot --set-active=b" echo " fastboot reboot" echo -echo "userdata will be ERASED: stock Android's data is lost, and stock Android on" -echo "slot A will need a factory reset if you ever boot it again. Slot A itself," -echo "the bootloader, radio, persist, efs, modem and devinfo are not touched." +echo "userdata will be ERASED: its data is lost, and an Android on slot A will" +echo "need a factory reset if you ever boot it again. Slot A itself, the" +echo "bootloader, radio, persist, efs, modem and devinfo are not touched." echo answer=$(ask "Type the phone's codename ($CODENAME) to go ahead") [[ $answer == "$CODENAME" ]] || die "not confirmed; nothing was written" From 4d72c398c0114d2cf25451e266c9e5dc21b75cea Mon Sep 17 00:00:00 2001 From: Matt Barr Date: Mon, 9 Nov 2026 23:00:55 -0500 Subject: [PATCH 3/5] omamobile push: rewrite enchilada's boot_b (android-v0) for day-2 updates tools/install-phone is now enchilada's first install, and its boot-update.conf says AUTO_WRITE=no because omamobile-boot-update takes only android-v4. push is the day-2 path: an android-v0 descriptor has one image, boot_b, which push already finds on a UFS_RW_LUNS LUN (sde), checks against the partition size and the storage guard's ro flag, writes and reads back by sha256. Lift its android-v0 refusal; fastboot and flash keep theirs, since the first install goes through the installer. tests/boot-method: enchilada push now stops at the missing images, still before any phone access. RELEASES: the BOOT_METHOD row says which tools take android-v0. Co-Authored-By: Claude Opus 5.5 --- bin/omamobile | 9 ++++----- docs/RELEASES.md | 2 +- tests/boot-method | 12 +++++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/omamobile b/bin/omamobile index ec88ecc25..537f6dd2d 100755 --- a/bin/omamobile +++ b/bin/omamobile @@ -1203,11 +1203,10 @@ cmd_flash() { cmd_push() { local img="$KERNEL_OUT/images" ssh="$ROOT/tools/phone-ssh" p dev want got rel load_device - # Same class of refusal as flash: boot_b is on sde here, and there is no - # in-tree day-2 rewrite path for qcom-abl yet. Refuse before any phone I/O - # (modules-push would otherwise rewrite the running root's modules). - [[ $DEV_BOOT_METHOD != android-v0 ]] || - die "push refuses BOOT_METHOD=android-v0 (RAM-only: fastboot boot \$KERNEL_OUT/images/boot.img)" + # android-v0 (enchilada) pushes like android-v4: its one image, boot_b, is + # found on a UFS_RW_LUNS LUN below. qcom-abl has no in-tree day-2 rewrite + # path yet: refuse before any phone I/O (modules-push would otherwise + # rewrite the running root's modules). [[ $DEV_BOOT_METHOD != qcom-abl ]] || die "push refuses BOOT_METHOD=qcom-abl (no in-tree day-2 update path yet; see device/$DEVICE/BRINGUP-M1.md)" images_for_device "$img" diff --git a/docs/RELEASES.md b/docs/RELEASES.md index 54d9f93d3..f756badc9 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -76,7 +76,7 @@ Bring-up tools (`*-stage`, `display-hz`, `usbc-deadman`) stay per plan: they pok | `OS_VERSION`, `OS_PATCH_LEVEL` | `17.0.0`, `2026-07` | The `init_boot` header values (the `boot` header's, on a device without `init_boot`) | | `AVB_FOOTERS` | (zuma, the Pixel 7a and the Pixel 7 Pro: `boot:0x4000000 init_boot:0x800000`) | Optional. For a phone whose `vbmeta_b` chains these partitions, as stock's does: libavb takes a chained partition with no AVB footer as invalid metadata, which an unlocked bootloader doesn't let through (zuma; the Pixel 7a; the Pixel 7 Pro, device/cheetah/NOTES.md 2026-10-28). A `vbmeta_b` that lists them as hash descriptors, or has verification disabled, never reads the footers. `image:partition_size`, each a `BOOT_IMAGES` entry, once; the size is the slot's partition size in bytes (stock's footer, `avbtool info_image`, or `fastboot getvar partition-size:_b`), a multiple of 4096. `images` adds a hash footer to each, padding it to that size, signed with AOSP's test key (an unlocked bootloader accepts any key); needs `external/avb` under `SRC_DIR` (or `AVBTOOL`, `AVB_KEY`) and `openssl` | | `AVB_ROLLBACK_INDEX`, `AVB_SECURITY_PATCH` | `1791158400`, `2026-10-05` | Required with `AVB_FOOTERS`, refused without it: stock's rollback index and `com.android.build..security_patch` from its footers. Never set the index above stock's: an index the bootloader stores locks stock's own images out of slot A. The `os_version` property is `OS_VERSION`'s major | -| `BOOT_METHOD` | `android-v4` (default when omitted) | Generic images, flash, push and installer accept only `android-v4`; other methods are refused before phone access. `ram-only` marks a probe with no persistent install support. `android-v0` (enchilada) is a header-v0 phone: `images` packs one `boot.img` for `fastboot boot`, and fastboot, flash, push and the installer refuse it | +| `BOOT_METHOD` | `android-v4` (default when omitted) | Generic images, flash, push and installer accept only `android-v4`; other methods are refused before phone access. `ram-only` marks a probe with no persistent install support. `android-v0` (enchilada) is a header-v0 phone: `images` packs one `boot.img`; the installer writes it to `boot_b` with `userdata` (`AUTO_WRITE=no`), push rewrites `boot_b` on `UFS_RW_LUNS`, and fastboot and flash refuse it | | `PAGESIZE`, `BASE`, `KERNEL_OFFSET`, `RAMDISK_OFFSET`, `SECOND_OFFSET`, `TAGS_OFFSET` | (enchilada: `4096`, `0x00000000`, `0x00008000`, `0x01000000`, `0x00f00000`, `0x00000100`) | `android-v0` only, all required: the header-v0 page size and load offsets, numbers in decimal or lower-case hex. `images` packs the gzip `Image` with the `DTB` appended as the kernel, the initramfs as the ramdisk and `CMDLINE` as the command line. `BOOT_IMAGES` is `boot` alone and `boot_b` must be on `UFS_RW` | | `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`) | | `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 | diff --git a/tests/boot-method b/tests/boot-method index c8b091ddf..e8ed2dc9a 100755 --- a/tests/boot-method +++ b/tests/boot-method @@ -44,23 +44,25 @@ echo 'ok - the shipped flame descriptor has no persistent installer path' # The shipped enchilada descriptor: android-v0 images get past the # descriptor checks (no kernel build here, so they stop at "build the -# kernel first"); fastboot, flash and push refuse it as RAM-only, and the -# installer takes the method and stops at the missing images, before the -# phone. None of it reaches a phone. +# kernel first"); fastboot and flash refuse it (the first install is +# tools/install-phone), and push and the installer take the method and stop +# at the missing images, before the phone. None of it reaches a phone. mkdir -p "$t/repo/device/enchilada" cp device/enchilada/device.conf "$t/repo/device/enchilada/" if DEVICE=enchilada KERNEL_OUT="$t/no-kernel" "$t/repo/bin/omamobile" images > "$t/log" 2>&1; then fail "enchilada images succeeds without a kernel"; fi grep -q 'build the kernel first' "$t/log" || fail "enchilada images fails for the wrong reason" -for cmd in fastboot flash push; do +for cmd in fastboot flash; do if DEVICE=enchilada "$t/repo/bin/omamobile" "$cmd" > "$t/log" 2>&1; then fail "enchilada $cmd succeeds"; fi grep -q "$cmd refuses BOOT_METHOD=android-v0" "$t/log" || fail "enchilada $cmd fails for the wrong reason" done +if DEVICE=enchilada KERNEL_OUT="$t/no-kernel" "$t/repo/bin/omamobile" push > "$t/log" 2>&1; then fail "enchilada push succeeds without images"; fi +grep -q "no-kernel/images holds images for 'an unknown device', not enchilada" "$t/log" || fail "enchilada push fails for the wrong reason" for dry in '' --dry-run; do if "$t/repo/tools/install-phone" --device enchilada --images "$t/no-images" $dry --work "$t/work" > "$t/log" 2>&1; then fail "enchilada installs without images"; fi grep -q "no-images holds images for 'an unknown device', not enchilada" "$t/log" || fail "enchilada installer fails for the wrong reason" done [[ ! -e $t/calls && ! -e $t/work ]] || fail "the enchilada descriptor accessed a phone or prepared an image" -echo 'ok - enchilada images reach the kernel check; fastboot/flash/push refuse android-v0; the installer takes it and stops at the images' +echo 'ok - enchilada images reach the kernel check; fastboot/flash refuse android-v0; push and the installer take it and stop at the images' # Header fields must be present and numeric; BOOT_IMAGES is boot only and # boot_b must be writable. From af6bc27edf1f023e4159c068a013e3eca4bb5720 Mon Sep 17 00:00:00 2001 From: Matt Barr Date: Tue, 10 Nov 2026 10:21:10 -0500 Subject: [PATCH 4/5] =?UTF-8?q?tools/mark-slot-b:=20the=20CONTRIBUTING=20?= =?UTF-8?q?=C2=A73.1=20write=20for=20slot=20B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a Qualcomm A/B phone slot B is marked successful in its GPT, which the storage guard can't police, so the write gets its own tool, run by hand once per install of slot B's boot image and never from a service. The descriptor names the write (SLOT_B_MARK: the LUN, the partition and the four LBAs). Over phone-ssh the tool reads both GPT copies through a private node under /run (the init removes the whole-disk node, and that stays so), checks both headers, both entry arrays and their CRCs, finds the partition by name once, and refuses unless its sectors are the named four, the phone booted slot B, and B is active and not unbootable. It sets bit 54 and nothing else, recomputes the entry-array CRC and both header CRCs, and checks that only those four sectors change. The default is a dry run; --write asks for 'mark boot_b', re-reads the four sectors, writes the primary pair, reads it back, then the backup pair. enchilada's entry: sde boot_b, LBA 1, 3, 786428 and 786431. Checked read-only against a copy of the real sde GPT: entry 38, the captured header and array CRCs match, and the plan changes only those fields. tests/mark-slot-b runs it against a synthetic 4096-byte-sector GPT. Co-Authored-By: Claude Opus 5.5 --- device/enchilada/device.conf | 3 + docs/RELEASES.md | 3 +- tests/all | 2 +- tests/mark-slot-b | 105 ++++++++++++++++ tools/mark-slot-b | 227 +++++++++++++++++++++++++++++++++++ 5 files changed, 338 insertions(+), 2 deletions(-) create mode 100755 tests/mark-slot-b create mode 100755 tools/mark-slot-b diff --git a/device/enchilada/device.conf b/device/enchilada/device.conf index e07ac6da1..ae1606a98 100644 --- a/device/enchilada/device.conf +++ b/device/enchilada/device.conf @@ -39,6 +39,9 @@ TAGS_OFFSET=0x00000100 BOOT_IMAGES=boot UFS_RW="boot_b userdata" UFS_RW_LUNS=sde +# CONTRIBUTING.md §3.1: boot_b is entry 38 of sde's 96, 4096-byte sectors, +# last LBA 786431; tools/mark-slot-b sets its bit 54 in these four sectors. +SLOT_B_MARK="sde boot_b 1 3 786428 786431" OMAMOBILE_SLOT=b # The first-light kernel builds the USB gadget as modules (USB_CONFIGFS=m) INITRAMFS_MODULES="libcomposite u_ether usb_f_ncm u_serial usb_f_acm" diff --git a/docs/RELEASES.md b/docs/RELEASES.md index f756badc9..5cfd10c36 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -80,7 +80,8 @@ Bring-up tools (`*-stage`, `display-hz`, `usbc-deadman`) stay per plan: they pok | `PAGESIZE`, `BASE`, `KERNEL_OFFSET`, `RAMDISK_OFFSET`, `SECOND_OFFSET`, `TAGS_OFFSET` | (enchilada: `4096`, `0x00000000`, `0x00008000`, `0x01000000`, `0x00f00000`, `0x00000100`) | `android-v0` only, all required: the header-v0 page size and load offsets, numbers in decimal or lower-case hex. `images` packs the gzip `Image` with the `DTB` appended as the kernel, the initramfs as the ramdisk and `CMDLINE` as the command line. `BOOT_IMAGES` is `boot` alone and `boot_b` must be on `UFS_RW` | | `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`) | | `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 but enchilada's), 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` | +| `SLOT_B_MARK` | (unset) | Optional, Qualcomm A/B only: the device's [CONTRIBUTING](../CONTRIBUTING.md) §3.1 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_MODULES` | (unset) | Optional: kernel modules the initramfs carries in `/lib/modules/omamobile/`, listed in load order in `/lib/modules/omamobile/order`, from this kernel build's `lib/modules/$(kernel_release)` (`omamobile modules` first). The shared init loads them before any other step, and only on a board whose first compatible is `COMPATIBLE`. For drivers the boot needs before the Arch root, such as the PMIC rails a `simple-framebuffer` waits for; `images` refuses an initramfs whose modules come from another build | | `INITRAMFS_I2C_TOOLS` | (unset) | `1`: `i2cget` and `i2cset` (and `libi2c`) from Alpine's i2c-tools in the initramfs, for an init that talks to a chip before any driver runs (raven closes the MAX77759 USB switch). Nothing else from the package | diff --git a/tests/all b/tests/all index 02cad4d38..5be4e40c3 100755 --- a/tests/all +++ b/tests/all @@ -45,7 +45,7 @@ sh -n device/flame/initramfs/build bash -n tools/build-flame-probe echo "ok - scripts parse" python3 tests/bt-uart-gpio.py -for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs; do +for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/mark-slot-b tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs; do echo "# $t" "$t" done diff --git a/tests/mark-slot-b b/tests/mark-slot-b new file mode 100755 index 000000000..725599c0e --- /dev/null +++ b/tests/mark-slot-b @@ -0,0 +1,105 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# tools/mark-slot-b against a synthetic GPT with 4096-byte sectors behind a +# fake phone-ssh: the dry run writes nothing, --write sets bit 54 on boot_b +# alone and changes exactly the four named sectors, and every refusal holds. +set -euo pipefail +cd "$(dirname "$0")/.." +command -v sfdisk >/dev/null || { echo "ok - # skip: no sfdisk for tests/mark-slot-b"; exit 0; } +fail() { echo "not ok - $*"; exit 1; } +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +mkdir -p "$t/repo/tools" "$t/repo/device/probe" "$t/bin" "$t/run" "$t/sys/block/sde/queue" +cp tools/mark-slot-b "$t/repo/tools/" + +# The phone: a 16384-sector LUN, 40 partitions, boot_b the 39th (entry 38, in +# the second entry sector, as on the real sde), active with priority 2 and 7 tries. +truncate -s $((16384 * 4096)) "$t/disk.img" +{ echo "label: gpt"; echo "table-length: 96" + for i in $(seq 1 40); do + case $i in + 11) echo 'size=8, name=boot_a, attrs="GUID:48,49,50,52"' ;; + 39) echo 'size=8, name=boot_b, attrs="GUID:49,50,51,52,53"' ;; + *) echo "size=8, name=p$i" ;; + esac + done; } | sfdisk -q --sector-size 4096 "$t/disk.img" +echo 8:64 > "$t/sys/block/sde/dev" +echo $((16384 * 8)) > "$t/sys/block/sde/size" +echo 4096 > "$t/sys/block/sde/queue/logical_block_size" +echo "console=tty0 androidboot.slot_suffix=_b" > "$t/cmdline" +printf '#!/bin/sh\nln -s "%s/disk.img" "$1"\n' "$t" > "$t/bin/mknod" +cat > "$t/ssh" <> "$t/log" +PATH="$t/bin:\$PATH" exec sh -c "\$c" +EOF +chmod +x "$t/ssh" "$t/bin/mknod" +export OMAMOBILE_MARK_SSH=$t/ssh + +# The four LBAs, read from the image as the §3.1 entry would record them +lbas=$(/usr/bin/python3 - "$t/disk.img" <<'EOF' +import struct, sys +f = open(sys.argv[1], "rb") +def hdr(lba): + f.seek(lba * 4096); h = f.read(92) + return struct.unpack_from(" "$t/repo/device/probe/device.conf"; } +conf "$lbas" +mark() { "$t/repo/tools/mark-slot-b" --device probe "$@"; } +sum() { sha256sum "$t/disk.img" | cut -d' ' -f1; } +before=$(sum); cp "$t/disk.img" "$t/disk.orig" + +mark > "$t/out" 2>&1 || { cat "$t/out"; fail "dry run fails"; } +grep -q "would set bit 54: 0x007e000000000000" "$t/out" || { cat "$t/out"; fail "dry run does not plan bit 54"; } +grep -q "dry run: nothing written" "$t/out" || fail "dry run does not say so" +[[ $(sum) == "$before" ]] || fail "dry run changed the disk" +grep -c 'dd of=' "$t/log" >/dev/null && fail "dry run ran a write" +[[ -z $(ls -A "$t/run") ]] || fail "the private node was left behind" + +echo "yes" | mark --write > "$t/out" 2>&1 && fail "--write takes a wrong confirmation" +grep -q "not confirmed; nothing written" "$t/out" || fail "wrong confirmation fails for the wrong reason" +[[ $(sum) == "$before" ]] || fail "a refused --write changed the disk" + +echo "mark boot_b" | mark --write > "$t/out" 2>&1 || { cat "$t/out"; fail "--write fails"; } +grep -q "boot_b marked successful" "$t/out" || fail "--write does not report the mark" +[[ -z $(ls -A "$t/run") ]] || fail "the private node was left behind after --write" +changed=$(cmp -l "$t/disk.orig" "$t/disk.img" | awk '{print int(($1 - 1) / 4096)}' | sort -nu | xargs) +[[ $changed == "$lbas" ]] || fail "--write changed sectors '$changed', not '$lbas'" +sfdisk -q --sector-size 4096 -V "$t/disk.img" > "$t/verify" 2>&1 || { cat "$t/verify"; fail "sfdisk rejects the marked GPT"; } +sfdisk --sector-size 4096 -d "$t/disk.img" > "$t/dump" 2>&1 +grep 'name="boot_b"' "$t/dump" | grep -q 'GUID:49,50,51,52,53,54' || { grep boot "$t/dump"; fail "boot_b is not marked in the dump"; } +grep 'name="boot_a"' "$t/dump" | grep -q 'attrs="GUID:48,49,50,52"$' || fail "boot_a changed" +mark > "$t/out" 2>&1 || fail "the marked GPT fails its own check" +grep -q "already marked successful" "$t/out" || fail "a second run does not see the mark" + +cp "$t/disk.orig" "$t/disk.img" +echo "console=tty0 androidboot.slot_suffix=_a" > "$t/cmdline" +mark > "$t/out" 2>&1 && fail "marks from a boot of slot A" +grep -q "did not boot slot B" "$t/out" || fail "slot A boot refused for the wrong reason" +echo "console=tty0 androidboot.slot_suffix=_b" > "$t/cmdline" + +read -r a b c d <<<"$lbas"; conf "$a $((b + 1)) $c $d" +mark > "$t/out" 2>&1 && fail "takes a GPT the entry does not name" +grep -q "not the descriptor's" "$t/out" || fail "wrong LBAs refused for the wrong reason" +conf "$lbas" + +printf '\xff' | dd of="$t/disk.img" bs=1 seek=$((c * 4096 + 100)) count=1 conv=notrunc status=none +mark > "$t/out" 2>&1 && fail "takes differing entry arrays" +grep -q "entry arrays differ" "$t/out" || { cat "$t/out"; fail "differing arrays refused for the wrong reason"; } + +cp "$t/disk.orig" "$t/disk.img" +sfdisk -q --sector-size 4096 --part-attrs "$t/disk.img" 39 "GUID:49,51,52,53" +mark > "$t/out" 2>&1 && fail "marks an inactive boot_b" +grep -q "not active" "$t/out" || fail "inactive boot_b refused for the wrong reason" + +printf 'CODENAME=probe\n' > "$t/repo/device/probe/device.conf" +mark > "$t/out" 2>&1 && fail "runs without a §3.1 entry" +grep -q "no CONTRIBUTING §3.1 entry" "$t/out" || fail "missing entry refused for the wrong reason" + +echo "ok - mark-slot-b: dry run, confirmation, bit 54 on boot_b in exactly LBA ${lbas// /,}, and its refusals" diff --git a/tools/mark-slot-b b/tools/mark-slot-b new file mode 100755 index 000000000..eb0d7bf59 --- /dev/null +++ b/tools/mark-slot-b @@ -0,0 +1,227 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Mark slot B successful in a Qualcomm GPT: the CONTRIBUTING §3.1 write. + + tools/mark-slot-b --device CODENAME [--write] + +For a device whose descriptor has SLOT_B_MARK="LUN PART P_HDR P_ENT B_ENT B_HDR" +(its §3.1 entry: the LUN, the slot-B boot partition, and the four LBAs: +primary header, primary entry sector holding PART, backup entry sector, +backup header). Over tools/phone-ssh it reads both GPT copies of the LUN +through a private block node (the init removes the whole-disk node), checks +both headers and both entry arrays (signature, sizes, CRCs, copies equal), +finds PART by name exactly once, and refuses unless its sectors are the four +LBAs above, the phone booted slot B (androidboot.slot_suffix=_b) and B is +active and not unbootable. Then it sets attribute bit 54 (successful) on PART +and nothing else, recomputes the entry-array CRC and both header CRCs, and +checks that exactly the four sectors change. + +Without --write it only prints the plan (read-only). With --write, after the +human types the confirmation on stdin, it re-reads the four sectors (they +must not have changed since the check), then writes the primary entry sector and header, +reads them back by SHA-256, then the backup pair, and removes the node. + +By hand, once per install of slot B's boot image, never from a service or at +boot (AGENTS.md §1). The rollback for a corrupted GPT is the device's NOTES. +""" +import argparse +import hashlib +import os +import re +import struct +import subprocess +import sys +import zlib + +SUCCESSFUL, ACTIVE, UNBOOTABLE = 54, 50, 55 +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# The phone side: a private node for the LUN, removed on exit whatever happens. +# $1 is the LUN (sd[b-z]); every command runs as `phone-ssh sh -c ... `. +NODE = ('set -e; l=$1; shift; d=/run/omamobile-mark-slot-b; ' + 'rm -rf "$d"; mkdir -m 700 "$d"; trap \'rm -rf "$d"\' EXIT; ' + 'IFS=: read -r ma mi < /sys/block/$l/dev; mknod "$d/$l" b "$ma" "$mi"; n="$d/$l"; ') + + +def die(msg): + print("mark-slot-b: " + msg, file=sys.stderr) + sys.exit(1) + + +def descriptor(path): + """KEY="value" or KEY=value lines, never sourced (as tools/bundle-manifest).""" + d = {} + with open(path) as f: + for n, line in enumerate(f, 1): + line = line.rstrip("\n") + if re.match(r"^\s*(#.*)?$", line): + continue + m = re.match(r'^([A-Z][A-Z0-9_]*)="([^"$`\\]*)"$', line) or \ + re.match(r"^([A-Z][A-Z0-9_]*)=([^\"$`\\'\s]*)$", line) + if not m: + die("%s:%d: not a KEY=value line" % (path, n)) + d[m.group(1)] = m.group(2) + return d + + +class Phone: + def __init__(self, ssh, lun): + self.ssh, self.lun = ssh, lun + + def run(self, script, data=None): + r = subprocess.run([self.ssh, "sh -c '%s' sh %s" % ((NODE + script).replace("'", "'\\''"), self.lun)], + input=data, stdout=subprocess.PIPE) + if r.returncode: + die("phone command failed (exit %d)" % r.returncode) + return r.stdout + + def text(self, cmd): + r = subprocess.run([self.ssh, cmd], stdout=subprocess.PIPE, text=True) + if r.returncode: + die("cannot run on the phone: " + cmd) + return r.stdout.strip() + + def read(self, lba, count, ss): + out = self.run('dd if="$n" bs=%d skip=%d count=%d 2>/dev/null' % (ss, lba, count)) + if len(out) != count * ss: + die("short read at LBA %d (%d bytes)" % (lba, len(out))) + return out + + def write(self, lba, data, ss): + self.run('dd of="$n" bs=%d seek=%d count=1 iflag=fullblock conv=notrunc,fsync 2>/dev/null' % (ss, lba), data) + + +def header(raw, lba): + """Check a GPT header sector; return its fields.""" + if raw[:8] != b"EFI PART": + die("no GPT header at LBA %d" % lba) + size, crc = struct.unpack_from("> 48 & 3, "yes" if a >> ACTIVE & 1 else "no", a >> 51 & 7, + "yes" if a >> SUCCESSFUL & 1 else "no", "yes" if a >> UNBOOTABLE & 1 else "no") + + +def plan(prim_hdr, prim_ent, back_hdr, back_ent, part, ss, want): + """Check both copies and build the four new sectors: {lba: (old, new)}.""" + p, b = header(prim_hdr, want[0]), header(back_hdr, want[3]) + if p["alt"] != want[3] or b["alt"] != want[0] or (p["num"], p["ecrc"]) != (b["num"], b["ecrc"]): + die("the primary and backup headers do not describe each other") + arr = p["num"] * 128 + if prim_ent[:arr] != back_ent[:arr]: + die("the primary and backup entry arrays differ") + if zlib.crc32(prim_ent[:arr]) != p["ecrc"]: + die("the entry-array CRC does not match") + hits = [i for i in range(p["num"]) + if prim_ent[i * 128 + 56:i * 128 + 128].decode("utf-16-le", "replace").rstrip("\0") == part] + if len(hits) != 1: + die("%s found %d times in the GPT" % (part, len(hits))) + i = hits[0] + off = i * 128 + sec = off // ss + if (p["ent"] + sec, b["ent"] + sec) != (want[1], want[2]): + die("%s (entry %d) is at LBA %d and %d, not the descriptor's %d and %d: the GPT is not the one " + "the §3.1 entry names; refusing" % (part, i, p["ent"] + sec, b["ent"] + sec, want[1], want[2])) + attrs, = struct.unpack_from("> SUCCESSFUL & 1: + print("%s is already marked successful; nothing to write" % part) + return + if not attrs >> ACTIVE & 1 or attrs >> UNBOOTABLE & 1: + die("%s is not active, or is unbootable: run fastboot --set-active=b first" % part) + new = attrs | 1 << SUCCESSFUL + print("would set bit %d: 0x%016x (%s)" % (SUCCESSFUL, new, bits(new))) + print("entry-array CRC 0x%08x -> 0x%08x; header CRCs recomputed" % (old_ecrc, ecrc)) + print("sectors to write (%d bytes each): LBA %s" % (ss, ", ".join(str(x) for x in want))) + if not a.write: + print("dry run: nothing written (add --write)") + return + sys.stderr.write("Type 'mark %s' to write these four sectors: " % part) + sys.stderr.flush() + if sys.stdin.readline().strip() != "mark " + part: + die("not confirmed; nothing written") + if any(ph.read(lba, 1, ss) != out[lba][0] for lba in want): + die("the GPT changed since it was checked; nothing written") + for pair in ((want[1], want[0]), (want[2], want[3])): + for lba in pair: + ph.write(lba, out[lba][1], ss) + for lba in pair: + if hashlib.sha256(ph.read(lba, 1, ss)).digest() != hashlib.sha256(out[lba][1]).digest(): + die("read-back of LBA %d does not match: restore from the NOTES rollback copies" % lba) + print("LBA %d and %d written and read back" % pair) + print("%s marked successful" % part) + + +if __name__ == "__main__": + main() From d3f60f975d10e986b39e96452ae8adfe23c255c2 Mon Sep 17 00:00:00 2001 From: Matt Barr Date: Tue, 10 Nov 2026 10:25:51 -0500 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20enchilada's=20CONTRIBUTING=20=C2=A7?= =?UTF-8?q?3.1=20entry=20for=20boot=5Fb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Write the entry the rule asks for before the GPT write is used: LUN sde, boot_b at entry 38, LBAs 1, 3, 786428 and 786431, bit 54, and the entry-array and header CRCs it rewrites. The generic wording names the four sectors by role, since the entry sector depends on the partition. The enchilada NOTES record the plan: the install, the GPT as read on 2026-11-09, the slot flags before and after (after: recorded when it runs), the rollback from the off-repo copy of both GPT copies, and the owner's written acceptance on #432 that slot A holds the rescue. tests/mark-slot-b: use grep -c instead of piping into grep -q under pipefail (tests/grep-q-pipes). Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- CONTRIBUTING.md | 3 +- device/enchilada/NOTES.md | 66 +++++++++++++++++++++++++++++++++++++-- docs/DEVICES.md | 2 +- tests/mark-slot-b | 4 +-- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a024081fc..0eabcfdb2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,7 +10,7 @@ Omarchy Mobile runs native Omarchy (Arch Linux ARM, Hyprland, Omarchy's packages - **Ask the human before every reboot, flash, `push`, overlay boot or irreversible write.** That includes RPMB writes, a first `storageproxyd` run, `devinfo` and anything under `/dev/sd*`. The one exception is `omamobile-fp`'s own start at boot (fingerprint below): its storageproxyd runs by default. The phone is real hardware with calibration data that can't be replaced, and a human has to be ready to recover it. - **The phone is shared with a human. Announce anything that affects the screen or the feel of the phone before you run it**: DPMS, display modes and refresh rate, brightness, `bl_power`, haptics, the torch, the shell restarting, rotation. Otherwise they think the phone is broken, or it buzzes in their hand. - **Only slot B and `userdata` are ours.** Write only `boot_b`, `init_boot_b`, `vendor_boot_b`, `vendor_kernel_boot_b` and `dtbo_b`, and only through `bin/omamobile flash|push` or, on a phone whose `/etc/omamobile/boot-update.conf` says `AUTO_WRITE=yes` (only `tools/install-phone` writes it, for a release install, or a human by hand in an approved runbook), `linux-omamobile`'s pacman hook `omamobile-boot-update` ([RELEASES](docs/RELEASES.md) §5.3, §12 decisions 3 and 10): it writes only `_b` for the descriptor's `BOOT_IMAGES`, each found by GPT name on the main LUN, on `UFS_RW` and left `ro` 0 by the storage guard, read back by sha256, and never reboots. A development phone has no such file, so `push` stays its only writer. Never touch bootloader, radio, `devinfo`, `persist`, `efs*`, `modem*` or `vbmeta`, and never run an unsuffixed `fastboot flash`, with one exception: `userdata`, and only through `tools/install-phone` (serial pinned, codename typed, allowlist, dry run first). Slot A's stock Android is the way back. -- **Qualcomm A/B phones (Pixel 4 family) keep the slot flags in GPT attributes,** so slot B can only be marked bootable by writing the partition table. That write is a narrow, named exception, never automatic: by hand, once per install of slot B's boot image, and only for a device whose entry in [CONTRIBUTING](CONTRIBUTING.md) §3.1 names the LUN, the four sectors (LBAs 1, 2, last-1 and last), the attribute bit and the CRCs it rewrites. That device's plan must also record the slot flags before and after, the rollback for a corrupted GPT, and the way back: stock restored on slot A first, or the owner's explicit acceptance of buttons-only recovery. The storage guard can't block this write, so it never runs from a service or at boot. +- **Qualcomm A/B phones (Pixel 4 family, OnePlus 6) keep the slot flags in GPT attributes,** so slot B can only be marked bootable by writing the partition table. That write is a narrow, named exception, never automatic: by hand, once per install of slot B's boot image, only through `tools/mark-slot-b` (ask the human before `--write`), and only for a device whose entry in [CONTRIBUTING](CONTRIBUTING.md) §3.1 names the LUN, the four sectors (both headers and the entry sector holding slot B's boot partition in each copy), the attribute bit and the CRCs it rewrites. That device's plan must also record the slot flags before and after, the rollback for a corrupted GPT, and the way back: stock restored on slot A first, or the owner's explicit acceptance of buttons-only recovery. The storage guard can't block this write, so it never runs from a service or at boot. - **Linux never writes the modem's NV partitions** (`efs`, `efs_backup`, `modem_userdata`, `persist`, `modem_a/b`). The modem's own NV writes persist only in its per-phone overlay on userdata (`/var/lib/omamobile/modem-nv-overlay`, `omamobile-modem` 0.1.15+, off until `/etc/omamobile/modem-nv-overlay-enable` exists), only for the files on the overlay's allow-list (`efs/nv_normal.bin` and its checksum), never for identity or calibration files (`nv_protected.*`, all of `efs_backup`), and only while bound to the checksums in `/etc/omamobile/modem-nv.sha256`, so a new backup sets it aside. `omamobile-modem nv-overlay reset`, then a reboot, returns the modem to the backup alone. Don't add a file to the allow-list without the human's say-so, never write or edit the overlay by hand, and never commit it or copy it to another phone: it is that phone's NV. [MODEM-PLAN](device/cheetah/MODEM-PLAN.md) "NV overlay" - **Never weaken the storage guard.** Don't `blockdev --setrw` a partition or recreate `/dev/sda`. Don't mount Android partitions read-write, and don't add names to the `UFS_RW` allowlist without the human's say-so. The guard is what keeps a bad command from erasing the IMEI. - **Check backups before radio, PMIC, AoC or Trusty work.** Run the checksum check of `efs`, `efs_backup`, `modem_userdata`, `persist` and `modem_a/b` against the off-repo backup first ([MODEM-PLAN.md](device/cheetah/MODEM-PLAN.md) M0.1). If there's no backup, stop. Find each partition by `PARTNAME` in `/sys/class/block/*/uevent`: the Arch root has no `/dev/disk/by-partlabel`. **Take a fresh read-only backup after any stock Android boot** (a slot A fallback counts): stock's modem stack writes `efs`, `persist` and `modem_userdata`, so the old checksums stop matching and the next check can't tell a change of ours from stock's. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c41462101..f14236a6f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,7 +57,8 @@ Every rule here exists because breaking it either bricks a phone or loses data n - Pixels have A/B slots. **Omarchy Mobile only ever lives on slot B.** Slot A keeps the stock factory build, so the phone always has a known-good system to fall back to and a way back to `fastboot` (`adb reboot bootloader`). - **We flash only these partitions:** the device's boot images on slot B (its descriptor's `BOOT_IMAGES`: `boot_b`, `vendor_boot_b` and `dtbo_b`, plus `init_boot_b` and `vendor_kernel_boot_b` where the phone has them), and `userdata`, which holds the Arch root. Slot B's boot images are written by `bin/omamobile flash` (fastboot) and `bin/omamobile push` (over SSH), and on a release install also by `linux-omamobile`'s pacman hook, `omamobile-boot-update` ([RELEASES](docs/RELEASES.md) §5.3, §12 decisions 3 and 10). The hook writes only when `/etc/omamobile/boot-update.conf` says `AUTO_WRITE=yes`, which only `tools/install-phone` writes (or a human by hand, in an approved runbook such as KERNEL-UPDATE-PLAN); it writes only `_b` for the descriptor's `BOOT_IMAGES`, each found by GPT name on the main LUN, on the storage guard's allowlist (`UFS_RW`) and left read-write (`ro` 0) by the guard, which it never changes; it reads every image back, and never reboots. A development phone has no such file, so `bin/omamobile push` stays its only writer. - **Never flash** `bootloader`, `abl`, `bl1`/`bl2`/`bl31`, `pbl`, `radio`/`modem`, `devinfo`, `persist`, `efs*`, `modem_userdata`, `vbmeta`, or anything without an explicit `_b` suffix, except `userdata` (it has no slots) and only through `tools/install-phone`, which pins the phone's serial, asks you to type the codename, checks an allowlist and runs a dry run first. `fastboot flash boot …` without a suffix writes whichever slot is active. -- **Qualcomm A/B phones (Pixel 4 family) store the slot flags in the partition table** (GPT attributes), and flashing `boot_b` clears `slot-successful:b`. Marking slot B bootable means writing four GPT sectors on the boot LUN, which the storage guard can't block. It is allowed only as a narrow, per-device exception, written into this section before it is used: the device, the LUN, the sectors (LBAs 1, 2, last-1 and last), the attribute bit and the CRCs it rewrites. The device's plan records the slot flags before and after, the rollback for a corrupted GPT, and the way back (stock restored on slot A first, or the owner's written acceptance of buttons-only recovery). It runs by hand, once per install of slot B's boot image, never from a service or at boot. No device has an entry yet. +- **Qualcomm A/B phones (Pixel 4 family, OnePlus 6) store the slot flags in the partition table** (GPT attributes), and flashing `boot_b` clears `slot-successful:b`. Marking slot B bootable means writing four GPT sectors on the boot LUN, which the storage guard can't block. It is allowed only as a narrow, per-device exception, written into this section before it is used: the device, the LUN, the four sectors (the primary header, the primary entry sector holding slot B's boot partition, the backup entry sector holding it, and the backup header, as LBAs), the attribute bit and the CRCs it rewrites. The device's plan records the slot flags before and after, the rollback for a corrupted GPT, and the way back (stock restored on slot A first, or the owner's written acceptance of buttons-only recovery). It runs by hand, once per install of slot B's boot image, never from a service or at boot, and only through `tools/mark-slot-b`, which reads the entry from the descriptor's `SLOT_B_MARK` and refuses a GPT that doesn't match it (dry run by default). Entries: + - **enchilada (OnePlus 6):** LUN `sde` (4096-byte sectors, last LBA 786431, 96 entries in three sectors per copy); partition `boot_b`, entry 38; LBAs 1 (primary header), 3 (primary entries 32-63), 786428 (backup entries 32-63) and 786431 (backup header); attribute bit 54 (successful), set and nothing else; CRCs rewritten: the entry-array CRC in both headers, then each header's own CRC. The whole-disk node stays removed by the init: the tool reads and writes through a private node under `/run` that it removes on exit. Plan, flags and rollback: [enchilada NOTES](device/enchilada/NOTES.md#2026-11-09-the-31-entry-for-boot_b); the way back is the owner's [written acceptance](https://github.com/derekross/omarchy-mobile/issues/432#issuecomment-6758389898) that slot A holds the rescue. - **Never relock the bootloader** (`fastboot flashing lock`) while any non-stock image is on the phone. - **Never flash a factory image older than the one installed.** Pixels enforce bootloader anti-rollback. - Before your first flash, check that both slots carry the same bootloader version (`fastboot getvar all`). If they don't, never flash a bootloader partition to fix it: from stock Android, sideload the full OTA for your build twice, so each slot gets the same build. If that doesn't make them match, stop and ask in an issue. diff --git a/device/enchilada/NOTES.md b/device/enchilada/NOTES.md index a3b456784..b1b9443df 100644 --- a/device/enchilada/NOTES.md +++ b/device/enchilada/NOTES.md @@ -47,8 +47,8 @@ until the slot-B install and its CONTRIBUTING.md §3.1 entry are agreed. | bootloader firmware (`xbl`, `abl`, `tz`, `modem`, ...) | OxygenOS firmware, identical on `_a` and `_b` | never written by this port | - | **Writes made by hand.** Every write below was typed by hand, outside -`tools/install-phone` and `bin/omamobile` (whose installer path refuses -`android-v0`), and none will be repeated: +`tools/install-phone` and `bin/omamobile` (whose installer path refused +`android-v0` then), and none will be repeated: - `fastboot`: `flash boot_a` and `flash system_a` (the rescue), `erase dtbo_b`, `flash userdata`, `flash boot_b` twice, and @@ -101,6 +101,68 @@ 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-09: the §3.1 entry for boot_b + +The plan for putting this port on slot B for good, and the one GPT write +it needs ([CONTRIBUTING](../../CONTRIBUTING.md) §3.1, enchilada entry). +Nothing below has run on the phone yet except the read-only GPT copy. + +**The way back.** Slot A holds the Arch rescue, not stock, and stays that +way: the owner's written acceptance of buttons-only recovery through the +rescue is on [#432](https://github.com/derekross/omarchy-mobile/issues/432#issuecomment-6758389898). + +**The install**, each step on the owner's go: + +1. `tools/install-phone --dry-run`, then the install, with + `--bootloader-slots-match unreported` (ABL reports no bootloader + version; every firmware partition is identical on `_a` and `_b` in the + 2026-11-05 backup). It writes `boot_b` and `userdata`, with + `AUTO_WRITE=no`, then `set-active b`. Day-2 kernels come by + `bin/omamobile push`, which finds `boot_b` on `sde`. +2. From that first boot of slot B: `tools/mark-slot-b --device enchilada` + (dry run), compared with the expected values below, then `--write`. + +**The GPT write.** `sde`'s GPT, read 2026-11-09 from the rescue +(`sfdisk --dump`, and the raw sectors of both copies): + +- 4096-byte sectors, 786432 of them; 96 entries of 128 bytes, entries in + LBA 2-4 (primary) and 786427-786429 (backup), headers at 1 and 786431; +- `boot_b` is `sde39`, entry 38, at byte 768 of LBA 3 and of LBA 786428; +- before the install its attributes read `0x003a000000000000`: priority + 2, not active, 7 tries, not successful, not unbootable; +- CRCs then: entries `0x0a9fe94a`, primary header `0xb62ccea8`, backup + header `0x619c2dc8`. `set-active b` rewrites all three, so the tool + checks the live ones rather than these. + +`tools/mark-slot-b` refuses unless the phone booted slot B, the GPT's +two copies are valid and equal, `boot_b` is found once at entry 38 in LBA +3 and 786428, and it is active and not unbootable. It then sets bit 54 +only, rewrites the entry-array CRC and both header CRCs, and changes no +byte outside LBA 1, 3, 786428 and 786431. It writes the primary pair +first and reads it back before the backup pair, so a valid copy exists +at every moment. A dry run of its check against the 2026-11-09 copy found +entry 38 and the CRCs above. + +**Slot flags, before and after** (A and B: successful / unbootable / +retry-count, `current-slot`): + +| Read | `current-slot` | A | B | +| --- | --- | --- | --- | +| before, 2026-11-07 (above) | a | no / no / 5 | no / no / 7 | +| after the install's `set-active b` | to be recorded | | | +| after `mark-slot-b --write` | to be recorded | | | + +**Rollback for a corrupted GPT.** 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 are kept off the repository: they hold the +disk's GUIDs. Should both copies end up invalid, boot the rescue on slot A +by the buttons (it keeps the whole-disk nodes), write the two ranges back +with `dd` (4096-byte blocks, `seek` 0 and 786426), and compare `sfdisk +--dump` with the saved one. That restores the attributes as they were +before the install, so the install's `set-active b` follows it. If only +one copy is invalid, ABL and `sfdisk` use the other, and the tool refuses +to run until both agree. + ## 2026-11-08: the LUN-aware guard, booted RAM-only `fastboot boot` of an initramfs built from commit 2331a85 (the diff --git a/docs/DEVICES.md b/docs/DEVICES.md index 446d6c59e..9e4d1870f 100644 --- a/docs/DEVICES.md +++ b/docs/DEVICES.md @@ -80,5 +80,5 @@ Devices we'd like to support, with the closest starting point. Open an issue to | Pixel 4 XL | coral | SM8150 (Snapdragon 855) | **WIP, community port**, in the matrix above: bring-up notes merged ([#52](https://github.com/derekross/omarchy-mobile/pull/52): [BRINGUP-M1](../device/coral/BRINGUP-M1.md), [NOTES](../device/coral/NOTES.md)), with companion kernel/userspace sources ([omarchy-mobile-coral v0.2.3](https://github.com/HemangKumawat/omarchy-mobile-coral/tree/v0.2.3)); slot-B installer and `CONTRIBUTING.md` §3.1 entry still to land | | POCO F3 | alioth | SM8250 (Snapdragon 870) | the first non-Pixel port: a guarded installer and root image in review ([#25](https://github.com/derekross/omarchy-mobile/pull/25)) | | OnePlus 13 | dodge | SM8750 (Snapdragon 8 Elite) | **WIP, community port**, in the matrix above: device files, notes and the qcom-abl boot images merged ([#111](https://github.com/derekross/omarchy-mobile/pull/111)); its kernel stays in the contributor's fork ([mrlund/linux-omarchy-mobile `dodge-v3-20261101`](https://github.com/mrlund/linux-omarchy-mobile/tree/dodge-v3-20261101); [kernel #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) closed: the SoC series is out of this tree's scope); the guarded installer follows in a later pull request | -| OnePlus 6 | enchilada | SDM845 (Snapdragon 845) | **WIP, community port: [#432](https://github.com/derekross/omarchy-mobile/issues/432)**, in the matrix above: descriptor and notes; RAM-only (`fastboot boot`) until the slot-B install and its CONTRIBUTING.md §3.1 entry are agreed; `omamobile images` packs its header-v0 boot image, and its `UFS_RW_LUNS=sde` (the guard's second-LUN list, #530) comes with the slot-B install | +| OnePlus 6 | enchilada | SDM845 (Snapdragon 845) | **WIP, community port: [#432](https://github.com/derekross/omarchy-mobile/issues/432)**, in the matrix above: descriptor and notes; RAM-only (`fastboot boot`) until the slot-B install runs; `omamobile images` packs its header-v0 boot image, `tools/install-phone` and `omamobile push` write `boot_b` on LUN `sde` (`UFS_RW_LUNS=sde`, the guard's second-LUN list, #530), and its CONTRIBUTING.md §3.1 entry has `tools/mark-slot-b` mark `boot_b` successful once per install | | PinePhone Pro | pinephone-pro | Rockchip RK3399S | No port in this tree yet; mainline's `rk3399-pinephone-pro.dts` is already in our kernel. Prior art: [Omarchy on the PinePhone Pro](https://github.com/FlorencioJP/omarchy-mobile-pinephone-pro) | diff --git a/tests/mark-slot-b b/tests/mark-slot-b index 725599c0e..aeb90ef99 100755 --- a/tests/mark-slot-b +++ b/tests/mark-slot-b @@ -73,8 +73,8 @@ changed=$(cmp -l "$t/disk.orig" "$t/disk.img" | awk '{print int(($1 - 1) / 4096) [[ $changed == "$lbas" ]] || fail "--write changed sectors '$changed', not '$lbas'" sfdisk -q --sector-size 4096 -V "$t/disk.img" > "$t/verify" 2>&1 || { cat "$t/verify"; fail "sfdisk rejects the marked GPT"; } sfdisk --sector-size 4096 -d "$t/disk.img" > "$t/dump" 2>&1 -grep 'name="boot_b"' "$t/dump" | grep -q 'GUID:49,50,51,52,53,54' || { grep boot "$t/dump"; fail "boot_b is not marked in the dump"; } -grep 'name="boot_a"' "$t/dump" | grep -q 'attrs="GUID:48,49,50,52"$' || fail "boot_a changed" +grep 'name="boot_b"' "$t/dump" | grep -c 'GUID:49,50,51,52,53,54' >/dev/null || { grep boot "$t/dump"; fail "boot_b is not marked in the dump"; } +grep 'name="boot_a"' "$t/dump" | grep -c 'attrs="GUID:48,49,50,52"$' >/dev/null || fail "boot_a changed" mark > "$t/out" 2>&1 || fail "the marked GPT fails its own check" grep -q "already marked successful" "$t/out" || fail "a second run does not see the mark"