+ pbar.update(len(chunk))
+ while chunk and totalread < size:
+ if len(chunk) != chunk_size:
+ padding_length = chunk_size - len(chunk)
+ chunk += b'\0' * padding_length
+ packed = pack_pkt(WRI_CMD, chunk, ack=True)
+ dev.send_data(packed)
+ reply_len = 7
+ reply = dev.recv_data(reply_len)
+ msg = unpack_pkt(reply)
+ chunk = f.read(chunk_size)
+ totalread += chunk_size
+ pbar.update(len(chunk))
+
+
+ if verify:
+ with tempfile.NamedTemporaryFile(prefix='.hidden_', delete=False) as tmp_file, open(img, 'rb') as cmp_file:
+ read_img(dev, tmp_file.name, start_addr, size)
+ c1 = tmp_file.read(file_size) # due to byte alignment read file is longer
+ c2 = cmp_file.read()
+ if c1 == c2:
+ print("Verify complete")
+ else:
+ print("Verify failed")