1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

flashrom: Check for flash access restricitons in verify_range()

Make verify_flash() skip read/write-protected regions based on the
FLASHROM_FLAG_SKIP_UNREADABLE and FLASHROM_FLAG_SKIP_UNWRITABLE flags.

If FLASHROM_FLAG_SKIP_UNREADABLE is false, read-protected regions will cause
verification to fail.

If FLASHROM_FLAG_SKIP_UNWRITABLE is false, read-only regions will still
be verified and any mismatch will cause verification to fail. It can be
useful to set the flag to true so that expected mismatches in read-only
regions are ignored by verify_range() after flashing.

BUG=b:260440773
BRANCH=none
TEST=flashrom -v on dedede (JSL)

Change-Id: I61dfadd3c75365f2e55abeea75f673ab791ca5cc
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>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/70515
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Nikolai Artemiev 2022-12-09 15:23:08 +11:00 committed by Edward O'Callaghan
parent 23018faa98
commit 92874fa6a7

View File

@ -604,15 +604,49 @@ int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int sta
return -1;
}
int ret = read_flash(flash, readbuf, start, len);
if (ret) {
msg_gerr("Verification impossible because read failed "
"at 0x%x (len 0x%x)\n", start, len);
ret = -1;
goto out_free;
int ret = 0;
msg_gdbg("%#06x..%#06x ", start, start + len - 1);
unsigned int read_len;
for (size_t addr = start; addr < start + len; addr += read_len) {
struct flash_region region;
get_flash_region(flash, addr, &region);
read_len = min(start + len, region.end) - addr;
if ((region.write_prot && flash->flags.skip_unwritable_regions) ||
(region.read_prot && flash->flags.skip_unreadable_regions)) {
msg_gdbg("%s: Skipping verification of %s region (%#08x..%#08x)\n",
__func__, region.name, region.start, region.end - 1);
free(region.name);
continue;
}
if (region.read_prot) {
msg_gerr("%s: Verification imposible because %s region (%#08x..%#08x) is unreadable.\n",
__func__, region.name, region.start, region.end - 1);
free(region.name);
goto out_free;
}
msg_gdbg("%s: Verifying %s region (%#08x..%#08x)\n",
__func__, region.name, region.start, region.end - 1);
free(region.name);
ret = read_flash(flash, readbuf, addr, read_len);
if (ret) {
msg_gerr("Verification impossible because read failed "
"at 0x%x (len 0x%x)\n", start, len);
ret = -1;
goto out_free;
}
ret = compare_range(cmpbuf + (addr - start), readbuf, addr, read_len);
if (ret)
goto out_free;
}
ret = compare_range(cmpbuf, readbuf, start, len);
out_free:
free(readbuf);
return ret;