data = open(r"C:/Users/vikto/Documents/Claude/rt-4d/radio-spi-dump.bin","rb").read()

def region_stats(start, end, label):
    seg = data[start:end]
    from collections import Counter
    c = Counter(seg)
    ff = c.get(0xff,0); zero=c.get(0x00,0); e80=c.get(0x80,0)
    print(f"{label} {start:#08x}-{end:#08x} len={len(seg):#x} ff={ff} zero={zero} 0x80={e80} distinct={len(c)}")

# Find real extents of DATA (non-FF) around each blob by scanning 0xFF runs
def find_ff_boundaries(approx_start, search_end):
    # scan forward to find where FF-run of >=256 begins (end of data)
    i = approx_start
    run = 0
    end = search_end
    while i < search_end:
        if data[i]==0xff:
            run+=1
            if run>=1024:
                end = i-run+1
                break
        else:
            run=0
        i+=1
    return end

print("=== 0x198000 blob ===")
region_stats(0x198000, 0x242000, "raw")
# check where FF starts
e = find_ff_boundaries(0x198000, 0x260000)
print("first long FF run start ~", hex(e))

print("=== 0x352000 blob ===")
region_stats(0x352000, 0x3DD000, "raw")

print("=== 0x3F0000 blob ===")
region_stats(0x3F0000, 0x400000, "raw")
