With SDK for Mesh v5.0.0 the STRATEGY_ON_POWER_DOWN doesn't work correctly over multiple power downs.
If an entry is set and the stack is powered down, the entry is written to flash correctly. During next boot it will read the entry from flash and call the setter callback correctly.
After doing this the Mesh Config system will call mesh_config_file_clear() if there isn't enough room to store all possible entries. By doing so the delete callback will be called for each entry and the ACTIVE flag will be remove. Thus in practice deleting the information during boot and if the entry is not set again before a power down the information will be lost.
The following patch fix this issue by setting the DIRTY flag on each ACTIVE entry before doing a backend file clean.
diff --git a/mesh/core/src/mesh_config.c b/mesh/core/src/mesh_config.c index 65d59e9..df0ca50 100644 --- a/mesh/core/src/mesh_config.c +++ b/mesh/core/src/mesh_config.c @@ -450,6 +450,7 @@ void mesh_config_load(void) mesh_config_file_clear(MESH_OPT_EMERGENCY_CACHE_FILE_ID); } +#if PERSISTENT_STORAGE FOR_EACH_FILE(p_file) { if (p_file->strategy == MESH_CONFIG_STRATEGY_ON_POWER_DOWN) @@ -457,10 +458,30 @@ void mesh_config_load(void) if (p_file->id != MESH_OPT_EMERGENCY_CACHE_FILE_ID && !mesh_config_backend_is_there_power_down_place(p_file->p_backend_data)) { - mesh_config_file_clear(p_file->id); + FOR_EACH_ENTRY(p_params) + { + if (p_params->p_id->file != p_file->id) + { + continue; + } + + for (uint32_t j = 0; j < p_params->max_count; ++j) + { + if (p_params->p_state[j] & MESH_CONFIG_ENTRY_FLAG_ACTIVE) + { + // As the backend will be cleaned all active entries + // also become dirty. + p_params->p_state[j] |= MESH_CONFIG_ENTRY_FLAG_DIRTY; + } + } + } + + m_file_in_progress_cnt++; + mesh_config_backend_file_clean(p_file->p_backend_data); } } } +#endif } void mesh_config_power_down(void)
This issue is hidden in how the replay cache is using the mesh config subsystem. The replay cache only use mesh_config_entry_set() function but never the get() part which is affected by this bug.
Thanks.