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, approved Edward O'Callaghan: Looks good to me, approved Anastasia Klimchuk: Looks good to me, approved
tests: ensure chip erase operation is executed

The `full_chip_erase_with_wp_dummyflasher_test_success` test case
checks that erasing a write-protected region of a dummyflasher chip
fails.

However erase optimization may cause the erase operation to be skipped
if the flash contents are already erased, so the erase operation appears
to succeed and the test case fails.

Writing a non-erased value to the chip ensures that an erase operation
will be executed and write protection will be properly tested.

BUG=b:237620197
BRANCH=none
TEST=ninja test

Change-Id: Ia00444dcd2ad96c64832a13201efbd064cd7302d
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69130
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M include/flash.h
M tests/chip_wp.c
2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/include/flash.h b/include/flash.h
index 238d010..ea8e25b 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -156,6 +156,7 @@
#define FEATURE_WRSR3 (1 << 23)

#define ERASED_VALUE(flash) (((flash)->chip->feature_bits & FEATURE_ERASED_ZERO) ? 0x00 : 0xff)
+#define UNERASED_VALUE(flash) (((flash)->chip->feature_bits & FEATURE_ERASED_ZERO) ? 0xff : 0x00)

enum test_state {
OK = 0,
diff --git a/tests/chip_wp.c b/tests/chip_wp.c
index c308959..40303ff 100644
--- a/tests/chip_wp.c
+++ b/tests/chip_wp.c
@@ -63,6 +63,7 @@
static const struct flashchip chip_W25Q128_V = {
.vendor = "aklm&dummyflasher",
.total_size = 16 * 1024,
+ .page_size = 1024,
.tested = TEST_OK_PREW,
.read = SPI_CHIP_READ,
.write = SPI_CHIP_WRITE256,
@@ -268,6 +269,14 @@
this stage WP is not enabled and erase completes successfully. */
assert_int_equal(0, flashrom_flash_erase(&flash));

+ /* Write non-erased value to entire chip so that erase operations cannot
+ * be optimized away. */
+ unsigned long size = flashrom_flash_getsize(&flash);
+ uint8_t *const contents = malloc(size);
+ memset(contents, UNERASED_VALUE(&flash), size);
+ assert_int_equal(0, flashrom_image_write(&flash, contents, size, NULL));
+ free(contents);
+
assert_int_equal(0, flashrom_wp_read_cfg(wp_cfg, &flash));

/* Hardware-protect first 4 KiB. */

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ia00444dcd2ad96c64832a13201efbd064cd7302d
Gerrit-Change-Number: 69130
Gerrit-PatchSet: 5
Gerrit-Owner: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
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