Sergii Dmytruk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/59713 )
Change subject: [RFC][OTP] tests: test OTP with security register ......................................................................
[RFC][OTP] tests: test OTP with security register
Change-Id: Ib0e4d948a200d0cf1e670d67623f7087005d5d39 Signed-off-by: Sergii Dmytruk sergii.dmytruk@3mdeb.com --- M tests/chip_otp.c M tests/tests.c M tests/tests.h 3 files changed, 95 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/13/59713/1
diff --git a/tests/chip_otp.c b/tests/chip_otp.c index 324f403..034554e 100644 --- a/tests/chip_otp.c +++ b/tests/chip_otp.c @@ -114,6 +114,38 @@ .otp = &en512_16384otp, };
+/* Setup the struct for MX25L6436, all values come from flashchips.c */ +static const struct flashchip chip_MX25L6436 = { + .vendor = "aklm&dummyflasher", + .total_size = 8192, + .page_size = 256, + .feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_SCUR, + .tested = TEST_OK_PREW, + .block_erasers = + { + { + .eraseblocks = { {4 * 1024, 2048} }, + .block_erase = spi_block_erase_20, + }, { + .eraseblocks = { {32 * 1024, 256} }, + .block_erase = spi_block_erase_52, + }, { + .eraseblocks = { {64 * 1024, 128} }, + .block_erase = spi_block_erase_d8, + }, { + .eraseblocks = { {8 * 1024 * 1024, 1} }, + .block_erase = spi_block_erase_60, + }, { + .eraseblocks = { {8 * 1024 * 1024, 1} }, + .block_erase = spi_block_erase_c7, + } + }, + .unlock = spi_disable_blockprotect_bp3_srwd, + .write = spi_chip_write_256, + .read = spi_chip_read, /* Fast read (0x0B) and multi I/O supported */ + .otp = &mx512otp, +}; + void otp_regs_status_dummyflasher_test_success(void **state) { (void) state; /* unused */ @@ -378,3 +410,62 @@
free(param_dup); } + +void otp_scur_user_lock_test_success(void **state) +{ + (void) state; /* unused */ + + enum { REGION_SIZE = 512 }; + + struct flashrom_flashctx flash = { 0 }; + struct flashchip mock_chip = chip_MX25L6436; + uint8_t buf[REGION_SIZE]; + + char *param_dup = strdup("bus=spi,emulate=MX25L6436"); + + setup(&flash, &mock_chip, param_dup); + + /* Write region and lock it */ + assert_int_equal(0, flashrom_otp_write(&flash, 0, image, REGION_SIZE)); + assert_int_equal(0, flashrom_otp_lock(&flash, 0)); + + /* Lost ability to write or erase it */ + assert_int_equal(1, flashrom_otp_write(&flash, 0, image, REGION_SIZE)); + assert_int_equal(1, flashrom_otp_erase(&flash, 0)); + + /* Region's content is correct after all manipulations */ + assert_int_equal(0, flashrom_otp_read(&flash, 0, buf, REGION_SIZE)); + assert_memory_equal(buf, image, REGION_SIZE); + + teardown(); + + free(param_dup); +} + +void otp_scur_factory_lock_test_success(void **state) +{ + (void) state; /* unused */ + + enum { REGION_SIZE = 512 }; + + struct flashrom_flashctx flash = { 0 }; + struct flashchip mock_chip = chip_MX25L6436; + uint8_t buf[REGION_SIZE]; + + char *param_dup = strdup("bus=spi,emulate=MX25L6436,spi_scur=0x01"); + + setup(&flash, &mock_chip, param_dup); + + /* Can't write, erase or lock (second time) OTP region */ + assert_int_equal(1, flashrom_otp_write(&flash, 0, image, REGION_SIZE)); + assert_int_equal(1, flashrom_otp_erase(&flash, 0)); + assert_int_equal(1, flashrom_otp_lock(&flash, 0)); + + /* Region's content is still empty after all manipulations */ + assert_int_equal(0, flashrom_otp_read(&flash, 0, buf, REGION_SIZE)); + assert_memory_equal(buf, empty, REGION_SIZE); + + teardown(); + + free(param_dup); +} diff --git a/tests/tests.c b/tests/tests.c index 29329c2..a0add07 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -377,6 +377,8 @@ cmocka_unit_test(otp_mode_ops_dummyflasher_test_success), cmocka_unit_test(otp_regs_in_locked_state_test_success), cmocka_unit_test(otp_mode_in_locked_state_test_success), + cmocka_unit_test(otp_scur_user_lock_test_success), + cmocka_unit_test(otp_scur_factory_lock_test_success), }; ret |= cmocka_run_group_tests_name("chip_otp.c tests", chip_otp_tests, NULL, NULL);
diff --git a/tests/tests.h b/tests/tests.h index ad1091d..8b95708 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -85,5 +85,7 @@ void otp_mode_ops_dummyflasher_test_success(void **state); void otp_regs_in_locked_state_test_success(void **state); void otp_mode_in_locked_state_test_success(void **state); +void otp_scur_user_lock_test_success(void **state); +void otp_scur_factory_lock_test_success(void **state);
#endif /* TESTS_H */