#!/usr/bin/env python3 # Copyright (C) 2024 Herbert Poetzl import os import sys import mmap import struct m = os.open("/dev/mem", os.O_RDWR | os.O_SYNC) reg = mmap.mmap(m, 0x2000, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE, offset=0x80500000) def hexdump(data, cols=16, digits=2, sep=" "): out = [ f"{x:0{digits}X}" for x in data ] off = 0 while len(out): print(f"{off:02X}: " + sep.join(out[:cols])) out = out[cols:] off = off + cols def reg_get(x): res = struct.unpack("> bit) & 1 mem[idx*8 + bit] = ba << 8 for idx in range(8): for bch in range(4): byte = data[idx + bch*8] for bit in range(4): bb = (byte >> (bit*2)) & 1 bc = (byte >> (bit*2+1)) & 1 # old implementation # mem[idx*4 + bit] |= bb << (bch+4) # mem[idx*4 + bit] |= bc << bch mem[idx*4 + bit] |= bb << bch mem[idx*4 + bit] |= bc << (bch+4) hexdump(head) hexdump(data) hexdump(mem, digits=3) for idx, val in enumerate(mem): reg_set(offs + idx, val)