#!/usr/bin/env python3 """Locate the LVGL font descriptors that app/g2/firmware-fonts.ts extracts. Usage: scripts/find-firmware-fonts.py [...] Scans the main-app component (ota/s200_firmware_ota.bin, loaded at 0x438000 after a 0x20-byte preamble) for lv_font_fmt_txt_dsc_t structs with 4 bpp, bitmap format 3 and a plausible cmap table, and prints one row per font. After a firmware rebase, match rows to FONT_SPECS by cmap count / code-point count (the EvenHub fallback chain is n=12/8081, n=9/9566, n=4/11590) and copy the new `dsc` addresses into firmware-fonts.ts. """ import struct, sys BASE=0x438000 def mainapp(path): d=open(path,'rb').read() for i in range(8): toc=0x40+i*16; off=struct.unpack_from('len(d): continue size=struct.unpack_from('>9)&0xf; fmt=(packed>>14)&3 if bpp!=4 or fmt!=3 or n==0 or n>64: continue # cmap entries 20 bytes: range_start u32, range_length u16, glyph_id_start u16, list ptr, list ptr, list_length u16, type u8 good=True; total=0 for i in range(n): c=cm+i*20 if not img.ok(c,20): good=False;break rs=img.u32(c); rl=img.u16(c+4); t=img.b[c-BASE+19] if t>3 or rl==0 or rs>0x10FFFF: good=False;break total+=rl if not good: continue out.append((a,bm,gd,cm,kd,n,total)) return out for path in sys.argv[1:]: print("==",path); img=Img(mainapp(path)) for a,bm,gd,cm,kd,n,total in find_dscs(img): print(f"dsc 0x{a:08x} bitmap 0x{bm:08x} glyphs 0x{gd:08x} cmaps 0x{cm:08x} n={n} codepoints={total}")