Attention is currently required from: Edward O'Callaghan.
Hello Edward O'Callaghan,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/70517
to review the following change.
Change subject: flashrom: Check for flash access restricitons erase path ......................................................................
flashrom: Check for flash access restricitons erase path
Skip unwritable regions if FLASHROM_FLAG_SKIP_UNWRITABLE_REGIONS is true. If the flag is false, erase operations that include an unwritable region will not erase anything and return an error.
BUG=b:260440773 BRANCH=none TEST=flashrom -E on dedede (JSL)
Change-Id: If027a96a024782c7707c6d38680709a1a117f3ef CoAuthored-by: Edward O'Callaghan quasisec@google.com Signed-off-by: Edward O'Callaghan quasisec@google.com Signed-off-by: Nikolai Artemiev nartemiev@google.com --- M flashrom.c 1 file changed, 53 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/17/70517/1
diff --git a/flashrom.c b/flashrom.c index 7a77845..23af5da 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1410,13 +1410,41 @@ all_skipped = false;
msg_cdbg("E"); - if (erasefn(flashctx, info->erase_start, erase_len)) - goto _free_ret; - if (check_erased_range(flashctx, info->erase_start, erase_len)) { - msg_cerr("ERASE FAILED!\n"); - goto _free_ret; + + unsigned int len; + for (unsigned int addr = info->erase_start; addr < info->erase_start + erase_len; addr += len) { + struct flash_region region; + get_flash_region(flashctx, addr, ®ion); + + len = min(info->erase_start + erase_len, region.end) - addr; + + if (region.write_prot) { + if (flashctx->flags.skip_unwritable_regions) { + msg_gdbg("%s: cannot erase inside %s region (%#08x..%#08x), skipping range (%#08x..%#08x).\n", + __func__, region.name, region.start, region.end - 1, addr, addr + len - 1); + free(region.name); + continue; + } + + msg_gerr("%s: cannot erase inside %s region (%#08x..%#08x).\n", + __func__, region.name, region.start, region.end - 1); + free(region.name); + return -1; + } + + msg_gdbg("%s: %s region (%#08x..%#08x) is writable, erasing range (%#08x..%#08x).\n", + __func__, region.name, region.start, region.end - 1, addr, addr + len - 1); + free(region.name); + + if (erasefn(flashctx, addr, len)) + goto _free_ret; + if (check_erased_range(flashctx, addr, len)) { + msg_cerr("ERASE FAILED!\n"); + goto _free_ret; + } }
+ if (region_unaligned) { unsigned int starthere = 0, lenhere = 0, writecount = 0; /* get_next_write() sets starthere to a new value after the call. */