Hello,

please, review the patch and, if okay, apply it.
It was tested with some basic scenarios for the upload size and
results are backward compatible and work for relevant parameters:

Use expected upload size when reading from device

In order to limit transfer on wires stop transmission when
expected size is reached.

Signed-off-by: Jakub Palider <[email protected]>
---
 src/dfu_load.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/dfu_load.c b/src/dfu_load.c
index 32c71b5..78db9ff 100644
--- a/src/dfu_load.c
+++ b/src/dfu_load.c
@@ -63,6 +63,15 @@ int dfuload_do_upload(struct dfu_if *dif, int xfer_size,
             break;
         }

+        /* If option --expected_size/-Z was issued then limit reading
+           size to the requested size and trim anything above that
+           limit (actual bus transfer may slightly exceed this value).
+           Here we also know rc < xfer_size which will stop transfer
+           down the execution path.
+        */
+        if (expected_size && (total_bytes + rc > expected_size))
+            rc = expected_size - total_bytes;
+
         dfu_file_write_crc(fd, 0, buf, rc);
         total_bytes += rc;

-- 
2.25.1

Regards,
Jakub
_______________________________________________
dfu-util mailing list
[email protected]
https://lists.osmocom.org/mailman/listinfo/dfu-util

Reply via email to