#!/usr/bin/env python3 """Rollback DTB for the 2720 Flip: the verified single-panel shipping layout. After enabling the opt-in two-panel DT, this is the file to put back in pmOS_boot (and in the standalone boot image via repack-beatles-bootimg.py) if the main panel or keypad regresses. It is simply the shipping DTB compiled from the tracked DTS, so no source file is ever modified. ./scripts/build-beatles-no-cover-dtb.py # writes images/...no-cover.dtb ./scripts/build-beatles-no-cover-dtb.py --check # validation only ./scripts/build-beatles-no-cover-dtb.py --install # also patch local images """ import argparse import pathlib import subprocess import sys import tempfile BASE = pathlib.Path(__file__).resolve().parent.parent SOURCE = BASE / "devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" OUTPUT = BASE / "images/qcom-msm8905-nokia-beatles-no-cover.dtb" def main(): parser = argparse.ArgumentParser() parser.add_argument("--check", action="store_true", help="validate the rollback DTB without writing images/") parser.add_argument("--install", action="store_true", help="also build a rollback boot.img and patch the local raw image") args = parser.parse_args() with tempfile.TemporaryDirectory(prefix="bananarchy-no-cover-") as tmp: root = pathlib.Path(tmp) dtb = root / "no-cover.dtb" dec = root / "no-cover.dts" for cmd in (["dtc", "-I", "dts", "-O", "dtb", "-o", str(dtb), str(SOURCE)], ["dtc", "-I", "dtb", "-O", "dts", "-o", str(dec), str(dtb)]): proc = subprocess.run(cmd, capture_output=True, text=True) if proc.returncode: sys.stderr.write("FAIL: %s\n%s" % (" ".join(cmd), proc.stderr)) return 1 text = dec.read_text(encoding="utf-8", errors="replace") for token in ('display@0 {', 'spidev@1 {', 'status = "okay";', 'qcom,msm-id = <0x14b 0x00>;', 'reg = <0x80000000 0x20000000>;'): if token not in text: sys.stderr.write("FAIL: rollback DTB lost %s\n" % token) return 1 if 'compatible = "spi-mux"' in text or 'display@1 {' in text: sys.stderr.write("FAIL: rollback DTB still contains the cover mux\n") return 1 if args.check: print("[ok] single-panel rollback DTB validated (%d bytes)" % dtb.stat().st_size) return 0 OUTPUT.parent.mkdir(parents=True, exist_ok=True) OUTPUT.write_bytes(dtb.read_bytes()) print("wrote %s" % OUTPUT.relative_to(BASE)) rollback_boot = BASE / "images/boot-bananarchy-nokia-beatles-no-cover.img" shipping_boot = BASE / "images/boot-bananarchy-nokia-beatles.img" raw = BASE / "images/bananarchy-nokia-beatles.img" repack = ["python3", str(BASE / "scripts/repack-beatles-bootimg.py"), "--boot-image", str(shipping_boot), "--dtb", str(OUTPUT), "--output", str(rollback_boot)] sync = ["python3", str(BASE / "scripts/sync-beatles-bootfs.py"), "--raw-image", str(raw), "--boot-image", str(rollback_boot), "--dtb", str(OUTPUT)] if not args.install: print("install with: %s" % " ".join(repack)) print("then: %s" % " ".join(sync)) return 0 for cmd in (repack, sync): proc = subprocess.run(cmd, capture_output=True, text=True) if proc.returncode: sys.stderr.write("FAIL: %s\n%s%s" % (" ".join(cmd), proc.stdout, proc.stderr)) return 1 print(proc.stdout.strip()) print("rollback installed into %s" % raw.name) return 0 if __name__ == "__main__": sys.exit(main())