1212from zipfile import ZipFile
1313from datetime import datetime
1414
15- from lib import extract_flash
15+ from lib import extract_flash , haldex_binfile
1616from lib import binfile
1717from lib import flash_uds
1818from lib import simos_flash_utils
@@ -232,6 +232,7 @@ def __init__(self, parent):
232232 # Create a drop down menu
233233
234234 self .flash_info = simos18 .s18_flash_info
235+ self .binfile_handler = binfile .BinFileHandler (self .flash_info )
235236 available_modules = [
236237 "Simos 18.1/6" ,
237238 "Simos 18.10" ,
@@ -325,6 +326,10 @@ def on_module_changed(self, event):
325326 dq381 .dsg_flash_info ,
326327 haldex4motion .haldex_flash_info ,
327328 ][module_number ]
329+ if self .flash_info == haldex4motion .haldex_flash_info :
330+ self .binfile_handler = haldex_binfile .HaldexBinFileHandler (self .flash_info )
331+ else :
332+ self .binfile_handler = binfile .BinFileHandler (self .flash_info )
328333
329334 def on_get_info (self , event ):
330335 (interface , interface_path ) = split_interface_name (self .options ["interface" ])
@@ -435,10 +440,8 @@ def flash_bin_file(self, selected_file, patch_cboot=False):
435440 )
436441 self .flash_bin (get_info = False , should_patch_cboot = patch_cboot )
437442 elif len (input_bytes ) == self .flash_info .binfile_size :
438- self .input_blocks = binfile .blocks_from_bin (
443+ self .input_blocks = self . binfile_handler .blocks_from_bin (
439444 self .row_obj_dict [selected_file ],
440- self .flash_info ,
441- module_selection_is_haldex (self .module_choice .GetSelection ()),
442445 )
443446 self .flash_bin (get_info = False , should_patch_cboot = patch_cboot )
444447 else :
@@ -477,8 +480,8 @@ def flash_cal(self, selected_file: str):
477480 )
478481 if module_selection_is_dq250 (self .module_choice .GetSelection ()):
479482 self .feedback_text .AppendText ("Extracting Driver from full binary...\n " )
480- input_blocks = binfile .blocks_from_bin (
481- self .row_obj_dict [selected_file ], self . flash_info
483+ input_blocks = self . binfile_handler .blocks_from_bin (
484+ self .row_obj_dict [selected_file ]
482485 )
483486 # Filter to only CAL block.
484487 self .input_blocks = {
@@ -647,12 +650,12 @@ def prepare_file(self, selected_file, output_dir):
647650 + "\n "
648651 )
649652
650- input_blocks = binfile . blocks_from_bin (selected_file , self . flash_info )
653+ input_blocks = self . binfile_handler . blocks_from_bin (selected_file )
651654 output_blocks = flash_utils .checksum_and_patch_blocks (
652655 self .flash_info , input_blocks , should_patch_cboot = should_patch_cboot
653656 )
654657 output_file = Path (output_dir , "PATCHED_" + Path (selected_file ).name )
655- outfile_data = binfile . bin_from_blocks (output_blocks , self . flash_info )
658+ outfile_data = self . binfile_handler . bin_from_blocks (output_blocks )
656659 output_file .write_bytes (outfile_data )
657660
658661 self .feedback_text .AppendText (
@@ -674,7 +677,7 @@ def flash_bin(self, get_info=True, should_patch_cboot=False):
674677
675678 self .feedback_text .AppendText (
676679 "Starting to flash the following software components : \n "
677- + binfile . input_block_info (self .input_blocks , self . flash_info )
680+ + self . binfile_handler . input_block_info (self .input_blocks )
678681 + "\n "
679682 )
680683
@@ -1034,7 +1037,11 @@ def try_extract_frf(self, frf_data: bytes):
10341037 def extract_frf_task (self , frf_path : str , output_path : str , callback ):
10351038 frf_name = str .removesuffix (frf_path , ".frf" )
10361039 [output_blocks , flash_info ] = self .try_extract_frf (Path (frf_path ).read_bytes ())
1037- outfile_data = binfile .bin_from_blocks (output_blocks , flash_info )
1040+ if flash_info == haldex4motion .haldex_flash_info :
1041+ bin_handler = haldex_binfile .HaldexBinFileHandler (flash_info )
1042+ else :
1043+ bin_handler = binfile .BinFileHandler (flash_info )
1044+ outfile_data = bin_handler .bin_from_blocks (output_blocks )
10381045 callback (50 )
10391046 Path (output_path , Path (frf_name ).name + ".bin" ).write_bytes (outfile_data )
10401047
0 commit comments