更新SLCP102程序打包流程;
This commit is contained in:
@@ -118,7 +118,6 @@ ParamMap_LaminaAdapter = {
|
||||
0x170: ["SN", 4, 16],
|
||||
0x180: ["MES", 4, 16],
|
||||
0x190: ["Datetime", 4, 16],
|
||||
0x1A0: ["版本前缀", 4, 5],
|
||||
}
|
||||
|
||||
|
||||
@@ -376,6 +375,42 @@ def GeneratePackage_SLCP101_p460(path_hex: Path):
|
||||
return bytearray(Image), bin_main
|
||||
|
||||
|
||||
def GeneratePackage_SLCP102_p460(path_hex: Path):
|
||||
""" 叠光适配器-460平台版本 生成升级包 """
|
||||
config = {
|
||||
'prod_type': [0x45, 0x00], # 产品类型
|
||||
'method_compress': False, # 文件压缩
|
||||
'prog_id': list(b"SLCP102"), # 程序识别号
|
||||
'prog_type': 'app', # 程序类型
|
||||
'area_code': [0x00, 0x00], # 地区
|
||||
}
|
||||
bin_main = tools.IntelHex.file_IntelHex_to_Bin(path_hex.read_text(), len_max=0x024000)
|
||||
encrypt_main = function.file_upgrade.file_encryption(bin_main)
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_main)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = tools.ByteConv.conv_int_to_array(len(bin_main))
|
||||
config['hex_name'] = list(path_hex.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (main_header:=function.file_upgrade.build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
print("Package generated successfully.")
|
||||
print(f"File name: {path_hex.name}")
|
||||
print(f"File Info:")
|
||||
print(f"\t header_length={len(main_header)}, bin_length={len(bin_main)}[{hex(len(bin_main))}]")
|
||||
|
||||
# 组装镜像
|
||||
Image = [0xFF] * (len(main_header) + len(encrypt_main))
|
||||
offset_image = 0
|
||||
Image[offset_image: offset_image + len(main_header)] = main_header
|
||||
offset_image += len(main_header)
|
||||
Image[offset_image: offset_image + len(encrypt_main)] = encrypt_main
|
||||
|
||||
return bytearray(Image), bin_main
|
||||
|
||||
|
||||
def GenerateImage_SLCP001_p4a0(path_boot: Path, path_main: Path, path_back: Path):
|
||||
""" 叠光适配器-4A0平台版本 镜像生成 """
|
||||
config = {
|
||||
@@ -486,6 +521,61 @@ def GenerateImage_SLCP101_p460(path_boot: Path, path_main: Path, path_back: Path
|
||||
return bytearray(Image), main_header, back_header
|
||||
|
||||
|
||||
def GenerateImage_SLCP102_p460(path_boot: Path, path_main: Path, path_back: Path):
|
||||
""" 叠光适配器-460平台版本 镜像生成 """
|
||||
config = {
|
||||
'prod_type': [0x45, 0x00], # 产品类型
|
||||
'method_compress': False, # 文件压缩
|
||||
'prog_id': list(b"SLCP102"), # 程序识别号
|
||||
'prog_type': 'app', # 程序类型
|
||||
'area_code': [0x00, 0x00], # 地区
|
||||
}
|
||||
bin_boot = tools.IntelHex.file_IntelHex_to_Bin(path_boot.read_text(), len_max=0x00C000)
|
||||
bin_main = tools.IntelHex.file_IntelHex_to_Bin(path_main.read_text(), len_max=0x024000)
|
||||
bin_back = tools.IntelHex.file_IntelHex_to_Bin(path_back.read_text(), len_max=0x024000)
|
||||
encrypt_main = function.file_upgrade.file_encryption(bin_main)
|
||||
encrypt_back = function.file_upgrade.file_encryption(bin_back)
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_main)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = tools.ByteConv.conv_int_to_array(len(bin_main))
|
||||
config['hex_name'] = list(path_main.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (main_header:=function.file_upgrade.build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_back)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = tools.ByteConv.conv_int_to_array(len(bin_back))
|
||||
config['hex_name'] = list(path_back.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (back_header:=function.file_upgrade.build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
print("Merge Image generated successfully.")
|
||||
print(f"Main File:")
|
||||
print(f"\t header_length={len(main_header)}, bin_length={len(bin_main)}[{hex(len(bin_main))}]")
|
||||
print(f"Back File:")
|
||||
print(f"\t header_length={len(back_header)}, bin_length={len(bin_back)}[{hex(len(bin_back))}]")
|
||||
|
||||
# 组装镜像
|
||||
Image = [0xFF] * 0x058000
|
||||
offset_image = 0
|
||||
Image[offset_image: offset_image + len(bin_boot)] = bin_boot
|
||||
offset_image = 0x00C000
|
||||
Image[offset_image: offset_image + len(bin_main)] = bin_main
|
||||
offset_image = 0x030000
|
||||
Image[offset_image: offset_image + len(bin_back)] = bin_back
|
||||
offset_image = 0x054000
|
||||
Image[offset_image: offset_image + len(main_header)] = main_header
|
||||
offset_image = 0x056000
|
||||
Image[offset_image: offset_image + len(back_header)] = back_header
|
||||
|
||||
return bytearray(Image), main_header, back_header
|
||||
|
||||
|
||||
def GeneratePackage_DLSY001_p460(path_hex: Path):
|
||||
""" 叠光优化器-460平台版本 生成升级包 """
|
||||
config = {
|
||||
|
||||
@@ -16,6 +16,8 @@ ParamMap_LaminaController = {
|
||||
# 5 - addr
|
||||
# 6 - float
|
||||
# 7 - numberList
|
||||
0x00: ["绝缘检测正电阻", 6],
|
||||
0x02: ["绝缘检测负电阻", 6],
|
||||
0x0B: ["事件标志", 1],
|
||||
0x0C: ["告警字1", 1],
|
||||
0x0D: ["告警字2", 1],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
from device.LaminaAdapter import GenerateImage_SLCP001_p4a0, GeneratePackage_SLCP001_p4a0
|
||||
from device.LaminaAdapter import GenerateImage_SLCP101_p460, GeneratePackage_SLCP101_p460
|
||||
from device.LaminaAdapter import GenerateImage_SLCP102_p460, GeneratePackage_SLCP102_p460
|
||||
from device.LaminaAdapter import GenerateImage_DLSY001_p460, GeneratePackage_DLSY001_p460
|
||||
|
||||
|
||||
@@ -102,6 +103,55 @@ def Process1(path_boot: Path, path_project: Path):
|
||||
file_image3.write_bytes(data_image)
|
||||
|
||||
|
||||
def Process1_v2(path_boot: Path, path_project: Path):
|
||||
""" 适配器-SLCP102 镜像生成流程 """
|
||||
root_boot = path_boot
|
||||
root_main = path_project
|
||||
result = root_main
|
||||
|
||||
# 正常启动镜像
|
||||
hex_boot = root_boot / "bootloader.hex"
|
||||
hex_main = root_main / "lamina_adapter.hex"
|
||||
hex_back = root_main / "lamina_adapter_back.hex"
|
||||
hex_update = hex_main
|
||||
if (not hex_boot.exists()) or (not hex_main.exists()) or (not hex_back.exists()):
|
||||
raise Exception("缺失必要程序文件")
|
||||
|
||||
file_image = result / f'{hex_main.stem}_ROM.bin'
|
||||
file_main_header = result / 'SLCP102_main.header'
|
||||
file_back_header = result / 'SLCP102_back.header'
|
||||
file_package = result / f'{hex_update.stem}.dat'
|
||||
file_bin = result / f'{hex_update.stem}.bin'
|
||||
|
||||
data_bins = GenerateImage_SLCP102_p460(hex_boot, hex_main, hex_back)
|
||||
data_package, data_bin = GeneratePackage_SLCP102_p460(hex_update)
|
||||
|
||||
file_image.write_bytes(data_bins[0].copy())
|
||||
file_main_header.write_bytes(data_bins[1].copy())
|
||||
file_back_header.write_bytes(data_bins[2].copy())
|
||||
file_package.write_bytes(data_package)
|
||||
file_bin.write_bytes(data_bin)
|
||||
|
||||
# 异常镜像-主分区md5错误
|
||||
file_image1 = result / f'{file_image.stem}_b1.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x054018: 0x05401A] = [0x00, 0x01]
|
||||
file_image1.write_bytes(data_image)
|
||||
|
||||
# 异常镜像-备份分区md5错误
|
||||
file_image2 = result / f'{file_image.stem}_b2.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x056018: 0x05601A] = [0x00, 0x01]
|
||||
file_image2.write_bytes(data_image)
|
||||
|
||||
# 异常镜像-双分区md5错误
|
||||
file_image3 = result / f'{file_image.stem}_b3.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x054018: 0x05401A] = [0x00, 0x01]
|
||||
data_image[0x056018: 0x05601A] = [0x00, 0x01]
|
||||
file_image3.write_bytes(data_image)
|
||||
|
||||
|
||||
def Process2():
|
||||
""" 优化器-DLSY001 镜像生成流程 """
|
||||
root = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_optimizer\lamina_optimizer\Debug")
|
||||
@@ -153,6 +203,7 @@ if __name__ == "__main__":
|
||||
path_boot2 = Path(r"D:\WorkingProject\LightStackAdapter\software\umon\460-PROJ_STACKLIGHT_PARALLEL_ADAPTOR")
|
||||
path_main = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\lamina_adapter\Debug")
|
||||
|
||||
Process0(path_boot1, path_main) # 适配器SLCP001
|
||||
# Process0(path_boot1, path_main) # 适配器SLCP001
|
||||
# Process1(path_boot2, path_main) # 适配器SLCP101
|
||||
Process1_v2(path_boot2, path_main) # 适配器SLCP102
|
||||
# Process2()
|
||||
|
||||
Reference in New Issue
Block a user