#!/usr/bin/env python3 """ Experimental HK Aura debug-log-over-SPP patch. Two changes: 1. FUN_0801F16E only sends AA/BB frames when channel[7] == 1. That flag is never set on this unit, so every SPP reply and log frame is dropped. Patch the two `bne` instructions to `nop` to ignore channel[7]. 2. FUN_08011F08 / FUN_08011F34 normally write formatted logs to UART via FUN_080202C8. Patch both output calls to FUN_0801F16E so logs go over the RN52/SPP link instead. The resulting AA/BB frames can be read by `aura_wifi_bt.py --framed-listen`. Patch table: 0x0801F18E 10 d1 -> 00 bf 0x0801F1C8 10 d1 -> 00 bf 0x08011F28 0e f0 ce f9 -> 0d f0 21 f9 (bl 0x0801F16E) 0x08011F54 0e f0 b8 f9 -> 0d f0 0b f9 (bl 0x0801F16E) Usage: python3 tools/patch_debuglog.py [input.bin] [output.bin] """ import hashlib import struct import sys SRC = 'firmware/HK_AURA_EU_spp_data_mode.bin' OUT = 'firmware/HK_AURA_EU_debuglog.bin' SEG1_START = 0x70 SEG1_SIZE = 0x323D4 SEG1_CHECKSUM_OFFSET = 0x40 PATCHES = [ (0x0801F18E, bytes.fromhex('10 d1'), bytes.fromhex('00 bf')), (0x0801F1C8, bytes.fromhex('10 d1'), bytes.fromhex('00 bf')), (0x08011F28, bytes.fromhex('0e f0 ce f9'), bytes.fromhex('0d f0 21 f9')), (0x08011F54, bytes.fromhex('0e f0 b8 f9'), bytes.fromhex('0d f0 0b f9')), ] def checksum(data): total = 0 for i in range(0, len(data), 4): total = (total + struct.unpack(' 1 else SRC out = sys.argv[2] if len(sys.argv) > 2 else OUT data = bytearray(open(src, 'rb').read()) if data[:4] != b'HUI ': sys.exit('not a HUI firmware image') old = struct.unpack(' {repl.hex(" ")}') new = checksum(bytes(data[SEG1_START:SEG1_START + SEG1_SIZE])) struct.pack_into(' {new:#x}') print(f'output: {out}') print(f'sha256: {hashlib.sha256(data).hexdigest()}') if __name__ == '__main__': main()