Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/riotconf: add root configuration backend #20501

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
4 changes: 4 additions & 0 deletions drivers/include/mtd_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extern "C" {
#include "mtd_emulated.h"
#endif

#if defined(MODULE_MTD_FLASHPAGE)
#include "mtd_flashpage.h"
#endif

#if defined(MODULE_MTD_SDCARD_DEFAULT)
extern mtd_sdcard_t mtd_sdcard_dev0;
#endif
Expand Down
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ PSEUDOMODULES += test_utils_main_exit_cb
# All auto_init modules are pseudomodules
PSEUDOMODULES += auto_init_%
NO_PSEUDOMODULES += auto_init_can
NO_PSEUDOMODULES += auto_init_configuration
NO_PSEUDOMODULES += auto_init_loramac
NO_PSEUDOMODULES += auto_init_multimedia
NO_PSEUDOMODULES += auto_init_security
Expand Down
4 changes: 4 additions & 0 deletions sys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ menu "System"

rsource "auto_init/Kconfig"
rsource "chunked_ringbuffer/Kconfig"
rsource "clif/Kconfig"
rsource "color/Kconfig"
rsource "configuration/Kconfig"
rsource "crypto/Kconfig"
rsource "congure/Kconfig"
rsource "debug_irq_disable/Kconfig"
rsource "entropy_source/Kconfig"
Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ endif
ifneq (,$(filter telnet,$(USEMODULE)))
DIRS += net/application_layer/telnet
endif
ifneq (,$(filter configuration,$(USEMODULE)))
DIRS += configuration
endif
ifneq (,$(filter constfs,$(USEMODULE)))
DIRS += fs/constfs
endif
Expand Down
4 changes: 4 additions & 0 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,8 @@ ifneq (,$(filter wifi_scan_list,$(USEMODULE)))
USEMODULE += l2scan_list
endif

ifneq (,$(filter configuration configuration_%,$(USEMODULE)))
include $(RIOTBASE)/sys/configuration/Makefile.dep
endif

include $(RIOTBASE)/sys/test_utils/Makefile.dep
8 changes: 8 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ ifneq (,$(filter riotboot,$(FEATURES_USED)))
include $(RIOTBASE)/sys/riotboot/Makefile.include
endif

ifneq (,$(filter riotconf,$(USEMODULE)))
include $(RIOTBASE)/sys/riotconf/Makefile.include
endif

ifneq (,$(filter skald, $(USEMODULE)))
include $(RIOTBASE)/sys/net/ble/skald/Makefile.include
endif
Expand Down Expand Up @@ -199,3 +203,7 @@ endif
ifneq (,$(filter nanocoap,$(USEMODULE)))
include $(RIOTBASE)/sys/net/application_layer/nanocoap/Makefile.include
endif

ifneq (,$(filter configuration configuration_%,$(USEMODULE)))
include $(RIOTBASE)/sys/configuration/Makefile.include
endif
4 changes: 4 additions & 0 deletions sys/auto_init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ifneq (,$(filter auto_init_can,$(USEMODULE)))
DIRS += can
endif

ifneq (,$(filter auto_init_configuration,$(USEMODULE)))
DIRS += configuration
endif

ifneq (,$(filter auto_init_loramac,$(USEMODULE)))
DIRS += loramac
endif
Expand Down
18 changes: 6 additions & 12 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,8 @@
#include "auto_init_priorities.h"
#include "kernel_defines.h"

#define ENABLE_DEBUG CONFIG_AUTO_INIT_ENABLE_DEBUG
#include "debug.h"

XFA_INIT_CONST(auto_init_module_t, auto_init_xfa);

static inline void _auto_init_module(const volatile auto_init_module_t *module)
{
#if IS_ACTIVE(CONFIG_AUTO_INIT_ENABLE_DEBUG)
DEBUG("auto_init: %s (%u)\n", module->name, module->prio);
#endif
module->init();
}

#if IS_USED(MODULE_AUTO_INIT_ZTIMER)
extern void ztimer_init(void);
AUTO_INIT(ztimer_init,
Expand Down Expand Up @@ -174,6 +163,11 @@ extern void auto_init_vfs(void);
AUTO_INIT(auto_init_vfs,
AUTO_INIT_PRIO_MOD_VFS);
#endif
#if IS_USED(MODULE_CONFIGURATION)
extern void auto_init_configuration(void);
AUTO_INIT(auto_init_configuration,
AUTO_INIT_PRIO_MOD_CONFIGURATION);
#endif
#if IS_USED(MODULE_AUTO_INIT_GNRC_IPV6_NIB)
extern void gnrc_ipv6_nib_init(void);
AUTO_INIT(gnrc_ipv6_nib_init,
Expand Down Expand Up @@ -348,6 +342,6 @@ AUTO_INIT(auto_init_gnrc_ipv6_static_addr,
void auto_init(void)
{
for (unsigned i = 0; i < XFA_LEN(auto_init_module_t, auto_init_xfa); i++) {
_auto_init_module(&auto_init_xfa[i]);
auto_init_module(&auto_init_xfa[i]);
}
}
3 changes: 3 additions & 0 deletions sys/auto_init/configuration/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = auto_init_configuration

include $(RIOTBASE)/Makefile.base
61 changes: 61 additions & 0 deletions sys/auto_init/configuration/auto_init_configuration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2023 ML!PA Consulting GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
*/

/**
* @ingroup sys_auto_init_configuration
* @{
*
* @file
* @brief Auto initialization for configuration subsystems
*
* @author Fabian Hüßler <[email protected]>
*
* @}
*/

#ifdef MODULE_CONFIGURATION

#include "auto_init_utils.h"
#include "configuration.h"
#if IS_USED(MODULE_RIOTCONF)
#include "configuration_backend_riotconf.h"
#endif

XFA_INIT_CONST(auto_init_module_t, auto_init_configuration_xfa);

#ifndef CONFIG_CONFIGURATION_ROOT_BACKEND_OPS
#if IS_USED(MODULE_RIOTCONF)
#define CONFIG_CONFIGURATION_ROOT_BACKEND_OPS &conf_backend_riotconf_ops
#else
#define CONFIG_CONFIGURATION_ROOT_BACKEND_OPS NULL
#endif
#endif

static const CONF_BACKEND(_root_backend,
CONFIG_CONFIGURATION_ROOT_BACKEND_OPS,
CONF_FMT_CBOR);

__attribute__((weak))
void auto_init_configuration_root_backend_init(void)
{
*configuration_get_src_backend(configuration_get_root()) = &_root_backend;
*configuration_get_dst_backend(configuration_get_root()) = &_root_backend;
}

void auto_init_configuration(void)
{
for (unsigned i = 0; i < XFA_LEN(auto_init_module_t, auto_init_configuration_xfa); i++) {
auto_init_module(&auto_init_configuration_xfa[i]);
}
auto_init_configuration_root_backend_init();
}

#else
typedef int dont_be_pedantic;
#endif /* MODULE_CONFIGURATION */
6 changes: 6 additions & 0 deletions sys/auto_init/include/auto_init_priorities.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ extern "C" {
*/
#define AUTO_INIT_PRIO_MOD_VFS 1260
#endif
#ifndef AUTO_INIT_PRIO_MOD_CONFIGURATION
/**
* @brief Configuration priority
*/
#define AUTO_INIT_PRIO_MOD_CONFIGURATION 1265
#endif
#ifndef AUTO_INIT_PRIO_MOD_GNRC_IPV6_NIB
/**
* @brief GNRC IPv6 NIB priority
Expand Down
18 changes: 18 additions & 0 deletions sys/configuration/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2023 ML!PA Consulting GmbH
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_CONFIGURATION
bool "Runtime Configuration Module"
help
Backend agnostic runtime configuration module.

if MODULE_CONFIGURATION

config CONFIGURATION_DEPTH_MAX
int "Maximum number of nested configuration items"

endif # MODULE_CONFIGURATION
11 changes: 11 additions & 0 deletions sys/configuration/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MODULE := configuration

SUBMODULES := 1

SRC := configuration.c default_handlers.c

ifneq (,$(filter configuration_backend_%,$(USEMODULE)))
DIRS += backend
endif

include $(RIOTBASE)/Makefile.base
42 changes: 42 additions & 0 deletions sys/configuration/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DEFAULT_MODULE += auto_init_configuration

USEMODULE += fmt

ifneq (,$(filter configuration_backend_%,$(USEMODULE)))
USEMODULE += configuration_backend
endif

ifneq (,$(filter configuration_backend_riotconf,$(USEMODULE)))
USEMODULE += riotconf
endif

ifneq (,$(filter configuration_backend_flashdb%,$(USEMODULE)))
# this backend needs strings
USEMODULE += configuration_strings
USEMODULE += configuration_backend_flashdb
USEMODULE += flashdb_kvdb
ifneq (,$(filter configuration_backend_flashdb_mtd,$(USEMODULE)))
USEMODULE += flashdb_mtd
endif
endif

ifneq (,$(filter configuration_strings,$(USEMODULE)))
USEMODULE += configuration_handler_parent
endif

ifneq (,$(filter configuration_delta_encoding,$(USEMODULE)))
USEMODULE += configuration_handler_parent
endif

ifneq (,$(filter configuration_delta_decoding,$(USEMODULE)))
USEMODULE += configuration_handler_parent
endif

ifneq (,$(filter configuration_delta_encoding_decoding,$(USEMODULE)))
USEMODULE += configuration_delta_encoding
USEMODULE += configuration_delta_decoding
endif

ifneq (,$(filter configuration_key_subkey,$(USEMODULE)))
USEMODULE += configuration_handler_parent
endif
29 changes: 29 additions & 0 deletions sys/configuration/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
USEMODULE_INCLUDES_configuration := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_configuration)

# any backend pseudo module
PSEUDOMODULES += configuration_backend_%

# Store a parent reference in the configuration handler
PSEUDOMODULES += configuration_handler_parent

# use if you want to use custom handlers for import, export, delete, encode, decode
PSEUDOMODULES += configuration_custom_operations

# use if source backend is unequal to destination backend
PSEUDOMODULES += configuration_destination_backend

# use if you want to construct a string path for a configuration item
PSEUDOMODULES += configuration_strings

# encode SIDs relative to their parent SID (delta encoding)
PSEUDOMODULES += configuration_delta_encoding

# decode SIDs relative to their parent SID (delta decoding)
PSEUDOMODULES += configuration_delta_decoding

# alias for configuration_delta_encoding and configuration_delta_decoding
PSEUDOMODULES += configuration_delta_encoding_decoding

# be able to export sub items which don't have a backend configured
PSEUDOMODULES += configuration_key_subkey
5 changes: 5 additions & 0 deletions sys/configuration/backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE := configuration_backend
SUBMODULES := 1
BASE_MODULE := configuration_backend

include $(RIOTBASE)/Makefile.base
Loading
Loading