Skip to content

Commit 45d048e

Browse files
committed
fix haldex bins maybe
1 parent bfeedc0 commit 45d048e

File tree

7 files changed

+350
-175
lines changed

7 files changed

+350
-175
lines changed

VW_Flash.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
from os import path
77

8+
from lib import haldex_binfile
89
from lib.extract_flash import extract_flash_from_frf
910
from lib.constants import (
1011
BlockData,
@@ -210,12 +211,15 @@
210211
if args.dsg:
211212
flash_utils = dsg_flash_utils
212213

213-
if args.haldex:
214-
flash_utils = haldex_flash_utils
215-
216214
if args.dq381:
217215
flash_utils = dq381_flash_utils
218216

217+
if args.haldex:
218+
flash_utils = haldex_flash_utils
219+
binfile_handler = haldex_binfile.HaldexBinFileHandler(flash_info)
220+
else:
221+
binfile_handler = binfile.BinFileHandler(flash_info)
222+
219223
if args.interface == "USBISOTP":
220224
if args.usb_name is None:
221225
logger.error(
@@ -255,8 +259,8 @@ def input_blocks_from_frf(frf_path: str) -> dict[str, BlockData]:
255259
input_blocks = input_blocks_from_frf(args.frf)
256260

257261
if args.input_bin:
258-
input_blocks = binfile.blocks_from_bin(args.input_bin, flash_info, args.haldex)
259-
logger.info(binfile.input_block_info(input_blocks, flash_info))
262+
input_blocks = binfile_handler.blocks_from_bin(args.input_bin)
263+
logger.info(binfile_handler.input_block_info(input_blocks))
260264

261265
# build the dict that's used to proces the blocks
262266
# 'filename' : BlockData (block_number, binary_data)
@@ -273,8 +277,8 @@ def callback_function(t, flasher_step, flasher_status, flasher_progress):
273277
t.set_description(flasher_status, refresh=True)
274278

275279

276-
def flash_bin(flash_info: FlashInfo, input_blocks: dict[str, BlockData], is_dsg=False):
277-
logger.info(binfile.input_block_info(input_blocks, flash_info))
280+
def flash_bin(flash_info: FlashInfo, input_blocks: dict[str, BlockData]):
281+
logger.info(binfile_handler.input_block_info(input_blocks))
278282

279283
t = tqdm.tqdm(
280284
total=100,
@@ -326,7 +330,7 @@ def wrap_callback_function(flasher_step, flasher_status, flasher_progress):
326330
)
327331

328332
if args.output_bin:
329-
outfile_data = binfile.bin_from_blocks(output_blocks, flash_info)
333+
outfile_data = binfile_handler.bin_from_blocks(output_blocks)
330334
Path(args.output_bin).write_bytes(outfile_data)
331335
else:
332336
for filename in output_blocks:
@@ -353,7 +357,7 @@ def wrap_callback_function(flasher_step, flasher_status, flasher_progress):
353357
for did in ecuInfo:
354358
logger.debug(did + " - " + ecuInfo[did])
355359

356-
logger.info(binfile.input_block_info(input_blocks, flash_info))
360+
logger.info(binfile_handler.input_block_info(input_blocks))
357361

358362
cal_flash_blocks = {}
359363

VW_Flash_GUI.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from zipfile import ZipFile
1313
from datetime import datetime
1414

15-
from lib import extract_flash
15+
from lib import extract_flash, haldex_binfile
1616
from lib import binfile
1717
from lib import flash_uds
1818
from 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

Comments
 (0)