From d9a2f67fb5240215d5bb3983935885b359e98b9a Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Wed, 14 Feb 2024 15:13:22 +0100 Subject: [PATCH] RAFlasher.py: minor cleanup --- src/RAConnect.py | 3 ++- src/RAFlasher.py | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RAConnect.py b/src/RAConnect.py index eec7ee9..f753d24 100644 --- a/src/RAConnect.py +++ b/src/RAConnect.py @@ -25,7 +25,8 @@ class RAConnect: for config in self.dev: intf = config[(1,0)] - print(f'Found usb device {self.vendor_id}:{self.product_id}') + product_name = usb.util.get_string(self.dev, self.dev.iProduct) + print(f'Found {product_name} ({self.vendor_id}:{self.product_id})') if self.dev.is_kernel_driver_active(intf.bInterfaceNumber): print("Found kernel driver, detaching ... ") self.dev.detach_kernel_driver(intf.bInterfaceNumber) diff --git a/src/RAFlasher.py b/src/RAFlasher.py index 1f6d4bf..e71aee7 100644 --- a/src/RAFlasher.py +++ b/src/RAFlasher.py @@ -104,7 +104,6 @@ def read_img(dev, img, start_addr, size): size = 0x3FFFF - start_addr # read maximum possible (start_addr, end_addr) = set_size_boundaries(start_addr, size) - print(hex(start_addr), hex(end_addr)) # setup initial communication SAD = int_to_hex_list(start_addr) @@ -139,7 +138,6 @@ def write_img(dev, img, start_addr, size, verify=False): raise ValueError("Write size > file size") (start_addr, end_addr) = set_size_boundaries(start_addr, size) - print(start_addr, end_addr) chunk_size = 1024 # max is 1024 according to protocol @@ -151,11 +149,12 @@ def write_img(dev, img, start_addr, size, verify=False): ret = dev.recv_data(7) unpack_pkt(ret) + totalread = 0 with open(img, 'rb') as f: - with tqdm(total=file_size, desc="Writing progress") as pbar: + with tqdm(total=size, desc="Writing progress") as pbar: chunk = f.read(chunk_size) pbar.update(len(chunk)) - while chunk: + while chunk and totalread < size: if len(chunk) != chunk_size: padding_length = chunk_size - len(chunk) chunk += b'\0' * padding_length @@ -165,6 +164,7 @@ def write_img(dev, img, start_addr, size, verify=False): reply = dev.recv_data(reply_len) msg = unpack_pkt(reply) chunk = f.read(chunk_size) + totalread += chunk_size pbar.update(len(chunk)) @@ -210,7 +210,6 @@ def main(): status_con = inquire_connection(dev) if not status_con: dev.confirm_connection() - #print(args.start_address, args.size) write_img(dev, args.file_name, args.start_address, args.size, args.verify) elif args.command == "read": dev = RAConnect(vendor_id=0x045B, product_id=0x0261) -- 2.7.4