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_DLSY001_p460, GeneratePackage_DLSY001_p460 def Process0(path_boot: Path, path_project: Path): """ 适配器-SLCP001 镜像生成流程 """ 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 / 'SLCP001_main.header' file_back_header = result / 'SLCP001_back.header' file_package = result / f'{hex_update.stem}.dat' file_bin = result / f'{hex_update.stem}.bin' data_bins = GenerateImage_SLCP001_p4a0(hex_boot, hex_main, hex_back) data_package, data_bin = GeneratePackage_SLCP001_p4a0(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[0x0FC018: 0x0FC01A] = [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[0x0FE018: 0x0FE01A] = [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[0x0FC018: 0x0FC01A] = [0x00, 0x01] data_image[0x0FE018: 0x0FE01A] = [0x00, 0x01] file_image3.write_bytes(data_image) def Process1(path_boot: Path, path_project: Path): """ 适配器-SLCP101 镜像生成流程 """ 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 / 'SLCP101_main.header' file_back_header = result / 'SLCP101_back.header' file_package = result / f'{hex_update.stem}.dat' file_bin = result / f'{hex_update.stem}.bin' data_bins = GenerateImage_SLCP101_p460(hex_boot, hex_main, hex_back) data_package, data_bin = GeneratePackage_SLCP101_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") # result = Path(r"test\p460_o1\result") result = root # 正常启动镜像 hex_boot = Path(r"test\p460_o1\bootloader.hex") hex_main = root / r"lamina_optimizer.hex" hex_back = root / r"lamina_optimizer.hex" hex_update = root / r"lamina_optimizer.hex" file_image = result / f'{hex_main.stem}_ROM.bin' file_main_header = result / 'DLSY001_header_main.bin' file_back_header = result / 'DLSY001_header_back.bin' file_package = result / f'{hex_update.stem}.dat' file_bin = result / f'{hex_update.stem}.bin' data_bins = GenerateImage_DLSY001_p460(hex_boot, hex_main, hex_back) data_package, data_bin = GeneratePackage_DLSY001_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) if __name__ == "__main__": path_boot1 = Path(r"D:\WorkingProject\LightStackAdapter\software\umon\4A0-PROJ_STACKLIGHT_PARALLEL_ADAPTOR") 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 # Process1(path_boot2, path_main) # 适配器SLCP101 # Process2()