Anastasia Klimchuk has uploaded this change for review.

View Change

erase/write: Deselect all smaller blocks when large block is selected

Previously the logic which selected large block did deselect of
smaller blocks, but only one level below. So some even smaller blocks
could still remain selected, and this would result in duplicate erase.

Change-Id: Icfc18d5c090b1dcb92ab157e2c139be71af59300
Spotted-by: persmule <persmule@hardenedlinux.org>
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
---
M erasure_layout.c
1 file changed, 22 insertions(+), 2 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/86/84686/1
diff --git a/erasure_layout.c b/erasure_layout.c
index c3a415b..ad333eb 100644
--- a/erasure_layout.c
+++ b/erasure_layout.c
@@ -229,9 +229,29 @@

const int total_blocks = sub_block_end - sub_block_start + 1;
if (count && count > total_blocks/2) {
+ /* More than a half of the region is covered by smaller blocks already.
+ We are selecting one large block instead, to send opcode once
+ instead of sending many smaller once. */
if (ll->start_addr >= rstart && ll->end_addr <= rend) {
- for (int j = sub_block_start; j <= sub_block_end; j++)
- layout[findex - 1].layout_list[j].selected = false;
+
+ /* Deselect all smaller blocks covering the same region. */
+ size_t index_to_deselect = findex - 1; // represents size of the block
+ int block_start_to_deselect = sub_block_start;
+ int block_end_to_deselect = sub_block_end;
+
+ while (true) {
+ for (int j = block_start_to_deselect; j <= block_end_to_deselect; j++)
+ layout[index_to_deselect].layout_list[j].selected = false;
+
+ block_start_to_deselect = layout[index_to_deselect].layout_list[block_start_to_deselect].first_sub_block_index;
+ block_end_to_deselect = layout[index_to_deselect].layout_list[block_end_to_deselect].last_sub_block_index;
+ if (index_to_deselect)
+ index_to_deselect--;
+ else
+ break; // index_to_deselect has already reached 0, the smallest size of block. we are done.
+ }
+
+ /* Select large block. */
ll->selected = true;
}
}

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

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