添加layout 和crc计算
This commit is contained in:
@@ -5,6 +5,7 @@ import struct
|
||||
import json
|
||||
from bin.log import myprint
|
||||
from bin.base import bin_path
|
||||
from bin.crc import CRC32
|
||||
|
||||
|
||||
# kunlun1,kunlun2,kunlun3的img类型
|
||||
@@ -67,6 +68,260 @@ _PatternType={
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_layout_cfg='''
|
||||
|
||||
g_layout_f1_v0
|
||||
part_name offset size size(kB) note
|
||||
SP 0x00000000 0x00008000 32
|
||||
SBL 0x00008000 0x00008000 32
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00006000 24
|
||||
LOG1 0x00018000 0x00001000 4
|
||||
PIB2 0x00019000 0x00006000 24
|
||||
LOG2 0x0001F000 0x00001000 4
|
||||
FW1 0x00020000 0x0006F000 444
|
||||
CUS 0x0008F000 0x00001000 4
|
||||
FW2 0x00090000 0x0006F000 444
|
||||
DUMP 0x00000000 0x00000000 0 not use
|
||||
CAL 0x000FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f2_v0
|
||||
part_name offset size size(kB) note
|
||||
SP 0x00000000 0x00008000 32
|
||||
SBL 0x00008000 0x00008000 32
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
RUN 0x00020000 0x000E0000 896 log part use the remaining space
|
||||
FW1 0x00100000 0x00070000 448
|
||||
FW2 0x00170000 0x00070000 448
|
||||
CUS 0x001E0000 0x0001E000 120
|
||||
DUMP 0x001FE000 0x00001000 4
|
||||
CAL 0x001FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f2_v1
|
||||
part_name offset size size(kB) note
|
||||
SBL 0x00000000 0x0000C000 48
|
||||
PIB1_EXT 0X0000C000 0X00002000 8
|
||||
PIB2_EXT 0X0000E000 0X00002000 8
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
RUN 0x00020000 0x000E0000 896
|
||||
FW1 0x00100000 0x00070000 448
|
||||
FW2 0x00170000 0x00070000 448
|
||||
DUMP 0x001E0000 0x00001000 4
|
||||
CUS 0x001E1000 0x0001E000 120
|
||||
CALI 0x001FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f2_v2
|
||||
part_name offset size size(kb) note
|
||||
SBL 0x00000000 0x0000C000 48
|
||||
PIB1_EXT 0X0000C000 0X00002000 8
|
||||
PIB2_EXT 0X0000E000 0X00002000 8
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
RUN_CUS 0x00020000 0x00028000 160
|
||||
RUN_FW 0x00048000 0x000B8000 736
|
||||
CUS1 0x00100000 0x00018000 96
|
||||
FW1 0x00118000 0x00058000 352
|
||||
CUS2 0x00170000 0x00018000 96
|
||||
FW2 0x00188000 0x00058000 352
|
||||
RESERVED 0x001E0000 0x00001000 4
|
||||
CUST 0x001E1000 0x0001E000 120
|
||||
CALI 0x001FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f2_p_v0
|
||||
part_name offset size size(kB) note
|
||||
SP 0x00000000 0x00008000 32
|
||||
SBL 0x00008000 0x00008000 32
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
FW1 0x00020000 0x000A0000 640
|
||||
LOG1 0x000C0000 0x00020000 128
|
||||
LOG2 0x000E0000 0x00020000 128
|
||||
FW2 0x00100000 0x000A0000 640
|
||||
CUS 0x001A0000 0x0005E000 376
|
||||
SP_FW1 0x001F0000 0x00000000 0 not use
|
||||
PARAM2 0x001F7000 0x00000000 0 not use
|
||||
DUMP 0x001FE000 0x00001000 4
|
||||
CAL 0x001FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f2_p_v1
|
||||
part_name offset size size(kB) note
|
||||
SBL 0x00000000 0x00010000 64
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
FW1 0x00020000 0x000A0000 640
|
||||
LOG1 0x000C0000 0x00020000 128
|
||||
FW2 0x000E0000 0x000A0000 640
|
||||
LOG2 0x00180000 0x00020000 128
|
||||
DUMP 0x001A0000 0x00001000 4
|
||||
CUS 0x001A1000 0x0005E000 376
|
||||
CALI 0x001FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f4_v0
|
||||
part_name offset size size(kb) note
|
||||
SP 0x00000000 0x00008000 32
|
||||
SBL 0x00008000 0x00008000 32
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
LOG1 0x00000000 0x00000000 0 not use
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
LOG2 0x00000000 0x00000000 0 not use
|
||||
RUN 0x00020000 0x00160000 1408 log part use the remaining space
|
||||
FW1 0x00180000 0x000C0000 768
|
||||
FW2 0x00240000 0x000C0000 768
|
||||
SP_FW1 0x00000000 0x00000000 0 not use
|
||||
PARAM2 0x00000000 0x00000000 0 not use
|
||||
SP_FW2 0x00000000 0x00000000 0 not use
|
||||
DUMP 0x00000000 0x00000000 0 not use
|
||||
CUS 0x00300000 0x000FF000 1020
|
||||
CAL 0x003FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f4_v1
|
||||
part_name offset size size(kb) note
|
||||
SBL 0x00000000 0x00010000 64
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
RUN 0x00020000 0x00160000 1408
|
||||
FW1 0x00180000 0x000B0000 704
|
||||
FW2 0x00230000 0x000B0000 704
|
||||
PIB1_EXT 0x002E0000 0x0000F000 60
|
||||
PIB2_EXT 0x002EF000 0x0000F000 60
|
||||
DUMP 0x002FE000 0x00001000 4
|
||||
RESERVED 0x002FF000 0x00001000 4
|
||||
CUS 0x00300000 0x000FF000 1020
|
||||
CALI 0x003FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f4_p_v0
|
||||
part_name offset size size(kb) note
|
||||
SP 0x00000000 0x00008000 32
|
||||
SBL 0x00008000 0x00008000 32
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
RUN 0x00020000 0x000FA000 1000
|
||||
LOG1 0x0011A000 0x00066000 408
|
||||
FW1 0x00180000 0x000FA000 1000
|
||||
LOG2 0x0027A000 0x00066000 408
|
||||
DUMP 0x002E0000 0x00001000 4
|
||||
RESERVED 0x002E1000 0x00001000 4
|
||||
SP_FW1 0x002E2000 0x0000F000 60
|
||||
SP_FW2 0x002F1000 0x0000F000 60
|
||||
CUS 0x00300000 0x000FF000 1020
|
||||
CAL 0x003FF000 0x00001000 4
|
||||
FW2 0x002E0000 0x00000000 0 not use
|
||||
PARAM2 0x00000000 0x00000000 0 not use
|
||||
-
|
||||
g_layout_f4_p_v1
|
||||
part_name offset size size(kb) note
|
||||
SBL 0x00000000 0x00010000 64
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
FW1 0x00020000 0x000FA000 1000
|
||||
LOG1 0x0011A000 0x00030000 192
|
||||
LOG2 0x0014A000 0x00030000 192
|
||||
RESERVED1 0x0017A000 0x00006000 24
|
||||
FW2 0x00180000 0x000FA000 1000
|
||||
PIB1_EXT 0x0027A000 0x0000F000 60
|
||||
PIB2_EXT 0x00289000 0x0000F000 60
|
||||
DUMP 0x00298000 0x00001000 4
|
||||
RESERVED2 0x00299000 0x00067000 412
|
||||
CUS 0x00300000 0x000FF000 1020
|
||||
CALI 0x003FF000 0x00001000 4
|
||||
-
|
||||
g_layout_f4_p_v2
|
||||
part_name offset size size(kb) note
|
||||
SBL 0x00000000 0x00010000 64
|
||||
PARAM 0x00010000 0x00001000 4
|
||||
OEM 0x00011000 0x00001000 4
|
||||
PIB1 0x00012000 0x00007000 28
|
||||
PIB2 0x00019000 0x00007000 28
|
||||
FW1-CUS 0x00020000 0x00080000 512
|
||||
FW1-PLC 0x000A0000 0x000E0000 896
|
||||
LOG1 0x00180000 0x00030000 192
|
||||
LOG2 0x001B0000 0x00030000 192
|
||||
FW2-CUS 0x001E0000 0x00080000 512
|
||||
FW2-PLC 0x00260000 0x000E0000 896
|
||||
PIB1_EXT 0x00340000 0x0000F000 60
|
||||
PIB2_EXT 0x0034F000 0x0000F000 60
|
||||
DUMP 0x0035E000 0x00001000 4
|
||||
CUST 0x0035F000 0x000A0000 640
|
||||
CALC 0x003FF000 0x00001000 4
|
||||
-
|
||||
'''
|
||||
|
||||
|
||||
_layout_list=[
|
||||
'g_layout_f1_v0',
|
||||
'g_layout_f2_v0',
|
||||
'g_layout_f2_p_v0',
|
||||
'g_layout_f4_v0',
|
||||
'g_layout_f4_p_v0',
|
||||
'g_layout_f2_v1',
|
||||
'g_layout_f2_p_v1',
|
||||
'g_layout_f4_v1',
|
||||
'g_layout_f4_p_v1',
|
||||
'g_layout_f4_p_v2',
|
||||
'g_layout_f2_v2',
|
||||
]
|
||||
|
||||
|
||||
|
||||
# 根据layout index 找到 layout
|
||||
def get_layout(index:int):
|
||||
layout_len=len(_layout_list)
|
||||
if(index>=layout_len):
|
||||
return None
|
||||
name=_layout_list[index]
|
||||
layout=_layout_cfg.split('-')
|
||||
for item in layout:
|
||||
if(item.find(name)>=0):
|
||||
part=item.split('\n')
|
||||
break
|
||||
part_dict_list:list[dict]=[]
|
||||
for item in part:
|
||||
sp=item.split()
|
||||
if(len(sp)>=4) and sp[3].isdigit():
|
||||
# myprint(f"layout {item}")
|
||||
d={
|
||||
'name':sp[0],
|
||||
'offset':int(sp[1],base=16),
|
||||
'size':int(sp[2],base=16),
|
||||
}
|
||||
part_dict_list.append(d)
|
||||
return part_dict_list
|
||||
|
||||
|
||||
# 校验 当前地址是不是分区地址
|
||||
def check_part_addr(addr:int,part_list:list[dict]):
|
||||
for item in part_list:
|
||||
if(item.get('offset',None)==addr):
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_PKT_HEADER_MAGIC_NO = 0x00005566
|
||||
_IMG_HEADER_MAGIC_NO = 0xa4e49a17
|
||||
|
||||
@@ -228,13 +483,15 @@ def pkt_encrypt_check(data:bytearray):
|
||||
|
||||
|
||||
# 转化为hex文本
|
||||
def bin_to_hex(bin:bytearray,f,oem_file=None):
|
||||
def bin_to_hex(bin:bytearray,f,oem_file=None,layout_index=None):
|
||||
all_size=len(bin)
|
||||
pack_size=32
|
||||
turned=0
|
||||
turned_old=0
|
||||
out_text=''
|
||||
kunlun=''
|
||||
if(layout_index is not None):
|
||||
layout_list=get_layout(layout_index)
|
||||
if(pkt_header_check(bin)):
|
||||
out_text=tran_pkg_header(bin[0:96])+'\n'
|
||||
f.write(out_text)
|
||||
@@ -268,12 +525,17 @@ def bin_to_hex(bin:bytearray,f,oem_file=None):
|
||||
size=int(ret["imgSize"])
|
||||
oem_bin=bin[turned_old+64:turned_old+64+size]
|
||||
oem_file.write(oem_bin)
|
||||
if(layout_index is not None):
|
||||
layout=check_part_addr(turned_old,layout_list)
|
||||
if(layout is not None):
|
||||
layout['crc32']=hex(CRC32(bin[turned_old:turned_old+layout['size']]))
|
||||
f.write(str(layout).replace(',',' ')+'\n')
|
||||
out_text=f"[{hex(turned_old)}] {data.hex(' ')}\n"
|
||||
f.write(out_text)
|
||||
return kunlun
|
||||
|
||||
|
||||
def bin_to_hex_file(bin_file_name:str,hex_file_name:str):
|
||||
def bin_to_hex_file(bin_file_name:str,hex_file_name:str,layout_index:int):
|
||||
with open(bin_file_name,mode='rb') as f:
|
||||
bin=bytearray(f.read())
|
||||
if(pkt_encrypt_check(bin)):
|
||||
@@ -287,7 +549,7 @@ def bin_to_hex_file(bin_file_name:str,hex_file_name:str):
|
||||
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)
|
||||
kl=bin_to_hex(bin,f,oem_f,layout_index)
|
||||
# 调用oem_tool 打印oem信息
|
||||
oem_tool=os.path.join(bin_path(),f"{kl}_oem.exe")
|
||||
if(os.path.exists(oem_tool)):
|
||||
@@ -325,4 +587,5 @@ def clear_tmp():
|
||||
|
||||
# bin_to_hex.py input_file
|
||||
if __name__ == "__main__":
|
||||
bin_to_hex_file(sys.argv[1],"work/"+sys.argv[1]+".txt")
|
||||
bin_to_hex_file(sys.argv[1],"work/"+sys.argv[1]+".txt",int(sys.argv[2]))
|
||||
# get_layout(0)
|
||||
|
Reference in New Issue
Block a user