diff --git a/bin/omamobile b/bin/omamobile index 4e9697e58..56850d56e 100755 --- a/bin/omamobile +++ b/bin/omamobile @@ -80,32 +80,17 @@ load_device() { die "$file:$n: not a KEY=value line" fi done < "$file" - [[ $DEV_BOOT_METHOD == android-v4 ]] \ - || die "$file: unsupported BOOT_METHOD=$DEV_BOOT_METHOD; this command supports only android-v4" - for key in CODENAME SOC PACKAGE DTB DTBO_SOURCE DTBO_BOARD_ID DTBO_BOARD_REV VENDOR_CMDLINE \ - VENDOR_PAGESIZE OS_VERSION OS_PATCH_LEVEL BOOT_IMAGES UFS_RW INITRAMFS_INIT PANEL_SIZE; do - p="DEV_$key" - [[ -n ${!p:-} ]] || die "$file: $key is missing" - done - # ABL picks the base DTB by /soc_id (gs101, gs201) or by /soc_compatible - # (zuma): a descriptor names exactly one of the two. - if [[ -n ${DEV_SOC_IDS:-} && -n ${DEV_SOC_COMPATIBLE:-} ]]; then - die "$file: SOC_IDS and SOC_COMPATIBLE are exclusive; name the one this bootloader matches on" - elif [[ -z ${DEV_SOC_IDS:-} && -z ${DEV_SOC_COMPATIBLE:-} ]]; then - die "$file: SOC_IDS is missing (or SOC_COMPATIBLE, for a bootloader that matches /soc_compatible)" - fi - local sc='^[a-z0-9]+(-[a-z0-9]+)*:0x[0-9a-f]+:[0-9]+:[0-9]+:[0-9]+$' labels=" " - for p in ${DEV_SOC_COMPATIBLE:-}; do - [[ $p =~ $sc ]] || die "$file: SOC_COMPATIBLE entries are label:product_id:major:minor:pkg_mode, not $p" - # One child node per entry: the label names it, so it must be unique - [[ $labels != *" ${p%%:*} "* ]] || die "$file: SOC_COMPATIBLE names ${p%%:*} twice" - labels+="${p%%:*} " - done + case $DEV_BOOT_METHOD in + android-v4|qcom-abl) ;; + *) die "$file: unsupported BOOT_METHOD=$DEV_BOOT_METHOD; this command supports android-v4 and qcom-abl" ;; + esac [[ $DEV_CODENAME == "$DEVICE" ]] || die "$file: CODENAME=$DEV_CODENAME, expected $DEVICE" # Safety: the guard's allowlist may name slot B's boot images and userdata # only, must hold userdata, and every boot image we write must be on it. # initramfs packs this list into the image, and the init checks it again. + # Shared across boot methods: never *_a, never persist/efs/modem/vbmeta. local rw_chars='^[a-z0-9_ ]+$' seen_rw=" " + [[ -n ${DEV_UFS_RW:-} ]] || die "$file: UFS_RW is missing" [[ $DEV_UFS_RW =~ $rw_chars ]] || die "$file: UFS_RW may hold only partition names ([a-z0-9_]) separated by spaces" for p in $DEV_UFS_RW; do [[ $p == *_b || $p == userdata ]] || die "$file: UFS_RW may hold only *_b partitions and userdata, not $p" @@ -115,19 +100,55 @@ load_device() { seen_rw+="$p " done [[ $seen_rw == *" userdata "* ]] || die "$file: UFS_RW must include userdata" - for p in $DEV_BOOT_IMAGES; do slot_b_allowed "$p" || die "$file: ${p}_b is not in UFS_RW"; done - # images builds one of two layouts from these names: a typo must not - # quietly pick the other one. - local seen=" " - for p in $DEV_BOOT_IMAGES; do - [[ " boot init_boot vendor_boot vendor_kernel_boot dtbo " == *" $p "* ]] \ - || die "$file: BOOT_IMAGES may hold only boot, init_boot, vendor_boot, vendor_kernel_boot and dtbo, not $p" - [[ $seen != *" $p "* ]] || die "$file: BOOT_IMAGES names $p twice" - seen+="$p " - done - for p in boot vendor_boot dtbo; do - [[ $seen == *" $p "* ]] || die "$file: BOOT_IMAGES must include $p" - done + + if [[ $DEV_BOOT_METHOD == qcom-abl ]]; then + for key in CODENAME SOC PACKAGE DTB BOOT_IMAGES UFS_RW INITRAMFS_INIT PANEL_SIZE; do + p="DEV_$key" + [[ -n ${!p:-} ]] || die "$file: $key is missing" + done + # Qualcomm ABL boots a single header-v2 boot.img (kernel + ramdisk + DTB). + local seen=" " + for p in $DEV_BOOT_IMAGES; do + [[ $p == boot ]] || die "$file: qcom-abl BOOT_IMAGES may hold only boot, not $p" + [[ $seen != *" $p "* ]] || die "$file: BOOT_IMAGES names $p twice" + seen+="$p " + done + [[ $seen == *" boot "* ]] || die "$file: BOOT_IMAGES must include boot" + slot_b_allowed boot || die "$file: boot_b is not in UFS_RW" + else + for key in CODENAME SOC PACKAGE DTB DTBO_SOURCE DTBO_BOARD_ID DTBO_BOARD_REV VENDOR_CMDLINE \ + VENDOR_PAGESIZE OS_VERSION OS_PATCH_LEVEL BOOT_IMAGES UFS_RW INITRAMFS_INIT PANEL_SIZE; do + p="DEV_$key" + [[ -n ${!p:-} ]] || die "$file: $key is missing" + done + # ABL picks the base DTB by /soc_id (gs101, gs201) or by /soc_compatible + # (zuma): a descriptor names exactly one of the two. + if [[ -n ${DEV_SOC_IDS:-} && -n ${DEV_SOC_COMPATIBLE:-} ]]; then + die "$file: SOC_IDS and SOC_COMPATIBLE are exclusive; name the one this bootloader matches on" + elif [[ -z ${DEV_SOC_IDS:-} && -z ${DEV_SOC_COMPATIBLE:-} ]]; then + die "$file: SOC_IDS is missing (or SOC_COMPATIBLE, for a bootloader that matches /soc_compatible)" + fi + local sc='^[a-z0-9]+(-[a-z0-9]+)*:0x[0-9a-f]+:[0-9]+:[0-9]+:[0-9]+$' labels=" " + for p in ${DEV_SOC_COMPATIBLE:-}; do + [[ $p =~ $sc ]] || die "$file: SOC_COMPATIBLE entries are label:product_id:major:minor:pkg_mode, not $p" + # One child node per entry: the label names it, so it must be unique + [[ $labels != *" ${p%%:*} "* ]] || die "$file: SOC_COMPATIBLE names ${p%%:*} twice" + labels+="${p%%:*} " + done + for p in $DEV_BOOT_IMAGES; do slot_b_allowed "$p" || die "$file: ${p}_b is not in UFS_RW"; done + # images builds one of two layouts from these names: a typo must not + # quietly pick the other one. + local seen=" " + for p in $DEV_BOOT_IMAGES; do + [[ " boot init_boot vendor_boot vendor_kernel_boot dtbo " == *" $p "* ]] \ + || die "$file: BOOT_IMAGES may hold only boot, init_boot, vendor_boot, vendor_kernel_boot and dtbo, not $p" + [[ $seen != *" $p "* ]] || die "$file: BOOT_IMAGES names $p twice" + seen+="$p " + done + for p in boot vendor_boot dtbo; do + [[ $seen == *" $p "* ]] || die "$file: BOOT_IMAGES must include $p" + done + fi # AVB hash footers, for a bootloader whose vbmeta chains these partitions # (zuma): image:partition_size, each a boot image, named once, the size # a whole number of 4 KiB blocks. Their rollback index and security patch @@ -525,9 +546,21 @@ cmd_initramfs() { cmd_images() { load_device - local img="$KERNEL_OUT/images" tools="$SRC_DIR/system/tools/mkbootimg" + local img="$KERNEL_OUT/images" + # Pixel path matches main: SRC_DIR only. Tree-local mkbootimg is for qcom-abl. + local tools="$SRC_DIR/system/tools/mkbootimg" + if [[ $DEV_BOOT_METHOD == qcom-abl ]]; then + tools="$ROOT/system/tools/mkbootimg" + [[ -f $tools/mkbootimg.py ]] || tools="$SRC_DIR/system/tools/mkbootimg" + fi local dtc="$KERNEL_OUT/scripts/dtc/dtc" boot="$KERNEL_OUT/arch/arm64/boot" local dtb="$boot/dts/$DEV_DTB" + # qcom-abl needs the device's chainload dir before we touch a build. + if [[ $DEV_BOOT_METHOD == qcom-abl ]]; then + local chainload="$ROOT/device/$DEVICE/chainload" + [[ -d $chainload && -f $chainload/init && -f $chainload/stage2-dtb.py ]] || + die "qcom-abl needs device/$DEVICE/chainload/ (init + stage2-dtb.py); refusing so the next phone does not inherit dodge's splash/panel/RSC" + fi [[ -f "$boot/Image" && -f "$dtb" ]] || die "build the kernel first: omamobile kernel" [[ -f "$KERNEL_OUT/initramfs.cpio.lz4" ]] || die "build the initramfs first: omamobile initramfs" # The init insmods INITRAMFS_MODULES, which only load into the kernel they @@ -558,6 +591,56 @@ cmd_images() { say "Kernel: Image.lz4" lz4 -l -9 -f -q "$boot/Image" "$img/Image.lz4" + if [[ $DEV_BOOT_METHOD == qcom-abl ]]; then + # Two-stage chain (device/$DEVICE/chainload, tools/dodge-chain): ABL refuses + # header v2 under fastboot boot, and a v4 boot.img ramdisk is ignored + # (stock DTB from vendor_boot). Stage 1 is a kernel-only header v4 image + # with a built-in /omamobile init that kexecs stage 2 (this Image, the + # board DTB with the live memory map, and the shared initramfs). LIVE_DTB + # is required and never committed. Pixel paths below are unchanged. + [[ -n ${LIVE_DTB:-} && -f ${LIVE_DTB:-} ]] || + die "qcom-abl images need LIVE_DTB= path to the rooted live FDT (never committed)" + if [[ ! -f $tools/mkbootimg.py ]]; then + command -v mkbootimg >/dev/null || + die "qcom-abl images need $ROOT/system/tools/mkbootimg/mkbootimg.py or $SRC_DIR/system/tools/mkbootimg/mkbootimg.py (or mkbootimg on PATH)" + fi + local chain_out="${CHAIN_OUT:-$KERNEL_OUT/chain}" + local chainload="$ROOT/device/$DEVICE/chainload" + # Descriptor CMDLINE feeds stage 2 when set; else the known-good default. + local stage2_cmdline="${STAGE2_CMDLINE:-}" + if [[ -z $stage2_cmdline ]]; then + if [[ -n ${DEV_CMDLINE:-} ]]; then + stage2_cmdline="rdinit=/init ${DEV_CMDLINE} omamobile.ufs-probe" + else + stage2_cmdline="rdinit=/init clk_ignore_unused pd_ignore_unused panic=10 console=tty0 omamobile.ufs-probe" + fi + fi + say "Boot image (qcom-abl chain, header v4): boot via tools/dodge-chain ($DEVICE)" + KERNEL_DIR="$KERNEL_DIR" \ + KERNEL_BASE="$KERNEL_BASE" \ + WORK="$WORK" \ + IMAGE="$IMAGE" \ + CLANG_DIR="$CLANG_DIR" \ + SRC_DIR="$SRC_DIR" \ + CHAINLOAD_DIR="$chainload" \ + STAGE2_OUT="$KERNEL_OUT" \ + STAGE2_IMAGE="$boot/Image" \ + STAGE2_DTB_IN="$dtb" \ + STAGE2_INITRD="$KERNEL_OUT/initramfs.cpio.lz4" \ + CHAIN_OUT="$chain_out" \ + LIVE_DTB="$LIVE_DTB" \ + DTB_OPTS="${DTB_OPTS:-splash fb}" \ + STAGE2_CMDLINE="$stage2_cmdline" \ + SLOT_SUFFIX="${SLOT_SUFFIX:-${DEV_OMAMOBILE_SLOT:+_$DEV_OMAMOBILE_SLOT}}" \ + JOBS="$JOBS" \ + "$ROOT/tools/dodge-chain" pack + cp -- "$chain_out/images/boot-chain.img" "$img/boot.img" + printf '%s\n' "$DEV_CODENAME" > "$img/DEVICE" + ls -lh "$img"/*.img + sha256sum "$img/boot.img" + return 0 + fi + local entry label id base="" out dtbs=() if [[ -n ${DEV_SOC_COMPATIBLE:-} ]]; then # ABL matches the base DTB on the children of /soc_compatible (product_id, @@ -776,6 +859,12 @@ cmd_fastboot() { cmd_flash() { local img="$KERNEL_OUT/images" p load_device + # Qualcomm ABL keeps slot flags in the GPT. A fastboot set_active can clear + # successful and refill retries; the bit-54 mark has no §3.1 entry yet. + # Refuse here; day-2 updates use push once that path is viable, and the + # installer PR can reopen flash with the rest. + [[ $DEV_BOOT_METHOD != qcom-abl ]] || + die "flash refuses BOOT_METHOD=qcom-abl (no in-tree day-2 update path yet; see device/$DEVICE/BRINGUP-M1.md)" images_for_device "$img" in_fastboot || die "phone not in fastboot (try: omamobile fastboot)" local serial @@ -808,6 +897,11 @@ 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 != 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" "$ssh" true || die "phone not reachable at 172.16.42.1" # Refuse before any write. A phone whose initramfs has no reboot-to would diff --git a/device/dodge/BRINGUP-M1.md b/device/dodge/BRINGUP-M1.md new file mode 100644 index 000000000..6448228ac --- /dev/null +++ b/device/dodge/BRINGUP-M1.md @@ -0,0 +1,210 @@ + +# OnePlus 13 (dodge): first light and install record + +Status (2026-10-29): boots native Arch / Omarchy on SM8750 from slot B's +`boot` partition. Companion kernel under review: +[linux-omarchy-mobile #115](https://github.com/derekross/linux-omarchy-mobile/pull/115). +This document is the CONTRIBUTING §5 / §6 first-light **record** of how this +phone was installed. It is not a procedure for other owners: the guarded +inactive-slot installer and firmware-match helper are deferred to a later PR. + +## 1. Sources + +- **Kernel base:** `omamobile` on + [derekross/linux-omarchy-mobile](https://github.com/derekross/linux-omarchy-mobile). +- **Board series:** subsystem-split commits on `dodge/pr-kernel-v2` + ([#115](https://github.com/derekross/linux-omarchy-mobile/pull/115)). Config + profile: `gpu2` (`CONFIG_QCOM_IPA=m`, MSM DRM). +- **Device tree:** `arch/arm64/boot/dts/qcom/sm8750-oneplus-dodge.dts` + (`compatible = "oneplus,dodge", …`). +- **Userspace:** `device/dodge/` and `packages/omamobile-device-dodge` in this + repository. Shared `initramfs/init` (storage guard + allowlist); no + dodge-forked init. **Untested on this phone from this PR tip until a + `tools/phone-smoke` report exists** (see §6). + +## 2. Descriptor and boot image + +[device.conf](device.conf): `BOOT_METHOD=qcom-abl`, `BOOT_IMAGES=boot`, +`UFS_RW="boot_b userdata"`, `OMAMOBILE_SLOT=b`, `COMPATIBLE="oneplus,dodge"`, +`FASTBOOT_PRODUCT=sun`. Omarchy runs on slot B; stock stays on slot A. + +`userdata` is on LUN **sda** (`sda15`); `boot_b` is on LUN **sde** (`sde48`). +The shared init only opens allowlisted partitions when they sit on `sda`, so +`boot_b` stays read-only today — good for the guard, but day-2 `push` cannot +rewrite the kernel until a LUN-aware change (optional follow-up, not in the +smoke image). Logical block size is 4096 on both LUNs. + +### Why the image is a two-stage chain + +This phone's ABL: + +1. **Refuses header v2** under `fastboot boot` (stays in fastboot). +2. **Starts header v4** but pairs the uploaded image with the flashed + `init_boot` / `vendor_boot`: stock DTB from `vendor_boot`, and the + uploaded boot ramdisk does not run. +3. The only RAM-only path to **our** DTB without flashing `vendor_boot` is + a built-in `/omamobile/` init + `CONFIG_CMDLINE_FORCE + rdinit=/omamobile/init`, packed as a kernel-only header v4 image, which + then `kexec -c` into stage 2. + +`bin/omamobile images` with `BOOT_METHOD=qcom-abl` builds that chain via +`tools/dodge-chain` / [chainload/](chainload/). Pixel descriptors are +unchanged. + +**Stage 1** (`device/dodge/chainload/init`) runs as **PID 1**. It mounts +proc (and optionally sysfs) only and **never opens a block device** +(soft-check: if `/proc/mounts` lists a `/dev/sd*` mount, stage 1 holds and +resets instead of kexec). Stage 1's `.config` disables `SCSI_UFS_QCOM` and +`SCSI_UFSHCD`, so the kernel does not probe UFS on stock's DTB either +(CONTRIBUTING §3.2). It also `cmp`s this boot's memory `reg` with the copy +saved at pack time from `$LIVE_DTB`, and appends `androidboot.slot_suffix` from `/proc/bootconfig`, +then `/proc/device-tree/chosen/bootargs`, then the packed `/omamobile/slot_suffix` +(from `OMAMOBILE_SLOT` in device.conf — this ABL omits the property under +`fastboot boot`) into stage 2's command line (stage 1's +own `/proc/cmdline` is `CMDLINE_FORCE`d and has no ABL keys). Stage 2 is the PR kernel +`Image`, the dodge DTB (live memory map from `$LIVE_DTB`, never committed), +and the shared initramfs from `bin/omamobile initramfs`. Stage 2 carries +the shared storage guard. + +`bin/omamobile flash` and `bin/omamobile push` both **refuse** +`BOOT_METHOD=qcom-abl` in this PR: a fastboot `--set-active` on this ABL +may clear the successful bit and refill retries, undoing the GPT bit-54 +mark that has no §3.1 entry yet, and `push` cannot see `boot_b` on sde +with today's sda-only lookup. **There is no in-tree day-2 update path for +dodge yet.** The installer PR can reopen those paths with the rest. + +## 3. How this phone was installed (record) + +On 2026-10-28, from private branch `oneplus13-dodge`, OxygenOS family +CPH2653 16.0.10: + +1. **Firmware match (ARB).** OxygenOS anti-rollback means booting a slot whose + `xbl_config` / firmware is below the fuse floor can hard-brick. Before + activating slot B, every A/B firmware pair was hashed; **27 differed**. + A byte-exact A→B copy of abl/aop/…/xbl/modem/… was done with sha256 + read-back. Left untouched: vbmeta, qweslicstore, oplusstanvbk, + modemst/fsg/fsc/persist/EFS/oplusdycnvbk/RPMB. A later helper RAM-boot + reported RESULT=MATCH with no writes. +2. **Flash.** Omarchy `boot_b` and Arch on `userdata`; stock OTA `boot.img` + left on `boot_a` only (not booted). `--set-active=b`, reboot. +3. **Boot-success (GPT bit 54).** Qualcomm ABL keeps the slot-successful flag + in GPT attribute bit 54 of `boot_` (primary + backup, both CRCs). + Without it, ABL burns a retry each boot, marks the slot unbootable, and + falls back to slot A (stock over Omarchy userdata). On this phone the bit + was set by hand after the first clean boot. Detail for Derek's §3.1 entry + is in §7 below. A oneshot service is not shipped in this PR. + +`version-bootloader` is empty on this ABL, so a Pixel-style BL string check +cannot substitute for the firmware match. + +## 4. Modem (opt-in) and off-phone backups + +Units under [modem/](modem/) stay inert unless +`/etc/omamobile/modem-probe.enable` exists. With the flag, each boot restores a +named good EFS *copy* under `/var/lib/omamobile/efs-good/` (read-only `dd` of +the phone's own partitions; never `-P` on the live partitions; never committed +to git). See [modem/README.md](modem/README.md). + +Per CONTRIBUTING §3.3, before any modem session this phone also keeps +**off-phone**, read-only backups of `modemst1`, `modemst2`, `fsg`, `fsc`, +`persist`, and the oplus NV partitions, with a `SHA256SUMS` checked before +each session. Those backups are never in git. + +## 5. Shared init assumptions (Pixel → dodge) + +- Allowlisted partitions are writable only when they live on `sda`. + `userdata` does (`sda15`); `boot_b` does not (`sde48`) — see §2. +- If `boot_arch` fails, the shared init waits ~45 s for a USB host then + triggers `sysrq c`. **Panic behaviour on this ABL is still open:** stage 2 + carries `panic=10`, so the kernel resets after 10 s. With + `slot-successful:b=yes` the expected path is a reboot back into slot B + rather than falling back to A, but whether this ABL enters a dump mode + first has not been confirmed with a deliberate `sysrq c` on a booted B. + Do not treat "returns to fastboot" as verified until that test is run. +- **Do not use `omamobile fastboot` on this phone yet.** That tool falls + through to `sysrq c` when `reboot-to bootloader` is ignored, and we have + not characterised what a panic does on this ABL. Prefer the buttons + instead of `omamobile fastboot` / sysrq-c. Button behaviour on this phone + (Omarchy Mobile on slot B; confirmed 2026-10-31): + - **Forced restart (working):** holding **Power** alone does **not** force + a restart under Omarchy Mobile — it opens the Omarchy power menu + (tested 2026-10-31). Holding **Power + Volume Up + Volume Down** until + the phone resets is what has worked for us when hung (confirmed; no + specific hold time claimed). + - **Fastboot / bootloader (working):** from power-off, hold **Volume Down** + while powering on (confirmed; usual method here). +- Until a `tools/phone-smoke` report from images built by + `bin/omamobile images` on this branch exists, treat the shared init path + as **untested on dodge**. + +## 6. Phone-smoke evidence + +| Gate | Evidence | Result | +| --- | --- | --- | +| Firmware-match | sha256 of every `*_a`/`*_b` pair: **27 differed**. Byte-exact A→B copy (read-back verified). Left untouched: vbmeta, qweslicstore, oplusstanvbk, modemst/fsg/fsc/persist/EFS/oplusdycnvbk/RPMB | pass | +| Inactive-slot boot | Omarchy `boot_b` set active; stock OTA `boot.img` on `boot_a` only | pass | +| `version-bootloader` | empty on this ABL | noted | +| Boot-success | GPT bit 54 set by hand on `boot_b` only after first clean boot (`boot_a` already set by stock) | pass | +| PR-tip chain smoke (2026-10-30 Europe/Copenhagen) | Morning (~07:46): RAM-only `fastboot boot` of chain image from this branch (no flash, no set_active). Stage-2 kernel was the private `7.3.0-rc6-dodge-gpu2` build (not the #115 head); package still `omamobile-device-dodge 20261016-1`. `tools/phone-smoke` overall **unknown**: required storage-guard/root/kernel-health/USB ok; display/GPU/touch/buttons/battery/sensors ok; required `boot` skip (forced cmdline, no slot suffix); required `session` not ok (Hyprland not up at ~40 s); sound cards none; Wi-Fi link down at that moment. A later #115-head RAM boot (~09:28) **hung** on the console (dual memory map; fixed in kernel DTS + stage2-dtb). Re-smoke of tip `f5e354e1c` after the fix: chain image booted; SSH in about 26 s; storage, root, USB and Hyprland ok; live FDT one `memory@a0000000`. GPU, touch, Wi-Fi, BT and battery failed only because the rootfs has no `/usr/lib/modules/` tree for `uname` `7.3.0-rc6-gf5e354e1cf2b` (only `7.3.0-rc6-dodge-gpu2` and `.held`; those drivers are `=m`). Phone returned to slot B. | partial | +| PR-tip chain smoke (2026-10-30 evening, Europe/Copenhagen) | First RAM boot (`7f5235b` / Image `1dc357e5ec2d`, boot.img `6650b71d…`): packed slot `_b` ok; after tmpfs overlay a bare `modprobe msm` (no dispcc) left msm-mdss at `-110` — display-msm had stamped on missing-.ko. Fix boot (same Image, stage-1 with slot-source kmsg + display-msm no-stamp; boot.img `fbc820c3…`): early unit logged `not stamping`; after overlay `modprobe dispcc_sm8750` then re-bind gave GMU + DSI-1; phone-smoke **GPU/touch/Wi-Fi/BT/battery/sound/sensors ok** (modem+adsp running). Returned to slot B; gpu2 healthy. | done | + +## 7. GPT bit-54 record (for §3.1) + + +**Modules on RAM-boot test Images.** `omamobile-kmod-overlay` needs `/usr/lib/modules/$uname.held` (absent for tip SHAs). `omamobile-display-msm` then finds no `dispcc-sm8750.ko` and **must not stamp** `/run/omamobile-display-msm.tried`, so a later tmpfs overlay on `/lib/modules/$uname` plus `modprobe dispcc_sm8750` **before** any `udevadm trigger` / `modprobe msm`, then `systemctl restart omamobile-display-msm`, can still bind msm. Triggering udev first loads msm without clocks and burns the deferred-probe timeout. Stamping on the missing-.ko path left msm-mdss at `-110` after bare `modprobe msm` past the deferred-probe timeout. + +**Shape:** by hand, once per install of slot B's boot image — never from a +service or at boot (§3.1). + +| Item | Value | +| --- | --- | +| LUN | **sde** (boot_a=sde12, boot_b=sde48); userdata on **sda** (sda15) | +| Sector size | 4096 logical | +| Partition entry / bit | GPT attribute **bit 54** on the `boot_b` entry | +| Record size | At **4096-byte** logical sectors the GPT record is **8 sectors in 4 files**: primary header (LBA 1), primary entries (LBAs 2–4, 3 sectors), backup entries (LBAs 634875–634877, 3 sectors), backup header (LBA 634879). "Four sectors" would only be right at 512-byte sectors. | +| Rollback (corrupted GPT) | Off-phone restore of the 4 dump files onto the matching LBAs. sde also holds `abl`/`xbl`; if both primary and backup GPTs on sde are corrupt the phone is likely EDL-only. Whether this ABL accepts `fastboot flash partition:` has **not** been checked (read-only docs / getvar only — not tried). | +| Slot check on RAM boots | Under `fastboot boot` this ABL passes `androidboot.slot_suffix` in **neither** `/proc/bootconfig` nor `chosen/bootargs` (stage-1 kmsg dumps both; both empty of the property on tip RAM boots). Stage 1 therefore keeps the packed `/omamobile/slot_suffix` fallback from `OMAMOBILE_SLOT` and logs `source=packed`. phone-smoke's boot check on those RAM boots reflects the descriptor, not a live ABL property. Live bootconfig/bootargs still win when present. | +| Way back | With the phone's serial: `fastboot -s --set-active=a` then a userdata wipe before booting stock A over Omarchy `userdata`. Stock's own factory-reset path when it finds a foreign userdata has **not** been confirmed on this phone, so the record still uses `fastboot -s -w` (unsuffixed erase of `userdata`, and on many Qualcomm phones `metadata` too). Replace `` with the value from `fastboot devices`; never paste a real serial into the repo. | + +### Morning read-only dump (2026-10-30 ~07:49 Europe/Copenhagen) + +No GPT write this round. On 2026-10-28 **only `boot_b`'s** bit 54 was +written by hand (no pre-write dump). `boot_a`'s bit 54 was already set +(stock) and was **not** written by hand. The numbers below are the +**current** state, not a before/after. The next by-hand write must record +both. + +| Item | Value | +| --- | --- | +| logical sector size sde / sda | **4096** / 4096 | +| sde last LBA | 634879 | +| primary header LBA | 1 | +| primary entries LBA | 2 (96 × 128 B over 3 sectors) | +| backup entries LBA | 634875 (3 sectors) | +| backup header LBA | 634879 | +| primary header CRC32 | 0x04411e69 (matches calc) | +| backup header CRC32 | 0x15af848b (matches calc) | +| partition array CRC32 | **0x4950baae** (primary + backup match) | +| boot_a attrs / bit 54 | 0x0072000000000000 / **1** (priority 2, retry 6, successful) | +| boot_b attrs / bit 54 | 0x0077000000000000 / **1** (priority 3, active, retry 6, successful) | + +Fastboot getvars from the same morning (and again 2026-10-29 21:50 +Europe/Copenhagen), matching the decoded attrs: + +| getvar | a | b | +| --- | --- | --- | +| `slot-successful` | yes | yes | +| `slot-unbootable` | no | no | +| `slot-retry-count` | 6 | 6 | +| `current-slot` | | **b** | + +Off-phone raw dumps (`sde-prim-hdr.bin`, `sde-bak-hdr.bin`, +`sde-prim-entries.bin`, `sde-bak-entries.bin`) stay on the desktop only — +never in the repo. + +### Still open for §3.1 + +1. Deliberate panic / `sysrq c` on a booted slot B, then re-read fastboot + slot-successful / unbootable / retry-count for both slots. +2. Concrete GPT restore path that avoids EDL if both copies on sde are bad + (whether `fastboot flash partition:` works on this ABL). diff --git a/device/dodge/NOTES.md b/device/dodge/NOTES.md new file mode 100644 index 000000000..557ee8193 --- /dev/null +++ b/device/dodge/NOTES.md @@ -0,0 +1,111 @@ + +# OnePlus 13 (dodge) + +Status (2026-10-30): native Arch Linux ARM / Omarchy Mobile on Qualcomm SM8750 +(`7.3.0-rc6-dodge-gpu2` lineage on the installed slot B; #115 head smoke via +RAM-only `fastboot boot`). Display, GPU (Adreno 830), touch, Wi-Fi, +Bluetooth pairing, speakers/mics, sensors (autorotate), USB gadget networking +and SSH work on the phone. Modem (MPSS + IPA + ModemManager + NetworkManager +cellular) works behind an opt-in flag with a per-phone EFS restore (see +[modem/README.md](modem/README.md)); no modem blobs or EFS snapshots are in +this repository. Fingerprint, cameras and NFC are not started. + +Kernel series: [linux-omarchy-mobile #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) +(`dodge/pr-kernel-v2`; subsystem-split; gpu2 + IPA). Device tree: +`arch/arm64/boot/dts/qcom/sm8750-oneplus-dodge.dts`. Userspace: this tree's +`device/dodge/` and `packages/omamobile-device-dodge` (0.1.0). + +Descriptor: `BOOT_METHOD=qcom-abl`, `OMAMOBILE_SLOT=b`, +`UFS_RW="boot_b userdata"`. Omarchy runs on slot B; stock stays on slot A. +`boot_b` is on UFS LUN **sde** (sde48); userdata is **sda15**. The shared +init's sda-only guard therefore keeps `boot_b` read-only, so day-2 `push` +cannot rewrite it on this phone until a LUN-aware change (optional follow-up). +Shared init untested on dodge until a full `tools/phone-smoke` of both PR +heads from images built by `bin/omamobile images` on this branch (see +[BRINGUP-M1.md](BRINGUP-M1.md) §5). +The guarded inactive-slot installer and firmware-match helper are deferred +to a later PR; how this phone was installed (firmware A→B copy for ARB, +GPT bit-54 mark) is a record in [BRINGUP-M1.md](BRINGUP-M1.md), not a +procedure for others. Never flash xbl, abl, vbmeta or modem from an image. + +**Boot image shape.** Every image that has booted dodge so far is a +header-v4, ramdisk-empty, empty-cmdline `boot.img` whose kernel carries a +built-in `/omamobile/` chain-loader that kexecs stage 2 (our Image, DTB, +initramfs). This ABL does not start header v2 under `fastboot boot`, and +ignores a ramdisk in an uploaded v4 `boot.img` (stock `vendor_boot` still +supplies the DTB for stage 1). `bin/omamobile images` with +`BOOT_METHOD=qcom-abl` now packs that chain via `tools/dodge-chain` +(tree-local / `$SRC_DIR` `mkbootimg.py`, header v4); a plain header-v2 +qcom-abl pack is still not bootable here. See [chainload/](chainload/) +and [BRINGUP-M1.md](BRINGUP-M1.md) §4 / §6. + +## Feature matrix (phone-verified) + +| Block | Status | Notes | +| --- | --- | --- | +| Boot | testing | Omarchy on `boot_b` (2026-10-28); stock `boot_a` kept; GPT bit 54 marked by hand (kernel in review, [#115](https://github.com/derekross/linux-omarchy-mobile/pull/115)) | +| Storage | testing | UFS; guard allowlists `boot_b` and `userdata` (shared `initramfs/init`) | +| Display | testing | Samsung panel through msm/dpu; brightness and DPMS; warm-boot drop fixed (QTB read) | +| GPU | testing | Adreno 830 (gpu2); glmark2 / Freedreno on the phone; Vulkan untested | +| Touch | testing | Synaptics over SPI | +| Buttons | testing | Power and volume | +| USB net | testing (kernel in review, #115) | CDC NCM gadget + ACM console; SSH. Gap: gadget stuck after cable replug until reboot | +| Wi-Fi | testing | WCN7860 (peach) / ath12k; autoconnect and 5 GHz | +| Bluetooth | testing (kernel in review, #115) | WCN7860; pairing verified; A2DP untested (no headset yet) | +| Battery | testing (kernel in review, #115) | gauge reads; charging path not fully claimed | +| Speakers/mics | testing | AW882xx + UCM2 + PipeWire; speaker, earpiece and built-in mics; headset plug untested | +| Sensors | testing | SSC via hexagonrpc / libssc; accel, proximity, compass; autorotate | +| Modem | testing | MPSS + IPA + MM + NM; LTE registration and data; EFS restore every boot; opt-in flag; calls/SMS untested | +| Suspend | WIP | screen-off idle works; s2idle not yet the default | +| Fingerprint | no | | +| Cameras | no | | +| NFC | no | | +| Charging / Haptics / Torch / GNSS | no | | +| AoC | - | Tensor-only block | + +## 2026-10-28: matrix evidence + +Phone-verified summary for [docs/DEVICES.md](../../docs/DEVICES.md). Companion +kernel in review as +[linux-omarchy-mobile #115](https://github.com/derekross/linux-omarchy-mobile/pull/115). +Full narrative for the slot-B move is in [BRINGUP-M1.md](BRINGUP-M1.md) §5. + +| Block | What was run on the phone | Status word | +| --- | --- | --- | +| Boot / storage | Firmware A→B match (27 pairs, sha256 read-back); Omarchy on `boot_b`; GPT bit 54 marked by hand; stock OTA `boot` kept on `boot_a` | testing | +| Display | msm/dpu panel up; brightness and DPMS; warm-boot drop closed (QTB read on MDSS enable; Martin verified cold start and idle/wake 2026-10-24) | testing | +| GPU | Adreno 830 via Freedreno on gpu2; Hyprland and glmark2 on the phone; Vulkan (turnip) not run | testing | +| Touch / buttons | `touchpanel` input; power and volume keys | testing | +| USB net | CDC NCM + ACM + SSH. Known gap: after a cable replug the UDC can stay stuck until a reboot | testing (kernel in review, #115) | +| Wi-Fi | WCN7860 / ath12k; autoconnect, DHCP, 5 GHz | testing | +| Bluetooth | hci0 up; pairing with another phone verified; A2DP / headset audio not tested | testing (kernel in review, #115) | +| Battery | fuel-gauge capacity reads; charging path not claimed | testing (kernel in review, #115) | +| Speakers/mics | Speaker and earpiece heard; built-in mic record+playback hands-on; USB-C headset plug untested | testing | +| Sensors | Accelerometer, proximity, compass through SSC; autorotate on by default after install | testing | +| Modem | With `/etc/omamobile/modem-probe.enable` and IPA (gpu2): LTE registration and data; EFS restore every boot; calls and SMS untested. Flag is opt-in in the package | testing | +| Suspend | Screen-off idle with GDSC off; `systemctl suspend` / s2idle not the default | WIP | + +## Provenance + +- Board DTS and driver enablement authored for Omarchy Mobile from public + mainline SM8750 support, OnePlus 13 DT fragments, and bring-up on this phone. +- Audio codec unmute and panel sequence: see kernel commit messages and + `Assisted-by` / `Signed-off-by` trailers. +- Missing upstream sign-offs from earlier community fragments (index986 / + ROCKNIX / Teguh) are listed in the kernel PR description for the maintainer. + +## What is not in this tree + +Lab notebooks (`dev-docs/`), DIAG trials, out-of-tree splash/fastrpc experiments, +EFS snapshots, modem firmware blobs, and AGENTS/PLAN files stay on the private +bring-up branch. The modem units document how to take **read-only** `dd` +copies of the phone's own EFS partitions onto the device; those copies are +never committed. + + +## Desktop setup (owners) + +`device/dodge/desktop/setup-stock` takes a required `USER` argument (no +default account name). It deliberately skips Omarchy's ufw step so root SSH +over Wi-Fi keeps working on this phone; that is an owner choice, not stock +Omarchy Mobile policy. USB-net SSH is unaffected either way. diff --git a/device/dodge/audio/OnePlus-dodge.m4 b/device/dodge/audio/OnePlus-dodge.m4 new file mode 100644 index 000000000..107f663ab --- /dev/null +++ b/device/dodge/audio/OnePlus-dodge.m4 @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: BSD-3-Clause +# AudioReach topology for the OnePlus 13 (dodge, SM8750). +# Derived from linux-msm/audioreach-topology SM8550-HDK.m4 and +# Google-SC7180-WSA-Speakers-SEC-I2S-VA-DMIC-WCD-TX3.m4 (Copyright, Linaro Ltd, 2023). +# Speakers: two smart amplifiers on Secondary MI2S (TLMM i2s1), playback on SD1. +# Headset: WCD939x HPH over RX codec DMA 0 (USB-C analog), fed from MultiMedia1. +# Microphones: WCD939x ADCs over SoundWire TX into TX codec DMA 3, captured on MultiMedia3. +# Build: m4 -I OnePlus-dodge.m4 > OnePlus-dodge.conf +# alsatplg -c OnePlus-dodge.conf -o OnePlus-dodge-tplg.bin +# Install on the phone as /lib/firmware/qcom/sm8750/OnePlus-dodge-tplg.bin +include(`audioreach/audioreach.m4') +include(`audioreach/stream-subgraph.m4') +include(`audioreach/device-subgraph.m4') +include(`util/route.m4') +include(`util/mixer.m4') +include(`audioreach/tokens.m4') +dnl Playback MultiMedia1 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA1, + `S16_LE', 48000, 48000, 2, 2, + 0x00004001, 0x00004001, 0x00006001, `110000') +dnl Capture MultiMedia3 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-capture.m4, FRONTEND_DAI_MULTIMEDIA3, + `S16_LE', 48000, 48000, 1, 2, + 0x00004003, 0x00004003, 0x00006020, `110000') +dnl Secondary MI2S Playback (speaker amplifiers). The amplifiers listen on +dnl i2s1 data1 (gpio124), the DSP's SD1: on SD0 they never left the noise gate. +DEVICE_SG_ADD(audioreach/subgraph-device-i2s-playback.m4, `Secondary', SECONDARY_MI2S_RX, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_LPAIF, I2S_INTF_TYPE_SECONDARY, SD_LINE_IDX_I2S_SD1, DATA_FORMAT_FIXED_POINT, + 0x00004005, 0x00004005, 0x00006050, `SECONDARY_MI2S_RX') +dnl WCD RX Playback (USB-C analog headset) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-playback.m4, `RX_CODEC_DMA_RX_0', RX_CODEC_DMA_RX_0, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_RX0, 0, DATA_FORMAT_FIXED_POINT, + 0x00004007, 0x00004007, 0x00006070) +dnl WCD TX Capture (built-in and headset microphones) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-capture.m4, `TX_CODEC_DMA_TX_3', TX_CODEC_DMA_TX_3, + `S16_LE', 48000, 48000, 1, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_TX3, 0, DATA_FORMAT_FIXED_POINT, + 0x00004009, 0x00004009, 0x00006090) +dnl +STREAM_DEVICE_PLAYBACK_MIXER(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX'', ``MultiMedia1'') +STREAM_DEVICE_PLAYBACK_ROUTE(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX Audio Mixer'', ``MultiMedia1, stream0.logger1'') +STREAM_DEVICE_PLAYBACK_MIXER(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0'', ``MultiMedia1'') +STREAM_DEVICE_PLAYBACK_ROUTE(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0 Audio Mixer'', ``MultiMedia1, stream0.logger1'') +STREAM_DEVICE_CAPTURE_MIXER(FRONTEND_DAI_MULTIMEDIA3, ``TX_CODEC_DMA_TX_3'') +STREAM_DEVICE_CAPTURE_ROUTE(FRONTEND_DAI_MULTIMEDIA3, ``MultiMedia3 Mixer'', ``TX_CODEC_DMA_TX_3, device120.logger1'') diff --git a/device/dodge/audio/audio-bringup.sh b/device/dodge/audio/audio-bringup.sh new file mode 100755 index 000000000..e3ad1c24e --- /dev/null +++ b/device/dodge/audio/audio-bringup.sh @@ -0,0 +1,118 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# dodge speaker audio bring-up, run as root by omamobile-dodge-audio.service +# after omamobile-adsp-battery.service has the ADSP running. Installed as +# /usr/local/lib/omamobile/audio-bringup.sh. +# Prefer modprobe so a tip Image with a tmpfs modules overlay gets matching +# kos. Fall back to the pinned held tree for gpu2-style boots. +# Order matters: the FastRPC audio heap must be assigned before q6apm +# probes, or APM_CMD_GET_SPF_STATE times out. +# Never rmmod the card or unbind q6apm-dai after the topology loaded: +# that oopsed in snd_soc_unregister_component_by_driver (2026-10-20). +set -u +HELD=/usr/lib/modules/6.16.0-gb3ee311dab85.held/kernel +RPC=/usr/local/lib/omamobile/fastrpc +log() { echo "audio-bringup: $*"; } + +# $1 = relative path under kernel/ (held) OR a bare module name. +# Prefer modprobe of the basename; else insmod held path. +load() { + local rel=$1 + shift || true + local base name err + base=$(basename "$rel" .ko) + name=$(echo "$base" | tr - _) + if awk -v m="$name" '$1==m {found=1} END{exit !found}' /proc/modules; then + return 0 + fi + if modprobe "$name" "$@" 2>/dev/null; then + return 0 + fi + err=$(insmod "$HELD/$rel" "$@" 2>&1) && return 0 + case $err in *"File exists"*) return 0 ;; esac + log "load $base failed: $err"; exit 1 +} + +[ -e /proc/device-tree/sound/compatible ] || { log "no sound node in this DTB"; exit 1; } +adsp_state() { + local r + for r in /sys/class/remoteproc/remoteproc*; do + [ "$(cat "$r/name" 2>/dev/null)" = adsp ] && { cat "$r/state" 2>/dev/null; return; } + done +} +for _ in $(seq 40); do + [ "$(adsp_state)" = running ] && break + sleep 0.5 +done +[ "$(adsp_state)" = running ] || { log "ADSP not running"; exit 1; } + +# 7.3: upstream fastrpc assigns the audio PD heap itself inside +# adsprpcd's create-static-PD call. Readiness: that call returned. +heap_ready() { + inv=$(systemctl show -p InvocationID --value x-adsprpcd 2>/dev/null) + [ -n "$inv" ] && journalctl -q -o cat _SYSTEMD_INVOCATION_ID="$inv" 2>/dev/null | + grep -q 'Successfully opened handle.*createstaticpd:audiopd' && return 0 + dmesg | grep -q "assigned audio heap" +} +load drivers/misc/fastrpc.ko +for _ in $(seq 20); do [ -e /dev/fastrpc-adsp-secure ] && break; sleep 0.5; done +if ! systemctl is-active -q x-adsprpcd; then + systemd-run --unit=x-adsprpcd -p WorkingDirectory=$RPC \ + -E LD_LIBRARY_PATH=$RPC $RPC/adsprpcd audiopd adsp +fi +for _ in $(seq 40); do + heap_ready && break + sleep 0.5 +done +heap_ready || { log "audio heap not assigned (no audiopd static PD)"; exit 1; } + +load drivers/soc/qcom/apr.ko +load sound/soc/qcom/qdsp6/snd-q6dsp-common.ko +load sound/soc/qcom/qdsp6/snd-q6apm.ko +load sound/soc/qcom/qdsp6/q6prm.ko +load sound/soc/qcom/qdsp6/q6prm-clocks.ko +for _ in $(seq 40); do + [ -e /sys/bus/platform/devices/6800000.remoteproc:glink-edge:gpr:service@1:dais ] && break + sleep 0.5 +done +load sound/soc/qcom/qdsp6/q6apm-dai.ko +load sound/soc/qcom/qdsp6/q6apm-lpass-dais.ko + +load drivers/i2c/busses/i2c-qcom-geni.ko +load sound/soc/codecs/snd-soc-aw882308.ko + +load drivers/soundwire/soundwire-bus.ko + +if [ -e /proc/device-tree/audio-codec/compatible ]; then + load drivers/pinctrl/qcom/pinctrl-lpass-lpi.ko + load drivers/pinctrl/qcom/pinctrl-sm8650-lpass-lpi.ko + load sound/soc/codecs/snd-soc-lpass-macro-common.ko + load sound/soc/codecs/snd-soc-lpass-va-macro.ko + load sound/soc/codecs/snd-soc-lpass-tx-macro.ko + load sound/soc/codecs/snd-soc-lpass-rx-macro.ko + load drivers/base/regmap/regmap-sdw.ko + load sound/soc/codecs/snd-soc-wcd-mbhc.ko + load sound/soc/codecs/snd-soc-wcd-classh.ko + load sound/soc/codecs/snd-soc-wcd-common.ko + load sound/soc/codecs/snd-soc-wcd939x-sdw.ko + load sound/soc/codecs/snd-soc-wcd939x.ko + load drivers/usb/typec/mux/wcd939x-usbss.ko + for _ in $(seq 20); do + [ -e /sys/bus/i2c/drivers/wcd939x-usbss/3-000e ] && break + sleep 0.5 + done + [ -e /sys/bus/i2c/drivers/wcd939x-usbss/3-000e ] || log "warning: wcd939x-usbss not bound" + load drivers/slimbus/slimbus.ko + load drivers/soundwire/soundwire-qcom.ko + for _ in $(seq 20); do + [ -e /sys/bus/platform/drivers/wcd939x_codec/audio-codec ] && break + sleep 0.5 + done + [ -e /sys/bus/platform/drivers/wcd939x_codec/audio-codec ] || log "warning: wcd939x not bound" +fi + +load sound/soc/qcom/snd-soc-qcom-common.ko +load sound/soc/qcom/snd-soc-qcom-sdw.ko +load sound/soc/qcom/snd-soc-sc8280xp.ko +for _ in $(seq 20); do grep -q OnePlusdodge /proc/asound/cards && break; sleep 0.5; done +cat /proc/asound/cards diff --git a/device/dodge/audio/install b/device/dodge/audio/install new file mode 100755 index 000000000..1c940ba9f --- /dev/null +++ b/device/dodge/audio/install @@ -0,0 +1,23 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install tip-aware audio-bringup. When /usr/local/lib/omamobile is a bind +# of omamobile.$R, also write through a private bind of / so tip RAM boots +# (no bind) see the tip-aware script on the real rootfs path. +set -eu +cd "$(dirname "$0")" +install -Dm755 audio-bringup.sh /usr/local/lib/omamobile/audio-bringup.sh +install -Dm644 omamobile-dodge-audio.service /etc/systemd/system/omamobile-dodge-audio.service +if mountpoint -q /usr/local/lib/omamobile 2>/dev/null; then + tmp=$(mktemp -d) + mount --bind / "$tmp" + install -Dm755 audio-bringup.sh "$tmp/usr/local/lib/omamobile/audio-bringup.sh" + for d in "$tmp"/usr/local/lib/omamobile.*; do + [ -d "$d" ] || continue + install -Dm755 audio-bringup.sh "$d/audio-bringup.sh" + done + umount "$tmp" + rmdir "$tmp" +fi +systemctl daemon-reload +systemctl enable omamobile-dodge-audio.service || true +echo "installed omamobile-dodge-audio" diff --git a/device/dodge/audio/omamobile-dodge-audio.service b/device/dodge/audio/omamobile-dodge-audio.service new file mode 100644 index 000000000..8fac34494 --- /dev/null +++ b/device/dodge/audio/omamobile-dodge-audio.service @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT +# dodge speaker audio at boot: FastRPC audio PD, q6apm, the amplifiers and +# the DT sound card, then the MultiMedia1 -> speakers route. +[Unit] +Description=dodge speaker audio bring-up +Requires=omamobile-adsp-battery.service +After=omamobile-adsp-battery.service systemd-udev-settle.service systemd-modules-load.service omamobile-kmod-overlay.service +ConditionPathExists=/usr/local/lib/omamobile/audio-bringup.sh + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/lib/omamobile/audio-bringup.sh +ExecStartPost=/usr/bin/amixer -q -c OnePlusdodge cset name="SECONDARY_MI2S_RX Audio Mixer MultiMedia1" 1 +ExecStartPost=/usr/bin/amixer -q -c OnePlusdodge cset name="Left Amp Volume" 703 +ExecStartPost=/usr/bin/amixer -q -c OnePlusdodge cset name="Right Amp Volume" 703 +TimeoutStartSec=180 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/audio/ucm2/OnePlus/dodge/HiFi.conf b/device/dodge/audio/ucm2/OnePlus/dodge/HiFi.conf new file mode 100644 index 000000000..96bd2843e --- /dev/null +++ b/device/dodge/audio/ucm2/OnePlus/dodge/HiFi.conf @@ -0,0 +1,215 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Speaker or USB-C headphones on MultiMedia1, and the built-in mics. +# One back end at a time (hw_params fails with both mixers on), and +# never none: a front end with no back end cannot be opened (EINVAL). +# So the speaker route is the default and Headphones swaps it out. Amplifier gain stays at the driver default; the driver +# caps it (attenuation floor) until speaker protection and calibration exist. + +SectionVerb { + EnableSequence [ + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia1' 0" + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 1" + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + ] + + Value { + TQ "HiFi" + } +} + +SectionDevice."Speaker" { + Comment "Speaker playback" + + # Amp Volume 703 is the driver's cap, attenuation 320 (about -30 dB). + # This is the level heard at 11:39. The driver default, 323 + # (attenuation 700, about -66 dB), is inaudible. + EnableSequence [ + cset "name='Left Amp Volume' 703" + cset "name='Right Amp Volume' 703" + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 1" + ] + + DisableSequence [ + ] + + Value { + PlaybackChannels 2 + PlaybackPriority 100 + PlaybackPCM "hw:${CardId},0" + } +} + +# Built-in microphones: AMIC1 (WCD939x ADC1, SoundWire TX channel 0) and +# AMIC5 (ADC4, channel 3), both on MIC BIAS1, into TX decimators 0 and 1. +SectionDevice."Mic" { + Comment "Internal microphones" + + EnableSequence [ + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + cset "name='ADC1_MIXER Switch' 1" + cset "name='ADC1 MUX' CH1_AMIC1" + cset "name='ADC1 Switch' 1" + cset "name='ADC1 Volume' 10" + cset "name='TX0 MODE' ADC_ULP" + cset "name='ADC4_MIXER Switch' 1" + cset "name='ADC4 MUX' CH4_AMIC5" + cset "name='ADC4 Switch' 1" + cset "name='ADC4 Volume' 10" + cset "name='TX3 MODE' ADC_ULP" + cset "name='TX DEC0 MUX' SWR_MIC" + cset "name='TX SMIC MUX0' SWR_MIC0" + cset "name='TX_DEC0 Volume' 100" + cset "name='TX_AIF1_CAP Mixer DEC0' 1" + cset "name='TX DEC1 MUX' SWR_MIC" + cset "name='TX SMIC MUX1' SWR_MIC3" + cset "name='TX_DEC1 Volume' 100" + cset "name='TX_AIF1_CAP Mixer DEC1' 1" + ] + + DisableSequence [ + cset "name='TX_AIF1_CAP Mixer DEC0' 0" + cset "name='TX_AIF1_CAP Mixer DEC1' 0" + cset "name='ADC1 Switch' 0" + cset "name='ADC4 Switch' 0" + cset "name='ADC1_MIXER Switch' 0" + cset "name='ADC4_MIXER Switch' 0" + ] + + Value { + CapturePriority 100 + CapturePCM "hw:${CardId},2" + CaptureChannels 2 + } +} + + +# USB-C analog headphones: WCD939x HPH behind RX codec DMA 0. Plug +# detection comes from the Type-C stack (audio accessory mode). +SectionDevice."Headset" { + Comment "Headset microphone" + + # USB-C analog headset: AMIC2 (MIC BIAS2) through the WCD939x USBSS, + # ADC2 on TX SWR_MIC1, DEC0, one channel on hw:CARD,2. The path is + # verified live with nothing plugged in (noise floor about -65 dBFS, + # EIO with ADC2 off). The jack and MBHC still need the plug test. + ConflictingDevice [ + "Mic" + ] + + EnableSequence [ + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + cset "name='ADC2_MIXER Switch' 1" + # Select AMIC2 twice (disable, then AMIC2). A single write after + # the Mic device sometimes leaves ADC2 silent until the mux moves. + cset "name='ADC2 MUX' CH2_AMIC_DISABLE" + cset "name='ADC2 MUX' CH2_AMIC2" + cset "name='ADC2 Switch' 1" + cset "name='ADC2 Volume' 10" + cset "name='TX1 MODE' ADC_LP" + cset "name='MBHC Switch' 1" + cset "name='TX_AIF1_CAP Mixer DEC1' 0" + cset "name='TX DEC0 MUX' SWR_MIC" + cset "name='TX SMIC MUX0' SWR_MIC1" + cset "name='TX_DEC0 Volume' 84" + cset "name='TX_AIF1_CAP Mixer DEC0' 1" + ] + + DisableSequence [ + cset "name='TX_AIF1_CAP Mixer DEC0' 0" + cset "name='MBHC Switch' 0" + cset "name='ADC2 Switch' 0" + cset "name='ADC2_MIXER Switch' 0" + cset "name='ADC2 MUX' CH2_AMIC_DISABLE" + cset "name='TX SMIC MUX0' SWR_MIC0" + ] + + Value { + CapturePriority 300 + CapturePCM "hw:${CardId},2" + CaptureChannels 1 + CaptureMixerElem "ADC2" + JackControl "Mic Jack" + } +} + +SectionDevice."Headphones" { + Comment "Headphones playback" + + ConflictingDevice [ + "Speaker" + ] + + EnableSequence [ + cset "name='RX_HPH PWR Mode' LOHIFI" + cset "name='RX_MACRO RX0 MUX' AIF1_PB" + cset "name='RX_MACRO RX1 MUX' AIF1_PB" + cset "name='RX INT0_1 MIX1 INP0' RX0" + cset "name='RX INT1_1 MIX1 INP0' RX1" + cset "name='RX INT0 DEM MUX' CLSH_DSM_OUT" + cset "name='RX INT1 DEM MUX' CLSH_DSM_OUT" + cset "name='HPHL_RDAC Switch' 1" + cset "name='HPHR_RDAC Switch' 1" + cset "name='HPHL_COMP Switch' 1" + cset "name='HPHR_COMP Switch' 1" + cset "name='HPHL Switch' 1" + cset "name='HPHR Switch' 1" + cset "name='CLSH Switch' 1" + cset "name='RX HPH Mode' CLS_H_LOHIFI" + cset "name='HPHL Volume' 20" + cset "name='HPHR Volume' 20" + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 0" + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia1' 1" + ] + + DisableSequence [ + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia1' 0" + cset "name='HPHL Switch' 0" + cset "name='HPHR Switch' 0" + cset "name='HPHL_RDAC Switch' 0" + cset "name='HPHR_RDAC Switch' 0" + cset "name='HPHL_COMP Switch' 0" + cset "name='HPHR_COMP Switch' 0" + cset "name='CLSH Switch' 0" + cset "name='RX_MACRO RX0 MUX' ZERO" + cset "name='RX_MACRO RX1 MUX' ZERO" + cset "name='RX INT0_1 MIX1 INP0' ZERO" + cset "name='RX INT1_1 MIX1 INP0' ZERO" + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 1" + ] + + Value { + PlaybackChannels 2 + PlaybackPriority 200 + PlaybackPCM "hw:${CardId},0" + JackControl "Headphone Jack" + } +} + +# Earpiece: the top (left) speaker in the stock Receiver profile, with the +# bottom amplifier muted. A profile change made while playing takes +# effect when the next stream is set up (hw_params). +SectionDevice."Earpiece" { + Comment "Earpiece playback" + + ConflictingDevice [ + "Speaker" + "Headphones" + ] + + EnableSequence [ + cset "name='Right Amp Volume' 0" + cset "name='Left Amp Volume' 703" + cset "name='Left Amp Profile' Receiver" + ] + + DisableSequence [ + cset "name='Right Amp Volume' 703" + cset "name='Left Amp Profile' Speaker" + ] + + Value { + PlaybackChannels 2 + PlaybackPriority 50 + PlaybackPCM "hw:${CardId},0" + } +} diff --git a/device/dodge/audio/ucm2/OnePlus/dodge/OnePlus-dodge.conf b/device/dodge/audio/ucm2/OnePlus/dodge/OnePlus-dodge.conf new file mode 100644 index 000000000..760d52099 --- /dev/null +++ b/device/dodge/audio/ucm2/OnePlus/dodge/OnePlus-dodge.conf @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# OnePlus 13 (dodge): two Awinic speaker amplifiers on SECONDARY_MI2S_RX. +# Install as /usr/share/alsa/ucm2/OnePlus/dodge/ and link +# /usr/share/alsa/ucm2/conf.d/sm8750/OnePlus-dodge.conf to this file. +# Speakers, built-in microphones, USB-C headset and headset mic (plug untested) and earpiece. +Syntax 4 + +SectionUseCase."HiFi" { + File "/OnePlus/dodge/HiFi.conf" + Comment "HiFi quality Music." +} + +Include.card-init.File "/lib/card-init.conf" diff --git a/device/dodge/audio/wireplumber/60-dodge-speaker-volume.conf b/device/dodge/audio/wireplumber/60-dodge-speaker-volume.conf new file mode 100644 index 000000000..5929a5d43 --- /dev/null +++ b/device/dodge/audio/wireplumber/60-dodge-speaker-volume.conf @@ -0,0 +1,24 @@ +## dodge: default route volume for the built-in card. +## WirePlumber's global default is 0.064 linear (0.40 on the cubic scale wpctl +## shows), which with the amplifiers at their -30 dB cap is too quiet. +## 0.614 linear is 0.85 cubic, about -4 dB. The amplifier driver still enforces +## the hardware cap (attenuation >= 320). This applies only while no route +## volume is saved; a user change is remembered as usual. +## Install to /etc/wireplumber/wireplumber.conf.d/. + +monitor.alsa.rules = [ + { + matches = [ + { + device.name = "alsa_card.platform-sound" + } + ] + actions = { + update-props = { + device.routes.default-sink-volume = 0.614 + # Without this the sources would fall back to the sink value above. + device.routes.default-source-volume = 1.0 + } + } + } +] diff --git a/device/dodge/bluetooth/README.md b/device/dodge/bluetooth/README.md new file mode 100644 index 000000000..530994215 --- /dev/null +++ b/device/dodge/bluetooth/README.md @@ -0,0 +1,9 @@ + +# dodge Bluetooth + +`omamobile-bt` brings up the WCN7860 HCI over the board's UART. It looks for +helper modules under `/usr/local/lib/omamobile/bt` and, for some out-of-tree +bits, `/usr/lib/modules/$(uname -r).held/`. A kernel installed only by +`modules-push` has neither path, so the unit fails safely (hci0 stays down) +until those modules are installed next to the running release or the package +ships them. Pairing was verified against another phone; A2DP is untested. diff --git a/device/dodge/bluetooth/install b/device/dodge/bluetooth/install new file mode 100755 index 000000000..948fa0e72 --- /dev/null +++ b/device/dodge/bluetooth/install @@ -0,0 +1,42 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install the dodge Bluetooth bring-up on the phone. Run as root, from +# this directory (copied to the phone), or with the directory as $1. +# Idempotent. +# +# Installs omamobile-bt (script and unit), enables it and BlueZ's +# bluetooth.service. It does not start them. +# +# It also copies the WCN7860 Bluetooth firmware from the phone's own +# bluetooth_a partition (read-only loop mount of a copy) to +# /lib/firmware/qca: gngbtfw20.mbn (rampatch) and gngbtnv20.* (NVM). +# Nothing is shipped or committed. Existing files are left alone. The +# kernel modules in /usr/local/lib/omamobile/bt are installed separately. +set -eu +SRC=${1:-$(dirname "$0")} +FW=/lib/firmware/qca + +log() { echo "dodge-bt-install: $*"; } + +[ "$(id -u)" = 0 ] || { log "run as root"; exit 1; } + +install -D -m 755 "$SRC/omamobile-bt" /usr/local/sbin/omamobile-bt +install -D -m 644 "$SRC/omamobile-bt.service" /etc/systemd/system/omamobile-bt.service +systemctl daemon-reload +systemctl enable omamobile-bt.service bluetooth.service + +if [ -s "$FW/gngbtfw20.mbn" ] && [ -s "$FW/gngbtnv20.bin" ]; then + log "firmware already in $FW" +else + part=$(readlink -f /dev/disk/by-partlabel/bluetooth_a) + [ -b "$part" ] || { log "no bluetooth_a partition"; exit 1; } + tmp=$(mktemp -d) + trap 'umount "$tmp/m" 2>/dev/null; rm -rf "$tmp"' EXIT + mkdir "$tmp/m" + dd if="$part" of="$tmp/bt.img" bs=1M status=none + mount -o ro,loop "$tmp/bt.img" "$tmp/m" + mkdir -p "$FW" + cp -n "$tmp/m/image/gngbtfw20.mbn" "$tmp/m/image"/gngbtnv20.* "$FW/" + log "copied $(ls "$FW" | grep -c '^gngbt') gngbt* files to $FW" +fi +log "done; the next boot brings up hci0" diff --git a/device/dodge/bluetooth/omamobile-bt b/device/dodge/bluetooth/omamobile-bt new file mode 100755 index 000000000..4bb454afd --- /dev/null +++ b/device/dodge/bluetooth/omamobile-bt @@ -0,0 +1,97 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Bring up Bluetooth on the WCN7860 (peach) once per boot: load the +# Bluetooth stack and hci_uart, wait for hci0, and give it a public +# address so it leaves the "unconfigured" state. +# +# Prefer modprobe so a tip Image with a tmpfs modules overlay gets +# matching kos. Fall back to /usr/local/lib/omamobile/bt (and +# /usr/local/lib/omamobile) for the packaged held tree. +# +# hci_qca powers the chip through the WCN7850 power sequencer that +# omamobile-wifi-pcie loads, downloads qca/gngbtfw20.mbn and +# qca/gngbtnv20.bin, and then waits for an address. +# +# The real BD address lives in the persist partition, which we never +# read. Instead this uses a random address generated once on this phone +# and kept in /var/lib/omamobile/bt-public-addr (mode 600, never +# committed). The first octet is 0x02 (locally administered). +set -u +D=/usr/local/lib/omamobile/bt +W=/usr/local/lib/omamobile +STAMP=/run/omamobile-bt.tried +ADDR=/var/lib/omamobile/bt-public-addr + +log() { echo "omamobile-bt: $*"; } + +if [ -e "$STAMP" ]; then + log "already tried this boot ($STAMP)" + exit 0 +fi +: > "$STAMP" + +load() { + name=$(echo "$1" | tr - _) + [ -e "/sys/module/$name" ] && return 0 + if modprobe "$name" 2>/dev/null; then + return 0 + fi + hyphen=$(echo "$name" | tr _ -) + for f in "$D/$name.ko" "$D/$hyphen.ko" "$W/$name.ko" "$W/$hyphen.ko"; do + [ -f "$f" ] && { insmod "$f" && return 0; } + done + [ -e "/sys/module/$name" ] +} + +# kpp is a module on 7.3 and built in on 6.16 (no file there). +if [ -f "$D/kpp.ko" ] || modprobe -n kpp 2>/dev/null; then + load kpp || log "kpp failed to load" +fi +for m in rfkill ecc ecdh_generic bluetooth btqca btbcm hci_uart; do + load "$m" || { log "$m failed to load"; exit 1; } +done + +# hci0 is registered before hci_qca has downloaded the firmware (about +# 1.5 s), so its sysfs node is not the signal. Wait until mgmt reports +# it either as a configured controller or as unconfigured with a +# missing public address. +state= +i=0 +while [ $i -lt 60 ]; do + if btmgmt info 2>/dev/null | grep -q '^hci0:.*Primary controller'; then + state=configured + break + fi + if btmgmt -i 0 config 2>/dev/null | + grep -q 'missing options:.*public-address'; then + state=needs-address + break + fi + sleep 0.5 + i=$((i + 1)) +done +case $state in +configured) + log "hci0 configured" + exit 0 ;; +needs-address) ;; +*) + log "hci0 did not finish setup in 30 s" + exit 1 ;; +esac + +if [ ! -s "$ADDR" ]; then + mkdir -p "${ADDR%/*}" + (umask 077 + od -An -N5 -tx1 /dev/urandom | + awk '{ printf "02:%s:%s:%s:%s:%s\n", $1, $2, $3, $4, $5 }' | + tr a-f A-F > "$ADDR") + log "generated a new public address in $ADDR" +fi +chmod 600 "$ADDR" +if btmgmt -i 0 public-addr "$(cat "$ADDR")" >/dev/null 2>&1; then + log "hci0 public address set from $ADDR" +else + log "setting the public address failed" + exit 1 +fi diff --git a/device/dodge/bluetooth/omamobile-bt.service b/device/dodge/bluetooth/omamobile-bt.service new file mode 100644 index 000000000..26bd83008 --- /dev/null +++ b/device/dodge/bluetooth/omamobile-bt.service @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +# Bluetooth on the WCN7860 (peach): stack, hci_uart and a public +# address, once per boot. After the Wi-Fi units, which load the power +# sequencer and rfkill. +[Unit] +Description=Bluetooth for the WCN7860 (peach), once per boot +After=omamobile-wifi-pcie.service omamobile-wifi-ath12k.service local-fs.target omamobile-kmod-overlay.service +Wants=omamobile-wifi-pcie.service +Before=bluetooth.service +ConditionPathExists=!/run/omamobile-bt.tried + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/sbin/omamobile-bt +TimeoutStartSec=90 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/chainload/README.md b/device/dodge/chainload/README.md new file mode 100644 index 000000000..3076d492a --- /dev/null +++ b/device/dodge/chainload/README.md @@ -0,0 +1,53 @@ + +# dodge chainload + +Stage 1 of the OnePlus 13 (dodge) RAM-only boot path. ABL refuses header +v2 under `fastboot boot`, and a header v4 `boot.img` ramdisk is ignored +(stock DTB comes from the flashed `vendor_boot`). The only way to reach +our DTB without flashing `vendor_boot` is this chain: + +1. Pack our kernel with a built-in initramfs (`/omamobile/…`) and + `CONFIG_CMDLINE_FORCE rdinit=/omamobile/init` as a kernel-only + header v4 image (`tools/dodge-chain pack`, also via + `bin/omamobile images` when `BOOT_METHOD=qcom-abl`). +2. Stage 1 (`init` here) runs as PID 1. It mounts proc (and optionally + sysfs) only, never opens a block device, compares this boot's memory + `reg` with the copy saved at pack time from `$LIVE_DTB`, appends + `androidboot.slot_suffix` from `/proc/bootconfig`, then + `/proc/device-tree/chosen/bootargs`, then the packed + `/omamobile/slot_suffix` (from `OMAMOBILE_SLOT` — this ABL puts the + property in neither bootconfig nor bootargs under `fastboot boot`; + stage 1 dumps both to kmsg and logs `source=packed`) (stage 1's own `/proc/cmdline` is + `CMDLINE_FORCE`d and has no ABL keys), and `kexec -c` + into stage 2. Stage 1's kernel config has UFS disabled + (`SCSI_UFS_QCOM` / `SCSI_UFSHCD`), so it does not probe storage on + stock's DTB. +3. Stage 2 is the PR kernel `Image`, the dodge DTB (live memory map + from `$LIVE_DTB`), and the shared initramfs from + `bin/omamobile initramfs` (`INITRAMFS_INIT=/initramfs/init`). + +`bin/omamobile images` refuses `qcom-abl` unless this directory exists +and passes `CHAINLOAD_DIR` into `tools/dodge-chain`, so the next +Qualcomm phone cannot inherit dodge's splash address, panel geometry, +apps RSC or SMMU stream ID by accident. + +## Files + +- `init` — stage 1 PID 1. No storage writes. +- `stage2-dtb.py` — builds stage 2's DTB from the board DTB plus the + rooted live FDT's memory map. `$LIVE_DTB` is never committed. Dodge + splash/panel/RSC/SMMU values live only in this script. + +## Variables + +See `tools/dodge-chain`. Defaults that match the known-good boot: + +- `DTB_OPTS='splash fb'` +- `STAGE2_CMDLINE` — from the descriptor's `CMDLINE` (via `bin/omamobile`) + or `rdinit=/init clk_ignore_unused pd_ignore_unused panic=10 console=tty0 omamobile.ufs-probe` +- `LIVE_DTB` — required; path to the rooted live FDT (outside the tree) +- `CHAINLOAD_DIR` — required; this directory +- `KERNEL_DIR` — required; same tree stage 2 was built from + +Nothing here is installed by `packages/omamobile-device-dodge`. Stage 2 +carries the shared storage guard; stage 1 never reaches it. diff --git a/device/dodge/chainload/init b/device/dodge/chainload/init new file mode 100755 index 000000000..48898d566 --- /dev/null +++ b/device/dodge/chainload/init @@ -0,0 +1,125 @@ +#!/omamobile/busybox sh +# SPDX-License-Identifier: MIT +# Stage 1 of the dodge kexec chain-loader (device/dodge/chainload/). +# +# Runs as PID 1 from the kernel's built-in initramfs, started by +# CONFIG_CMDLINE_FORCE rdinit=/omamobile/init. ABL has started this +# kernel on the stock DTB from vendor_boot; the uploaded boot.img +# ramdisk is ignored on header v4, so everything lives under /omamobile +# and cannot be replaced by Magisk's init_boot or vendor_boot. +# +# This script mounts only proc (and optionally sysfs). It never opens +# a block device, never mounts userdata, and never writes storage. +# kexec_load (kexec-tools -c -l --dtb) starts stage 2: our kernel, our +# DTB, and the shared initramfs from `bin/omamobile initramfs`. -c +# matters: kexec-tools 2.0.32 tries kexec_file_load first, which +# ignores --dtb on arm64 and would hand stage 2 the running (stock) +# FDT. Failure holds: +# memory.reg mismatch -> sleep 230 s, then reset +# kexec -l fails -> sleep 230 s, then reset +# kexec -e returns -> sleep 200 s, then reset +# PID 1 never exits. +B=/omamobile/busybox +hold() { + echo "omamobile-chain: $1" > /dev/kmsg 2>/dev/null || true + $B sleep 230 + echo b > /proc/sysrq-trigger + while :; do $B sleep 60; done +} +$B mount -t proc proc /proc +CMDLINE=$($B cat /omamobile/cmdline) +# Append the bootloader's slot suffix so stage 2's phone-smoke boot check can run. +# Stage 1 uses CONFIG_CMDLINE_FORCE, so /proc/cmdline is only STAGE1_CMDLINE and +# never carries ABL's androidboot.* keys. Read the suffix from /proc/bootconfig +# first, then from the live DT chosen/bootargs (stock DTB with ABL fixups). +SLOT_SUFFIX= +SLOT_SRC= +# Dump what ABL actually handed stage 1. Under `fastboot boot` this ABL is +# expected to leave both empty of androidboot.slot_suffix (stage-2 evidence so +# far: BOOTCONFIG empty, packed fallback used; a boot with omamobile.slot_src= +# will confirm stage 1's view). Log the chosen source so a stage-1 kmsg +# captures it before kexec (stage 2 never sees these dumps). +if [ -f /proc/bootconfig ]; then + echo "omamobile-chain: /proc/bootconfig:" > /dev/kmsg 2>/dev/null || true + $B cat /proc/bootconfig > /dev/kmsg 2>/dev/null || true +else + echo "omamobile-chain: /proc/bootconfig: (missing)" > /dev/kmsg 2>/dev/null || true +fi +if [ -f /proc/device-tree/chosen/bootargs ]; then + echo "omamobile-chain: chosen/bootargs: $($B cat /proc/device-tree/chosen/bootargs)" > /dev/kmsg 2>/dev/null || true +else + echo "omamobile-chain: chosen/bootargs: (missing)" > /dev/kmsg 2>/dev/null || true +fi +if [ -f /proc/bootconfig ]; then + # bootconfig lines look like: androidboot.slot_suffix = "_b" + SLOT_SUFFIX=$($B awk -F= '/^androidboot\.slot_suffix/ { + v=$2; gsub(/^[ \t"]+|[ \t"]+$/, "", v); print v; exit + }' /proc/bootconfig) + [ -n "$SLOT_SUFFIX" ] && SLOT_SRC=bootconfig +fi +if [ -z "$SLOT_SUFFIX" ] && [ -f /proc/device-tree/chosen/bootargs ]; then + for tok in $($B cat /proc/device-tree/chosen/bootargs); do + case $tok in + androidboot.slot_suffix=*) SLOT_SUFFIX=${tok#androidboot.slot_suffix=}; SLOT_SRC=bootargs ;; + esac + done +fi +# This ABL does not put androidboot.slot_suffix in bootconfig or +# chosen/bootargs under `fastboot boot` (expected empty; keep the packed +# /omamobile/slot_suffix fallback from OMAMOBILE_SLOT until a slot_src= boot +# shows otherwise). +if [ -z "$SLOT_SUFFIX" ] && [ -f /omamobile/slot_suffix ]; then + SLOT_SUFFIX=$($B cat /omamobile/slot_suffix) + SLOT_SRC=packed +fi +if [ -n "$SLOT_SUFFIX" ]; then + echo "omamobile-chain: slot_suffix=$SLOT_SUFFIX source=$SLOT_SRC" > /dev/kmsg 2>/dev/null || true + tok="androidboot.slot_suffix=$SLOT_SUFFIX" + case " $CMDLINE " in + *" $tok "*) ;; + *) CMDLINE="$CMDLINE $tok" ;; + esac + # stage-1 kmsg is lost at kexec; carry the source on stage 2's cmdline too + if [ -n "$SLOT_SRC" ]; then + tok="omamobile.slot_src=$SLOT_SRC" + case " $CMDLINE " in + *" $tok "*) ;; + *) CMDLINE="$CMDLINE $tok" ;; + esac + fi +else + echo "omamobile-chain: slot_suffix=(none) source=(none)" > /dev/kmsg 2>/dev/null || true +fi +# sysfs is optional; used only for the memory.reg cmp via /proc/device-tree. +$B mount -t sysfs sysfs /sys 2>/dev/null || true +# Soft storage-guard note: stage 1 must never have a block device mounted. +if $B grep -E '^/dev/sd' /proc/mounts >/dev/null 2>&1; then + hold "refuse: block device mounted in stage 1" +fi +# LIVE_DTB memory map baked at pack time must match this boot's map. +MEM_REG="" +if [ -f /proc/device-tree/memory/reg ]; then + MEM_REG=/proc/device-tree/memory/reg +elif [ -f /proc/device-tree/memory@a0000000/reg ]; then + MEM_REG=/proc/device-tree/memory@a0000000/reg +else + for cand in /proc/device-tree/memory@*/reg; do + if [ -f "$cand" ]; then MEM_REG=$cand; break; fi + done +fi +if [ -z "$MEM_REG" ] || [ ! -f /omamobile/memory.reg ]; then + hold "refuse: no memory reg to cmp" +fi +if ! $B cmp -s "$MEM_REG" /omamobile/memory.reg; then + hold "refuse: this boot memory reg != pack-time copy" +fi +KEXEC="/omamobile/lib/ld-musl-aarch64.so.1 --library-path /omamobile/lib /omamobile/kexec" +if $KEXEC -c -l /omamobile/Image --dtb=/omamobile/stage2.dtb \ + --initrd=/omamobile/initrd --command-line="$CMDLINE"; then + $KEXEC -e + $B sleep 200 +else + $B sleep 230 +fi +echo b > /proc/sysrq-trigger +while :; do $B sleep 60; done diff --git a/device/dodge/chainload/resolve-slot-suffix.sh b/device/dodge/chainload/resolve-slot-suffix.sh new file mode 100755 index 000000000..8b7a2de78 --- /dev/null +++ b/device/dodge/chainload/resolve-slot-suffix.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Resolve androidboot.slot_suffix the same way device/dodge/chainload/init does. +# Usage: resolve-slot-suffix.sh [packed-fallback] +# Prints the bare suffix (e.g. _b) or nothing. For tests; not packed into stage 1. +set -eu +BOOTCONFIG=${1:-} +BOOTARGS=${2:-} +PACKED=${3:-} +SLOT_SUFFIX= +if [ -n "$BOOTCONFIG" ] && [ -f "$BOOTCONFIG" ]; then + SLOT_SUFFIX=$(awk -F= '/^androidboot\.slot_suffix/ { + v=$2; gsub(/^[ \t"]+|[ \t"]+$/, "", v); print v; exit + }' "$BOOTCONFIG") +fi +if [ -z "$SLOT_SUFFIX" ] && [ -n "$BOOTARGS" ] && [ -f "$BOOTARGS" ]; then + # shellcheck disable=SC2046 + for tok in $(cat "$BOOTARGS"); do + case $tok in + androidboot.slot_suffix=*) SLOT_SUFFIX=${tok#androidboot.slot_suffix=} ;; + esac + done +fi +if [ -z "$SLOT_SUFFIX" ] && [ -n "$PACKED" ] && [ -f "$PACKED" ]; then + SLOT_SUFFIX=$(cat "$PACKED") +fi +printf '%s' "$SLOT_SUFFIX" diff --git a/device/dodge/chainload/stage2-dtb.py b/device/dodge/chainload/stage2-dtb.py new file mode 100755 index 000000000..a9a63b73c --- /dev/null +++ b/device/dodge/chainload/stage2-dtb.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Make the stage 2 DTB for the dodge kexec chain-loader. + +Usage: stage2-dtb.py [ramoops] [splash] [fb] [peripheral] [hs] [rscpd] + +ABL fills the `memory` node at boot and kexec does not, so its reg is +taken from the phone's live FDT (/sys/firmware/fdt from a rooted +capture, kept outside git). The upstream DTS carries another phone's +map. `memory@a0000000` keeps size 0. + +ramoops add a ramoops node at OxygenOS's ramoops address and layout +splash reserve ABL's splash buffer with an identity map on mdss +fb add a simple-framebuffer over ABL's splash buffer, reusing + splash's reservation if set. Works on our DTB with splash +ramoops was booted on 2026-10-15, also on stock's DTB, so it has not +really been tried either. +peripheral dr_mode = "peripheral" and no usb-role-switch on the dwc3 + node. The role otherwise comes from pmic_glink, which this + initramfs does not load. Not needed: otg works on our DTB. +hs peripheral, and drop the usb3-phy so dwc3 does not wait + on the combo PHY. Also drops the dwc3 iommus entry, which + blocks its DMA under ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT. +rscpd drop power-domains from the apps RSC, so RPMh does not wait + on PSCI's cpuidle genpd, which does not bind after kexec. +""" +import re +import subprocess +import sys + + +def dts(path): + return subprocess.run(["dtc", "-q", "-I", "dtb", "-O", "dts", path], + capture_output=True, text=True, check=True).stdout + + +def node_span(s, header): + i = s.index(header) + depth = 0 + for k in range(i, len(s)): + if s[k] == "{": + depth += 1 + elif s[k] == "}": + depth -= 1 + if depth == 0: + return i, k + raise ValueError(header) + + +def memory_span(s): + """ABL / live FDT uses `memory {`; the dodge DTS uses `memory@…`.""" + for header in ("\n\tmemory {",): + try: + return node_span(s, header) + except ValueError: + pass + m = re.search(r"\n\tmemory@[0-9a-fA-F]+ \{", s) + if not m: + raise ValueError("no memory node") + return node_span(s, m.group(0)) + + +def insert_in(s, header, text): + _, j = node_span(s, header) + line = s.rindex("\n", 0, j) + return s[:line] + text.rstrip("\n") + s[line:] + + +built, live, out, *opts = sys.argv[1:] +ours, theirs = dts(built), dts(live) + +i, j = memory_span(theirs) +live_reg = re.search(r"reg = <[^>]*>;", theirs[i:j]).group(0) +i, j = memory_span(ours) +block = ours[i:j] +ours = ours[:i] + block.replace(re.search(r"reg = <[^>]*>;", block).group(0), live_reg) + ours[j:] + +# One top-level memory node only. A second hardcoded map beside +# memory@a0000000 (filled above) hung a 2026-10-30 tip RAM boot. +extras = list(re.finditer(r"\n\tmemory@[0-9a-fA-F]+ \{", ours)) +# memory_span already picked one; drop any other memory@… at root depth. +if len(extras) > 1: + keep = memory_span(ours)[0] + for m in reversed(extras): + if m.start() == keep: + continue + a, b = node_span(ours, m.group(0)) + # include the trailing newline after the closing brace line + end = b + 1 + if end < len(ours) and ours[end] == "\n": + end += 1 + ours = ours[:a] + ours[end:] + +if "ramoops" in opts: + ours = insert_in(ours, "reserved-memory {", """ + ramoops@880000000 { + compatible = "ramoops"; + reg = <0x08 0x80000000 0x00 0x240000>; + record-size = <0x00>; + console-size = <0x40000>; + ftrace-size = <0x00>; + pmsg-size = <0x200000>; + ecc-size = <0x00>; + no-map; + }; +""") + +def force_peripheral(s): + if s.count('dr_mode = "otg";') != 1 or s.count("usb-role-switch;") != 1: + raise SystemExit("expected exactly one otg dr_mode and one usb-role-switch") + s = s.replace('dr_mode = "otg";', 'dr_mode = "peripheral";', 1) + return re.sub(r"\n[ \t]*usb-role-switch;\n", "\n", s, count=1) + + +if "peripheral" in opts or "hs" in opts: + ours = force_peripheral(ours) + +if "hs" in opts: + m = re.search( + r'phys = <(0x[0-9a-fA-F]+)[^>]*>;\n(\s*)phy-names = "usb2-phy", "usb3-phy";', + ours) + if not m: + raise SystemExit("expected usb2-phy and usb3-phy on one phys entry") + ours = (ours[:m.start()] + + f'phys = <{m.group(1)}>;\n{m.group(2)}phy-names = "usb2-phy";' + + ours[m.end():]) + # The dwc3 node is the only one with this SID. Dropping it avoids + # waiting on apps_smmu after kexec. + if 'iommus = <0x23 0x40 0x00>;' not in ours: + raise SystemExit("expected the dwc3 iommus entry") + ours = ours.replace('\n\t\t\t\tiommus = <0x23 0x40 0x00>;\n', '\n', 1) + +if "splash" in opts: + # SID 0x800 is mdss. ABL leaves it scanning 0xfc800000. The identity + # map is what arm-smmu installs from iommu-addresses. + if "qcom,sm8750-mdss" not in ours: + raise SystemExit("no mdss node") + ours = ours.replace( + "display-subsystem@ae00000 {", + "mdss: display-subsystem@ae00000 {", + 1) + ours = ours.replace( + 'compatible = "qcom,sm8750-mdss";', + 'compatible = "qcom,sm8750-mdss";\n\t\t\tmemory-region = <&cont_splash_mem>;', + 1) + ours = insert_in(ours, "reserved-memory {", """ + cont_splash_mem: splash@fc800000 { + reg = <0x00 0xfc800000 0x00 0x2b00000>; + no-map; + iommu-addresses = <&mdss 0x00 0xfc800000 0x00 0x2b00000>; + }; +""") + +# The apps RSC's only supplier is PSCI's power-domain-system genpd. After +# kexec the PSCI cpuidle domain does not bind, so fw_devlink holds the RSC +# (and RPMh clocks, GCC, regulators, everything after) unprobed. Without +# power-domains rpmh-rsc uses its CPU PM notifier instead +if "rscpd" in opts: + i, j = node_span(ours, "\n\t\trsc@16500000 {") + # Three tabs: the RSC's own property, not a child's. + m = re.search(r"\n\t\t\tpower-domains = <0x[0-9a-f]+>;", ours[i:j]) + if not m: + raise SystemExit("expected power-domains on the apps RSC") + ours = ours[:i + m.start()] + ours[i + m.end():] + +if "fb" in opts: + # splash already reserves this region and asks for the identity map. + # A second node at the same address is a broken DTB. + if "splash" not in opts: + ours = insert_in(ours, "reserved-memory {", """ + splash@fc800000 { + reg = <0x00 0xfc800000 0x00 0x2b00000>; + no-map; + }; +""") + ours = insert_in(ours, "\n\tchosen {", """ + framebuffer@fc800000 { + compatible = "simple-framebuffer"; + reg = <0x00 0xfc800000 0x00 0x1167000>; + width = <1440>; + height = <3168>; + stride = <5760>; + format = "a8r8g8b8"; + }; +""") + +subprocess.run(["dtc", "-q", "-I", "dts", "-O", "dtb", "-o", out, "-"], + input=ours, text=True, check=True) diff --git a/device/dodge/desktop/install b/device/dodge/desktop/install new file mode 100755 index 000000000..d4b615110 --- /dev/null +++ b/device/dodge/desktop/install @@ -0,0 +1,13 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install the dodge desktop unit (Hyprland on tty1) on the phone. Run as +# root, from this directory (copied to the phone), or with it as $1. +# Idempotent. Enables the unit; does not restart a running desktop. +set -eu +SRC=${1:-$(dirname "$0")} +log() { echo "dodge-desktop-install: $*"; } +[ "$(id -u)" = 0 ] || { log "run as root"; exit 1; } +install -D -m 644 "$SRC/omamobile-hyprland.service" /etc/systemd/system/omamobile-hyprland.service +systemctl daemon-reload +systemctl enable omamobile-hyprland.service +log "done; takes effect on the next start of the desktop" diff --git a/device/dodge/desktop/login-sddm b/device/dodge/desktop/login-sddm new file mode 100755 index 000000000..1873fd13b --- /dev/null +++ b/device/dodge/desktop/login-sddm @@ -0,0 +1,101 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# dodge-login-sddm: start the desktop the stock Omarchy Mobile way, SDDM +# autologin into Omarchy's session (omamobile-firstboot's s_login), instead of +# dodge's omamobile-hyprland.service (uwsm on tty1 under PAM "login"). The +# lock (lock-on-start, setup-stock) then asks for the PIN, as on stock. +# Run as root: +# +# login-sddm [USER] stage SDDM autologin for the next boot +# login-sddm --revert [USER] back to omamobile-hyprland.service on tty1 +# login-sddm --status show which path the next boot takes +# +# Never starts, stops or restarts sddm, getty or the running desktop: the +# change takes effect at the next boot. Idempotent. +# +# What it changes (all undone by --revert): +# - /etc/sddm.conf.d/autologin.conf and /var/lib/sddm/state.conf, as +# firstboot writes them (Session=omarchy.desktop: uwsm + Hyprland). +# - sddm.service drop-in: after the msm panel and touch units, as +# omamobile-hyprland.service was (they order Before= that unit only). +# - (removed) /etc/xdg/uwsm/env.d/50-dodge-software-gl: formerly LIBGL_ALWAYS_SOFTWARE=1 for +# the session, which omamobile-hyprland.service set. Hyprland renders on +# the GPU either way (aquamarine/GBM ignores it); apps keep llvmpipe GL, so +# the login switch changes one thing only. Dropping it is a separate step. +# - omamobile-hyprland.service disabled (not stopped), sddm.service enabled, +# default target graphical.target (sddm is PartOf graphical.target; dodge +# booted to multi-user.target, which is why the enabled sddm never ran). +# sddm.service Conflicts=getty@tty1.service, so the two never share the seat. +set -euo pipefail +mode=apply +case ${1:-} in --revert) mode=revert; shift ;; --status) mode=status; shift ;; esac +U=${1:-ml} +st=/var/lib/dodge-login-sddm +conf=/etc/sddm.conf.d/autologin.conf +state=/var/lib/sddm/state.conf +dropin=/etc/systemd/system/sddm.service.d/50-dodge.conf +uenv=/etc/xdg/uwsm/env.d/50-dodge-software-gl +[[ $(id -u) == 0 ]] || { echo "run as root" >&2; exit 1; } + +if [[ $mode == status ]]; then + echo "default target: $(systemctl get-default)" + echo "sddm.service: $(systemctl is-enabled sddm.service 2>&1)" + echo "omamobile-hyprland: $(systemctl is-enabled omamobile-hyprland.service 2>&1)" + echo "autologin.conf: $([[ -f $conf ]] && tr '\n' ' ' < "$conf" || echo none)" + exit 0 +fi + +if [[ $mode == revert ]]; then + [[ -d $st ]] || { echo "nothing staged by login-sddm ($st missing)" >&2; exit 1; } + [[ -f $st/created-autologin ]] && rm -f "$conf" + [[ -f $st/state.conf ]] && cp -p "$st/state.conf" "$state" + [[ -f $st/created-state ]] && rm -f "$state" + rm -f "$dropin" "$uenv" + rmdir "${dropin%/*}" "${uenv%/*}" "/etc/xdg/uwsm" 2>/dev/null || true + systemctl daemon-reload + [[ -f $st/sddm-was-disabled ]] && systemctl disable sddm.service + systemctl enable omamobile-hyprland.service + systemctl set-default "$(cat "$st/default.target")" + rm -rf "$st" + echo "reverted: next boot starts the desktop with omamobile-hyprland.service on tty1" + exit 0 +fi + +id "$U" >/dev/null +command -v sddm >/dev/null || { echo "sddm is not installed" >&2; exit 1; } +session="" +for d in /usr/local/share/wayland-sessions /usr/share/wayland-sessions; do + [[ -f $d/omarchy.desktop ]] && { session=omarchy; break; } +done +[[ -n $session ]] || { echo "Omarchy's session (omarchy.desktop) is not installed" >&2; exit 1; } +[[ -f /etc/pam.d/sddm-autologin ]] || { echo "/etc/pam.d/sddm-autologin missing" >&2; exit 1; } + +# What was there before, once (a second run must keep the first state) +if [[ ! -d $st ]]; then + install -d -m 700 "$st" + systemctl get-default > "$st/default.target" + [[ -f $conf ]] || touch "$st/created-autologin" + if [[ -f $state ]]; then cp -p "$state" "$st/state.conf"; else touch "$st/created-state"; fi + systemctl is-enabled --quiet sddm.service || touch "$st/sddm-was-disabled" +fi + +# omamobile-firstboot s_login, as is +mkdir -p /etc/sddm.conf.d /var/lib/sddm +printf '[Autologin]\nUser=%s\nSession=%s.desktop\n' "$U" "$session" > "$conf" +printf '[Last]\nSession=%s.desktop\nUser=%s\n' "$session" "$U" > "$state" +chown -R sddm:sddm /var/lib/sddm 2>/dev/null || true + +install -d "${dropin%/*}" +cat > "$dropin" <<'UNIT' +# dodge (login-sddm): the panel and touch first, as omamobile-hyprland.service had +[Unit] +After=omamobile-display-msm.service omamobile-touch.service +UNIT +# GPU works on 7.3 gpu1 (2026-10-25): no software-GL override any more. +# Remove the one older runs of this script wrote. +rm -f "$uenv" +systemctl daemon-reload +systemctl disable omamobile-hyprland.service +systemctl enable sddm.service +systemctl set-default graphical.target +echo "staged: the next boot autologins $U with SDDM ($session.desktop); revert with: $0 --revert $U" diff --git a/device/dodge/desktop/omamobile-hyprland.service b/device/dodge/desktop/omamobile-hyprland.service new file mode 100644 index 000000000..da47089e3 --- /dev/null +++ b/device/dodge/desktop/omamobile-hyprland.service @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: MIT +# The desktop: Hyprland (through uwsm) on tty1 as user ml, no display +# manager. Starts after omamobile-display-msm (the msm DSI panel) without +# requiring it, so it comes up on simpledrm if msm did not load. +# Rendering is software (llvmpipe) on either path. +[Unit] +Description=Hyprland desktop (msm DSI panel, simpledrm fallback) +After=systemd-user-sessions.service systemd-logind.service omamobile-display-msm.service +Conflicts=getty@tty1.service +OnFailure=getty@tty1.service + +[Service] +User=ml +Group=ml +PAMName=login +TTYPath=/dev/tty1 +TTYReset=yes +TTYVHangup=yes +StandardInput=tty +StandardOutput=journal +StandardError=journal +WorkingDirectory=/home/ml +Environment=LIBGL_ALWAYS_SOFTWARE=1 +ExecStart=/usr/bin/uwsm start -e -D Hyprland hyprland.desktop +Restart=no + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/desktop/setup-stock b/device/dodge/desktop/setup-stock new file mode 100755 index 000000000..2a616e803 --- /dev/null +++ b/device/dodge/desktop/setup-stock @@ -0,0 +1,132 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# dodge-setup-stock: the rest of the stock Omarchy Mobile setup on the +# OnePlus 13 (dodge), after setup-ui: lock screen with PIN pad, power and +# volume keys, on-screen keyboard (squeekboard), the phone window rules, +# menu entries, Chromium flags, screensaver branding. Run as root: +# +# setup-stock USER apply for USER (required; no default account) +# setup-stock --revert USER undo: no lock, no PIN, dodge idle screen-off +# +# The user part is the packaged omamobile-setup-user (omamobile-shell) as is, +# plus the tail of omamobile-firstboot's user step (credential type, the +# lock-keypad toggle; lock-on-start only once a PIN exists). The PIN is the +# account password (stock: omamobile-set-pin runs passwd); this script never +# sets or stores one. Set it as root with `passwd USER`, or later from the +# phone's menu (System > PIN). +# +# Kept dodge-specific, stock skipped (would break dodge): +# - ufw (firstboot allows ssh on usb0 only): root ssh over Wi-Fi must work. +# - sddm autologin: staged separately by login-sddm (it changes how the +# phone boots); until then omamobile-hyprland.service starts Hyprland. +# - `usermod -L root`: root ssh is key-only already (sshd 10-omamobile.conf). +# Replaced: dodge's omamobile-idle-off.service (screen off at 150 s, no lock) +# is disabled; the stock idle path runs instead (screensaver 150 s, lock +# 300 s, the lock blanks the panel 10 s later). `--revert` brings it back. +# Backups: ~USER/.local/state/dodge-setup-stock/, /var/lib/dodge-setup-stock/. +# Omarchy's default keyring (step 1b) is kept on --revert: it may hold +# Chromium's cookie key and other secrets by then. Remove it by hand if needed +# (~USER/.local/share/keyrings/Default_keyring.keyring and default). +set -euo pipefail +revert=0 +[[ ${1:-} == --revert ]] && { revert=1; shift; } +U=${1:-} +[[ -n $U ]] || { echo "usage: setup-stock [--revert] USER" >&2; exit 2; } +[[ $(id -u) == 0 ]] || { echo "run as root" >&2; exit 1; } +id "$U" >/dev/null +H=$(getent passwd "$U" | cut -d: -f6) +uid=$(id -u "$U") +bk=$H/.local/state/dodge-setup-stock +rbk=/var/lib/dodge-setup-stock +files=(.config/hypr/autostart.lua .config/hypr/looknfeel.lua .config/omarchy/shell.json + .config/omarchy/extensions/omarchy-menu.jsonc .config/chromium-flags.conf + .config/omarchy/branding/screensaver.txt .config/foot/screensaver.ini) +added_toggles=(lock-keypad lock-on-start lock-after-screensaver suspend-off credential-password) + +as_user() { + local sig + sig=$(ls -t "/run/user/$uid/hypr" 2>/dev/null | head -1 || true) + runuser -u "$U" -- env LANG=C.UTF-8 HOME="$H" USER="$U" LOGNAME="$U" PATH=/usr/share/omarchy/bin:/usr/local/bin:/usr/bin \ + XDG_RUNTIME_DIR="/run/user/$uid" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \ + WAYLAND_DISPLAY=wayland-1 HYPRLAND_INSTANCE_SIGNATURE="$sig" OMARCHY_PATH=/usr/share/omarchy "$@" +} +live() { # apply to a running session, if there is one + pgrep -u "$U" -x Hyprland >/dev/null || return 0 + as_user hyprctl reload >/dev/null || true + as_user bash -c "$1" /dev/null 2>&1 || true # daemons: keep no pipe open + as_user bash -c 'setsid omarchy-restart-shell' /dev/null 2>&1 & +} + +if ((revert)); then + [[ -f $bk/files.tgz ]] || { echo "no backup in $bk; nothing to revert" >&2; exit 1; } + # Removing the PAM file under a held lock would leave a lock nobody can open + # (the shell prints a locale WARN on stdout without LANG, hence grep -x). + if pgrep -u "$U" -x Hyprland >/dev/null && as_user omarchy-shell lock isLocked 2>/dev/null | grep -qx true; then + echo "the session is locked; unlock it first (or reboot), then revert" >&2; exit 1 + fi + as_user bash -s "$bk" "${files[@]}" <<'SH' +set -u; bk=$1; shift; cd ~ +for f in "$@"; do grep -qxF "$f" "$bk/files.list" || rm -f "$f"; done +tar -xzf "$bk/files.tgz" +t=~/.local/state/omarchy/toggles d=~/.local/state/omarchy/done +for x in lock-keypad lock-on-start lock-after-screensaver suspend-off credential-password screensaver-off; do + if grep -qxF "$x" "$bk/toggles.list"; then touch "$t/$x"; else rm -f "$t/$x"; fi +done +for m in "$d"/*; do grep -qxF "$(basename "$m")" "$bk/done.list" || rm -f "$m"; done +[[ -f $bk/credential ]] || rm -f ~/.config/omamobile/credential +gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false 2>/dev/null || true +SH + # The PIN is the account password: put back what was there before (locked). + if [[ -f $rbk/shadow.$U ]]; then usermod -p "$(cat "$rbk/shadow.$U")" "$U"; else usermod -p '!' "$U"; fi + [[ -f $rbk/pam-created ]] && rm -f /etc/pam.d/omarchy-lock-password /etc/pam.d/omarchy-lock-fingerprint "$rbk/pam-created" + systemctl --global enable omamobile-idle-off.service 2>/dev/null || true + live 'pkill -u "$USER" -x squeekboard; omarchy-shell lock unlock >/dev/null 2>&1; systemctl --user start omamobile-idle-off.service' + echo "reverted: no lock, no PIN, dodge idle screen-off"; exit 0 +fi + +command -v omamobile-setup-user >/dev/null || { echo "omamobile-shell is not installed" >&2; exit 1; } +command -v squeekboard >/dev/null || { echo "squeekboard is not installed" >&2; exit 1; } +# Backups, once (a second run must not overwrite the pre-stock state). +install -d -m 700 "$rbk" +[[ -f $rbk/shadow.$U ]] || { getent shadow "$U" | cut -d: -f2 > "$rbk/shadow.$U"; chmod 600 "$rbk/shadow.$U"; } +if [[ ! -f $bk/files.tgz ]]; then + as_user bash -s "$bk" "${files[@]}" <<'SH' +set -eu; bk=$1; shift; mkdir -p "$bk"; cd ~ +: > "$bk/files.list"; for f in "$@"; do [[ -e $f ]] && echo "$f" >> "$bk/files.list"; done +tar -czf "$bk/files.tgz" -T "$bk/files.list" +ls ~/.local/state/omarchy/toggles > "$bk/toggles.list"; ls ~/.local/state/omarchy/done > "$bk/done.list" +[[ -f ~/.config/omamobile/credential ]] && cp ~/.config/omamobile/credential "$bk/credential" || true +SH +fi + +# 0. The lock's PAM service (Omarchy install/config/lockscreen-pam.sh, which +# omamobile-firstboot runs; dodge's rootfs never ran firstboot). Without it +# the lock refuses to engage ("missing-pam"). +[[ -f /etc/pam.d/omarchy-lock-password || -f $rbk/pam-created ]] || touch "$rbk/pam-created" +OMARCHY_INSTALL_USER=$U omarchy-apply-lock >/dev/null +# 1. Stock user setup, unchanged (idempotent via omarchy-done markers). +as_user omamobile-setup-user +# 1b. Omarchy's default keyring (install/user/default-keyring.sh, from +# omarchy-provision-user, which firstboot runs; dodge never did). Without it +# gnome-keyring raises an invisible "create keyring" prompt and Chromium +# (--password-store=gnome-libsecret) hangs every request with cookies. +# Idempotent: it only writes the files that are missing. +kr=$H/.local/share/keyrings/Default_keyring.keyring +had_kr=0; [[ -f $kr ]] && had_kr=1 +as_user bash -eu /usr/share/omarchy/install/user/default-keyring.sh +if ((!had_kr)) && pgrep -u "$U" -f gnome-keyring-daemon >/dev/null; then + echo "new default keyring: restart gnome-keyring-daemon (or log in again) to use it" +fi +# 2. omamobile-firstboot's user tail: PIN type, number pad, lock after start. +as_user bash -c 't=~/.local/state/omarchy/toggles; mkdir -p "$t" ~/.config/omamobile + [[ -f ~/.config/omamobile/credential ]] || echo pin > ~/.config/omamobile/credential + touch "$t/lock-keypad"; rm -f "$t/screensaver-off"' +if [[ $(passwd -S "$U" | awk '{print $2}') == P ]]; then + as_user touch "$H/.local/state/omarchy/toggles/lock-on-start" +else + echo "no PIN yet: set one with 'passwd $U' (digits for the number pad), then rerun to lock after start" +fi +# 3. Stock idle path instead of dodge's screen-off-without-lock. +systemctl --global disable omamobile-idle-off.service 2>/dev/null || true +live 'systemctl --user stop omamobile-idle-off.service; pgrep -u "$USER" -x squeekboard >/dev/null || setsid squeekboard >/dev/null 2>&1 &' +echo "done: stock lock, keys and keyboard; revert with: $0 --revert $U" diff --git a/device/dodge/desktop/setup-ui b/device/dodge/desktop/setup-ui new file mode 100755 index 000000000..a5773751a --- /dev/null +++ b/device/dodge/desktop/setup-ui @@ -0,0 +1,69 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# dodge-setup-ui: the stock Omarchy Mobile display setup for the OnePlus 13, +# plus the dodge overrides (shell.toml here). Run as the desktop user (not +# root), from this directory or with it as $1. Idempotent. +# +# It does the display part of omamobile-setup-user (omamobile-shell): the +# phone shell plugins, the phone bar profile and the scale-3 monitor, and +# records the same omarchy-done markers, so a later full omamobile-setup-user +# keeps them. The lock, power-key and keyboard steps are in setup-stock. +# Backups: ~/.config/omarchy/shell.json.pre-dodge-ui, +# ~/.config/hypr/monitors.lua.pre-dodge-ui. `--revert` puts them back. +# +# Sharp PNG app icons (workaround for Omarchy's shell, omarchy 4.0.4): its +# AppLibrary icon index keeps the FIRST file `find` lists per icon name, SVGs +# first, then PNGs in directory order. For PNG-only icons that is often +# hicolor/16x16 or 48x48 (chromium.png: 16x16), which the home grid scales to +# 52 px x scale 3 = 156 px: blurry. The index scans ~/.local/share/icons +# before /usr/share/icons, so we link the largest hicolor PNG (512 or 256) of +# every icon without an SVG there. Links listed in +# ~/.local/state/dodge-setup-ui/icon-links; `--revert` removes them. +set -euo pipefail +if [[ ${1:-} == --revert ]]; then SRC=$(cd "$(dirname "$0")" && pwd) +else SRC=$(cd "${1:-$(dirname "$0")}" && pwd); fi +[[ $(id -u) != 0 ]] || { echo "run as the desktop user" >&2; exit 1; } +share=/usr/share/omamobile/shell +cfg=~/.config/omarchy +mon=~/.config/hypr/monitors.lua +links=~/.local/state/dodge-setup-ui/icon-links + +if [[ ${1:-} == --revert ]]; then + [[ -f $cfg/shell.json.pre-dodge-ui ]] && cp "$cfg/shell.json.pre-dodge-ui" "$cfg/shell.json" + [[ -f $mon.pre-dodge-ui ]] && cp "$mon.pre-dodge-ui" "$mon" + rm -f "$cfg/shell.toml" + if [[ -f $links ]]; then + while read -r l; do [[ -L $l ]] && rm -f "$l"; done < "$links" + rm -f "$links" + fi + echo "reverted; restart with: hyprctl reload; omarchy-restart-shell"; exit 0 +fi + +[[ -d $share/plugins ]] || { echo "omamobile-shell is not installed" >&2; exit 1; } +[[ -f $cfg/shell.json.pre-dodge-ui ]] || cp "$cfg/shell.json" "$cfg/shell.json.pre-dodge-ui" +[[ -f $mon.pre-dodge-ui ]] || cp "$mon" "$mon.pre-dodge-ui" + +mkdir -p "$cfg/plugins" +for p in "$share"/plugins/omamobile.*; do ln -sfn "$p" "$cfg/plugins/$(basename "$p")"; done +cp "$share/profile/shell.json" "$cfg/shell.json" +sed -i 's/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = 3/' "$mon" +install -m 644 "$SRC/shell.toml" "$cfg/shell.toml" +# Large PNG icons first in the shell's icon index (see the top) +declare -A svg=() have=() +while read -r n; do svg[$n]=1; done < <(find ~/.icons ~/.local/share/icons /usr/local/share/icons /usr/share/icons \ + \( -path '*/apps/*' -o -path '*/devices/*' \) -name '*.svg' -printf '%f\n' 2>/dev/null | sed 's/\.svg$//' | sort -u) +mkdir -p "${links%/*}"; touch "$links" +for sz in 512x512 256x256; do + for f in /usr/share/icons/hicolor/$sz/apps/*.png; do + [[ -f $f ]] || continue + n=$(basename "$f" .png) + [[ -n ${svg[$n]:-} || -n ${have[$n]:-} ]] && continue + have[$n]=1 + l=~/.local/share/icons/hicolor/$sz/apps/$n.png + [[ -e $l ]] && continue + mkdir -p "${l%/*}"; ln -s "$f" "$l"; echo "$l" >> "$links" + done +done +omarchy-done mark omamobile-shell-profile +omarchy-done mark omamobile-monitor-scale +echo "done; apply with: hyprctl reload; omarchy-restart-shell" diff --git a/device/dodge/desktop/shell.toml b/device/dodge/desktop/shell.toml new file mode 100644 index 000000000..3676e356e --- /dev/null +++ b/device/dodge/desktop/shell.toml @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +# OnePlus 13 (dodge) overrides for the Omarchy shell, installed as +# ~/.config/omarchy/shell.toml (user keys win over the theme's shell.toml). +# Only what differs from the stock Omarchy Mobile phone profile. +# +# Panel: 1440x3168, 6.82 in, about 510 ppi (20.1 px/mm). At the stock phone +# scale 3 one logical px is about 0.15 mm. + +[bar] +# omamobile.bar is max(44, size-horizontal) tall: 44 is 6.6 mm here, 48 is +# 7.2 mm, inside a 7-9 mm touch target. +size-horizontal = 48 + +[spacing] +# The bar's left/right inset (stock 18 = 2.7 mm). 22 (3.3 mm) keeps the clock +# and battery icon clear of the rounded corners: the panel radius isn't +# published, but an arc of up to about 220 px leaves the icons' top edge +# inside this inset. +huge = 22 diff --git a/device/dodge/device.conf b/device/dodge/device.conf new file mode 100644 index 000000000..bb67aa66d --- /dev/null +++ b/device/dodge/device.conf @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: MIT +# Device descriptor: OnePlus 13 (dodge). Format rules: device/cheetah/device.conf. +# +# Omarchy runs on slot B; stock stays on slot A. boot_b lives on LUN sde +# (not sda), so the shared init's sda-only storage guard keeps it read-only +# and day-2 `push` cannot rewrite it until a later LUN-aware change. This PR +# ships the device files only: the inactive-slot installer and firmware-match +# helper are deferred. How this phone was installed (including the firmware +# copy already done and the GPT bit-54 mark) is a record in BRINGUP-M1.md, +# not a procedure for others. FASTBOOT_PRODUCT=sun is ABL getvar product. +# Never flash xbl/abl/vbmeta/modem from an image. +# +# Boot format: this ABL refuses header v2 under fastboot boot and ignores a +# ramdisk in an uploaded v4 boot.img. `omamobile images` with +# BOOT_METHOD=qcom-abl packs a header-v4 kernel-only chain-loader via +# tools/dodge-chain, requiring device/dodge/chainload/ (see NOTES.md / +# chainload/ / BRINGUP-M1.md). CMDLINE feeds stage 2's command line. + +CODENAME=dodge +FASTBOOT_PRODUCT=sun +NAME="OnePlus 13" +SOC=sm8750 +COMPATIBLE="oneplus,dodge" +PACKAGE=omamobile-device-dodge +BOOT_METHOD=qcom-abl + +DTB=qcom/sm8750-oneplus-dodge.dtb +INITRAMFS_INIT=/initramfs/init +PANEL_SIZE=1440x3168 + +BOOT_IMAGES=boot +UFS_RW="boot_b userdata" +OMAMOBILE_SLOT=b +CMDLINE="clk_ignore_unused pd_ignore_unused panic=10 console=tty0" diff --git a/device/dodge/display/display-try b/device/dodge/display/display-try new file mode 100755 index 000000000..dc7555615 --- /dev/null +++ b/device/dodge/display/display-try @@ -0,0 +1,29 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Hand-test of the msm display path on dodge (run as root, once per boot). +# Arms a dead-man reboot first: a reboot always brings simpledrm back. +set -u +DM=${DM:-300} +H=/lib/modules/$(uname -r).held/kernel +[ -d "$H" ] || H=/lib/modules/$(uname -r)/kernel +P=/usr/local/lib/omamobile/display +systemd-run --quiet --unit=dm-display-$$ --on-active="$DM" systemctl reboot --force +echo "dead-man reboot in ${DM}s (unit dm-display-$$)" +[ "${DRMDBG:-0}" != 0 ] && echo "$DRMDBG" > /sys/module/drm/parameters/debug 2>/dev/null +for k in \ + $H/drivers/clk/qcom/dispcc-sm8750.ko \ + $H/drivers/video/backlight/backlight.ko \ + $H/drivers/gpu/drm/display/drm_display_helper.ko \ + $H/drivers/gpu/drm/display/drm_dp_aux_bus.ko \ + $H/drivers/gpu/drm/drm_exec.ko \ + $H/drivers/gpu/drm/scheduler/gpu-sched.ko \ + $H/drivers/soc/qcom/llcc-qcom.ko \ + $H/drivers/soc/qcom/ocmem.ko \ + $H/drivers/soc/qcom/mdt_loader.ko \ + $P/panel-aa569-p-3-a0019-dsc.ko \ + $( [ -f $P/msm.ko ] && echo $P/msm.ko || echo $H/drivers/gpu/drm/msm/msm.ko ) +do + n=$(basename "$k" .ko | tr - _) + if grep -q "^$n " /proc/modules; then echo "have $n"; continue; fi + insmod "$k" && echo "ok $n" || { echo "FAIL $n"; exit 1; } +done diff --git a/device/dodge/display/install b/device/dodge/display/install new file mode 100755 index 000000000..ef2eac1be --- /dev/null +++ b/device/dodge/display/install @@ -0,0 +1,23 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install the msm display load at boot on the phone. Run as root, from +# this directory (copied to the phone), or with the directory as $1. +# Idempotent. Installs omamobile-display-msm (script and unit) and +# display-try, and enables the unit; it does not start it (one load per +# boot, the next boot loads it). msm.ko and the panel module in +# /usr/local/lib/omamobile/display are installed separately. +# Off switch: touch /etc/omamobile/display-msm.disable +set -eu +SRC=${1:-$(dirname "$0")} +log() { echo "dodge-display-install: $*"; } +[ "$(id -u)" = 0 ] || { log "run as root"; exit 1; } +install -D -m 755 "$SRC/omamobile-display-msm" /usr/local/sbin/omamobile-display-msm +install -D -m 644 "$SRC/omamobile-display-msm.service" /etc/systemd/system/omamobile-display-msm.service +install -D -m 755 "$SRC/display-try" /usr/local/sbin/display-try +systemctl daemon-reload +systemctl enable omamobile-display-msm.service +for f in msm.ko panel-aa569-p-3-a0019-dsc.ko; do + [ -f "/usr/local/lib/omamobile/display/$f" ] || log "warning: /usr/local/lib/omamobile/display/$f missing" +done +[ -e /etc/omamobile/display-msm.disable ] && log "note: disabled by /etc/omamobile/display-msm.disable" +log "done; the next boot loads msm" diff --git a/device/dodge/display/omamobile-display-msm b/device/dodge/display/omamobile-display-msm new file mode 100755 index 000000000..2fb7fb152 --- /dev/null +++ b/device/dodge/display/omamobile-display-msm @@ -0,0 +1,166 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Load the msm display path (dispcc, deps, AA569 panel, msm) once per +# boot, before Hyprland. Needs the kernel fix that keeps MDSS_GDSC on +# across runtime suspend, or the first screen off breaks the display. +# +# Off switch: touch /etc/omamobile/display-msm.disable (then reboot). +# Fallback: if msm has not bound a DSI connector within $WAIT seconds, +# it says so and exits 0; Hyprland starts anyway. As long as msm has not +# bound, simpledrm is untouched (msm only takes the framebuffer over +# once it binds). +set -u +WAIT=${WAIT:-20} +DISABLE=/etc/omamobile/display-msm.disable +STAMP=/run/omamobile-display-msm.tried +if [ -n "${OMAMOBILE_MODULES_H:-}" ]; then + H=$OMAMOBILE_MODULES_H +else + H=/lib/modules/$(uname -r).held/kernel + [ -d "$H" ] || H=/lib/modules/$(uname -r)/kernel +fi +P=/usr/local/lib/omamobile/display + +log() { echo "omamobile-display-msm: $*"; echo "omamobile-display-msm: $*" > /dev/kmsg 2>/dev/null; } + +[ -e "$DISABLE" ] && { log "disabled by $DISABLE, staying on simpledrm"; exit 0; } +# Module present is not enough: udev can load msm.ko before dispcc, after which +# msm-mdss fails -110 and leaves /sys/module/msm set with no DSI connector. +# Dodge's panel shows up as card*-DSI-1 (not eDP/HDMI). +for c in /sys/class/drm/card*-DSI-1; do + if [ -r "$c/status" ] && [ "$(cat "$c/status")" = connected ]; then + log "msm already bound: $(basename "$c")" + exit 0 + fi +done +[ -e "$STAMP" ] && { log "already tried this boot ($STAMP)"; exit 0; } + +# Do not stamp when the modules tree is missing. On a RAM-boot test Image +# without $R.held, kmod-overlay fails and this unit runs too early; a later +# tmpfs overlay on /lib/modules/$R (or installing $R.held) must be able to +# retry. Stamping on a missing-.ko failure left tip boots on simpledrm after +# msm-mdss -110 (dispcc never loaded before the deferred-probe timeout). +DISPCC=$H/drivers/clk/qcom/dispcc-sm8750.ko +if [ ! -f "$DISPCC" ] && ! grep -q '/dispcc-sm8750.ko$' "${H%/kernel}/modules.builtin" 2>/dev/null; then + log "no dispcc-sm8750 at $DISPCC (and not builtin); not stamping, staying on simpledrm" + exit 0 +fi +: > "$STAMP" + +# Load what modules.dep lists for $1 first, last entry first. With the +# 6.16 list below these are already loaded; a newer kernel's msm.ko +# needs more (7.3: drm_gpuvm, ubwc_config, cec). +load_deps() { + local d n dep=${H%/kernel}/modules.dep + [ -r "$dep" ] || return 0 + for d in $(sed -n "s#^[^:]*/$(basename "$1"):##p" "$dep" | head -1 | tr ' ' '\n' | tac); do + n=$(basename "$d" .ko | tr - _) + grep -q "^$n " /proc/modules && continue + insmod "${H%/kernel}/$d" || return 1 + done +} + +# Prefer an out-of-tree .ko under $P only when its vermagic matches this +# uname; otherwise a tip Image with a tmpfs modules overlay would insmod a +# stale 6.16 panel/msm from userdata and give up (Invalid module format). +ko_for() { + local p_ko=$1 h_ko=$2 v + if [ -f "$p_ko" ]; then + v=$(modinfo -F vermagic "$p_ko" 2>/dev/null || true) + case $v in + "$(uname -r) "*) echo "$p_ko"; return ;; + esac + fi + echo "$h_ko" +} +PANEL_KO=$(ko_for "$P/panel-aa569-p-3-a0019-dsc.ko" "$H/drivers/gpu/drm/panel/panel-aa569-p-3-a0019-dsc.ko") +MSM_KO=$(ko_for "$P/msm.ko" "$H/drivers/gpu/drm/msm/msm.ko") + +# Only rebind when udev loaded msm before we had dispcc. Rebinding a +# device we just insmod'd races the in-flight probe and can hang the +# oneshot past TimeoutStartSec (no /dev/dri, load spikes). +msm_preloaded= +grep -q '^msm ' /proc/modules && msm_preloaded=1 + +# dispcc first: msm-mdss otherwise fails -110 after the deferred-probe timeout. +for k in \ + $H/drivers/clk/qcom/dispcc-sm8750.ko \ + $H/drivers/video/backlight/backlight.ko \ + $H/drivers/gpu/drm/display/drm_display_helper.ko \ + $H/drivers/gpu/drm/display/drm_dp_aux_bus.ko \ + $H/drivers/gpu/drm/drm_exec.ko \ + $H/drivers/gpu/drm/scheduler/gpu-sched.ko \ + $H/drivers/soc/qcom/llcc-qcom.ko \ + $H/drivers/soc/qcom/ocmem.ko \ + $H/drivers/soc/qcom/mdt_loader.ko \ + $PANEL_KO \ + $MSM_KO +do + n=$(basename "$k" .ko | tr - _) + grep -q "^$n " /proc/modules && continue + # Another kernel (via omamobile-kmod-overlay) may build this one in. + [ -f "$k" ] || ! grep -q "/$(basename "$k")\$" "${H%/kernel}/modules.builtin" 2>/dev/null || continue + load_deps "$k" || { log "a dependency of $n failed; staying on simpledrm"; exit 0; } + insmod "$k" || { log "insmod $n failed; staying on simpledrm"; exit 0; } +done + +# If udev already loaded msm before dispcc, mdss probed with -110 and will +# not retry on its own. After we have loaded dispcc, kick the platform device +# so probe runs again with clocks available. +# Wait briefly for panel attach: a just-loaded or preloaded msm can bind DSI +# and register DRM before status=connected. Immediate rebind then destroys a +# good probe (seen on a RAM boot: an early rebind tore down a probe that was about to connect). +dsi_bound= +i=0 +while [ $i -lt 6 ]; do + for c in /sys/class/drm/card*-DSI-1; do + if [ -r "$c/status" ] && [ "$(cat "$c/status")" = connected ]; then + dsi_bound=1 + break 2 + fi + done + # Fixed grace: simpledrm already provides card0, so "any card" is not proof of msm progress; wait before deciding to rebind. + for c in /sys/class/drm/card[0-9]*; do + if [ -e "$c" ]; then + sleep 0.5 + i=$((i + 1)) + continue 2 + fi + done + break +done +# Only rebind when msm was preloaded before dispcc AND there is still no DSI +# connector node at all (classic mdss -110 / no DRM). Never unbind a +# half-ready probe that already registered card*-DSI-1. +if [ -n "$msm_preloaded" ] && [ -z "$dsi_bound" ] && grep -q '^msm ' /proc/modules; then + have_dsi_node= + for c in /sys/class/drm/card*-DSI-1; do + [ -e "$c" ] && have_dsi_node=1 && break + done + if [ -z "$have_dsi_node" ]; then + dev=ae00000.display-subsystem + drv=/sys/bus/platform/drivers/msm-mdss + if [ -d "$drv" ]; then + log "msm was preloaded with no DSI node; rebinding $dev after dispcc" + echo "$dev" > "$drv/unbind" 2>/dev/null || true + sleep 0.5 + echo "$dev" > "$drv/bind" 2>/dev/null || true + fi + else + log "msm has DSI node but not connected yet; skipping rebind" + fi +fi + +i=0 +while [ $i -lt $((WAIT * 2)) ]; do + for c in /sys/class/drm/card*-DSI-1; do + if [ -r "$c/status" ] && [ "$(cat "$c/status")" = connected ]; then + log "msm bound: $(basename "$c") after $((i / 2)) s" + exit 0 + fi + done + sleep 0.5 + i=$((i + 1)) +done +log "msm did not bind a DSI connector within ${WAIT} s; Hyprland starts on whatever is there ($(ls /dev/dri 2>/dev/null | tr '\n' ' '))" +exit 0 diff --git a/device/dodge/display/omamobile-display-msm.service b/device/dodge/display/omamobile-display-msm.service new file mode 100644 index 000000000..315cde4fb --- /dev/null +++ b/device/dodge/display/omamobile-display-msm.service @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +# msm display path, loaded once per boot before Hyprland. Never blocks +# the desktop: the script exits 0 on any failure, and Hyprland only +# orders after this unit (no Requires), so a timeout here still lets it +# start. +[Unit] +Description=msm display (DSI panel) for dodge, loaded once +After=local-fs.target systemd-modules-load.service +Before=omamobile-hyprland.service +ConditionPathExists=!/etc/omamobile/display-msm.disable + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/sbin/omamobile-display-msm +TimeoutStartSec=60 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/display/selfheal/omamobile-display-selfheal b/device/dodge/display/selfheal/omamobile-display-selfheal new file mode 100755 index 000000000..4f51eda89 --- /dev/null +++ b/device/dodge/display/selfheal/omamobile-display-selfheal @@ -0,0 +1,41 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Display self-heal (dodge), OPT-IN. If the first msm panel init this boot +# failed with a DSI cmd DMA timeout (-110: the warm-boot display drop), the +# screen stays dark and the phone freezes ~6 min later. Reboot once so the +# next warm boot (usually good) brings the display back. +# +# Enable: touch /etc/omamobile/display-selfheal.enable +# systemctl enable omamobile-display-selfheal.service +# Loop guard: at most one self-heal reboot per $GAP seconds (marker mtime +# in /var/lib/omamobile). A good boot removes the marker. +set -u +MARK=/var/lib/omamobile/display-selfheal +GAP=${GAP:-600} +WAIT=${WAIT:-25} +log() { echo "omamobile-display-selfheal: $*"; echo "omamobile-display-selfheal: $*" > /dev/kmsg 2>/dev/null; } + +# give msm time to bind and send the first panel commands +i=0 +while [ $i -lt "$WAIT" ]; do + journalctl -k -b -q --no-pager | grep -q -e 'cmd dma tx failed' -e 'Failed to initialize panel' && break + [ -e /sys/class/drm/card1-DSI-1 ] || [ -e /sys/class/drm/card0-DSI-1 ] && [ $i -ge 10 ] && break + sleep 1; i=$((i + 1)) +done + +if ! journalctl -k -b -q --no-pager | grep -q -e 'ret=-110' -e 'Failed to initialize panel: -110'; then + [ -e "$MARK" ] && { rm -f "$MARK"; log "display OK, cleared marker"; } + exit 0 +fi + +mkdir -p "${MARK%/*}" +if [ -e "$MARK" ]; then + age=$(( $(date +%s) - $(stat -c %Y "$MARK") )) + if [ "$age" -lt "$GAP" ]; then + log "panel init -110 again, but already self-healed ${age}s ago; not rebooting" + exit 0 + fi +fi +: > "$MARK"; sync +log "first panel init failed with -110 (display dark); rebooting once" +systemctl reboot diff --git a/device/dodge/display/selfheal/omamobile-display-selfheal.service b/device/dodge/display/selfheal/omamobile-display-selfheal.service new file mode 100644 index 000000000..1cbd1a7cc --- /dev/null +++ b/device/dodge/display/selfheal/omamobile-display-selfheal.service @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +# OPT-IN: not enabled by default. Reboots once if msm's first panel init +# failed with -110 (see omamobile-display-selfheal). +[Unit] +Description=Reboot once if the msm panel init timed out (dodge display drop) +After=omamobile-display-msm.service +ConditionPathExists=/etc/omamobile/display-selfheal.enable + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/omamobile-display-selfheal +TimeoutStartSec=60 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/idle/install b/device/dodge/idle/install new file mode 100755 index 000000000..b9d02d0bf --- /dev/null +++ b/device/dodge/idle/install @@ -0,0 +1,23 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install the dodge idle screen-off (no lock). Run as root, from this +# directory (copied to the phone), or with it as $1. Idempotent. +# - /usr/share/omamobile/idle-off/shell.qml and the user unit +# /etc/systemd/user/omamobile-idle-off.service, enabled globally. +# - Omarchy's screensaver is switched off for $IDLE_USER (its own toggle, +# omarchy-toggle-screensaver turns it back on): it ran llvmpipe at about +# 650 % CPU and never turned the screen off. +# Nothing touches the lock or PAM. Undo: systemctl --global disable +# omamobile-idle-off.service and remove the toggle file. +set -eu +SRC=${1:-$(dirname "$0")} +IDLE_USER=${IDLE_USER:-ml} +log() { echo "dodge-idle-install: $*"; } +[ "$(id -u)" = 0 ] || { log "run as root"; exit 1; } +install -D -m 644 "$SRC/omamobile-idle-off/shell.qml" /usr/share/omamobile/idle-off/shell.qml +install -D -m 644 "$SRC/omamobile-idle-off.service" /etc/systemd/user/omamobile-idle-off.service +systemctl --global enable omamobile-idle-off.service +home=$(getent passwd "$IDLE_USER" | cut -d: -f6) +runuser -u "$IDLE_USER" -- mkdir -p "$home/.local/state/omarchy/toggles" +runuser -u "$IDLE_USER" -- touch "$home/.local/state/omarchy/toggles/screensaver-off" +log "done; starts with the next graphical session (or: systemctl --user start omamobile-idle-off as $IDLE_USER)" diff --git a/device/dodge/idle/omamobile-idle-off.service b/device/dodge/idle/omamobile-idle-off.service new file mode 100644 index 000000000..3f4e8b4f2 --- /dev/null +++ b/device/dodge/idle/omamobile-idle-off.service @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +# dodge: screen off after inactivity, no lock (user unit, see shell.qml). +# Timeout: OMAMOBILE_IDLE_OFF_SECONDS here or in a drop-in. Off switch: +# systemctl --user disable --now omamobile-idle-off.service +[Unit] +Description=Screen off after inactivity (dodge, no lock) +PartOf=graphical-session.target +After=graphical-session.target + +[Service] +Environment=OMAMOBILE_IDLE_OFF_SECONDS=150 +Environment=PATH=/usr/share/omarchy/bin:/usr/local/bin:/usr/bin +Environment=OMARCHY_PATH=/usr/share/omarchy +ExecStart=/usr/bin/quickshell -n -p /usr/share/omamobile/idle-off +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=graphical-session.target diff --git a/device/dodge/idle/omamobile-idle-off/shell.qml b/device/dodge/idle/omamobile-idle-off/shell.qml new file mode 100644 index 000000000..5a198d562 --- /dev/null +++ b/device/dodge/idle/omamobile-idle-off/shell.qml @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: MIT +// dodge: turn the screen off after inactivity, no lock (Martin's choice +// for now). A separate Quickshell instance next to omarchy-shell. After +// OMAMOBILE_IDLE_OFF_SECONDS (default 150) without input it runs +// `omarchy-brightness-display off` (DPMS off plus bl_power 4); the first +// input after that (touch, key) runs `omarchy-brightness-display on`. +// Honours idle inhibitors (video, `noidle` windows) and Omarchy's +// stay-awake toggle. +import QtQuick +import Quickshell +import Quickshell.Io +import Quickshell.Wayland + +ShellRoot { + id: root + readonly property int seconds: { + var v = parseInt(Quickshell.env("OMAMOBILE_IDLE_OFF_SECONDS") || "150") + return v > 0 ? v : 150 + } + property bool turnedOff: false + + function run(cmd) { + proc.command = ["bash", "-lc", cmd] + proc.running = true + } + + IdleMonitor { + id: monitor + timeout: root.seconds + respectInhibitors: true + onIsIdleChanged: { + if (isIdle) { + console.log("omamobile-idle-off: idle " + root.seconds + " s, screen off") + root.turnedOff = true + root.run("[[ -f $HOME/.local/state/omarchy/indicators/stay-awake ]] && exit 0; omarchy-brightness-display off") + } else if (root.turnedOff) { + console.log("omamobile-idle-off: activity, screen on") + root.turnedOff = false + root.run("omarchy-brightness-display on") + } + } + } + + Process { id: proc } + + Component.onCompleted: console.log("omamobile-idle-off: ready, " + root.seconds + " s") +} diff --git a/device/dodge/initramfs/reboot-to.c b/device/dodge/initramfs/reboot-to.c new file mode 100644 index 000000000..f663f18e4 --- /dev/null +++ b/device/dodge/initramfs/reboot-to.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT +// reboot-to: reboot with a reason ABL reads from the PMIC SDAM. +// "reboot-to bootloader" is LINUX_REBOOT_CMD_RESTART2. Busybox reboot +// cannot pass a reason. Same call as +// packages/omamobile-device-cheetah/src/reboot-to.c, built without a +// libc so the ramdisk pack needs no aarch64 sysroot. +// +// aarch64 Linux entry: sp points at argc, then the argv pointers. + +#define __NR_sync 81 +#define __NR_reboot 142 +#define __NR_exit_group 94 + +#define LINUX_REBOOT_MAGIC1 0xfee1dead +#define LINUX_REBOOT_MAGIC2 672274793 +#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 + +static long scall(long n, long a, long b, long c, long d) +{ + register long x8 __asm__("x8") = n; + register long x0 __asm__("x0") = a; + register long x1 __asm__("x1") = b; + register long x2 __asm__("x2") = c; + register long x3 __asm__("x3") = d; + + __asm__ volatile("svc #0" + : "+r"(x0) + : "r"(x1), "r"(x2), "r"(x3), "r"(x8) + : "memory"); + return x0; +} + +/* A C _start has a prologue, so sp there is no longer the entry stack. + Linux put argc at [sp] and argv just after it. */ +__attribute__((naked)) void _start(void) +{ + __asm__ volatile( + "ldr x0, [sp]\n" + "add x1, sp, #8\n" + "b go\n"); +} + +void go(long argc, char **argv) +{ + const char *reason = "bootloader"; + + if (argc > 1 && argv[1] && argv[1][0]) + reason = argv[1]; + + scall(__NR_sync, 0, 0, 0, 0); + scall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_RESTART2, (long)reason); + scall(__NR_exit_group, 1, 0, 0, 0); + for (;;) + ; +} diff --git a/device/dodge/kernel/install b/device/dodge/kernel/install new file mode 100755 index 000000000..31e3d7570 --- /dev/null +++ b/device/dodge/kernel/install @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Install the kmod-overlay + tip-modules-overlay helpers into /usr/local/sbin +# (not under the omamobile bind). Run as root. +set -eu +cd "$(dirname "$0")" +install -Dm755 omamobile-kmod-overlay /usr/local/sbin/omamobile-kmod-overlay +install -Dm755 omamobile-tip-modules-overlay /usr/local/sbin/omamobile-tip-modules-overlay +install -Dm644 omamobile-kmod-overlay.service /etc/systemd/system/omamobile-kmod-overlay.service +systemctl daemon-reload +systemctl enable omamobile-kmod-overlay.service || true +echo "installed omamobile-kmod-overlay + tip-modules-overlay" diff --git a/device/dodge/kernel/omamobile-kmod-overlay b/device/dodge/kernel/omamobile-kmod-overlay new file mode 100755 index 000000000..854d670e9 --- /dev/null +++ b/device/dodge/kernel/omamobile-kmod-overlay @@ -0,0 +1,46 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# dodge's module loaders historically insmod from two fixed places, built +# for the pinned release: /usr/lib/modules/$PINNED.held and +# /usr/local/lib/omamobile. When another kernel runs (a test Image), bind +# its own copies over both, so nothing loads modules built for a +# different kernel. With the pinned kernel this does nothing, and the +# original directories are never changed. +# +# Tip RAM path: there is no $R.held / omamobile.$R. After a tmpfs modules +# overlay lands at /lib/modules/$R (modules.dep present), this unit exits +# 0 so After= dependents can start. The actual stamp-clear + unit restart +# is omamobile-tip-modules-overlay (the one hand step). +PINNED=6.16.0-gb3ee311dab85 +R=$(uname -r) +[ "$R" = "$PINNED" ] && exit 0 + +H=/usr/lib/modules/$R.held +L=/usr/local/lib/omamobile.$R +if [ -d "$H" ] && [ -d "$L" ]; then + mountpoint -q "/usr/lib/modules/$PINNED.held" || \ + mount --bind "$H" "/usr/lib/modules/$PINNED.held" + mountpoint -q /usr/local/lib/omamobile || \ + mount --bind "$L" /usr/local/lib/omamobile + echo "kmod-overlay: $R modules over $PINNED paths" + if [ -r "$L/skip-units" ]; then + mkdir -p /run/omamobile-skip + grep -v '^#' "$L/skip-units" | while read -r u; do + [ -n "$u" ] || continue + : > "/run/omamobile-skip/$u" + echo "kmod-overlay: skip $u on $R" + done + fi + exit 0 +fi + +# Tip RAM: modules tree already extracted (tmpfs overlay). Exit 0 so a +# late `systemctl start` after the hand overlay unblocks After= chains; +# tip-modules-overlay does the stamp clear + restarts. +if [ -r "/usr/lib/modules/$R/modules.dep" ] || [ -r "/lib/modules/$R/modules.dep" ]; then + echo "kmod-overlay: tip modules present for $R" + exit 0 +fi + +echo "kmod-overlay: no $H or $L for $R; loaders will fail vermagic" >&2 +exit 1 diff --git a/device/dodge/kernel/omamobile-kmod-overlay.service b/device/dodge/kernel/omamobile-kmod-overlay.service new file mode 100644 index 000000000..cfeaafc94 --- /dev/null +++ b/device/dodge/kernel/omamobile-kmod-overlay.service @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=Omarchy Mobile dodge: per-release module overlay for test kernels +DefaultDependencies=no +After=local-fs.target +Before=sysinit.target omamobile-adsp-battery.service omamobile-display-msm.service omamobile-wifi-pcie.service omamobile-wifi-ath12k.service omamobile-bt.service omamobile-touch.service omamobile-dodge-audio.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/sbin/omamobile-kmod-overlay + +[Install] +WantedBy=sysinit.target diff --git a/device/dodge/kernel/omamobile-tip-modules-overlay b/device/dodge/kernel/omamobile-tip-modules-overlay new file mode 100755 index 000000000..6c670ef4c --- /dev/null +++ b/device/dodge/kernel/omamobile-tip-modules-overlay @@ -0,0 +1,129 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Tip RAM boot: apply a matching modules tar as a tmpfs overlay under +# /lib/modules/$(uname -r), depmod, clear early-boot stamps, restart the +# tip-aware bring-up units, and bounce sddm once DSI is up. Intended as +# the ONLY hand step after `fastboot boot` of an unpackaged tip Image. +# +# Usage: omamobile-tip-modules-overlay /path/to/modules-overlay-….tar +# omamobile-tip-modules-overlay # if tar already extracted +set -eu +R=$(uname -r) +DEST=/lib/modules/$R +TAR=${1:-} + +log() { echo "tip-modules-overlay: $*"; } + +if [ -n "$TAR" ]; then + [ -f "$TAR" ] || { log "no such file: $TAR"; exit 1; } + mkdir -p "$DEST" + if [ ! -r "$DEST/modules.dep" ]; then + if ! mountpoint -q "$DEST" 2>/dev/null; then + mount -t tmpfs -o size=512M tip-modules "$DEST" + log "mounted tmpfs on $DEST" + fi + fi + # Tar layout is lib/modules/$R/...; extract at / so paths land in DEST. + if tar -tf "$TAR" | head -1 | grep -q "^lib/modules/$R/"; then + tar -xf "$TAR" -C / + else + tar -xf "$TAR" -C "$DEST" + fi + depmod -a "$R" 2>/dev/null || depmod -a + log "extracted $(basename "$TAR") into $DEST" +fi + +[ -r "$DEST/modules.dep" ] || [ -r "/usr/lib/modules/$R/modules.dep" ] || { + log "no modules.dep under $DEST; pass the modules-overlay tar as \$1" + exit 1 +} + +# Mark kmod-overlay successful for After= dependents. +systemctl reset-failed omamobile-kmod-overlay.service 2>/dev/null || true +systemctl stop omamobile-kmod-overlay.service 2>/dev/null || true +systemctl start omamobile-kmod-overlay.service + +# Stamps set by early units that ran before the overlay. +rm -f /run/omamobile-bt.tried \ + /run/omamobile-ath12k.tried \ + /run/omamobile-display-msm.tried \ + /run/omamobile-wifi-pcie.tried 2>/dev/null || true +rm -f /run/omamobile-skip/omamobile-display-msm.service \ + /run/omamobile-skip/omamobile-wifi-pcie.service \ + /run/omamobile-skip/omamobile-wifi-ath12k.service \ + /run/omamobile-skip/omamobile-touch.service \ + /run/omamobile-skip/omamobile-adsp-battery.service \ + /run/omamobile-skip/omamobile-bt.service \ + /run/omamobile-skip/omamobile-dodge-audio.service \ + /run/omamobile-skip/omamobile-sensors.service 2>/dev/null || true + +systemctl daemon-reload 2>/dev/null || true +systemctl reset-failed \ + omamobile-display-msm.service \ + omamobile-wifi-pcie.service \ + omamobile-wifi-ath12k.service \ + omamobile-touch.service \ + omamobile-adsp-battery.service \ + omamobile-bt.service \ + omamobile-dodge-audio.service \ + omamobile-sensors.service 2>/dev/null || true + +# Display first so DSI is up before the session bounce. +systemctl restart omamobile-display-msm.service 2>/dev/null || \ + systemctl start omamobile-display-msm.service 2>/dev/null || true +i=0 +while [ $i -lt 40 ]; do + for c in /sys/class/drm/card*-DSI-1; do + [ -r "$c/status" ] || continue + [ "$(cat "$c/status")" = connected ] && break 2 + done + sleep 0.5 + i=$((i + 1)) +done + +systemctl restart omamobile-wifi-pcie.service 2>/dev/null || \ + systemctl start omamobile-wifi-pcie.service 2>/dev/null || true +systemctl restart omamobile-wifi-ath12k.service 2>/dev/null || \ + systemctl start omamobile-wifi-ath12k.service 2>/dev/null || true +systemctl restart omamobile-touch.service 2>/dev/null || \ + systemctl start omamobile-touch.service 2>/dev/null || true +systemctl restart omamobile-adsp-battery.service 2>/dev/null || \ + systemctl start omamobile-adsp-battery.service 2>/dev/null || true + +# BT needs a WLAN iface; give ath12k a moment. +i=0 +while [ $i -lt 30 ]; do + [ -e /sys/class/net/wlan0/address ] || [ -e /sys/class/net/wlp1s0/address ] && break + sleep 0.5 + i=$((i + 1)) +done +systemctl restart omamobile-bt.service 2>/dev/null || \ + systemctl start omamobile-bt.service 2>/dev/null || true + +systemctl restart omamobile-dodge-audio.service 2>/dev/null || \ + systemctl start omamobile-dodge-audio.service 2>/dev/null || true + +if [ -e /etc/omamobile/sensors.enable ]; then + systemctl restart omamobile-sensors.service 2>/dev/null || \ + systemctl start omamobile-sensors.service 2>/dev/null || true +fi + +# Session: tip boots start sddm on simpledrm; msm handoff kills +# sddm-helper (exit 255). On B, sddm.service.d/50-dodge.conf After= +# omamobile-display-msm so the greeter never starts on simpledrm. After tip +# overlay, bounce sddm once DSI is up (stamp so a re-run does not kill a live session). +dsi= +for c in /sys/class/drm/card*-DSI-1; do + [ -r "$c/status" ] || continue + [ "$(cat "$c/status")" = connected ] && dsi=$(basename "$c") +done +if [ -n "$dsi" ] && systemctl is-enabled -q sddm.service 2>/dev/null; then + if [ ! -e /run/omamobile-tip-sddm.bounced ]; then + touch /run/omamobile-tip-sddm.bounced + log "bouncing sddm after $dsi bound" + systemctl restart sddm.service 2>/dev/null || true + else + log "sddm already bounced this boot; leaving session alone" + fi +fi +log "done" diff --git a/device/dodge/modem/78-omamobile-mm-fake-net.rules b/device/dodge/modem/78-omamobile-mm-fake-net.rules new file mode 100644 index 000000000..da2dc8bdf --- /dev/null +++ b/device/dodge/modem/78-omamobile-mm-fake-net.rules @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Experiment (2026-10-21): ModemManager refuses a QMI modem without a net port, +# and SM8750 has no IPA driver in 6.16 yet. Offer a tun device as the +# qcom-soc net port so MM creates the modem for control (registration, SIM, +# voice/SMS). Data through it cannot work. Remove once IPA exists. +ACTION!="add|change|move|bind", GOTO="omamobile_mm_fake_end" +SUBSYSTEM=="net", KERNEL=="rmnet_mm0", ENV{ID_MM_DEVICE_PROCESS}="1", ENV{ID_MM_QCOM_SOC}="1", ENV{ID_MM_PHYSDEV_UID}="qcom-soc", ENV{ID_MM_CANDIDATE}="1" +LABEL="omamobile_mm_fake_end" diff --git a/device/dodge/modem/ModemManager-omamobile.conf b/device/dodge/modem/ModemManager-omamobile.conf new file mode 100644 index 000000000..d641fe9af --- /dev/null +++ b/device/dodge/modem/ModemManager-omamobile.conf @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# Drop-in: ModemManager runs only with the dodge modem flag, after the modem +# DSP, the SIM provisioning/online step and the stand-in net port are up. +[Unit] +ConditionPathExists=/etc/omamobile/modem-probe.enable +Wants=omamobile-modem.service omamobile-modem-online.service omamobile-mm-netport.service +After=omamobile-modem.service omamobile-modem-online.service omamobile-mm-netport.service diff --git a/device/dodge/modem/README.md b/device/dodge/modem/README.md new file mode 100644 index 000000000..9a01deaba --- /dev/null +++ b/device/dodge/modem/README.md @@ -0,0 +1,84 @@ + +# dodge modem + +Everything here is inert unless `/etc/omamobile/modem-probe.enable` exists. +Default in the package: **off** (no `/etc/omamobile/modem-probe.enable`). +Owners who opt in need their own firmware under `/lib/firmware` and their +own EFS copies (never shipped). On a kernel without an enabled IPA DT node +`omamobile-modem-efs` exits without touching the copies, so rmtfs and the MPSS +are never started and a rollback stays safe even with the flag on. + +## Boot sequence (flag present) + +1. `adsp-battery.sh` loads `qcom_q6v5_pas`. The MPSS is probed; the CDSP may + fail its load without firmware (harmless). +2. `omamobile-modem-efs.service` runs before rmtfs when IPA is present. It + restores the named good EFS *copy set* from + `/var/lib/omamobile/efs-good/` (name in + `/etc/omamobile/modem-efs-good`). Good sets are never rotated. Optional + auto-snapshots under `/var/lib/omamobile/efs-snapshots/` stay on the phone. +3. `omamobile-rmtfs.service` loads `qcom_rmtfs_mem` and runs **only** + `rmtfs -r -o /var/lib/omamobile/modem-efs -v`: read-only copies of the EFS + partitions, with modem writes kept in RAM. Never `-P`. +4. `omamobile-tqftpserv.service` serves MCFG from `/lib/firmware`. +5. `omamobile-modem.service` starts the MPSS by name. Do **not** stop the + modem remoteproc (hard-reset risk on 7.3); the unit has no ExecStop. +6. `omamobile-modem-online.service` provisions SIM slot 1 if needed, goes + online, waits for registration. +7. ModemManager (drop-in `ModemManager-omamobile.conf`) and the NM profile + `omamobile-cellular.nmconnection` (APN `internet`, metric 700) bring up + data on `rmnet_ipa0` / `qmapmux0.0`. + +## EFS restore (no blobs in git) + +The modem needs the phone's own non-volatile calibration. This repository +ships **units and docs only** — never EFS snapshots, NV backups, or modem +firmware. + +On the phone, once, take read-only copies of the current slot's partitions +(`dd if=` only, mode 600) into `/var/lib/omamobile/modem-efs/` (and promote a +known-good set into `/var/lib/omamobile/efs-good/`): + +- `oplusstanvbk_` → `oem_stanvbk` +- `oplusdycnvbk` → `oem_dycnvbk` (per-unit; keep off any shared medium) + +A set the modem has written to for a few minutes can crash the next boot +(rtsar), so the good set is restored on every boot. Firmware for the MPSS +belongs under `/lib/firmware/qcom/sm8750/OnePlus/` from the owner's own +OxygenOS / factory image; it is not in git. (`tools/phone-provision` and the +Pixel extract scripts only know Pixel factory images — do not use them for +dodge firmware.) + + +## Off-phone backups (CONTRIBUTING §3.3) + +Before any modem session, keep **off-phone**, read-only copies of: + +- `modemst1`, `modemst2` +- `fsg`, `fsc` +- `persist` +- oplus NV (`oplusstanvbk_`, `oplusdycnvbk`) + +Store them with a `SHA256SUMS` and re-check the hashes before each modem +session. Never commit those copies (or any EFS / modem firmware) to git. On +this phone the off-phone set lives outside the repository; the on-phone +`/var/lib/omamobile/efs-good/` set above is a separate, phone-local restore +path used when the opt-in flag is present. + +## Install + +Copy this directory to the phone and run `./install` as root. It expects +`rmtfs` and `tqftpserv` (linux-msm), the in-tree `rmtfs_mem` module for the +running kernel, and the firmware + EFS copies above. + +Turn on: `touch /etc/omamobile/modem-probe.enable`, then reboot. Turn off: +remove the flag and reboot. + +## Modules path on a stock modules-push install + +`omamobile-modem` (and the Bluetooth helper) currently look for out-of-tree +modules under `/usr/lib/modules/$(uname -r).held/` and +`/usr/local/lib/omamobile/…`. A kernel installed by `modules-push` has +neither path — the scripts fail safely (no load) until the package installs +those modules next to the running release. Until then, treat modem/BT bring-up +on a pure `modules-push` tree as manual. diff --git a/device/dodge/modem/adsp-battery.sh b/device/dodge/modem/adsp-battery.sh new file mode 100755 index 000000000..5aa4728eb --- /dev/null +++ b/device/dodge/modem/adsp-battery.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Bring up the ADSP and the PMIC battery manager. Not required for boot. +# Installed as /usr/local/lib/omamobile/adsp-battery.sh (omamobile-adsp-battery.service). +# +# Prefer modprobe so a tip Image with a tmpfs modules overlay gets matching +# kos. Fall back to the pinned held tree (bind-mounted over by +# omamobile-kmod-overlay on gpu2-style boots) and /usr/local/lib/omamobile +# for out-of-tree held kos (pd_mapper / q6v5_pas on 6.16). +# +# The PAS driver is loaded with only_adsp=1 by default, so the modem and the +# CDSP are not probed. Creating /etc/omamobile/modem-probe.enable loads it with +# only_adsp=0 instead. +set -u +HELD=/usr/lib/modules/6.16.0-gb3ee311dab85.held/kernel +D=/usr/local/lib/omamobile + +log() { echo "adsp-battery: $*"; } + +# Load by module name. modprobe first; else insmod held path or $D. +# Extra args are module parameters (e.g. only_adsp=1). +load() { + name=$(echo "$1" | tr - _) + shift || true + if awk -v m="$name" '$1==m {found=1} END{exit !found}' /proc/modules; then + return 0 + fi + if modprobe "$name" "$@" 2>/dev/null; then + return 0 + fi + hyphen=$(echo "$name" | tr _ -) + # $D (LOCAL out-of-tree) before pinned $HELD — held also ships + # qcom_q6v5_pas / qcom_pd_mapper; LOCAL copies are the intentional ones. + for f in \ + "$D/$name.ko" "$D/$hyphen.ko" \ + "$HELD/net/qrtr/$name.ko" "$HELD/net/qrtr/$hyphen.ko" \ + "$HELD/drivers/soc/qcom/$name.ko" "$HELD/drivers/soc/qcom/$hyphen.ko" \ + "$HELD/drivers/remoteproc/$name.ko" "$HELD/drivers/remoteproc/$hyphen.ko" \ + "$HELD/drivers/rpmsg/$name.ko" "$HELD/drivers/rpmsg/$hyphen.ko" \ + "$HELD/drivers/power/supply/$name.ko" "$HELD/drivers/power/supply/$hyphen.ko" \ + "$HELD/drivers/misc/$name.ko" "$HELD/drivers/misc/$hyphen.ko" + do + [ -f "$f" ] || continue + if [ "$#" -gt 0 ]; then + insmod "$f" "$@" 2>/dev/null && return 0 + else + insmod "$f" 2>/dev/null && return 0 + fi + done + return 1 +} + +opt() { + if load "$@"; then + return 0 + fi + log "$1 not loaded (built-in, or no matching .ko yet)" + return 0 +} + +opt qrtr +opt qrtr_smd +opt qmi_helpers +opt qcom_pdr_msg +opt pdr_interface +opt qcom_pil_info +opt mdt_loader +opt qcom_glink_smem +opt qcom_common +opt qcom_sysmon +opt qcom_q6v5 +opt qcom_pd_mapper + +ONLY_ADSP=1 +[ -e /etc/omamobile/modem-probe.enable ] && ONLY_ADSP=0 +if ! load qcom_q6v5_pas only_adsp=$ONLY_ADSP; then + log "qcom_q6v5_pas failed to load" + exit 1 +fi + +adsp_state() { + for r in /sys/class/remoteproc/remoteproc*; do + [ "$(cat "$r/name" 2>/dev/null)" = adsp ] && { cat "$r/state"; return; } + done +} +i=0 +while [ $i -lt 10 ]; do + state=$(adsp_state 2>/dev/null || true) + [ "$state" = running ] && break + sleep 0.5 + i=$((i + 1)) +done +[ "$state" = running ] || log "ADSP not running yet (state=${state:-none})" + +opt pmic_glink +opt qcom_battmgr +# FastRPC device for sensors / audio PDs (module only; adsprpcd is audio's job). +opt fastrpc diff --git a/device/dodge/modem/install b/device/dodge/modem/install new file mode 100755 index 000000000..d5901e676 --- /dev/null +++ b/device/dodge/modem/install @@ -0,0 +1,46 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Run as root on the phone from device/dodge/modem. Installs the modem helper +# and units, the ModemManager drop-in and udev rule, and enables them. They do nothing unless +# /etc/omamobile/modem-probe.enable exists. Needs: /usr/local/bin/rmtfs and +# tqftpserv (built from linux-msm git), qcom_rmtfs_mem.ko, the EFS copies. +set -eu +cd "$(dirname "$0")" +for f in /usr/local/bin/rmtfs /usr/local/bin/tqftpserv /usr/local/lib/omamobile/modem/qcom_rmtfs_mem.ko; do + [ -e "$f" ] || { echo "missing $f" >&2; exit 1; } +done +install -Dm755 omamobile-modem /usr/local/lib/omamobile/modem/omamobile-modem + +# Install adsp-battery into the live path, and when that path is a bind +# (omamobile-kmod-overlay), also into the real rootfs via a private bind of / +# plus every omamobile.* tree so tip RAM (no bind) sees the tip-aware script. +install_adsp_battery() { + install -Dm755 adsp-battery.sh /usr/local/lib/omamobile/adsp-battery.sh + mountpoint -q /usr/local/lib/omamobile 2>/dev/null || return 0 + tmp=$(mktemp -d) + mount --bind / "$tmp" + install -Dm755 adsp-battery.sh "$tmp/usr/local/lib/omamobile/adsp-battery.sh" + for d in "$tmp"/usr/local/lib/omamobile.*; do + [ -d "$d" ] || continue + install -Dm755 adsp-battery.sh "$d/adsp-battery.sh" + done + umount "$tmp" + rmdir "$tmp" +} +install_adsp_battery + +install -Dm644 omamobile-adsp-battery.service /etc/systemd/system/omamobile-adsp-battery.service +systemctl enable omamobile-adsp-battery.service || true +install -Dm644 78-omamobile-mm-fake-net.rules /etc/udev/rules.d/78-omamobile-mm-fake-net.rules +install -Dm600 omamobile-cellular.nmconnection /etc/NetworkManager/system-connections/omamobile-cellular.nmconnection +install -Dm644 ModemManager-omamobile.conf /etc/systemd/system/ModemManager.service.d/omamobile.conf +for u in omamobile-modem-efs omamobile-rmtfs omamobile-tqftpserv omamobile-modem omamobile-modem-online omamobile-mm-netport; do + install -Dm644 "$u.service" "/etc/systemd/system/$u.service" +done +systemctl daemon-reload +nmcli connection reload || true +udevadm control --reload +systemctl unmask ModemManager.service +systemctl enable omamobile-modem-efs.service omamobile-modem-online.service omamobile-rmtfs.service omamobile-tqftpserv.service omamobile-modem.service \ + omamobile-mm-netport.service ModemManager.service +echo "installed; active only with /etc/omamobile/modem-probe.enable" diff --git a/device/dodge/modem/omamobile-adsp-battery.service b/device/dodge/modem/omamobile-adsp-battery.service new file mode 100644 index 000000000..348e9e17a --- /dev/null +++ b/device/dodge/modem/omamobile-adsp-battery.service @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=ADSP and PMIC battery manager +After=local-fs.target omamobile-kmod-overlay.service +ConditionPathExists=/lib/firmware/qcom/sm8750/OnePlus/adsp.mbn + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/lib/omamobile/adsp-battery.sh +TimeoutStartSec=40 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/modem/omamobile-cellular.nmconnection b/device/dodge/modem/omamobile-cellular.nmconnection new file mode 100644 index 000000000..e1dff0a1a --- /dev/null +++ b/device/dodge/modem/omamobile-cellular.nmconnection @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: MIT +# Mobile data through NetworkManager + ModemManager. NM reads the bearer's +# IP config from MM (static on QMI) and applies address, routes, DNS and MTU +# on the qmapmux link (rmnet_ipa0 underneath on the IPA kernel). The APN is +# the generic "internet"; no SIM-specific value lives here. Wi-Fi stays +# preferred: lower autoconnect priority than Wi-Fi profiles (default 0) and +# route metric 700 against Wi-Fi's 600, so with both up the default route is +# Wi-Fi and cellular takes over only when Wi-Fi is gone. +# Inert without a ModemManager modem (modem flag /etc/omamobile/modem-probe.enable off). +[connection] +id=omamobile-cellular +type=gsm +autoconnect=true +autoconnect-priority=-10 +autoconnect-retries=0 + +[gsm] +apn=internet + +[ipv4] +method=auto +route-metric=700 + +[ipv6] +method=auto +addr-gen-mode=stable-privacy +route-metric=700 diff --git a/device/dodge/modem/omamobile-mm-netport.service b/device/dodge/modem/omamobile-mm-netport.service new file mode 100644 index 000000000..a4075d9ff --- /dev/null +++ b/device/dodge/modem/omamobile-mm-netport.service @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: MIT +# ModemManager needs a net port for a QMI modem; SM8750 has no IPA driver yet. +# A tun device tagged by 78-omamobile-mm-fake-net.rules stands in, so MM can +# create the modem for control (SIM, registration, voice/SMS). No data. +[Unit] +Description=dodge stand-in net port for ModemManager (no IPA yet) +ConditionPathExists=/etc/omamobile/modem-probe.enable +Before=ModemManager.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/ip tuntap add mode tun name rmnet_mm0 +ExecStop=/usr/bin/ip tuntap del mode tun name rmnet_mm0 + +[Install] +WantedBy=multi-user.target diff --git a/device/dodge/modem/omamobile-modem b/device/dodge/modem/omamobile-modem new file mode 100755 index 000000000..56e16aa8f --- /dev/null +++ b/device/dodge/modem/omamobile-modem @@ -0,0 +1,131 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-modem rmtfs-mem|start|stop|efs-prepare|snapshot