#!/usr/bin/env python3 """B9B: build the panel-mipi-dbi firmware file from the stock Aurora ST7735S init sequence. Source of truth = stock LK command table (lk.bin @0x8f64849c, 19 entries); it must equal stock dtb_01 qcom,mdss-spi-on-command byte-for-byte (else STOP). Nothing is "improved": same commands, same parameters, same delays. Only the final RAMWR (0x2c, no params) is dropped - the mipi-dbi driver issues CASET/RASET/RAMWR itself for every frame update. Format (drivers/gpu/drm/tiny/panel-mipi-dbi.c): "MIPI DBI" + 7x00 + version 1, then cmd, nparams, params...; delay = cmd 0x00 with 1 param (ms). usage: mk-panel-fw.py lk.bin dtb_01.dts out.bin""" import importlib.util, os, sys spec = importlib.util.spec_from_file_location('dp', os.path.join(os.path.dirname(__file__), '../b9a/decode-panel.py')) sys_argv = sys.argv; sys.argv = [sys_argv[0], sys_argv[1], sys_argv[2]] import io, contextlib dp = importlib.util.module_from_spec(spec) with contextlib.redirect_stdout(io.StringIO()): spec.loader.exec_module(dp) # defines lkc (LK table) and dtc (DT on-command) sys.argv = sys_argv lk, dt = dp.lkc, dp.dtc if lk != dt or len(lk) != 19: sys.exit('STOP: stock LK table != stock DT on-command') assert lk[-1] == (b'\x2c', 0), lk[-1] out = bytearray(b'MIPI DBI' + bytes(7) + bytes([1])) for payload, wait in lk[:-1]: # 18 commands, RAMWR dropped out += bytes([payload[0], len(payload) - 1]) + payload[1:] if wait: assert wait <= 255 out += bytes([0x00, 0x01, wait]) open(sys.argv[3], 'wb').write(out) # human-readable listing for payload, wait in lk[:-1]: print(f'{payload[0]:02x} {dp.NAMES.get(payload[0], "?"):8s} {payload[1:].hex(" ")}' + (f' + delay {wait} ms' if wait else '')) print(f'dropped: 2c RAMWR (driver writes memory itself); file {len(out)} bytes')