可以烧录和获取固件
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
work/
|
work/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
history/
|
@@ -254,6 +254,7 @@ def bin_to_hex_file(bin_file_name:str,hex_file_name:str,info_file_name:str=None)
|
|||||||
else:
|
else:
|
||||||
info=load_flash_info(info_file_name)
|
info=load_flash_info(info_file_name)
|
||||||
text=bin_to_hex2(bin)
|
text=bin_to_hex2(bin)
|
||||||
|
print(f"write to file {hex_file_name}")
|
||||||
with open(hex_file_name,mode='w+',encoding="utf-8") as f:
|
with open(hex_file_name,mode='w+',encoding="utf-8") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
||||||
|
BIN
bootram_kl3_build.bin
Normal file
BIN
bootram_kl3_build.bin
Normal file
Binary file not shown.
BIN
kl3_ram_build.bin
Normal file
BIN
kl3_ram_build.bin
Normal file
Binary file not shown.
132
kunlun.py
132
kunlun.py
@@ -24,7 +24,6 @@ def init_send(s_port:serial.Serial, send_str):
|
|||||||
bytes2read = s_port.in_waiting
|
bytes2read = s_port.in_waiting
|
||||||
tmp = s_port.read(bytes2read)
|
tmp = s_port.read(bytes2read)
|
||||||
s_info += tmp
|
s_info += tmp
|
||||||
# m_ram = re.search("Recieving RAM-IMAGE in xmodem : C", s_info.decode("utf-8"))
|
|
||||||
if(s_info.find(b"Recieving RAM-IMAGE in xmodem : C")>=0):
|
if(s_info.find(b"Recieving RAM-IMAGE in xmodem : C")>=0):
|
||||||
m_ram=True
|
m_ram=True
|
||||||
else:
|
else:
|
||||||
@@ -45,21 +44,22 @@ def burn_ram_bin(x_modem:xmodem.XMODEM, r_file):
|
|||||||
myprint("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
myprint("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
xmodem_send = x_modem.send(stream, callback=status_update_0)
|
xmodem_send = x_modem.send(stream, callback=download_callback)
|
||||||
etime = datetime.datetime.now()
|
etime = datetime.datetime.now()
|
||||||
trans_time_0 = (etime - stime).seconds
|
trans_time_0 = (etime - stime).seconds
|
||||||
myprint ("\nTransferring ram.bin result: %s, consuming time: %s s \n" % (xmodem_send, trans_time_0))
|
myprint ("\nTransferring %s result: %s, consuming time: %s s \n" % (r_file, xmodem_send, trans_time_0))
|
||||||
|
|
||||||
def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
|
def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
|
||||||
global trans_time_1
|
global trans_time_1
|
||||||
s_info = bytearray()
|
s_info = bytearray()
|
||||||
while True:
|
while True:
|
||||||
s_info += s_port.read(1)
|
|
||||||
myprint(f"recv:{s_info.hex(' ')}")
|
|
||||||
bytes2read = s_port.in_waiting
|
bytes2read = s_port.in_waiting
|
||||||
tmp = s_port.read(bytes2read)
|
tmp = s_port.read(bytes2read)
|
||||||
|
if(len(tmp)==0):
|
||||||
|
continue
|
||||||
|
print_device_str(tmp)
|
||||||
s_info += tmp
|
s_info += tmp
|
||||||
if(s_info.find(b'C')>=0):
|
if(s_info.find(b'C')>=0 and bytes2read==1):
|
||||||
m_flash=True
|
m_flash=True
|
||||||
else:
|
else:
|
||||||
m_flash=False
|
m_flash=False
|
||||||
@@ -69,7 +69,6 @@ def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
|
|||||||
m_done=False
|
m_done=False
|
||||||
|
|
||||||
if m_flash:
|
if m_flash:
|
||||||
# myprint m_flash.group(0)
|
|
||||||
myprint (r"Recieving FLASH-IMAGE in xmodem : C")
|
myprint (r"Recieving FLASH-IMAGE in xmodem : C")
|
||||||
s_info = bytearray()
|
s_info = bytearray()
|
||||||
stime = datetime.datetime.now()
|
stime = datetime.datetime.now()
|
||||||
@@ -80,20 +79,37 @@ def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
|
|||||||
myprint("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
myprint("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
xmodem_send = x_modem.send(stream, quiet=True, callback=status_update_1)
|
xmodem_send = x_modem.send(stream, quiet=True, callback=download_callback)
|
||||||
etime = datetime.datetime.now()
|
etime = datetime.datetime.now()
|
||||||
trans_time_1 = (etime - stime).seconds
|
trans_time_1 = (etime - stime).seconds
|
||||||
myprint ("\nTransferring iot_flash.bin result: %s, consuming time: %d s \n" % (xmodem_send, trans_time_1))
|
myprint ("\nTransferring %s result: %s, consuming time: %d s \n" % (f_file,xmodem_send, trans_time_1))
|
||||||
elif m_done:
|
elif m_done:
|
||||||
myprint (m_done.group(0))
|
myprint("Update done.")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def upload_callback(total_packets, success_count, error_count, packet_size):
|
def upload_callback(total_packets, success_count, error_count, packet_size):
|
||||||
# callback(total_packets, success_count, error_count, packet_size)
|
if total_packets % 10 == 0:
|
||||||
myprint("upload:",total_packets, success_count, error_count, packet_size)
|
sys.stdout.write('.')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def download_callback(total_packets, success_count, error_count):
|
||||||
|
if total_packets % 10 == 0:
|
||||||
|
sys.stdout.write('.')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
# 打印串口收到的字符
|
||||||
|
def print_device_str(data:bytearray):
|
||||||
|
data:list[bytearray]=data.split(b"\r\n")
|
||||||
|
for item in data:
|
||||||
|
try:
|
||||||
|
d=item.decode('utf-8')
|
||||||
|
myprint(d.strip())
|
||||||
|
except Exception as e:
|
||||||
|
myprint(f" {item.hex()}")
|
||||||
|
|
||||||
# 上传固件
|
# 上传固件
|
||||||
def upload_bin(x_modem:xmodem.XMODEM, w_file):
|
def upload_bin(x_modem:xmodem.XMODEM, w_file):
|
||||||
@@ -116,28 +132,14 @@ def upload_bin(x_modem:xmodem.XMODEM, w_file):
|
|||||||
|
|
||||||
def getc(size, timeout=1):
|
def getc(size, timeout=1):
|
||||||
data=ser.read(size)
|
data=ser.read(size)
|
||||||
# myprint("getc:",data.hex(' '))
|
|
||||||
return data or None
|
return data or None
|
||||||
|
|
||||||
|
|
||||||
def putc(data, timeout=1):
|
def putc(data, timeout=1):
|
||||||
# myprint("putc:",data.hex(' '))
|
|
||||||
ser.write(data)
|
ser.write(data)
|
||||||
time.sleep(0.03)
|
time.sleep(0.03)
|
||||||
|
|
||||||
|
|
||||||
def status_update_0(total_packets, success_count, error_count):
|
|
||||||
myprint ("total_packets: %s, success_count: %s, error_count: %d" % (total_packets, success_count, error_count))
|
|
||||||
# if total_packets % 10 == 0:
|
|
||||||
# myprint ('.'),
|
|
||||||
|
|
||||||
|
|
||||||
def status_update_1(total_packets, success_count, error_count):
|
|
||||||
myprint ("total_packets: %s, success_count: %s, error_count: %d" % (total_packets, success_count, error_count))
|
|
||||||
# if total_packets % 50 == 0:
|
|
||||||
# myprint ('.'),
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -173,6 +175,52 @@ def calc_flash_info_name():
|
|||||||
return os.path.join(_work_dir,name)
|
return os.path.join(_work_dir,name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 上传固件
|
||||||
|
def upload_fun():
|
||||||
|
# 显示flash信息
|
||||||
|
ser.write(b"f i\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
ser_read_data=ser.read(4096)
|
||||||
|
print_device_str(ser_read_data)
|
||||||
|
with open(calc_flash_info_name(),mode='w+',encoding='utf-8') as f:
|
||||||
|
f.writelines(ser_read_data.decode('utf-8').split('\r\n'))
|
||||||
|
# 显示image信息
|
||||||
|
ser.write(b"f s\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
ser_read_data=ser.read(4096)
|
||||||
|
print_device_str(ser_read_data)
|
||||||
|
with open(calc_flash_info_name(),mode='a+',encoding='utf-8') as f:
|
||||||
|
f.writelines(ser_read_data.decode('utf-8').split('\r\n'))
|
||||||
|
# 上传整个镜像
|
||||||
|
ser.write(b"fw u d all\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
myprint(ser.read(4096).decode('utf-8'))
|
||||||
|
upload_bin(modem,calc_upload_name())
|
||||||
|
|
||||||
|
myprint ("Total transmission time: %s s" % str(trans_time_0+trans_time_1))
|
||||||
|
myprint("Start transform bin to hex.")
|
||||||
|
bin_to_hex_file(calc_upload_name(), calc_hex_name(),calc_flash_info_name())
|
||||||
|
myprint("Transform to hex end.")
|
||||||
|
|
||||||
|
|
||||||
|
# 烧录固件
|
||||||
|
def burn_fun():
|
||||||
|
time.sleep(3)
|
||||||
|
ser_read_data=ser.read(4096)
|
||||||
|
print_device_str(ser_read_data)
|
||||||
|
ser.baudrate=nb_rate
|
||||||
|
|
||||||
|
burn_flash_bin(ser, modem, iot_flash_file)
|
||||||
|
myprint ("Total transmission time: %s s" % str(trans_time_0+trans_time_1))
|
||||||
|
time.sleep(3)
|
||||||
|
ser_read_data=ser.read(4096)
|
||||||
|
print_device_str(ser_read_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# kunlun.py [upload.bin]
|
# kunlun.py [upload.bin]
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if(len(sys.argv)<2):
|
if(len(sys.argv)<2):
|
||||||
@@ -212,33 +260,7 @@ if __name__ == '__main__':
|
|||||||
# 发送启动字符让设备进入xmodem模式
|
# 发送启动字符让设备进入xmodem模式
|
||||||
init_send(ser, init_str.encode("utf-8"))
|
init_send(ser, init_str.encode("utf-8"))
|
||||||
burn_ram_bin(modem, ram_file)
|
burn_ram_bin(modem, ram_file)
|
||||||
|
# burn_ram_bin(modem, "kl3_ram_build.bin")
|
||||||
|
|
||||||
# # ser.baudrate=nb_rate
|
upload_fun()
|
||||||
# time.sleep(0.5)
|
# burn_fun()
|
||||||
|
|
||||||
# burn_flash_bin(ser, modem, iot_flash_file)
|
|
||||||
# 显示flash信息
|
|
||||||
ser.write(b"f i\n")
|
|
||||||
time.sleep(0.5)
|
|
||||||
ser_read_data=ser.read(4096).decode('utf-8')
|
|
||||||
myprint(ser_read_data)
|
|
||||||
with open(calc_flash_info_name(),mode='w+',encoding='utf-8') as f:
|
|
||||||
f.writelines(ser_read_data.split('\r\n'))
|
|
||||||
# 显示image信息
|
|
||||||
ser.write(b"f s\n")
|
|
||||||
time.sleep(0.5)
|
|
||||||
ser_read_data=ser.read(4096).decode('utf-8')
|
|
||||||
myprint(ser_read_data)
|
|
||||||
with open(calc_flash_info_name(),mode='a+',encoding='utf-8') as f:
|
|
||||||
f.writelines(ser_read_data.split('\r\n'))
|
|
||||||
# 上传整个镜像
|
|
||||||
ser.write(b"fw u d all\n")
|
|
||||||
time.sleep(0.5)
|
|
||||||
myprint(ser.read(4096).decode('utf-8'))
|
|
||||||
upload_bin(modem,calc_upload_name())
|
|
||||||
|
|
||||||
myprint ("Total transmission time: %s s" % str(trans_time_0+trans_time_1))
|
|
||||||
myprint("Start transform bin to hex.")
|
|
||||||
bin_to_hex_file(calc_upload_name(), calc_hex_name(),calc_flash_info_name())
|
|
||||||
myprint("Transform to hex end.")
|
|
||||||
|
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
init_str = WQKL
|
init_str = WQKL
|
||||||
|
|
||||||
serial_port_num = 3
|
serial_port_num = 11
|
||||||
baud_rate = 115200
|
baud_rate = 115200
|
||||||
new_baud_rate = 460800
|
new_baud_rate = 468000
|
||||||
|
|
||||||
ram_file = bootram_kl1.bin
|
ram_file = bootram_kl3_build.bin
|
||||||
iot_flash_file = HZ-SG-QJCCO03-SOLAR-F-PSRAM-E-P12087-RF-DUAL-11.0.0.1-dbd3324-20240709.bin
|
iot_flash_file = HTZD_STA_xts.bin
|
Reference in New Issue
Block a user