-
Notifications
You must be signed in to change notification settings - Fork 0
/
knit_k2g_together_rom.py
32 lines (24 loc) · 1009 Bytes
/
knit_k2g_together_rom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def get_data(file_name):
with open(file_name, 'r') as f:
bits = f.readlines()[1:]
return [int(l.split(',')[1], 16) for l in bits]
low_bits_measured = get_data('full_dump_d0_d6_rising_edge_10us.txt')
high_bits_measured = get_data('full_dump_d0d5_d7_rising_edge.txt')
length = 2**20
bit0_6 = 0x7F
bit_6 = 0x40
# shifting bit 6 to bit 7, and stitching low and high bits for each byte
rom = bytes(((high & bit_6)) << 1 | (low & bit0_6) for low, high in zip(low_bits_measured[:length], high_bits_measured[:length]))
with open('rom_full.bin', 'wb') as f:
f.write(rom)
# verify
with open('rom_official.bin', 'rb') as f:
actual_rom = f.read()[:length]
first_6_bit_mask = 0x3F
full_mask = 0xFF
diff_mask = full_mask
diffing_indices = [(i, a, b) for i, (a, b) in enumerate(zip(rom[:length], actual_rom[:length])) if ((a & diff_mask) != (b & diff_mask))]
print(length)
print(len(diffing_indices))
# 14056 / 531007 = 3% noisy with falling edge
# 0 / 531007 = 0% noisy with rising edge