Skip to content

Commit

Permalink
Add prepare file option to checksum & patch file
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorHowell committed Jun 6, 2024
1 parent 60c81fd commit c7b4abe
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion VW_Flash_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,54 @@ def update_callback(self, **kwargs):
else:
wx.CallAfter(self.threaded_callback, kwargs["logger_status"], "0", 0)

def prepare_file(self, selected_file, output_dir):
should_patch_cboot = False

if module_selection_is_dq250(self.module_choice.GetSelection()):
flash_utils = dsg_flash_utils
elif module_selection_is_dq381(self.module_choice.GetSelection()):
flash_utils = dq381_flash_utils
elif module_selection_is_haldex(self.module_choice.GetSelection()):
flash_utils = haldex_flash_utils
else:
flash_utils = simos_flash_utils
should_patch_cboot = True

input_bytes = Path(selected_file).read_bytes()
if len(input_bytes) != self.flash_info.binfile_size:
self.feedback_text.AppendText(
"File did not appear to be a valid BIN for "
+ self.module_choice.GetString(self.module_choice.GetSelection())
+ "\n"
)
return

self.progress_bar.Pulse()

self.feedback_text.AppendText(
"Starting to prepare the following file : "
+ Path(selected_file).name
+ "\n"
)

input_blocks = binfile.blocks_from_bin(selected_file, self.flash_info)
output_blocks = flash_utils.checksum_and_patch_blocks(
self.flash_info, input_blocks, should_patch_cboot=should_patch_cboot
)
output_file = Path(output_dir, "PATCHED_" + Path(selected_file).name)
outfile_data = binfile.bin_from_blocks(output_blocks, self.flash_info)
output_file.write_bytes(
outfile_data
)

self.feedback_text.AppendText(
"File prepared and saved as : "
+ output_file.name
+ "\n"
)

self.progress_bar.SetValue(0)

def flash_bin(self, get_info=True, should_patch_cboot=False):
(interface, interface_path) = split_interface_name(self.options["interface"])
if module_selection_is_dq250(self.module_choice.GetSelection()):
Expand Down Expand Up @@ -721,6 +769,17 @@ def create_menu(self):
source=extract_frf_menu_item,
)

prepare_file_menu_item = file_menu.Append(
wx.ID_ANY,
"Prepare File...",
"Checksums and patches a file for flashing to the selected ECU with a different tool",
)
self.Bind(
event=wx.EVT_MENU,
handler=self.on_select_prepare_file,
source=prepare_file_menu_item,
)

unlock_ecu_menu_item = file_menu.Append(
wx.ID_ANY,
"Unlock ECU...",
Expand Down Expand Up @@ -834,6 +893,20 @@ def on_select_unlock(self, event):
self.panel.flash_unlock(self.selected_unlock)
dlg.Destroy()

def on_select_prepare_file(self, event):
title = "Choose a file to prepare:"
dlg = wx.FileDialog(self, title, style=wx.FD_DEFAULT_STYLE, wildcard="*.bin")
if dlg.ShowModal() == wx.ID_OK:
file_path = dlg.GetPath()
dlg.Destroy()
title = "Choose an output directory:"
dlg = wx.DirDialog(self, title)
if dlg.ShowModal() == wx.ID_OK:
output_dir = dlg.GetPath()
self.panel.prepare_file(file_path, output_dir)

dlg.Destroy()

def on_select_stmin(self, event):
title = "Change STMIN_TX:"
stmin_override = self.panel.options.get("stmin_override", DEFAULT_STMIN)
Expand Down Expand Up @@ -887,7 +960,6 @@ def on_stop_logger(self, event):
self.hsl_logger.stop()
self.hsl_logger = None


def on_select_interface(self, event):
progress_dialog = wx.ProgressDialog(
"Scanning for devices...",
Expand Down

0 comments on commit c7b4abe

Please sign in to comment.