#!/usr/bin/env python import re import sys baseaddr=0x53FA8000 pinfunc="/home/markus/projects/amx-tablet/linux/arch/arm/boot/dts/nxp/imx/imx53-pinfunc.h" memdump=sys.argv[1] re_define = re.compile(r'^#define (\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$') pinfuncs = {} with open(pinfunc) as file: for line in file: m = re_define.match(line) if m: name = m.group(1) offset = baseaddr + int(m.group(2), 16) mux_mode = int(m.group(5), 16) if not offset in pinfuncs: pinfuncs[offset] = [None] * 8 pinfuncs[offset][mux_mode] = name with open(memdump) as file: for line in file: name = line.split() addr = int(name[0], 16) value = int(name[1], 16) if addr in pinfuncs: mux_mode = value & 7 func_str = pinfuncs[addr][mux_mode] func = func_str.split("__") print(f"{func[0]}:\r\t\t\t\t{func[1]}")