From 0c7a7e913e976570b941dbc12aa41b3464766d58 Mon Sep 17 00:00:00 2001 From: bri3d Date: Tue, 24 Nov 2020 10:19:26 -0700 Subject: [PATCH] SBOOT checksum support, fancy progress bars, less logging --- checksumsimos18.py | 2 ++ flashsimos18.py | 21 +++++++++------------ logging.conf | 47 ++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100755 logging.conf diff --git a/checksumsimos18.py b/checksumsimos18.py index 601e1f2..7bc8e73 100644 --- a/checksumsimos18.py +++ b/checksumsimos18.py @@ -4,6 +4,7 @@ import struct checksum_block_location = { + 0: 0x300, # SBOOT 1: 0x300, # CBOOT 2: 0x300, # ASW1 3: 0x0, # ASW2 @@ -12,6 +13,7 @@ } base_addresses = { + 0: 0x80000000, # SBOOT 1: 0x8001C000, # CBOOT 2: 0x80040000, # ASW1 3: 0x80140000, # ASW2 diff --git a/flashsimos18.py b/flashsimos18.py index ec573d8..1d58c2b 100644 --- a/flashsimos18.py +++ b/flashsimos18.py @@ -1,7 +1,8 @@ import argparse -import isotp import time import udsoncan +from os import path +from tqdm import tqdm from udsoncan.connections import IsoTPSocketConnection from udsoncan.client import Client from udsoncan import configs @@ -146,7 +147,7 @@ def block_transfer_sizes_patch(block_number, address): return 0x100 return 0x8 -udsoncan.setup_logging() +udsoncan.setup_logging(path.join(path.dirname(path.abspath(__file__)), 'logging.conf')) params = { 'tx_padding': 0x55 @@ -248,8 +249,7 @@ def flash_block(client, block_files, block_number): print("Transferring data... " + str(len(data)) + " bytes to write") # Transfer Data counter = 1 - for block_base_address in range(0, len(data), block_transfer_sizes[block_number]): - print("Transferring " + str(block_base_address) + " of " + str(len(data)) + " bytes") + for block_base_address in tqdm(range(0, len(data), block_transfer_sizes[block_number]), unit_scale=True, unit="B"): block_end = min(len(data), block_base_address+block_transfer_sizes[block_number]) client.transfer_data(counter, data[block_base_address:block_end]) counter = next_counter(counter) @@ -295,9 +295,9 @@ def patch_block(client, block_files, block_number): # Transfer Data counter = 1 transfer_address = 0 + progress = tqdm(total=len(data), unit="B", unit_scale=True) while(transfer_address < len(data)): transfer_size = block_transfer_sizes_patch(block_number, transfer_address) - print("Transferring PATCH:" + str(transfer_address) + " of " + str(len(data)) + " bytes using size " + str(transfer_size)) block_end = min(len(data), transfer_address+transfer_size) transfer_data = data[transfer_address:block_end] @@ -307,19 +307,19 @@ def patch_block(client, block_files, block_number): try: client.transfer_data(counter, transfer_data) success = True + progress.update(block_end) counter = next_counter(counter) - except exceptions.NegativeResponseException as e: - print('PATCH refused block (EXPECTED): %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code)) + except exceptions.NegativeResponseException: success = False counter = next_counter(counter) transfer_address += transfer_size - + progress.close() print("Exiting PATCH transfer...") # Exit Transfer client.request_transfer_exit() - for block in block_files: + for block in tqdm(block_files, unit="Block"): if block <= 5: flash_block(client, block_files, block) if block > 5: @@ -341,10 +341,7 @@ def patch_block(client, block_files, block_number): print("Sending 0x4 Clear Emissions DTCs over OBD-2") send_obd(bytes([0x4])) - print("Clearing DTC...") - client.change_session(services.DiagnosticSessionControl.Session.extendedDiagnosticSession) client.tester_present() - client.control_dtc_setting(udsoncan.services.ControlDTCSetting.SettingType.off, data=bytes([0xFF, 0xFF, 0xFF])) print("Done!") except exceptions.NegativeResponseException as e: diff --git a/logging.conf b/logging.conf new file mode 100755 index 0000000..3c476b4 --- /dev/null +++ b/logging.conf @@ -0,0 +1,47 @@ +[loggers] +keys=root,UdsClient,Connection,UdsClient_unittest,Connection_unittest + +[handlers] +keys=consoleHandler,fileHandler,nullHandler + +[formatters] +keys=simpleFormatter + + + +[logger_root] +level=ERROR +handlers=consoleHandler + +[logger_UdsClient] +level=INFO +handlers=fileHandler +qualname=UdsClient +propagate=0 + +[logger_Connection] +level=DEBUG +handlers=fileHandler +qualname=Connection +propagate=0 + +[handler_consoleHandler] +class=StreamHandler +formatter=simpleFormatter +args=(sys.stdout,) + +[handler_fileHandler] +class=FileHandler +formatter=simpleFormatter +args=('udsoncan.log',) + +[handler_nullHandler] +class=NullHandler +formatter=simpleFormatter +args=() + + + +[formatter_simpleFormatter] +format=%(asctime)s [%(levelname)s] %(name)s: %(message)s +datefmt=%Y-%m-%d %H:%M:%S diff --git a/requirements.txt b/requirements.txt index 896df5e..3ed1940 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ udsoncan can-isotp sa2-seed-key +tqdm