-
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,62 @@ | |||||
| #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_PAGE_LAYOUT) | ||||||
|
|
||||||
| #define MAX_NUM_PAGES 2 | ||||||
|
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
|
||||||
| 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 int erase_flash(void) | ||||||
| { | ||||||
| int rc; | ||||||
| off_t address = FIXED_PARTITION_OFFSET(storage_partition); | ||||||
| struct flash_pages_info page_info; | ||||||
|
|
||||||
| while (address < FLASH_ERASE_END_ADDR) { | ||||||
| rc = flash_get_page_info_by_offs(fdev, address, &page_info); | ||||||
| if (rc < 0) { | ||||||
| return rc; | ||||||
| } | ||||||
|
|
||||||
| #if defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE) | ||||||
|
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. Avoid using Flash API Kconfig in code that is not Flash API. Make test/subsystem specific Kconfig dependent on the Flash API kconfig. |
||||||
| /* Lacking an explicit erase, just write all ones to the pages */ | ||||||
| uint8_t empty[page_info.size]; | ||||||
|
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. VLAs are not allowed |
||||||
|
|
||||||
|
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
|
||||||
| memset(empty, 0xff, page_info.size); | ||||||
|
|
||||||
| TC_PRINT("Setting %d at %ld to 0xff\n", page_info.size, page_info.start_offset); | ||||||
|
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
|
||||||
| rc = flash_write(fdev, page_info.start_offset, empty, page_info.size); | ||||||
| if (rc < 0) { | ||||||
| return rc; | ||||||
| } | ||||||
| #else | ||||||
| TC_PRINT("Erasing %d at %ld\n", page_info.size, page_info.start_offset); | ||||||
|
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
|
||||||
| rc = flash_erase(fdev, page_info.start_offset, page_info.size); | ||||||
| if (rc < 0) { | ||||||
| return rc; | ||||||
| } | ||||||
| #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
|
||||||
|
|
||||||
| address += page_info.size; | ||||||
| } | ||||||
|
|
||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| /* Low priority to ensure we run after any flash drivers are initialized */ | ||||||
| SYS_INIT(erase_flash, POST_KERNEL, 100); | ||||||
|
|
||||||
| #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 | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.