|
1 | 1 | /* Copyright (c) 2024 Nordic Semiconductor |
2 | 2 | * SPDX-License-Identifier: Apache-2.0 |
3 | 3 | */ |
| 4 | +#include <zephyr/types.h> |
4 | 5 | #include <zephyr/ztest.h> |
| 6 | +#include <zephyr/drivers/flash.h> |
| 7 | +#include <zephyr/storage/flash_map.h> |
5 | 8 | #include <psa/internal_trusted_storage.h> |
6 | 9 |
|
7 | 10 | /* The flash must be erased after this test suite is run for the write-once entry test to pass. */ |
| 11 | +#if !defined(CONFIG_BUILD_WITH_TFM) && defined(CONFIG_FLASH_PAGE_LAYOUT) |
| 12 | +static int erase_flash(void) |
| 13 | +{ |
| 14 | + const struct device *const fdev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); |
| 15 | + int rc; |
| 16 | + |
| 17 | + rc = flash_flatten(fdev, FIXED_PARTITION_OFFSET(storage_partition), |
| 18 | + FIXED_PARTITION_SIZE(storage_partition)); |
| 19 | + if (rc < 0) { |
| 20 | + TC_PRINT("Failed to flatten the storage partition (%d) !", rc); |
| 21 | + return rc; |
| 22 | + } |
| 23 | + |
| 24 | + return 0; |
| 25 | +} |
| 26 | + |
| 27 | +/* Low priority to ensure we run after any flash drivers are initialized */ |
| 28 | +SYS_INIT(erase_flash, POST_KERNEL, 100); |
| 29 | + |
| 30 | +#endif /* !CONFIG_BUILD_WITH_TFM && CONFIG_FLASH_PAGE_LAYOUT */ |
| 31 | + |
8 | 32 | ZTEST_SUITE(secure_storage_psa_its, NULL, NULL, NULL, NULL, NULL); |
9 | 33 |
|
10 | 34 | #ifdef CONFIG_SECURE_STORAGE |
@@ -119,8 +143,11 @@ ZTEST(secure_storage_psa_its, test_write_once_flag) |
119 | 143 | struct psa_storage_info_t info; |
120 | 144 |
|
121 | 145 | ret = psa_its_set(uid, sizeof(data), data, PSA_STORAGE_FLAG_WRITE_ONCE); |
122 | | - zassert_equal(ret, PSA_SUCCESS, "%s%d", (ret == PSA_ERROR_NOT_PERMITTED) ? |
123 | | - "Has the flash been erased since this test ran? " : "", ret); |
| 146 | + zassert_equal(ret, PSA_SUCCESS, "%s%d", |
| 147 | + (ret == PSA_ERROR_NOT_PERMITTED) |
| 148 | + ? "Has the flash been erased since this test ran? " |
| 149 | + : "", |
| 150 | + ret); |
124 | 151 |
|
125 | 152 | ret = psa_its_get_info(uid, &info); |
126 | 153 | zassert_equal(ret, PSA_SUCCESS); |
|
0 commit comments