Edward O'Callaghan submitted this change.

View Change



3 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Approvals: build bot (Jenkins): Verified Angel Pons: Looks good to me, but someone else must approve Edward O'Callaghan: Looks good to me, approved
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>
---
M flashrom.c
1 file changed, 72 insertions(+), 7 deletions(-)

diff --git a/flashrom.c b/flashrom.c
index d036b5c..573f10b 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -604,15 +604,49 @@
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;

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I61dfadd3c75365f2e55abeea75f673ab791ca5cc
Gerrit-Change-Number: 70515
Gerrit-PatchSet: 5
Gerrit-Owner: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged