From 9a40af33197bce2e758889834e96fc99c4745c4f Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Wed, 16 Oct 2024 23:59:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=8A=9F=E6=8F=90=E5=8F=96oem?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B9=B6=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/bin_to_hex.py | 23 +++++++++++++---------- kunlun.py | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/bin/bin_to_hex.py b/bin/bin_to_hex.py index fd8a843..559c306 100644 --- a/bin/bin_to_hex.py +++ b/bin/bin_to_hex.py @@ -233,6 +233,7 @@ def bin_to_hex(bin:bytearray,f,oem_file=None): turned+=pack_size else: data=bin[turned:] + turned_old=turned turned=all_size if(all_size-turned_old>=64): hdr_data=bin[turned_old:turned_old+64] @@ -253,7 +254,7 @@ def bin_to_hex(bin:bytearray,f,oem_file=None): if(oem_file is not None): if(_ImgType[hdr_data[1]]=="imgV1OEM"): size=int(ret["imgSize"]) - oem_bin=bin[turned_old+32:turned_old+32+size] + oem_bin=bin[turned_old+64:turned_old+64+size] oem_file.write(oem_bin) out_text=f"[{hex(turned_old)}] {data.hex(' ')}\n" f.write(out_text) @@ -272,17 +273,19 @@ def bin_to_hex_file(bin_file_name:str,hex_file_name:str,enc=0): with open(hex_file_name,mode='w+',encoding="utf-8") as f: # oem_bin 去除原始后缀 .bin.txt 添加新后缀 -oem.bin oem_name=hex_file_name[0:-8]+'-oem.bin' + oem_name=os.path.normpath(oem_name) with open(oem_name,mode='wb+') as oem_f: kl=bin_to_hex(bin,f,oem_f) - # 调用oem_tool 打印oem信息 - myprint(bin_path()) - oem_tool=os.path.join(bin_path(),f"{kl}_oem.exe") - if(os.path.exists(oem_tool)): - cmd_str=f"{oem_tool} --parse={oem_name}" - myprint(cmd_str) - os.system(cmd_str) - else: - myprint(f"oem_tool not found: {oem_tool}") + # 调用oem_tool 打印oem信息 + oem_tool=os.path.join(bin_path(),f"{kl}_oem.exe") + if(os.path.exists(oem_tool)): + cmd_str=f"{oem_tool} --parse={oem_name}" + with os.popen(cmd_str) as f: + for line in f.readlines(): + myprint(line.strip()) + # os.system(cmd_str) + else: + myprint(f"oem_tool not found: {oem_tool}") def bin_file_decrypt(bin_file:str): with open(bin_file,mode='rb') as f: diff --git a/kunlun.py b/kunlun.py index 52e7b42..e460a2f 100644 --- a/kunlun.py +++ b/kunlun.py @@ -236,17 +236,30 @@ def global_def(): global time_stamp_start global time_stamp_end global upload + global encrypt init_str="WQKL" serial_com=sys.argv[1] b_rate=115200 nb_rate=1500000 + arg_num=len(sys.argv) - if(sys.argv[3]=='upload'): - upload=True - elif(sys.argv[3]=='download'): - upload=False - else: + if(arg_num==2): + if(sys.argv[1].endswith('.bin')): + iot_flash_file=sys.argv[1] + return + elif(arg_num==3): + if(sys.argv[1].endswith('.bin')): + iot_flash_file=sys.argv[1] + encrypt=1 + return + elif(arg_num==5): + if(sys.argv[3]=='upload'): + upload=True + elif(sys.argv[3]=='download'): + upload=False + iot_flash_file=sys.argv[4] + elif(arg_num==4): if(sys.argv[3].endswith('.bin')): if(os.path.exists(sys.argv[3])): # 存在这个文件 是下载 @@ -257,12 +270,12 @@ def global_def(): else: print("param err.") sys.exit(-1) + iot_flash_file=sys.argv[3] if(upload): ram_file=f'bootram_{sys.argv[2]}.bin' else: ram_file=f'{sys.argv[2]}_ram_build.bin' ram_file=os.path.join(bin_path(),ram_file) - iot_flash_file=sys.argv[-1] def print_help(): @@ -281,23 +294,19 @@ def print_help(): # kunlun.py [com] [kl1/kl3] [upload/download] [upload.bin/download.bin] # kunlun.py [file.bin] if __name__ == '__main__': - if(len(sys.argv)<4): - if(len(sys.argv)>=2): - if(sys.argv[1].endswith('.bin')): - if(len(sys.argv)>=3): - enc=1 - else: - enc=0 - bin_to_hex_file(sys.argv[1],"work/"+sys.argv[1]+".txt",enc) - sys.exit(0) - print("param too less") - print_help() - sys.exit(-1) upload=None time_stamp_start, time_stamp_end = 0, 0 init_str, serial_com, b_rate, nb_rate, ram_file, iot_flash_file, ser = None, None, None, None, None, None, None + encrypt=0 global_def() + if(iot_flash_file is None): + print("param err.") + print_help() + sys.exit(-1) log_init(calc_log_file_name()) + if(ram_file is None): + bin_to_hex_file(iot_flash_file,calc_hex_name(),encrypt) + sys.exit(0) try: ser = serial.Serial(port=serial_com, baudrate=b_rate, timeout=0.3) except Exception: