-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_fw.py
35 lines (30 loc) · 1.31 KB
/
check_fw.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
33
34
35
import array
import binascii
from pathlib import Path
import ADSP_ecc
def is_ff(data):
for b in data:
if b != 0xff:
return False
return True
if __name__ == '__main__':
file = '/Users/tolsi/Documents/op-1-rev/MT29F4G08ABBDA@BGA63_2131_without_3627_BB.BIN'
filebytes = array.array('B')
filebytes.fromfile(open(file, 'rb'), Path(file).stat().st_size)
data_size = 256 * 8
ecc_size = 8 * 8
page_size = data_size + ecc_size
block_size = page_size * 64
for block in range(0, 4096):
for page in range(0, 64):
start_index = block * block_size + page_size * page
# data = filebytes[start_index:start_index + data_size]
# ecc = filebytes[start_index + data_size:start_index + page_size]
for i in range(0, 8):
i_ecc = filebytes[start_index + data_size + i * 8:start_index + data_size + i * 8 + 3]
i_data = filebytes[start_index + i * 256: start_index + i * 256 + 256]
if not (is_ff(i_data) and is_ff(i_ecc)):
calc_ecc = ADSP_ecc.ecc(i_data)
if i_ecc != calc_ecc:
print('Bad block detected! block %d, page %d, piece %d: %s != %s' % (block, page, i, binascii.hexlify(i_ecc), binascii.hexlify(calc_ecc)))
print('Done!')