能够正常下载ram.bin 和上载flash镜像
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
log.txt
|
BIN
KL3_RAM.bin
Normal file
BIN
KL3_RAM.bin
Normal file
Binary file not shown.
BIN
bootram_kl1.bin
Normal file
BIN
bootram_kl1.bin
Normal file
Binary file not shown.
BIN
bootram_kl3.bin
Normal file
BIN
bootram_kl3.bin
Normal file
Binary file not shown.
72
build_htzd.py
Normal file
72
build_htzd.py
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DEF_CUS_APP="17"
|
||||||
|
DEF_PLC_APP="0"
|
||||||
|
DEF_CORE_TYPE="plc"
|
||||||
|
DEF_REL="debug"
|
||||||
|
DEF_PROTO_TYPE="p12087"
|
||||||
|
DEF_BOARDS_TYPE="evb03"
|
||||||
|
DEF_RF_OPT="no_rf"
|
||||||
|
DEF_DUAL_OPT="no_dual"
|
||||||
|
DEF_INCREMENT_OPT=""
|
||||||
|
DEF_BUILD_RECORD="./KL3_SG_BUILD_RECORE"
|
||||||
|
DEF_INDEX=0
|
||||||
|
|
||||||
|
CHIP_ID=("HZ", "HZ", "HZ", "HZ", "HZ", "HZ", "HZ", "HZ", "HZ")
|
||||||
|
IMAGE_TYPE=("cco", "cco", "sta", "sta", "new_type_cco", "new_type_cco", "cco", "sta", "new_type_cco")
|
||||||
|
GROUP_FLASH=("4m", "4m", "4m", "4m", "4m", "4m", "4m", "4m", "4m")
|
||||||
|
GROUP_PSRAM=("8m", "8m", "0m", "0m", "8m", "8m", "8m", "0m", "8m")
|
||||||
|
GROUP_RF_OPT=("rf", "no_rf", "rf", "no_rf", "rf", "no_rf", "rf", "rf", "rf")
|
||||||
|
GROUP_DUAL_OPT=("dual", "no_dual", "dual", "no_dual", "dual", "no_dual", "no_dual", "no_dual", "no_dual")
|
||||||
|
|
||||||
|
GROUP_PROTO_TYPE=("p12087", "p1901")
|
||||||
|
GROUP_BOARDS_TYPE=("fpga03", "evb03", "htzd03", "qj03", "flx03", "spe03", "gx03", "dt03", "yp03", "wtz03", "htzd03norf", "qc03")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 错误退出
|
||||||
|
def _error_handle(e:Exception):
|
||||||
|
file=e.__traceback__.tb_frame.f_globals['__file__']
|
||||||
|
line=e.__traceback__.tb_lineno
|
||||||
|
print(e)
|
||||||
|
print(f"文件: {file}:{line}" )
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 获取proto,这个参数没有位置限制
|
||||||
|
def _get_proto_type(params:list):
|
||||||
|
global DEF_PROTO_TYPE
|
||||||
|
for item in params:
|
||||||
|
if(item in GROUP_PROTO_TYPE):
|
||||||
|
DEF_PROTO_TYPE=item
|
||||||
|
return
|
||||||
|
|
||||||
|
# 获取index,这个参数只能在第一位
|
||||||
|
def _get_index(params:list):
|
||||||
|
global DEF_INDEX
|
||||||
|
try:
|
||||||
|
DEF_INDEX=int(params[1])
|
||||||
|
except Exception as e:
|
||||||
|
_error_handle(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 参数 image_type
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# a=dict(os.environ)
|
||||||
|
# print(a)
|
||||||
|
# for item in sys.argv:
|
||||||
|
# print(item)
|
||||||
|
# _get_proto_type(sys.argv)
|
||||||
|
# _get_index(sys.argv)
|
||||||
|
a={"ssss":"ssss","dddd":"dddd","cccc":"cccc"}
|
||||||
|
b={"ssss":"ssss"}
|
||||||
|
c=a.items()-b.items()
|
||||||
|
print(type(c),dict(c))
|
||||||
|
print(a)
|
||||||
|
|
5488
build_log.log
Normal file
5488
build_log.log
Normal file
File diff suppressed because one or more lines are too long
BIN
kl1_cco.bin
Normal file
BIN
kl1_cco.bin
Normal file
Binary file not shown.
BIN
kl1_sta.bin
Normal file
BIN
kl1_sta.bin
Normal file
Binary file not shown.
218
kunlun.py
Normal file
218
kunlun.py
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import fileinput
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import serial
|
||||||
|
import time
|
||||||
|
import xmodem
|
||||||
|
import os
|
||||||
|
import binascii
|
||||||
|
|
||||||
|
|
||||||
|
def init_send(s_port:serial.Serial, send_str):
|
||||||
|
s_info = bytearray()
|
||||||
|
while True:
|
||||||
|
s_port.write(send_str)
|
||||||
|
time.sleep(0.1)
|
||||||
|
s_info += s_port.read(1)
|
||||||
|
bytes2read = s_port.in_waiting
|
||||||
|
tmp = s_port.read(bytes2read)
|
||||||
|
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):
|
||||||
|
m_ram=True
|
||||||
|
else:
|
||||||
|
m_ram=False
|
||||||
|
|
||||||
|
if m_ram:
|
||||||
|
print ("Program enters transmission mode...")
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def burn_ram_bin(x_modem:xmodem.XMODEM, r_file):
|
||||||
|
global trans_time_0
|
||||||
|
wf = open(log_file, 'a')
|
||||||
|
stime = datetime.datetime.now()
|
||||||
|
print ("Transferring %s..." % r_file)
|
||||||
|
wf.writelines("Transferring %s..." % r_file)
|
||||||
|
try:
|
||||||
|
stream = open(r_file, 'rb')
|
||||||
|
except Exception:
|
||||||
|
print("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
xmodem_send = x_modem.send(stream, callback=status_update_0)
|
||||||
|
etime = datetime.datetime.now()
|
||||||
|
trans_time_0 = (etime - stime).seconds
|
||||||
|
print ("\nTransferring ram.bin result: %s, consuming time: %s s \n" % (xmodem_send, trans_time_0))
|
||||||
|
wf.writelines("Transferring %s..." % r_file)
|
||||||
|
wf.close()
|
||||||
|
|
||||||
|
def burn_flash_bin(s_port:serial.Serial, x_modem:xmodem.XMODEM, f_file):
|
||||||
|
global trans_time_1
|
||||||
|
s_info = bytearray()
|
||||||
|
wf = open(log_file, 'a')
|
||||||
|
while True:
|
||||||
|
s_info += s_port.read(1)
|
||||||
|
print(f"recv:{s_info.hex(' ')}")
|
||||||
|
bytes2read = s_port.in_waiting
|
||||||
|
tmp = s_port.read(bytes2read)
|
||||||
|
s_info += tmp
|
||||||
|
if(s_info.find(b'C')>=0):
|
||||||
|
m_flash=True
|
||||||
|
else:
|
||||||
|
m_flash=False
|
||||||
|
if(s_info.find(b"Updating done, PLS reboot the device...")>=0):
|
||||||
|
m_done=True
|
||||||
|
else:
|
||||||
|
m_done=False
|
||||||
|
|
||||||
|
if m_flash:
|
||||||
|
# print m_flash.group(0)
|
||||||
|
print (r"Recieving FLASH-IMAGE in xmodem : C")
|
||||||
|
wf.writelines("Recieving FLASH-IMAGE in xmodem : C")
|
||||||
|
s_info = bytearray()
|
||||||
|
stime = datetime.datetime.now()
|
||||||
|
print ("Transferring %s..." % f_file)
|
||||||
|
wf.writelines("Transferring %s..." % f_file)
|
||||||
|
try:
|
||||||
|
stream = open(f_file, 'rb')
|
||||||
|
except Exception:
|
||||||
|
print("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=status_update_1)
|
||||||
|
etime = datetime.datetime.now()
|
||||||
|
trans_time_1 = (etime - stime).seconds
|
||||||
|
print ("\nTransferring iot_flash.bin result: %s, consuming time: %d s \n" % (xmodem_send, trans_time_1))
|
||||||
|
wf.writelines("\nTransferring iot_flash.bin result: %s, consuming time: %d s \n" % (xmodem_send, trans_time_1))
|
||||||
|
elif m_done:
|
||||||
|
print (m_done.group(0))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
wf.close()
|
||||||
|
|
||||||
|
|
||||||
|
def upload_callback(total_packets, success_count, error_count, packet_size):
|
||||||
|
# callback(total_packets, success_count, error_count, packet_size)
|
||||||
|
print("upload:",total_packets, success_count, error_count, packet_size)
|
||||||
|
|
||||||
|
# 上传固件
|
||||||
|
def upload_bin(x_modem:xmodem.XMODEM, w_file):
|
||||||
|
global trans_time_0
|
||||||
|
wf = open(log_file, 'a')
|
||||||
|
stime = datetime.datetime.now()
|
||||||
|
print ("Transferring %s..." % w_file)
|
||||||
|
wf.writelines("Transferring %s..." % w_file)
|
||||||
|
try:
|
||||||
|
stream = open(w_file, 'wb+')
|
||||||
|
except Exception:
|
||||||
|
print("Cannot load file, please check the file path and retry. Press <enter> to exit")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
xmodem_send = x_modem.recv(stream, callback=upload_callback)
|
||||||
|
etime = datetime.datetime.now()
|
||||||
|
trans_time_0 = (etime - stime).seconds
|
||||||
|
print ("\nTransferring ram.bin result: %s, consuming time: %s s \n" % (xmodem_send, trans_time_0))
|
||||||
|
wf.writelines("Transferring %s..." % w_file)
|
||||||
|
wf.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getc(size, timeout=1):
|
||||||
|
data=ser.read(size)
|
||||||
|
print("getc:",data.hex(' '))
|
||||||
|
return data or None
|
||||||
|
|
||||||
|
|
||||||
|
def putc(data, timeout=1):
|
||||||
|
# print("putc:",data.hex(' '))
|
||||||
|
ser.write(data)
|
||||||
|
time.sleep(0.03)
|
||||||
|
|
||||||
|
|
||||||
|
def status_update_0(total_packets, success_count, error_count):
|
||||||
|
print ("total_packets: %s, success_count: %s, error_count: %d" % (total_packets, success_count, error_count))
|
||||||
|
# if total_packets % 10 == 0:
|
||||||
|
# print ('.'),
|
||||||
|
|
||||||
|
|
||||||
|
def status_update_1(total_packets, success_count, error_count):
|
||||||
|
print ("total_packets: %s, success_count: %s, error_count: %d" % (total_packets, success_count, error_count))
|
||||||
|
# if total_packets % 50 == 0:
|
||||||
|
# print ('.'),
|
||||||
|
|
||||||
|
log_file = "log.txt"
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
initial_info = """
|
||||||
|
*** Version 11.0.0.1
|
||||||
|
*** This is the tool for chip files transmission
|
||||||
|
*** You can modify xmodem_config.txt to configure
|
||||||
|
*** Serial Port, Baud Rate, Transfer Files Path
|
||||||
|
*** Press RST Button to continue the operation...
|
||||||
|
"""
|
||||||
|
print (initial_info)
|
||||||
|
wf = open(log_file, 'w+')
|
||||||
|
wf.writelines(initial_info)
|
||||||
|
exit_flag = 0
|
||||||
|
trans_time_0, trans_time_1 = 0, 0
|
||||||
|
config_file = r"xmodem_config.txt"
|
||||||
|
init_str, sp_num, b_rate, nb_rate, ram_file, iot_flash_file, ser = None, None, None, None, None, None, None
|
||||||
|
for eachline in fileinput.FileInput(config_file):
|
||||||
|
m_info = re.match(r"(\w+)\s*=\s*(.+)", eachline)
|
||||||
|
if m_info:
|
||||||
|
if m_info.group(1) == "init_str":
|
||||||
|
init_str = m_info.group(2)
|
||||||
|
elif m_info.group(1) == "serial_port_num":
|
||||||
|
sp_num = int(m_info.group(2))
|
||||||
|
elif m_info.group(1) == "baud_rate":
|
||||||
|
b_rate = int(m_info.group(2))
|
||||||
|
elif m_info.group(1) == "new_baud_rate":
|
||||||
|
nb_rate = int(m_info.group(2))
|
||||||
|
elif m_info.group(1) == "ram_file":
|
||||||
|
ram_file = m_info.group(2)
|
||||||
|
elif m_info.group(1) == "iot_flash_file":
|
||||||
|
iot_flash_file = m_info.group(2)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
ser = serial.Serial(port='COM' + str(sp_num), baudrate=b_rate, timeout=0.3)
|
||||||
|
except Exception:
|
||||||
|
print("Serial Port COM%s Conflicts!!! Press <enter> to Close it and retry..." % str(sp_num))
|
||||||
|
wf.writelines("Serial Port COM%s Conflicts!!! Press <enter> to Close it and retry..." % str(sp_num))
|
||||||
|
sys.exit()
|
||||||
|
modem = xmodem.XMODEM(getc, putc, mode='xmodem1k')
|
||||||
|
|
||||||
|
# 发送启动字符让设备进入xmodem模式
|
||||||
|
# init_send(ser, init_str.encode("utf-8"))
|
||||||
|
# burn_ram_bin(modem, ram_file)
|
||||||
|
|
||||||
|
# ser.baudrate=nb_rate
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
# burn_flash_bin(ser, modem, iot_flash_file)
|
||||||
|
# 显示flash信息
|
||||||
|
ser.write(b"f i\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
print(ser.read(4096).decode('utf-8'))
|
||||||
|
# 显示image信息
|
||||||
|
ser.write(b"f s\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
print(ser.read(4096).decode('utf-8'))
|
||||||
|
# 上传整个镜像
|
||||||
|
ser.write(b"fw u d all\n")
|
||||||
|
time.sleep(0.5)
|
||||||
|
print(ser.read(4096).decode('utf-8'))
|
||||||
|
# upload_bin(modem,"upload.bin")
|
||||||
|
|
||||||
|
print ("Total transmission time: %s s" % str(trans_time_0+trans_time_1))
|
||||||
|
wf.writelines("Total transmission time: %s s" % str(trans_time_0+trans_time_1))
|
||||||
|
wf.close()
|
||||||
|
|
BIN
upload.bin
Normal file
BIN
upload.bin
Normal file
Binary file not shown.
79
vscode_cpp_setting.py
Normal file
79
vscode_cpp_setting.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
2024.8.26
|
||||||
|
kunlun项目生成vscode配置
|
||||||
|
在Mainline文件夹中运行
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
# 定义配置文件路径
|
||||||
|
_vscode_cfg_path=os.path.normpath(os.path.abspath('.')+'/../../../.vscode/c_cpp_properties.json')
|
||||||
|
|
||||||
|
# 定义编译日志路径
|
||||||
|
_build_log_path='build_log.log'
|
||||||
|
|
||||||
|
# 定义编译器关键字
|
||||||
|
_complier_list = [
|
||||||
|
"riscv64-unknown-elf-gcc",
|
||||||
|
"gcc",
|
||||||
|
"g++"
|
||||||
|
]
|
||||||
|
|
||||||
|
# 读取编译日志,提取需要的编译项
|
||||||
|
def read_build_log():
|
||||||
|
current_path=''
|
||||||
|
def_list=[]
|
||||||
|
inc_list=[]
|
||||||
|
with open(_build_log_path,encoding='utf-8') as f:
|
||||||
|
lines=f.readlines()
|
||||||
|
for line in lines:
|
||||||
|
if(line.find("进入目录")>0):
|
||||||
|
start_str="“"
|
||||||
|
end_str="”"
|
||||||
|
start=line.find(start_str)
|
||||||
|
end=line.find(end_str)
|
||||||
|
current_path=line[start+len(start_str):end]
|
||||||
|
else:
|
||||||
|
sp_list=line.split()
|
||||||
|
if(len(sp_list)==0):
|
||||||
|
continue
|
||||||
|
if(sp_list[0] in _complier_list):
|
||||||
|
for item in sp_list:
|
||||||
|
if(item.startswith('-D')):
|
||||||
|
define=item[2:]
|
||||||
|
if(define not in def_list):
|
||||||
|
def_list.append(define)
|
||||||
|
elif(item.startswith('-I')):
|
||||||
|
path=item[2:]
|
||||||
|
if(path[0]!='/'):
|
||||||
|
path=os.path.join(current_path,path)
|
||||||
|
path=os.path.normpath(path)
|
||||||
|
# if(os.path.exists(path)) and (path not in inc_list):
|
||||||
|
if(path not in inc_list):
|
||||||
|
inc_list.append(path)
|
||||||
|
return def_list,inc_list
|
||||||
|
|
||||||
|
|
||||||
|
def setting(defs:list,incs:list):
|
||||||
|
with open(_vscode_cfg_path) as f:
|
||||||
|
cfgs=json.loads(f.read())
|
||||||
|
predef_info=cfgs["configurations"][0]
|
||||||
|
predef_info["includePath"]=incs
|
||||||
|
predef_info["defines"]=defs
|
||||||
|
with open(_vscode_cfg_path,mode='w+', encoding='utf-8') as f:
|
||||||
|
f.write(json.dumps(cfgs,sort_keys=True, indent=2, separators=(',', ': ')))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
defs,incs=read_build_log()
|
||||||
|
setting(defs,incs)
|
||||||
|
|
||||||
|
|
14
xmodem_config.txt
Normal file
14
xmodem_config.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
###################################################################################################################
|
||||||
|
# #
|
||||||
|
# Xmodem Config #
|
||||||
|
# #
|
||||||
|
###################################################################################################################
|
||||||
|
|
||||||
|
init_str = WQKL
|
||||||
|
|
||||||
|
serial_port_num = 3
|
||||||
|
baud_rate = 115200
|
||||||
|
new_baud_rate = 460800
|
||||||
|
|
||||||
|
ram_file = bootram_kl1.bin
|
||||||
|
iot_flash_file = HZ-SG-QJCCO03-SOLAR-F-PSRAM-E-P12087-RF-DUAL-11.0.0.1-dbd3324-20240709.bin
|
Reference in New Issue
Block a user