mirror of
https://review.coreboot.org/flashrom.git
synced 2025-06-30 21:52:36 +02:00
Display progress for what is actually erased/written
The patch updates calculation of total length for the operation which is displayed with progress. The reason is: even if, for example the whole chip erase or write was requested, the actual length of bytes modified can be less than whole chip size (areas which already have expected content, are skipped). Change-Id: I88ac4d40f1b6ccc1636b1efb690d8d68bdebec08 Co-developed-by: Anastasia Klimchuk <aklm@flashrom.org> Co-developed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/84439 Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
56
flashrom.c
56
flashrom.c
@ -1243,6 +1243,56 @@ static void setup_progress_from_layout(struct flashctx *flashctx,
|
||||
init_progress(flashctx, stage, total);
|
||||
}
|
||||
|
||||
|
||||
static void setup_progress_from_layout_and_diff(struct flashctx *flashctx,
|
||||
const void *have,
|
||||
const void *want,
|
||||
enum flashrom_progress_stage stage)
|
||||
{
|
||||
if (!flashctx->progress_callback)
|
||||
return;
|
||||
|
||||
const struct flashrom_layout *flash_layout = get_layout(flashctx);
|
||||
const size_t page_size = flashctx->chip->page_size;
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
const struct romentry *entry = NULL;
|
||||
while ((entry = layout_next_included(flash_layout, entry))) {
|
||||
const struct flash_region *region = &entry->region;
|
||||
|
||||
if (stage == FLASHROM_PROGRESS_ERASE) {
|
||||
size_t offset;
|
||||
for (offset = region->start; offset <= region->end; offset += page_size) {
|
||||
const size_t len = min(page_size, region->end + 1 - offset);
|
||||
|
||||
if (need_erase(have, want, len, flashctx->chip->gran, ERASED_VALUE(flashctx)))
|
||||
total += len;
|
||||
}
|
||||
}
|
||||
|
||||
if (stage == FLASHROM_PROGRESS_WRITE) {
|
||||
unsigned int start = region->start;
|
||||
unsigned int len;
|
||||
while ((len = get_next_write(have + start, want + start,
|
||||
region->end + 1 - start, &start, flashctx->chip->gran))) {
|
||||
start += len;
|
||||
total += len;
|
||||
}
|
||||
|
||||
if (flashctx->chip->feature_bits & FEATURE_NO_ERASE)
|
||||
/* For chips with FEATURE_NO_ERASE erase op is running as write under the hood.
|
||||
* So typical write, which usually consists of erasing and then writing,
|
||||
* would be writing and then writing again. The planned total length for the
|
||||
* progress indicator for write is double. */
|
||||
total *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
init_progress(flashctx, stage, total);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads the included layout regions into a buffer.
|
||||
*
|
||||
@ -1374,7 +1424,7 @@ static int erase_by_layout(struct flashctx *const flashctx)
|
||||
memset(newcontents, ERASED_VALUE(flashctx), flash_size);
|
||||
|
||||
setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_READ);
|
||||
setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_ERASE);
|
||||
setup_progress_from_layout_and_diff(flashctx, curcontents, newcontents, FLASHROM_PROGRESS_ERASE);
|
||||
|
||||
const struct flashrom_layout *const flash_layout = get_layout(flashctx);
|
||||
const struct romentry *entry = NULL;
|
||||
@ -1413,8 +1463,8 @@ static int write_by_layout(struct flashctx *const flashctx,
|
||||
}
|
||||
|
||||
setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_READ);
|
||||
setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_WRITE);
|
||||
setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_ERASE);
|
||||
setup_progress_from_layout_and_diff(flashctx, curcontents, newcontents, FLASHROM_PROGRESS_WRITE);
|
||||
setup_progress_from_layout_and_diff(flashctx, curcontents, newcontents, FLASHROM_PROGRESS_ERASE);
|
||||
|
||||
const struct romentry *entry = NULL;
|
||||
while ((entry = layout_next_included(flash_layout, entry))) {
|
||||
|
Reference in New Issue
Block a user