109 lines
4.2 KiB
Python
109 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""Build the opt-in 2720 Flip two-panel DTB (external GC9305 on /dev/fb1).
|
||
|
|
|
||
|
|
The shipping DTB keeps the verified single-panel layout. A live test showed
|
||
|
|
that registering the external panel makes the main panel go dark, so this DT
|
||
|
|
is deliberately opt-in until gpio13 mux polarity and the gpio21/gpio23 DC/
|
||
|
|
reset routing are probed on hardware.
|
||
|
|
|
||
|
|
./scripts/build-beatles-cover-panel.py # writes images/...cover.dtb
|
||
|
|
./scripts/build-beatles-cover-panel.py --check # validation only
|
||
|
|
./scripts/build-beatles-cover-panel.py --install # also patch local images
|
||
|
|
|
||
|
|
--install builds a separate cover boot.img and replaces boot.img/DTB in the
|
||
|
|
local raw image's pmOS_boot; it never changes the tracked DTS/DTB.
|
||
|
|
"""
|
||
|
|
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-cover.dts"
|
||
|
|
OUTPUT = BASE / "images/qcom-msm8905-nokia-beatles-cover.dtb"
|
||
|
|
|
||
|
|
|
||
|
|
def validate(text):
|
||
|
|
checks = (
|
||
|
|
'compatible = "spi-mux";',
|
||
|
|
'compatible = "gpio-mux";',
|
||
|
|
'nokia,beatles-gc9305-ext-panel',
|
||
|
|
'display@1 {',
|
||
|
|
'dc-gpios = <0x27 0x15 0x00>;',
|
||
|
|
'reset-gpios = <0x27 0x17 0x00>;',
|
||
|
|
'spi-max-frequency = <0x17d7840>;',
|
||
|
|
'status = "disabled";',
|
||
|
|
'qcom,msm-id = <0x14b 0x00>;',
|
||
|
|
'qcom,board-id = <0x1000b 0x100>;',
|
||
|
|
'qcom,pmic-id = <0x1000d 0x00 0x00 0x00>;',
|
||
|
|
'reg = <0x80000000 0x20000000>;',
|
||
|
|
)
|
||
|
|
for token in checks:
|
||
|
|
if token not in text:
|
||
|
|
return "opt-in DTB lost %s" % token
|
||
|
|
if 'pins = "gpio13";' not in text or \
|
||
|
|
'pins = "gpio21", "gpio23", "gpio13";' in text:
|
||
|
|
return "gpio13 is not isolated from the external panel pinctrl group"
|
||
|
|
return None
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
parser = argparse.ArgumentParser()
|
||
|
|
parser.add_argument("--check", action="store_true",
|
||
|
|
help="validate the opt-in DT without writing images/")
|
||
|
|
parser.add_argument("--install", action="store_true",
|
||
|
|
help="also build a cover boot.img and patch the local raw image")
|
||
|
|
args = parser.parse_args()
|
||
|
|
if not SOURCE.is_file():
|
||
|
|
sys.stderr.write("FAIL: missing %s\n" % SOURCE.relative_to(BASE))
|
||
|
|
return 1
|
||
|
|
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-dtb-") as tmp:
|
||
|
|
root = pathlib.Path(tmp)
|
||
|
|
dtb = root / "cover.dtb"
|
||
|
|
dec = root / "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")
|
||
|
|
problem = validate(text)
|
||
|
|
if problem:
|
||
|
|
sys.stderr.write("FAIL: %s\n" % problem)
|
||
|
|
return 1
|
||
|
|
if args.check:
|
||
|
|
print("[ok] opt-in two-panel 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))
|
||
|
|
cover_boot = BASE / "images/boot-bananarchy-nokia-beatles-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(cover_boot)]
|
||
|
|
sync = ["python3", str(BASE / "scripts/sync-beatles-bootfs.py"),
|
||
|
|
"--raw-image", str(raw), "--boot-image", str(cover_boot),
|
||
|
|
"--dtb", str(OUTPUT)]
|
||
|
|
if not args.install:
|
||
|
|
print("install with: %s" % " ".join(repack))
|
||
|
|
print("then: %s" % " ".join(sync))
|
||
|
|
print("WARNING: verify the main panel before using this DT as a default.")
|
||
|
|
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("opt-in DT installed into %s; update the pinned image hash in "
|
||
|
|
"check-rebuild.sh if this image is kept." % raw.name)
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|