修复DSP平台Hex文件转换错误问题;
添加叠光控制器DSP转换流程函数;
This commit is contained in:
@@ -22,11 +22,11 @@ Header_Tag = {
|
|||||||
'hex_name': [0xFF, -1, 80], # 255 - Hex文件名; less than 80byte
|
'hex_name': [0xFF, -1, 80], # 255 - Hex文件名; less than 80byte
|
||||||
}
|
}
|
||||||
|
|
||||||
def file_IntelHex_to_Bin(file_data, base_address=-1, len_max=-1, **kwargs):
|
def file_IntelHex_to_Bin(file_data, base_address=0, len_max=1, **kwargs):
|
||||||
"""
|
"""
|
||||||
将Intel Hex格式文件转换为Bin格式;
|
将Intel Hex格式文件转换为Bin格式;
|
||||||
"""
|
"""
|
||||||
if base_address == -1:
|
if base_address == 0:
|
||||||
if file_data[8] == '2':
|
if file_data[8] == '2':
|
||||||
base_address = int(file_data[9: 13], 16) * 16
|
base_address = int(file_data[9: 13], 16) * 16
|
||||||
offset_begin = 16
|
offset_begin = 16
|
||||||
@@ -38,9 +38,7 @@ def file_IntelHex_to_Bin(file_data, base_address=-1, len_max=-1, **kwargs):
|
|||||||
offset_begin = 0
|
offset_begin = 0
|
||||||
base_address += int(file_data[offset_begin + 3: offset_begin + 7], 16)
|
base_address += int(file_data[offset_begin + 3: offset_begin + 7], 16)
|
||||||
base_address &= ~0x0FFF
|
base_address &= ~0x0FFF
|
||||||
if len_max == -1:
|
|
||||||
len_space = 0x10
|
|
||||||
else:
|
|
||||||
len_space = len_max
|
len_space = len_max
|
||||||
result = bytearray(len_space).replace(b'\x00', b'\xff')
|
result = bytearray(len_space).replace(b'\x00', b'\xff')
|
||||||
lines = file_data.split('\n')
|
lines = file_data.split('\n')
|
||||||
@@ -64,17 +62,16 @@ def file_IntelHex_to_Bin(file_data, base_address=-1, len_max=-1, **kwargs):
|
|||||||
data[i] = data[i+1]
|
data[i] = data[i+1]
|
||||||
data[i+1] = t
|
data[i+1] = t
|
||||||
|
|
||||||
|
if (address + len_line) > max_address:
|
||||||
|
max_address = address + len_line
|
||||||
if max_address >= len_space:
|
if max_address >= len_space:
|
||||||
if len_max == -1:
|
if len_max == 1:
|
||||||
result += bytearray((len_line & ~0x0F) + 0x10).replace(b'\x00', b'\xff')
|
result += bytearray(max_address - len_space).replace(b'\x00', b'\xff')
|
||||||
len_space += (len_line & ~0x0F) + 0x10
|
len_space += max_address - len_space
|
||||||
else:
|
else:
|
||||||
raise Exception("Bin file Oversize.")
|
raise Exception("Bin file Oversize.")
|
||||||
result[address:address+len_line] = data
|
result[address:address+len_line] = data
|
||||||
|
|
||||||
if (address + len_line) > max_address:
|
|
||||||
max_address = address + len_line
|
|
||||||
|
|
||||||
elif line[7:9] == '01':
|
elif line[7:9] == '01':
|
||||||
break
|
break
|
||||||
elif line[7:9] == '02':
|
elif line[7:9] == '02':
|
||||||
@@ -449,6 +446,46 @@ def GeneratePackage_SLCP001_p460(path_hex):
|
|||||||
|
|
||||||
return bytearray(Image), main_data_b
|
return bytearray(Image), main_data_b
|
||||||
|
|
||||||
|
def GeneratePackage_XXX001_p280039(path_hex):
|
||||||
|
""" 叠光控制器DSP-280039平台版本 生成升级包 """
|
||||||
|
config = {
|
||||||
|
'prod_type': [0x46, 0x00], # 产品类型
|
||||||
|
'method_compress': False, # 文件压缩
|
||||||
|
'prog_id': list(b"SLCP001"), # 程序识别号
|
||||||
|
'prog_type': 'app', # 程序类型
|
||||||
|
'area_code': [0x00, 0x00], # 地区
|
||||||
|
}
|
||||||
|
|
||||||
|
path_hex = Path(path_hex)
|
||||||
|
file_data = path_hex.read_text()
|
||||||
|
data_bin = file_IntelHex_to_Bin(file_data, conv_end = False)
|
||||||
|
md5_ctx = hashlib.md5()
|
||||||
|
md5_ctx.update(data_bin)
|
||||||
|
config['file_length'] = conv_int_to_array(len(data_bin))
|
||||||
|
config["md5"] = list(md5_ctx.digest())
|
||||||
|
config['hex_name'] = list(path_hex.name.encode())[:64]
|
||||||
|
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||||
|
|
||||||
|
data_header = build_header_new(config)
|
||||||
|
if data_header is None:
|
||||||
|
raise Exception("Header tag oversize. ")
|
||||||
|
data_encrypt = file_encryption(data_bin)
|
||||||
|
|
||||||
|
main_header, main_data_b, main_data_e = data_header, data_bin, data_encrypt
|
||||||
|
|
||||||
|
print("Merge Image generated successfully.")
|
||||||
|
print(f"File Info:")
|
||||||
|
print(f"\t header_length={len(main_header)}, bin_length={len(main_data_b)}[{hex(len(main_data_b))}]")
|
||||||
|
|
||||||
|
# 组装镜像
|
||||||
|
Image = [0xFF] * (len(main_header) + len(main_data_e))
|
||||||
|
offset_image = 0
|
||||||
|
Image[offset_image: offset_image + len(main_header)] = main_header
|
||||||
|
offset_image += len(main_header)
|
||||||
|
Image[offset_image: offset_image + len(main_data_e)] = main_data_e
|
||||||
|
|
||||||
|
return bytearray(Image), main_data_b
|
||||||
|
|
||||||
def Process1():
|
def Process1():
|
||||||
""" 镜像生成流程 """
|
""" 镜像生成流程 """
|
||||||
root = Path(r"test\p460")
|
root = Path(r"test\p460")
|
||||||
@@ -499,6 +536,19 @@ def Process2():
|
|||||||
file_package.write_bytes(data_package)
|
file_package.write_bytes(data_package)
|
||||||
file_bin.write_bytes(data_bins)
|
file_bin.write_bytes(data_bins)
|
||||||
|
|
||||||
|
def Process3():
|
||||||
|
""" 升级包生成流程 """
|
||||||
|
root = Path(r"test\p280039")
|
||||||
|
result = Path(r"test\p280039\result")
|
||||||
|
|
||||||
|
hex_main = root / r"lamina_controller_dsp_t1.hex"
|
||||||
|
file_package = result / f'{hex_main.stem}.dat'
|
||||||
|
file_bin = result / f'{hex_main.stem}.bin'
|
||||||
|
|
||||||
|
data_package, data_bins = GeneratePackage_XXX001_p280039(hex_main)
|
||||||
|
file_package.write_bytes(data_package)
|
||||||
|
file_bin.write_bytes(data_bins)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# path_bin = Path("F:\\Work\\FPGA\\Test\\Vivado\\test_update\\test_update.vitis\\upgrade_system\\Debug\\sd_card\\BOOT.BIN")
|
# path_bin = Path("F:\\Work\\FPGA\\Test\\Vivado\\test_update\\test_update.vitis\\upgrade_system\\Debug\\sd_card\\BOOT.BIN")
|
||||||
|
|||||||
Reference in New Issue
Block a user