From 6c49b8fe94d114943df2bf59dd7c9fcded59447d Mon Sep 17 00:00:00 2001 From: ranchuan Date: Wed, 18 Dec 2024 17:21:35 +0800 Subject: [PATCH] =?UTF-8?q?download=E6=97=B6=E5=8F=AF=E4=BB=A5=E4=B8=8D?= =?UTF-8?q?=E7=94=A8=E6=8C=87=E5=AE=9A=20-k=20=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/bin_to_hex.py | 16 ++++++++++++++++ kunlun.py | 24 +++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bin/bin_to_hex.py b/bin/bin_to_hex.py index 809bc6c..de3d9c4 100644 --- a/bin/bin_to_hex.py +++ b/bin/bin_to_hex.py @@ -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: diff --git a/kunlun.py b/kunlun.py index dc451c6..b0053ef 100644 --- a/kunlun.py +++ b/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):