Anastasia Klimchuk has uploaded this change for review.

View Change

Display progress for what is actually erased/written

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>
---
M flashrom.c
1 file changed, 52 insertions(+), 3 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/39/84439/1
diff --git a/flashrom.c b/flashrom.c
index b8e9621..857b539 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1245,6 +1245,53 @@
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) {
+ // TODO: take FEATURE_NO_ERASE into account?
+
+ 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)))
+ // FIXME: round up to granularity?
+ 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;
+ // FIXME: should be rounded up to page size?
+ total += len;
+ }
+ }
+ }
+
+ init_progress(flashctx, stage, total);
+}
+
+
/**
* @brief Reads the included layout regions into a buffer.
*
@@ -1376,7 +1423,8 @@
memset(newcontents, ERASED_VALUE(flashctx), flash_size);

setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_READ);
- setup_progress_from_layout(flashctx, FLASHROM_PROGRESS_ERASE);
+ // TODO: use erase_layout?
+ 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;
@@ -1415,8 +1463,9 @@
}

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);
+ // TODO: use erase_layout?
+ 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))) {

To view, visit change 84439. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: I88ac4d40f1b6ccc1636b1efb690d8d68bdebec08
Gerrit-Change-Number: 84439
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>