-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathext4-get-file.py
More file actions
executable file
·117 lines (101 loc) · 2.28 KB
/
ext4-get-file.py
File metadata and controls
executable file
·117 lines (101 loc) · 2.28 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
from __future__ import absolute_import
import codecs
import os
import sys
import threading
import serial
from serial.tools.list_ports import comports
from serial.tools import hexlify_codec
import time
import re
try:
raw_input
except NameError:
# pylint: disable=redefined-builtin,invalid-name
raw_input = input # in python3 it's "raw"
unichr = chr
if len(sys.argv) < 4:
print(sys.argv[0]+" <mmc_dev:mmc_part> <device_file> <local_file>")
sys.exit(1)
mmc_conf = sys.argv[1]
device_file = sys.argv[2]
local_file = sys.argv[3]
port = "/dev/ttyUSB0"
baudrate = 115200
databits = 8
stopbits = 1
parity = 'N'
rtscts = False
xonxoff = False
rts = None
dtr = None
exclusive = False
echo = False
eol='CRLF'
raw = False
filters = ['default']
serial_port_encoding = 'UTF-8'
quiet = False
s = serial.serial_for_url(
port,
baudrate,
timeout=.1,
bytesize=databits,
parity=parity,
stopbits=stopbits,
rtscts=rtscts,
xonxoff=xonxoff,
do_not_open=True)
s.dtr = dtr
s.rts = rts
s.exclusive = exclusive
s.open()
# LOAD CMD
cmd = 'ext4load mmc ' + mmc_conf + ' 0xc2600000 ' + device_file + '\n'
print("CMD: "+ cmd.strip())
s.write(cmd.encode('utf-8'))
s.flush()
time.sleep(5)
# LOAD CMD RESP
out = bytes()
while s.inWaiting() > 0:
out += s.read(1)
out = out.decode("utf-8")
print("RESP: "+ out)
# PARSE READ SIZE
size = 0
try:
size = int(re.search("[0-9]+ bytes read", out).group(0)[:-11])
except:
sys.exit(1)
print("READ SIZE: " + str(size))
# MEMORY READ CMD
cmd = 'md.b 0xc2600000 ' + hex(size) + '\r\n'
print("CMD: " + cmd.strip())
s.write(cmd.encode('utf-8'))
# MEMORY READ CMD RESP
out = bytes()
while 1:
# read all that is there or wait for one byte
o = s.read(s.in_waiting or 1)
out += o
if len(o) == 0:
break
# PARSE MEMORY READ
rawdata = bytes()
for line in out.decode("utf-8").split("\r\n"):
try:
d = re.search(r'([0-9a-f])+: ([0-9a-f]{2}\s)+', line).group(0)
d = bytes.fromhex(re.search(r'([0-9a-f]{2}\s)+', d).group(0).replace(" ",""))
rawdata += d
except:
pass
# WRITE FILE TO STDOUT
#print()
#print("================ FILE CONTENTS ================")
#sys.stdout.buffer.write(rawdata)
# WRITE FILE TO LOCAL FILE
f = open(local_file,'wb')
f.write(rawdata)
s.close()