添加加密固件烧录

This commit is contained in:
ranchuan
2024-10-15 18:05:42 +08:00
parent 6b05ffa251
commit 92d7b0e878
4 changed files with 72 additions and 18 deletions

View File

@@ -13,6 +13,7 @@ import binascii
from log import myprint
from log import log_init
from bin_to_hex import bin_to_hex_file
from bin_to_hex import bin_file_decrypt
def init_send(s_port:serial.Serial, send_str):
@@ -59,7 +60,7 @@ def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
continue
print_device_str(tmp)
s_info += tmp
if(s_info.find(b'C')>=0 and bytes2read==1):
if(s_info.find(b'CCC')>=0 and bytes2read==1):
m_flash=True
else:
m_flash=False
@@ -79,10 +80,12 @@ 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")
sys.exit()
xmodem_send = x_modem.send(stream, quiet=True, callback=download_callback)
xmodem_send = x_modem.send(stream, quiet=True, callback=download_callback,retry=16)
etime = datetime.datetime.now()
trans_time_1 = (etime - stime).seconds
myprint ("\nTransferring %s result: %s, consuming time: %d s \n" % (f_file,xmodem_send, trans_time_1))
if(xmodem_send is False):
break
elif m_done:
myprint("Update done.")
break
@@ -107,9 +110,9 @@ def print_device_str(data:bytearray):
for item in data:
try:
d=item.decode('utf-8')
myprint(d.strip())
myprint("DEVICE:",d.strip())
except Exception as e:
myprint(f" {item.hex()}")
myprint("DEVICE:",item)
# 上传固件
def upload_bin(x_modem:xmodem.XMODEM, w_file):
@@ -250,8 +253,17 @@ if __name__ == '__main__':
# 发送启动字符让设备进入xmodem模式
init_send(ser, init_str.encode("utf-8"))
burn_ram_bin(modem, ram_file)
# burn_ram_bin(modem, "kl3_ram_build.bin")
upload_fun()
# burn_fun()
# burn_ram_bin(modem, ram_file)
# upload_fun()
burn_ram_bin(modem, "bin/kl3_ram_build.bin")
dir_path="\\\\10.0.15.200\\内网拷贝进来的\\ran.chuan\\"
for item in os.listdir(dir_path):
if(item.endswith('.bin')):
iot_flash_file=os.path.join(dir_path,item)
break
# iot_flash_file="C:\\new\\buildout\\kl3_sta_kunlun.bin"
iot_flash_file="C:\\new\\buildout\\HZ-SG-TCE3PS03.bin"
iot_flash_file=bin_file_decrypt(iot_flash_file)
burn_fun()