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)
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)
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
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
reply = dev.recv_data(reply_len)
msg = unpack_pkt(reply)
chunk = f.read(chunk_size)
+ totalread += chunk_size
pbar.update(len(chunk))
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)