-
Notifications
You must be signed in to change notification settings - Fork 0
/
rzx2l-loader.py
executable file
·160 lines (123 loc) · 3.93 KB
/
rzx2l-loader.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
#
# This program automatically flashes eMMC memory connected to Renesas RZ-G2L/V2L SOC
#
import sys
import os
import time
import serial
import select
import time
from YModem import YModem
def progressBar(count_value, total, suffix=''):
bar_length = 100
filled_up_Length = int(round(bar_length* count_value / float(total)))
percentage = round(100.0 * count_value/float(total),1)
bar = '=' * filled_up_Length + '-' * (bar_length - filled_up_Length)
sys.stdout.write('[%s] %s%s %s\r' %(bar, percentage, '%', suffix))
sys.stdout.flush()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description='Simple eMMC flasher for Renesas RZ-G2L/V2L SoC')
parser.add_argument(
'-p', '--port',
help="serial port name")
parser.add_argument(
'-q', '--quiet',
action='store_true',
help='suppress non error messages',
default=False)
parser.add_argument(
'-l', '--loader',
help="Initial loader file (S-Record format!)")
parser.add_argument(
'-i', '--image',
help="boot partition image file (binary format)")
args = parser.parse_args()
# connect to serial port
ser = serial.Serial()
ser.port = args.port
ser.baudrate = 115200
# open serial port
print('Opening serial port: ' + args.port)
try:
ser.open()
except serial.SerialException as e:
sys.stderr.write('Could not open serial port {}: {}\n'.format(ser.name, e))
sys.exit(1)
print('Please perform board reset...')
# wait for BOOTROM message
while True:
line = ser.readline().decode().strip()
print('==> ' + line)
if line == 'please send !':
break
start_time = time.time()
print('sending loader...')
loaderStream = open(args.loader, 'r')
loader = loaderStream.readlines()
count = 0
for line in loader:
ser.write(bytes(line, 'ascii'))
count += 1
progressBar(count, len(loader), os.path.basename(args.loader))
print('')
# wait for loader boot
while True:
line = ser.readline().decode().strip()
print('==> ' + line)
if line.find('Product Code :') != -1:
break
# send command to change speed to 921600
time.sleep(0.5)
print('switching to 921600...')
ser.write(b'sup\r\n')
while True:
line = ser.readline().decode().strip()
print('==> ' + line)
if line.find('921.6Kbps') != -1:
break
ser.baudrate = 921600
time.sleep(0.1)
# wait until new baudrate setting is active
while True:
time.sleep(0.1)
ser.write(b'\r\n')
line = ser.readline().decode().strip()
print('==> ' + line )
if line == '>':
break
# send boot partition image
print('sending binary file...')
ser.write(b'EM_WYB1\r\n')
while True:
line = ser.readline().decode().strip()
print('==> ' + line )
if line == 'Please send a file (YMODEM)!':
break
def sender_getc(size):
return ser.read(size) or None
def sender_putc(data, timeout=15):
return ser.write(data)
def ymodem_progress(pos, total):
progressBar(pos, total, os.path.basename(args.image))
ymodem = YModem(sender_getc, sender_putc, data_pad=b'\xFF')
ymodem_progress(0,1)
ymodem.send_file(args.image, 20, ymodem_progress)
while True:
line = ser.readline().decode().strip()
print('==> ' + line )
if line == 'EM_WYB done':
break
# change eMMC configuration
ser.write(b'EM_BCFG\r\n')
while True:
line = ser.readline().decode().strip()
print('==> ' + line )
if line == 'EM_BCFG done':
break
print("device flashed successfully!")
# print elapsed time for debugging
print("Elapsed time: ", int(time.time() - start_time), " seconds")
exit()