Skip to content

Commit

Permalink
Improve Nvram version management & add Nvram properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger authored and jarevalo-ledger committed Jun 4, 2024
1 parent 6ae43c9 commit 2daf4e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
23 changes: 16 additions & 7 deletions include/nvram_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
#include "nvram_data.h"
#endif // HAVE_BOLOS

///< bit to indicate in properties that the NVRAM contains settings
#define CONTAINS_SETTINGS (1 << 0)
///< bit to indicate in properties that the NVRAM contains sensitive data
#define CONTAINS_SENSITIVE_DATA (1 << 1)

/**
* @brief Structure defining the header of NVRAM
*
*/
typedef struct Nvram_header_s {
char tag[4]; ///< ['N','V','R','A'] array, when properly initialized
uint32_t size; ///< size in bytes of the data
uint32_t struct_version; ///< version of the structure of data (to be set once at first
uint32_t size; ///< size in bytes of the data (Nvram_data_t structure)
uint16_t struct_version; ///< version of the structure of data (to be set once at first
///< application start-up)
uint16_t properties; ///< used as a bitfield to set properties, like: contains settings,
///< contains sensitive data
uint32_t data_version; ///< version of the content of data (to be updated every time data are
///< updated)
} Nvram_header_t;
Expand Down Expand Up @@ -51,10 +58,12 @@ extern const Nvram_t N_nvram_real;
*/
#define N_nvram (*(volatile Nvram_t *) PIC(&N_nvram_real))

extern void nvram_init(void);
extern uint32_t nvram_get_size(void);
extern uint8_t nvram_get_struct_version(void);
extern uint8_t nvram_get_data_version(void);
extern bool nvram_is_initalized(void);
void nvram_init(uint32_t data_version);
uint32_t nvram_get_size(void);
uint16_t nvram_get_struct_version(void);
uint16_t nvram_get_properties(void);
uint32_t nvram_get_data_version(void);
bool nvram_is_initalized(void);
void nvram_set_data_version(uint32_t data_version);

#endif // HAVE_BOLOS
36 changes: 29 additions & 7 deletions lib_standard_app/nvram_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
const Nvram_t N_nvram_real;

/**
* @brief init header of NVRAM structure (set "NVRA" tag)
* @brief init header of NVRAM structure :
* - set "NVRA" tag
* - set size
* - set struct and data versions
* - set properties
* @param data_version Version of the data
*/
void nvram_init(void)
void nvram_init(uint32_t data_version)
{
Nvram_header_t header;

memcpy(header.tag, (void *) "NVRA", 4);
// NVRAM_STRUCT_VERSION and NVRAM_DATA_VERSION must be defined in nvram_data.h
// NVRAM_STRUCT_VERSION and NVRAM_DATA_PROPERTIES must be defined in nvram_data.h
header.struct_version = NVRAM_STRUCT_VERSION;
header.data_version = NVRAM_DATA_VERSION;
header.data_version = data_version;
header.properties = NVRAM_DATA_PROPERTIES;
header.size = sizeof(Nvram_data_t);
nvm_write((void *) &N_nvram.header, (void *) &header, sizeof(Nvram_header_t));
}
Expand All @@ -38,15 +44,23 @@ uint32_t nvram_get_size(void)
/**
* @brief get the version of app data structure
*/
uint8_t nvram_get_struct_version(void)
uint16_t nvram_get_struct_version(void)
{
return N_nvram.header.struct_version;
}

/**
* @brief get the version of app data data
* @brief get the version of app data
*/
uint8_t nvram_get_data_version(void)
uint32_t nvram_get_data_version(void)
{
return N_nvram.header.data_version;
}

/**
* @brief get the properties of app data
*/
uint16_t nvram_get_properties(void)
{
return N_nvram.header.data_version;
}
Expand All @@ -65,4 +79,12 @@ bool nvram_is_initalized(void)
return true;
}

/**
* @brief set data version of app data
*/
void nvram_set_data_version(uint32_t data_version)
{
nvm_write((void *) &N_nvram.header.data_version, (void *) &data_version, sizeof(uint32_t));
}

#endif // HAVE_APP_NVRAM

0 comments on commit 2daf4e0

Please sign in to comment.