From jpalider at gmail.com Fri Sep 4 23:30:19 2020 From: jpalider at gmail.com (Jakub Palider) Date: Sat, 5 Sep 2020 01:30:19 +0200 Subject: [Dfu-util] Patch for activating --upload-size option Message-ID: 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 --- 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