-
Notifications
You must be signed in to change notification settings - Fork 8.3k
tests: subsys: secure_storage: Erase flash before write once test #99701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,49 @@ | |||||
| #include <zephyr/ztest.h> | ||||||
| #include <psa/internal_trusted_storage.h> | ||||||
|
|
||||||
| #include <zephyr/types.h> | ||||||
| #include <zephyr/storage/flash_map.h> | ||||||
| #include <zephyr/drivers/flash.h> | ||||||
|
|
||||||
| /* The flash must be erased after this test suite is run for the write-once entry test to pass. */ | ||||||
|
|
||||||
| #if !defined(CONFIG_BUILD_WITH_TFM) && defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) | ||||||
|
|
||||||
| #define MAX_NUM_PAGES 2 | ||||||
| static const struct device *const fdev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); | ||||||
|
|
||||||
| #define FLASH_ERASE_END_ADDR \ | ||||||
| (FIXED_PARTITION_OFFSET(storage_partition) + FIXED_PARTITION_SIZE(storage_partition)) | ||||||
|
|
||||||
| static void erase_flash(void) | ||||||
| { | ||||||
| int rc; | ||||||
| off_t address = FIXED_PARTITION_OFFSET(storage_partition); | ||||||
| struct flash_pages_info page_info; | ||||||
|
|
||||||
| #if defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE) | ||||||
| const struct flash_parameters *fparam = flash_get_parameters(fdev); | ||||||
|
|
||||||
| if (!(flash_params_get_erase_cap(fparam) & FLASH_ERASE_C_EXPLICIT)) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe in case we have no erase operation (e.g. nRF54 RRAM and MRAM) we should fully overwrite the region with zeroes or ones? (edit: native_sim can also simulate such NVM model IIRC, so it should be testable even without such HW. Please take a look at native simulator flash Kconfig file for details, or if it's missing such a variant you might need to open an issue |
||||||
| return; | ||||||
| } | ||||||
| #endif | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| for (int i = 0; i < MAX_NUM_PAGES && address < FLASH_ERASE_END_ADDR; i++) { | ||||||
| rc = flash_get_page_info_by_offs(fdev, address, &page_info); | ||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-blocking nit to unify the code style here
Suggested change
|
||||||
| zassert_equal(rc, 0, "should succeed"); | ||||||
|
|
||||||
| TC_PRINT("Erasing %d at %ld\n", page_info.size, page_info.start_offset); | ||||||
| rc = flash_erase(fdev, page_info.start_offset, page_info.size); | ||||||
| zassert_equal(rc, 0, "should succeed"); | ||||||
|
|
||||||
| address += page_info.size; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #endif | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ZTEST_SUITE(secure_storage_psa_its, NULL, NULL, NULL, NULL, NULL); | ||||||
|
|
||||||
| #ifdef CONFIG_SECURE_STORAGE | ||||||
|
|
@@ -118,6 +160,10 @@ ZTEST(secure_storage_psa_its, test_write_once_flag) | |||||
| const uint8_t data[MAX_DATA_SIZE] = {}; | ||||||
| struct psa_storage_info_t info; | ||||||
|
|
||||||
| #if !defined(CONFIG_BUILD_WITH_TFM) && defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) | ||||||
| erase_flash(); | ||||||
| #endif | ||||||
|
|
||||||
| ret = psa_its_set(uid, sizeof(data), data, PSA_STORAGE_FLAG_WRITE_ONCE); | ||||||
| zassert_equal(ret, PSA_SUCCESS, "%s%d", (ret == PSA_ERROR_NOT_PERMITTED) ? | ||||||
| "Has the flash been erased since this test ran? " : "", ret); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you come up with this value? Is it even needed?