Add a no-cover DTB rollback for 2720 Flip hardware sign-off

This commit is contained in:
Luxferre committed 2026-11-10 14:14:47 +02:00
1 parent 90e6771700
commit 31db372779
8 files changed
+153 -11

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""Build a 2720 Flip DTB with the external panel disabled (hardware rollback).
The cover panel DT is shipped enabled, but gpio13 mux polarity / external
reset polarity still need a live sign-off. If the main panel or keypad
regresses, this script produces a DTB that keeps the verified internal panel
and disables only display@1, without touching the spi-mux or the DTS source.
./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 patches local images
--install builds a separate no-cover boot.img and replaces boot.img/DTB in
the local raw image's pmOS_boot; it never changes the tracked DTS/DTB. Run
check-rebuild.sh before rolling back: in the rollback state its pmOS_boot
check expects the shipping DTB and will report the deliberate mismatch.
"""
import argparse
import pathlib
import subprocess
import sys
import tempfile
BASE = pathlib.Path(__file__).resolve().parent.parent
DTS = BASE / "devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts"
OUTPUT = BASE / "images/qcom-msm8905-nokia-beatles-no-cover.dtb"
OPENING = '\t\t\t\tdisplay@1 {\n'
MARKER = 'nokia,beatles-gc9305-ext-panel'
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true",
help="validate the transformation without writing images/")
parser.add_argument("--install", action="store_true",
help="also build a no-cover boot.img and patch the local raw image")
args = parser.parse_args()
source = DTS.read_text()
start = source.find(OPENING)
if start < 0:
sys.stderr.write("FAIL: display@1 is missing from the shipping DTS\n")
return 1
end = source.find("\n\t\t\t\t};\n", start)
if end < 0:
sys.stderr.write("FAIL: display@1 node is not terminated\n")
return 1
block = source[start:end]
if MARKER not in block or 'status = "disabled";' in block:
sys.stderr.write("FAIL: unexpected display@1 node contents\n")
return 1
patched = (source[:start] + OPENING +
'\t\t\t\t\tstatus = "disabled";\n' +
source[start + len(OPENING):])
with tempfile.TemporaryDirectory(prefix="bananarchy-no-cover-") as tmp:
root = pathlib.Path(tmp)
dts = root / "no-cover.dts"
dtb = root / "no-cover.dtb"
dec = root / "no-cover-decomp.dts"
dts.write_text(patched)
for cmd in (["dtc", "-I", "dts", "-O", "dtb", "-o", str(dtb), str(dts)],
["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")
ext_start = text.find("display@1 {")
ext = text[ext_start:text.find("\n\t\t\t\t};", ext_start) + 10] \
if ext_start >= 0 else ""
if 'status = "disabled";' not in ext or MARKER not in ext:
sys.stderr.write("FAIL: rollback DTB did not disable the external panel\n")
return 1
for token in ('qcom,msm-id = <0x14b 0x00>;',
'qcom,board-id = <0x1000b 0x100>;',
'qcom,pmic-id = <0x1000d 0x00 0x00 0x00>;',
'reg = <0x80000000 0x20000000>;',
'dc-gpios = <0x27 0x6e 0x00>;',
'spi-max-frequency = <0x17d7840>;'):
if token not in text:
sys.stderr.write("FAIL: rollback DTB lost %s\n" % token)
return 1
if args.check:
print("[ok] no-cover DTB transformation 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))
no_cover_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(no_cover_boot)]
sync = ["python3", str(BASE / "scripts/sync-beatles-bootfs.py"),
"--raw-image", str(raw), "--boot-image", str(no_cover_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; restore the shipping DTB/boot.img with "
"sync-beatles-bootfs.py (no overrides) to undo." % raw.name)
return 0
if __name__ == "__main__":
sys.exit(main())
+14
View File
@@ -1343,6 +1343,20 @@ if ! grep -qF 'bananarchy-cover-diagnose.sh' \
fail "apply-bananarchy-overlay.sh no longer installs the cover diagnostics"
fi
echo "[check] 2720 Flip cover rollback..."
if [ ! -x "$BASE_DIR/scripts/build-beatles-no-cover-dtb.py" ]; then
fail "missing rollback builder scripts/build-beatles-no-cover-dtb.py"
elif command -v dtc >/dev/null 2>&1 && \
! "$BASE_DIR/scripts/build-beatles-no-cover-dtb.py" --check >/dev/null 2>&1; then
fail "the no-cover DTB rollback transformation failed validation"
fi
if ! grep -qF 'parser.add_argument("--dtb"' \
"$BASE_DIR/scripts/sync-beatles-bootfs.py" || \
! grep -qF 'parser.add_argument("--boot-image"' \
"$BASE_DIR/scripts/sync-beatles-bootfs.py"; then
fail "sync-beatles-bootfs.py lost its DTB/boot-image overrides"
fi
if [ "$FAILURES" -ne 0 ]; then
echo "[check] $FAILURES check(s) failed."
exit 1
+17 -7
View File
@@ -118,7 +118,9 @@ def validate_cmdline(conf, allow_debug=False):
return append
def check(raw_path, dtb_path, boot_img_path, verbose=True, allow_debug=False):
def check(raw_path, dtb_path, boot_img_path, verbose=True, allow_debug=False,
files=None):
files = files if files is not None else BOOT_FS_FILES
raw = open(raw_path, "rb").read(1024 * 1024 + 4096)
offset, size = mbr_first_partition(raw)
if len(raw) < offset + 2048 or raw[offset + EXT2_MAGIC_OFFSET:offset + EXT2_MAGIC_OFFSET + 2] != EXT2_MAGIC:
@@ -140,7 +142,7 @@ def check(raw_path, dtb_path, boot_img_path, verbose=True, allow_debug=False):
if "fdt /qcom-msm8905-nokia-beatles.dtb" not in conf:
raise ValueError("extlinux.conf does not name the beatles DTB")
validate_cmdline(conf, allow_debug)
for name, expected in BOOT_FS_FILES.items():
for name, expected in files.items():
got = sha(cat(fs, "/" + name))
want = sha(open(expected, "rb").read())
if got != want:
@@ -166,10 +168,17 @@ def main():
parser.add_argument("--allow-debug", action="store_true",
help="With --check, accept a diagnostic cmdline")
parser.add_argument("--check", action="store_true")
parser.add_argument("--dtb", default=str(BOOT_FS_FILES["qcom-msm8905-nokia-beatles.dtb"]),
help="Override the DTB written to/checked in pmOS_boot")
parser.add_argument("--boot-image", default=str(BOOT_FS_FILES["boot.img"]),
help="Override the boot.img written to/checked in pmOS_boot")
args = parser.parse_args()
dtb = BOOT_FS_FILES["qcom-msm8905-nokia-beatles.dtb"]
boot_img = BOOT_FS_FILES["boot.img"]
dtb = Path(args.dtb)
boot_img = Path(args.boot_image)
boot_files = dict(BOOT_FS_FILES)
boot_files["qcom-msm8905-nokia-beatles.dtb"] = dtb
boot_files["boot.img"] = boot_img
for path in (args.raw_image, str(dtb), str(boot_img)):
if not os.path.isfile(path):
print("FAIL: missing %s" % path)
@@ -177,7 +186,8 @@ def main():
if args.check:
try:
check(args.raw_image, dtb, boot_img, allow_debug=args.allow_debug)
check(args.raw_image, dtb, boot_img, allow_debug=args.allow_debug,
files=boot_files)
return 0
except ValueError as exc:
print("FAIL: %s" % exc)
@@ -212,7 +222,7 @@ def main():
raise ValueError("source boot fs has no ext2 superblock")
commands = []
for name, host_path in BOOT_FS_FILES.items():
for name, host_path in boot_files.items():
commands += ["rm /%s" % name,
"write %s /%s" % (host_path, name)]
conf = cat(fs, "/extlinux/extlinux.conf").decode("utf-8", "replace")
@@ -251,7 +261,7 @@ def main():
os.unlink(fs)
try:
check(args.raw_image, dtb, boot_img)
check(args.raw_image, dtb, boot_img, files=boot_files)
except ValueError as exc:
print("FAIL: %s" % exc)
return 1