libflashrom: Return progress state to the library user

Projects using libflashrom like fwupd expect the user to wait for the
operation to complete. To avoid the user thinking the process has
"hung" or "got stuck" report back the progress complete of the erase,
write and read operations.

Add a new --progress flag to the CLI to report progress of operations.

Include a test for the dummy spi25 device.

Tested: ./test_build.sh; ./flashrom -p lspcon_i2c_spi:bus=7 -r /dev/null --progress

flashrom-stable:
* Closer to original libflashrom API.
* Split update_progress() into progress_start/_set/_add/_finish:
  Simplifies progress calls scattered through the code base. We let
  the core code in `flashprog.c` handle the total progress. Only API
  is flashprog_progress_add().  Erase progress is completely handled
  in `flashprog.c`. Fine grained read/write progress can be reported
  at the chip/programmer level.
* Add calls to all chip read/write paths and opaque programmers
  except for read_memmapped() (which is handled in follow ups).
* At least one wrinkle left: Erasing unaligned regions will slightly
  overshoot total progress.

Change-Id: I7197572bb7f19e3bdb2bde855d70a0f50fd3854c
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Daniel Campello <campello@chromium.org>
Signed-off-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/49643
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/74731
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/dediprog.c b/dediprog.c
index 4d6df5c..af9e157 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -207,6 +207,7 @@
 }
 
 struct dediprog_transfer_status {
+	struct flashctx *flash;
 	int error; /* OK if 0, ERROR else */
 	unsigned int queued_idx;
 	unsigned int finished_idx;
@@ -219,6 +220,7 @@
 		status->error = 1;
 		msg_perr("SPI bulk read failed!\n");
 	}
+	flashprog_progress_add(status->flash, transfer->actual_length);
 	++status->finished_idx;
 }
 
@@ -459,7 +461,7 @@
 	const unsigned int chunksize = 512;
 	const unsigned int count = len / chunksize;
 
-	struct dediprog_transfer_status status = { 0, 0, 0 };
+	struct dediprog_transfer_status status = { flash, 0, 0, 0 };
 	struct libusb_transfer *transfers[DEDIPROG_ASYNC_TRANSFERS] = { NULL, };
 	struct libusb_transfer *transfer;
 
@@ -671,6 +673,7 @@
 			msg_perr("SPI bulk write failed, expected %i, got %s!\n", 512, libusb_error_name(ret));
 			return 1;
 		}
+		flashprog_progress_add(flash, chunksize);
 	}
 
 	return 0;