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 --- cli_output.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli_output.c') diff --git a/cli_output.c b/cli_output.c index 629db676d..e5b829a7d 100644 --- a/cli_output.c +++ b/cli_output.c @@ -64,6 +64,31 @@ void start_logging(void) verbose_screen = oldverbose_screen; } +static const char *flashrom_progress_stage_to_string(enum flashrom_progress_stage stage) +{ + if (stage == FLASHROM_PROGRESS_READ) + return "READ"; + if (stage == FLASHROM_PROGRESS_WRITE) + return "WRITE"; + if (stage == FLASHROM_PROGRESS_ERASE) + return "ERASE"; + return "UNKNOWN"; +} + +void flashrom_progress_cb(struct flashrom_flashctx *flashctx) +{ + struct flashrom_progress *progress_state = flashctx->progress_state; + unsigned int pc = 0; + unsigned int *percentages = progress_state->user_data; + if (progress_state->current > 0 && progress_state->total > 0) + pc = ((unsigned long long) progress_state->current * 10000llu) / + ((unsigned long long) progress_state->total * 100llu); + if (percentages[progress_state->stage] != pc) { + percentages[progress_state->stage] = pc; + msg_ginfo("[%s] %u%% complete... ", flashrom_progress_stage_to_string(progress_state->stage), pc); + } +} + /* Please note that level is the verbosity, not the importance of the message. */ int flashrom_print_cb(enum flashrom_log_level level, const char *fmt, va_list ap) { -- cgit v1.2.3