From 40892b0c08fbc8029921e91511dd3f91fc956f90 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 15 Jan 2021 09:48:12 +0000 Subject: 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. TEST=./test_build.sh; ./flashrom -p lspcon_i2c_spi:bus=7 -r /dev/null --progress Change-Id: I7197572bb7f19e3bdb2bde855d70a0f50fd3854c Signed-off-by: Richard Hughes Signed-off-by: Daniel Campello Reviewed-on: https://review.coreboot.org/c/flashrom/+/49643 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan Reviewed-by: Anastasia Klimchuk Reviewed-by: Thomas Heijligen --- libflashrom.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libflashrom.c') diff --git a/libflashrom.c b/libflashrom.c index e70c1d1a..0c6613e9 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -65,6 +65,25 @@ int print(const enum flashrom_log_level level, const char *const fmt, ...) return 0; } +void flashrom_set_progress_callback(struct flashrom_flashctx *flashctx, flashrom_progress_callback *progress_callback, struct flashrom_progress *progress_state) +{ + flashctx->progress_callback = progress_callback; + flashctx->progress_state = progress_state; +} +/** @private */ +void update_progress(struct flashrom_flashctx *flashctx, enum flashrom_progress_stage stage, size_t current, size_t total) +{ + if (flashctx->progress_callback == NULL) + return; + if (current > total) + current = total; + + flashctx->progress_state->stage = stage; + flashctx->progress_state->current = current; + flashctx->progress_state->total = total; + flashctx->progress_callback(flashctx); +} + const char *flashrom_version_info(void) { return flashrom_version; -- cgit v1.2.3