download时可以不用指定 -k 选项
This commit is contained in:
@@ -561,6 +561,7 @@ def bin_to_hex_file(bin_file_name:str,hex_file_name:str,layout_index:int):
|
||||
else:
|
||||
myprint(f"oem_tool not found: {oem_tool}")
|
||||
|
||||
# 固件解密
|
||||
def bin_file_decrypt(bin_file:str):
|
||||
with open(bin_file,mode='rb') as f:
|
||||
bin=bytearray(f.read())
|
||||
@@ -578,6 +579,21 @@ def bin_file_decrypt(bin_file:str):
|
||||
return "tmp.bin"
|
||||
|
||||
|
||||
|
||||
# 判断一个固件是kl1还是kl3的,需要解密后的固件
|
||||
def check_bin_type(file:str):
|
||||
with open(file,mode='rb') as f:
|
||||
bin=bytearray(f.read())
|
||||
while len(bin)>32:
|
||||
tmp=img_header_check(bin[:32])
|
||||
if(tmp=="V1"):
|
||||
return '3'
|
||||
elif(tmp=="V0"):
|
||||
return '1'
|
||||
bin=bin[32:]
|
||||
return None
|
||||
|
||||
|
||||
def clear_tmp():
|
||||
tmp_list=['tmp.bin']
|
||||
for item in tmp_list:
|
||||
|
24
kunlun.py
24
kunlun.py
@@ -19,6 +19,7 @@ from bin.bin_to_hex import bin_to_hex_file
|
||||
from bin.bin_to_hex import bin_file_decrypt
|
||||
from bin.bin_to_hex import clear_tmp
|
||||
from bin.bin_to_hex import load_flash_info
|
||||
from bin.bin_to_hex import check_bin_type
|
||||
from bin.base import bin_path
|
||||
from bin.factory_mode import ftm_handle
|
||||
|
||||
@@ -216,9 +217,9 @@ if not os.path.exists(_work_dir):
|
||||
|
||||
# 日志文件 固定存放在work目录
|
||||
def calc_log_file_name():
|
||||
name=os.path.split(iot_flash_file)[-1]
|
||||
log_file=name+'.log'
|
||||
return os.path.join(_work_dir,log_file)
|
||||
name=os.path.split(log_file)[-1]
|
||||
file=name+'.log'
|
||||
return os.path.join(_work_dir,file)
|
||||
|
||||
# 上传的flash镜像 固定存放在work目录
|
||||
def calc_upload_name():
|
||||
@@ -342,6 +343,7 @@ def global_def():
|
||||
global user_log
|
||||
global log_timeout
|
||||
global layout_index
|
||||
global log_file
|
||||
args = parser.parse_args()
|
||||
|
||||
init_str="WQKL"
|
||||
@@ -356,8 +358,12 @@ def global_def():
|
||||
# 上传或者下载flash镜像
|
||||
if(args.flash_file is not None):
|
||||
iot_flash_file=args.flash_file
|
||||
log_file=iot_flash_file
|
||||
if(os.path.exists(iot_flash_file)):
|
||||
function_type='download'
|
||||
iot_flash_file=bin_file_decrypt(iot_flash_file)
|
||||
if args.kunlun_version is None:
|
||||
args.kunlun_version=check_bin_type(iot_flash_file)
|
||||
ram_file=f'kl{args.kunlun_version}_ram_build.bin'
|
||||
ram_file=os.path.join(bin_path(),ram_file)
|
||||
else:
|
||||
@@ -374,18 +380,18 @@ def global_def():
|
||||
elif(args.ram_file is not None):
|
||||
function_type='ram'
|
||||
ram_file=ram_file_redirect(args.ram_file)
|
||||
iot_flash_file=args.ram_file
|
||||
log_file=args.ram_file
|
||||
elif(args.bin_convert is not None):
|
||||
function_type='convert'
|
||||
iot_flash_file=args.bin_convert
|
||||
log_file=args.bin_convert
|
||||
elif(args.console is not None):
|
||||
iot_flash_file=args.console
|
||||
log_file=args.console
|
||||
function_type='console'
|
||||
elif(args.ftm):
|
||||
iot_flash_file=time.strftime("%Y%m%d-%H%M%S")
|
||||
log_file=time.strftime("%Y%m%d-%H%M%S")
|
||||
function_type='ftm'
|
||||
elif(args.list):
|
||||
iot_flash_file=time.strftime("%Y%m%d-%H%M%S")
|
||||
log_file=time.strftime("%Y%m%d-%H%M%S")
|
||||
function_type='list'
|
||||
|
||||
|
||||
@@ -435,6 +441,7 @@ if __name__ == '__main__':
|
||||
user_log=False
|
||||
log_timeout=0
|
||||
layout_index=None
|
||||
log_file=None
|
||||
parser_init()
|
||||
global_def()
|
||||
if(function_type is None):
|
||||
@@ -476,7 +483,6 @@ if __name__ == '__main__':
|
||||
if(function_type=='upload'):
|
||||
upload_fun()
|
||||
elif(function_type=='download'):
|
||||
iot_flash_file=bin_file_decrypt(iot_flash_file)
|
||||
burn_fun()
|
||||
clear_tmp()
|
||||
if(user_log):
|
||||
|
Reference in New Issue
Block a user