Skip to content

Commit

Permalink
sys/configuration: drop configuration_backend_flashdb_vfs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Jan 8, 2025
1 parent d255c36 commit e76147e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 64 deletions.
5 changes: 1 addition & 4 deletions sys/configuration/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ ifneq (,$(filter configuration_backend_flashdb%,$(USEMODULE)))
USEMODULE += configuration_strings
USEMODULE += configuration_backend_flashdb
USEMODULE += flashdb_kvdb
ifneq (,$(filter configuration_backend_flashdb_vfs,$(USEMODULE)))
USEMODULE += flashdb_vfs
USEMODULE += vfs_default
else ifneq (,$(filter configuration_backend_flashdb_mtd,$(USEMODULE)))
ifneq (,$(filter configuration_backend_flashdb_mtd,$(USEMODULE)))
USEMODULE += flashdb_mtd
endif
endif
Expand Down
40 changes: 2 additions & 38 deletions sys/configuration/backend/flashdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

#include <assert.h>
#include <errno.h>
#include <stdint.h>

#include "configuration.h"
#include "configuration_backend_flashdb.h"
#include "macros/math.h"
#include "macros/units.h"
#include "mutex.h"
#include "mtd_default.h"
#include "vfs_default.h"
#include "fal_cfg.h"

static mutex_t _kvdb_locker = MUTEX_INIT;
Expand All @@ -45,18 +45,6 @@ const char *configuration_backend_flashdb_mtd_choose_partition(void)
return FAL_PART0_LABEL;
}

__attribute__((weak))
mtd_dev_t *configuration_backend_flashdb_vfs_choose_dev(void)
{
return mtd_default_get_dev(0);
}

__attribute__((weak))
const char *configuration_backend_flashdb_vfs_choose_path(void)
{
return VFS_DEFAULT_DATA"/"CONFIGURATION_FLASHDB_VFS_FOLDER;
}

static void _lock(fdb_db_t db)
{
mutex_lock(db->user_data);
Expand All @@ -70,36 +58,16 @@ static void _unlock(fdb_db_t db)
static int _be_fdb_init(mtd_dev_t *mtd)
{
assert(mtd);
uint32_t size;
#if IS_USED(MODULE_CONFIGURATION_BACKEND_FLASHDB_VFS)
bool file_mode = true;
fdb_kvdb_control(&_kvdb, FDB_KVDB_CTRL_SET_FILE_MODE, &file_mode);
int fail;
if ((fail = vfs_mkdir(configuration_backend_flashdb_vfs_choose_path(), 0777)) < 0) {
if (fail != -EEXIST) {
/* probably not mounted (try with vfs_auto_format) */
return fail;
}
}
#endif
/* The MTD must be initialized! */
size = mtd->pages_per_sector * mtd->page_size;
uint32_t size = mtd->pages_per_sector * mtd->page_size;
size = DIV_ROUND_UP((CONFIGURATION_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB * KiB(1)), size) * size;
/* sector size must be set before max size */
fdb_kvdb_control(&_kvdb, FDB_KVDB_CTRL_SET_SEC_SIZE, &size);
#if IS_USED(MODULE_CONFIGURATION_BACKEND_FLASHDB_VFS)
size *= CONFIGURATION_FLASHDB_VFS_MAX_SECTORS;
fdb_kvdb_control(&_kvdb, FDB_KVDB_CTRL_SET_MAX_SIZE, &size);
#endif
fdb_kvdb_control(&_kvdb, FDB_KVDB_CTRL_SET_LOCK, (void *)(uintptr_t)_lock);
fdb_kvdb_control(&_kvdb, FDB_KVDB_CTRL_SET_UNLOCK, (void *)(uintptr_t)_unlock);
if (fdb_kvdb_init(&_kvdb,
"kvdb_configuration",
#if IS_USED(MODULE_CONFIGURATION_BACKEND_FLASHDB_VFS)
configuration_backend_flashdb_vfs_choose_path(),
#elif IS_USED(MODULE_CONFIGURATION_BACKEND_FLASHDB_MTD)
configuration_backend_flashdb_mtd_choose_partition(),
#endif
NULL,
&_kvdb_locker) != FDB_NO_ERR) {
return -EINVAL;
Expand Down Expand Up @@ -195,13 +163,9 @@ int configuration_backend_flashdb_init(mtd_dev_t *mtd)

void auto_init_configuration_backend_flashdb(void)
{
#if IS_USED(MODULE_CONFIGURATION_BACKEND_FLASHDB_MTD)
extern void fdb_mtd_init(mtd_dev_t *mtd);
fdb_mtd_init(configuration_backend_flashdb_mtd_choose_dev());
int fail = configuration_backend_flashdb_init(configuration_backend_flashdb_mtd_choose_dev());
#else
int fail = configuration_backend_flashdb_init(configuration_backend_flashdb_vfs_choose_dev());
#endif
assert(!fail); (void)fail;
#if (IS_USED(MODULE_CONFIGURATION_BACKEND_RESET_FLASHDB))
fail = configuration_backend_flashdb_reset();
Expand Down
22 changes: 0 additions & 22 deletions sys/configuration/include/configuration_backend_flashdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "board.h"
#include "modules.h"
#include "mtd.h"
#include "vfs_default.h"
#include "configuration.h"
#if IS_USED(MODULE_FLASHDB_KVDB)
#include "fal_cfg.h"
Expand Down Expand Up @@ -76,27 +75,6 @@ mtd_dev_t *configuration_backend_flashdb_mtd_choose_dev(void);
*/
const char *configuration_backend_flashdb_mtd_choose_partition(void);

/**
* @brief __attribute__((weak)) function to select the MTD for FlashDB
* when the module configuration_backend_flashdb_vfs is used
*
* The default implementation is to return @ref MTD_0.
*
* @return MTD device to use in the VFS mode of FlashDB
*/
mtd_dev_t *configuration_backend_flashdb_vfs_choose_dev(void);

/**
* @brief __attribute__((weak)) function to select the path for FlashDB
* when the module configuration_backend_flashdb_vfs is used
*
* The default implementation is to return VFS_DEFAULT_DATA"/"CONFIGURATION_FLASHDB_VFS_FOLDER.
* @ref CONFIGURATION_FLASHDB_VFS_FOLDER
*
* @return Path to use in the VFS mode of FlashDB
*/
const char *configuration_backend_flashdb_vfs_choose_path(void);

/**
* @brief Reset the FlashDB backend, which deletes all configuration data
*
Expand Down

0 comments on commit e76147e

Please sign in to comment.