1 /* 2 * Copyright (c) 2019,2020 Linaro Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 9 #include "psa/error.h" 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 /** 16 * @brief The struct used to persist config data to secure storage. 17 * 18 * The first 6 bytes of this struct should remain consistent in any future 19 * firmware updates, since they can be used to identify to layout of the rest 20 * of the struct in cases where config data version management becomes 21 * a necessity. 22 */ 23 struct cfg_data { 24 /** 25 * @brief Magic number for config data payloads (0x55CFDA7A). 26 */ 27 uint32_t magic; 28 29 /** 30 * @brief The version number for the stored config record. 31 * 32 * This number should be incremented any time the config_data struct 33 * definition changes to allow version management of config data at 34 * the application level. 35 */ 36 uint16_t version; 37 38 /** @brief 256-byte debug scratch area. */ 39 uint8_t scratch[256]; 40 }; 41 42 /** 43 * @brief Creates a new config record in secure storage. 44 * 45 * @return #PSA_SUCCESS on success, otherwise a appropriate psa_status_t code. 46 */ 47 psa_status_t cfg_create_data(void); 48 49 /** 50 * @brief Attempts to load the config record from secure storage. If the 51 * record is not found in secure storage, a new record will be created 52 * using default config settings. 53 * 54 * @param p_cfg_data Pointer to the cfg_data struct where the config data 55 * should be assigned once loaded. 56 * 57 * @return #PSA_SUCCESS on success, otherwise a appropriate psa_status_t code. 58 */ 59 psa_status_t cfg_load_data(struct cfg_data *p_cfg_data); 60 61 #ifdef __cplusplus 62 } 63 #endif 64