-
Notifications
You must be signed in to change notification settings - Fork 1
/
uboot-nand.py
68 lines (62 loc) · 1.85 KB
/
uboot-nand.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import serial
import os
import sys
import re
import struct
BAUD = 38400
PAGE_SIZE = 0x200
NAND_SIZE = 64 * (1024*1024)
DRAM = 128 * (1024*1024)
ENV = {}
ser = None
def send_cmd(cmd):
ser.write(cmd+"\n")
resp = ser.read_until("=>")
return resp
def get_env():
resp = send_cmd("printenv")
lines = resp.split("\n")
for line in lines:
if "=" in line:
env_var = line.split("=")
ENV[env_var[0]] = env_var[1]
def dump_mem(addr):
memstr = ''
resp = send_cmd("md.l 0x{:X} 0x200".format(addr)).split("\n")
for line in resp:
md_vals = re.split('(([0-9a-f]{8}\s){4})',line)
if len(md_vals) > 2:
mem_vals = md_vals[1]
mem_vals = mem_vals.replace(" ",'')
memstr += mem_vals.decode("hex")
return memstr
def dump_nand(block):
bytestr = ''
resp = send_cmd("nand dump {:X}".format(block)).split("\n")
for line in resp:
if re.search('(([0-9a-f]{2}\s){8})\s',line):
line = line.strip("\t")
line = line.strip("\n")
line = line.strip("\r")
line = line.replace(" ",'')
bytestr += line.decode("hex")
return bytestr
def main(ser):
get_env()
#print(dump_mem(0x10F40))
with open("memdump.bin",'wb') as md:
for x in range(0,DRAM/(4*0x200)):
print("Dumping page {:X} of {:X}".format(x,DRAM/(4*0x200)))
md.write(dump_mem(x*(4*0x200)))
'''
with open("NAND-TEST.bin",'wb') as t:
for x in range(0,(NAND_SIZE/PAGE_SIZE)+1):
print("Dumping page {:X} of {:X}".format(x,NAND_SIZE/PAGE_SIZE))
print("Dumping page {:X}".format(x*0x200,NAND_SIZE/PAGE_SIZE))
bytestr = dump_nand(x*0x200)
t.write(bytestr)
'''
if __name__ == "__main__":
port = sys.argv[1]
ser = serial.Serial(port,BAUD)
main(ser)