1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _NRF_HW_MODEL_NHW_NVM_BACKEND_H 8 #define _NRF_HW_MODEL_NHW_NVM_BACKEND_H 9 10 #include <stdint.h> 11 #include "bs_types.h" 12 #include "nsi_utils.h" 13 14 #ifdef __cplusplus 15 extern "C"{ 16 #endif 17 18 typedef struct { 19 uint8_t *storage; 20 const char *file_path; 21 const char *type_s; 22 int fd; 23 size_t size; 24 bool erase_at_start; 25 bool rm_at_exit; 26 bool in_ram; 27 } nvm_storage_state_t; 28 29 struct nhw_nvm_st_args_t { 30 char *file; 31 bool erase; 32 bool rm; 33 bool in_ram; 34 }; 35 36 void nhw_nvm_initialize_data_storage(nvm_storage_state_t *st); 37 void nhw_nvm_clear_storage(nvm_storage_state_t *st); 38 void nhw_nvm_init_storage(nvm_storage_state_t *st, struct nhw_nvm_st_args_t *args, 39 size_t size, char *type); 40 41 #define NVM_BACKEND_PARAMS(x, arg, X) \ 42 { .is_switch = true, \ 43 .option = NSI_STRINGIFY(x) "_erase", \ 44 .type = 'b', \ 45 .dest = (void*)&nvmc_args. arg .erase, \ 46 .descript = "Reset the " # X " storage to their erase values (0xFF) at boot"\ 47 }, \ 48 { .option = NSI_STRINGIFY(x) "_file", \ 49 .name = "path", \ 50 .type = 's', \ 51 .dest = (void*)&nvmc_args. arg .file, \ 52 .call_when_found = arg_##x##_file_found, \ 53 .descript = "Path to the binary file where the " #X " content " \ 54 "is stored (if set, toggles " NSI_STRINGIFY(x) "_in_ram to false)" \ 55 }, \ 56 { .option = NSI_STRINGIFY(x), \ 57 .name = "path", \ 58 .type = 's', \ 59 .dest = (void*)&nvmc_args. arg . file, \ 60 .call_when_found = arg_##x##_file_found, \ 61 .descript = "Alias for " NSI_STRINGIFY(x) "_file" \ 62 }, \ 63 { .is_switch = true, \ 64 .option = NSI_STRINGIFY(x) "_rm", \ 65 .type = 'b', \ 66 .dest = (void*)&nvmc_args. arg .rm, \ 67 .descript = "Remove the " # X " file when terminating the execution " \ 68 "(default no)" \ 69 }, \ 70 { .is_switch = true, \ 71 .option = NSI_STRINGIFY(x) "_in_ram", \ 72 .type = 'b', \ 73 .call_when_found = arg_##x##_in_ram_found, \ 74 .descript = "(default) Instead of a file, keep the " #X " content in RAM." \ 75 "If this is set " NSI_STRINGIFY(x) "_erase/_file & _rm " \ 76 "are ignored, and the " #X " content is always reset at startup" \ 77 } 78 79 #define NVM_BACKEND_PARAMS_CALLBACS(x, args) \ 80 static void arg_##x##_file_found(char *argv, int offset){ \ 81 nvmc_args. args .in_ram = false; \ 82 } \ 83 static void arg_##x##_in_ram_found(char *argv, int offset){ \ 84 nvmc_args. args .in_ram = true; \ 85 } 86 87 88 #ifdef __cplusplus 89 } 90 #endif 91 92 #endif /* _NRF_HW_MODEL_NHW_NVM_BACKEND_H */ 93