From bcb4f037d820859a0f9406641fc39d4b4ba23d29 Mon Sep 17 00:00:00 2001 From: Aarya Chaumal Date: Thu, 14 Jul 2022 12:51:14 +0530 Subject: [PATCH] flashrom.c:Add a function to get list of sectors that need erasing Add a function that returns a list of sectors (as seen by the first erase function) that need erasing. Change-Id: Ic57ca1cca3d1646543f6b5939ba9c35db8d08256 Signed-off-by: Aarya Chaumal --- flashrom.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/flashrom.c b/flashrom.c index ab82d1ff5..c22c591e2 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1036,6 +1036,42 @@ void align_region(const struct erase_layout *layout, struct flashctx *const flas } } +void select_erase_functions(const struct erase_layout *layout, size_t function_index, size_t block_num, struct flashctx *flashctx, void *curcontents, void *newcontents, chipoff_t region_start, chipoff_t region_end); + +void select_erase_functions(const struct erase_layout *layout, size_t function_index, size_t block_num, struct flashctx *flashctx, void *curcontents, void *newcontents, chipoff_t region_start, chipoff_t region_end) +{ + if (function_index == 0) + { + if (layout[function_index].layout_list[block_num].start_addr >= region_start && + layout[function_index].layout_list[block_num].end_addr <= region_end) { + chipoff_t start_addr = layout[function_index].layout_list[block_num].start_addr; + chipoff_t end_addr = layout[function_index].layout_list[block_num].end_addr; + const chipsize_t erase_len = end_addr - start_addr + 1; + const uint8_t erased_value = ERASED_VALUE(flashctx); + layout[function_index].layout_list[block_num].selected = need_erase(curcontents + start_addr, newcontents + start_addr, erase_len, flashctx->chip->gran, erased_value); + } + } + else { + int count = 0; + int sub_block_start = layout[function_index].layout_list[block_num].first_sub_block_index; + int sub_block_end = layout[function_index].layout_list[block_num].last_sub_block_index; + + for(int j = sub_block_start; j <= sub_block_end; j++) { + select_erase_functions(layout, function_index - 1, j, flashctx, curcontents, newcontents, region_start, region_end); + if (layout[function_index - 1].layout_list[j].selected) + count++; + } + if (count && count > (sub_block_end - sub_block_start + 1)/2) { + if (layout[function_index].layout_list[block_num].start_addr >= region_start && + layout[function_index].layout_list[block_num].end_addr <= region_end) { + for (int j = sub_block_start; j <= sub_block_end; j++) + layout[function_index - 1].layout_list[j].selected = false; + layout[function_index].layout_list[block_num].selected = true; + } + } + } +} + static int walk_by_layout(struct flashctx *const flashctx, struct walk_info *const info, const per_blockfn_t per_blockfn) {