diff --git a/include/linker/common-rom.ld b/include/linker/common-rom.ld index 6b700941d08..ee474f3bc02 100644 --- a/include/linker/common-rom.ld +++ b/include/linker/common-rom.ld @@ -109,15 +109,6 @@ } GROUP_LINK_IN(ROMABLE_REGION) #endif -#if defined(CONFIG_BT_SETTINGS) - SECTION_DATA_PROLOGUE(_bt_settings_area,,SUBALIGN(4)) - { - _bt_settings_start = .; - KEEP(*(SORT_BY_NAME("._bt_settings_handler.static.*"))) - _bt_settings_end = .; - } GROUP_LINK_IN(ROMABLE_REGION) -#endif - SECTION_DATA_PROLOGUE(log_const_sections,,) { __log_const_start = .; diff --git a/include/settings/settings.h b/include/settings/settings.h index 30110218eb8..5917a357438 100644 --- a/include/settings/settings.h +++ b/include/settings/settings.h @@ -150,17 +150,29 @@ struct settings_handler_static { }; /** - * Register a static handler for settings items + * Define a static handler for settings items * - * @param _handler Structure containing registration info, this must be const - * The handler name in ROM needs to be unique, it is generated from - * _handler and the linenumber of SETTINGS_REGISTER_STATIC() + * @param _hname handler name + * @param _tree subtree name + * @param _get get routine (can be NULL) + * @param _set set routine (can be NULL) + * @param _commit commit routine (can be NULL) + * @param _export export routine (can be NULL) + * + * This createa a variable _hname prepended by settings_handler_. * */ -#define SETTINGS_STATIC_HANDLER_DEFINE(_handler) \ - const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \ - _CONCAT(_handler, __LINE__))\ - = _handler + +#define SETTINGS_STATIC_HANDLER_DEFINE(_hname, _tree, _get, _set, _commit, \ + _export) \ + const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \ + settings_handler_ ## _hname) = { \ + .name = _tree, \ + .h_get = _get, \ + .h_set = _set, \ + .h_commit = _commit, \ + .h_export = _export, \ + } /** * Initialization of settings and backend diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 285ab1f0a80..49528eadfb1 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -3629,7 +3629,7 @@ static int ccc_set(const char *name, size_t len_rd, settings_read_cb read_cb, return 0; } -BT_SETTINGS_DEFINE(ccc, ccc_set, NULL, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_ccc, "bt/ccc", NULL, ccc_set, NULL, NULL); #if defined(CONFIG_BT_GATT_CACHING) static int cf_set(const char *name, size_t len_rd, settings_read_cb read_cb, @@ -3676,7 +3676,7 @@ static int cf_set(const char *name, size_t len_rd, settings_read_cb read_cb, return 0; } -BT_SETTINGS_DEFINE(cf, cf_set, NULL, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_cf, "bt/cf", NULL, cf_set, NULL, NULL); static u8_t stored_hash[16]; @@ -3719,6 +3719,7 @@ static int db_hash_commit(void) return 0; } -BT_SETTINGS_DEFINE(hash, db_hash_set, db_hash_commit, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_hash, "bt/hash", NULL, db_hash_set, + db_hash_commit, NULL); #endif /*CONFIG_BT_GATT_CACHING */ #endif /* CONFIG_BT_SETTINGS */ diff --git a/subsys/bluetooth/host/keys.c b/subsys/bluetooth/host/keys.c index b37a1d445ea..7719693ae37 100644 --- a/subsys/bluetooth/host/keys.c +++ b/subsys/bluetooth/host/keys.c @@ -365,5 +365,7 @@ static int keys_commit(void) return 0; } -BT_SETTINGS_DEFINE(keys, keys_set, keys_commit, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_keys, "bt/keys", NULL, keys_set, keys_commit, + NULL); + #endif /* CONFIG_BT_SETTINGS */ diff --git a/subsys/bluetooth/host/mesh/settings.c b/subsys/bluetooth/host/mesh/settings.c index e7c6f3bed7f..d2b69cb5a09 100644 --- a/subsys/bluetooth/host/mesh/settings.c +++ b/subsys/bluetooth/host/mesh/settings.c @@ -24,7 +24,6 @@ #define LOG_MODULE_NAME bt_mesh_settings #include "common/log.h" -#include "../settings.h" #include "mesh.h" #include "net.h" #include "crypto.h" @@ -824,7 +823,8 @@ static int mesh_commit(void) return 0; } -BT_SETTINGS_DEFINE(mesh, mesh_set, mesh_commit, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh, "bt/mesh", NULL, mesh_set, mesh_commit, + NULL); /* Pending flags that use K_NO_WAIT as the storage timeout */ #define NO_WAIT_PENDING_BITS (BIT(BT_MESH_NET_PENDING) | \ diff --git a/subsys/bluetooth/host/settings.c b/subsys/bluetooth/host/settings.c index e2a0483a992..abf3d7d81b4 100644 --- a/subsys/bluetooth/host/settings.c +++ b/subsys/bluetooth/host/settings.c @@ -19,10 +19,6 @@ #include "hci_core.h" #include "settings.h" -/* Linker-defined symbols bound to the bt_settings_handler structs */ -extern const struct bt_settings_handler _bt_settings_start[]; -extern const struct bt_settings_handler _bt_settings_end[]; - void bt_settings_encode_key(char *path, size_t path_size, const char *subsys, bt_addr_le_t *addr, const char *key) { @@ -90,7 +86,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb, void *cb_arg) { ssize_t len; - const struct bt_settings_handler *h; const char *next; if (!name) { @@ -100,12 +95,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb, len = settings_name_next(name, &next); - for (h = _bt_settings_start; h < _bt_settings_end; h++) { - if (!strncmp(name, h->name, len)) { - return h->set(next, len_rd, read_cb, cb_arg); - } - } - if (!strncmp(name, "id", len)) { /* Any previously provided identities supersede flash */ if (atomic_test_bit(bt_dev.flags, BT_DEV_PRESET_ID)) { @@ -211,8 +200,6 @@ void bt_settings_save_id(void) static int commit(void) { - const struct bt_settings_handler *h; - BT_DBG(""); #if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC) @@ -234,36 +221,10 @@ static int commit(void) bt_finalize_init(); } - for (h = _bt_settings_start; h < _bt_settings_end; h++) { - if (h->commit) { - h->commit(); - } - } - return 0; } -static int export(int (*export_func)(const char *name, const void *val, - size_t val_len)) - -{ - const struct bt_settings_handler *h; - - for (h = _bt_settings_start; h < _bt_settings_end; h++) { - if (h->export) { - h->export(export_func); - } - } - - return 0; -} - -static struct settings_handler bt_settings = { - .name = "bt", - .h_set = set, - .h_commit = commit, - .h_export = export, -}; +SETTINGS_STATIC_HANDLER_DEFINE(bt, "bt", NULL, set, commit, NULL); int bt_settings_init(void) { @@ -277,11 +238,5 @@ int bt_settings_init(void) return err; } - err = settings_register(&bt_settings); - if (err) { - BT_ERR("settings_register failed (err %d)", err); - return err; - } - return 0; } diff --git a/subsys/bluetooth/host/settings.h b/subsys/bluetooth/host/settings.h index 069346d9eae..c918ad426c4 100644 --- a/subsys/bluetooth/host/settings.h +++ b/subsys/bluetooth/host/settings.h @@ -4,23 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -struct bt_settings_handler { - const char *name; - int (*set)(const char *name, size_t len, settings_read_cb read_cb, - void *cb_arg); - int (*commit)(void); - int (*export)(int (*func)(const char *name, - const void *val, size_t val_len)); -}; - -#define BT_SETTINGS_DEFINE(_name, _set, _commit, _export) \ - const Z_STRUCT_SECTION_ITERABLE(bt_settings_handler, _name) = { \ - .name = STRINGIFY(_name), \ - .set = _set, \ - .commit = _commit, \ - .export = _export, \ - } - /* Max settings key length (with all components) */ #define BT_SETTINGS_KEY_MAX 36 diff --git a/subsys/bluetooth/services/dis.c b/subsys/bluetooth/services/dis.c index 65df95070ba..36026ee649b 100644 --- a/subsys/bluetooth/services/dis.c +++ b/subsys/bluetooth/services/dis.c @@ -25,8 +25,6 @@ #include #include -#include "../host/settings.h" - #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SERVICE) #define LOG_MODULE_NAME bt_dis #include "common/log.h" @@ -235,5 +233,6 @@ static int dis_set(const char *name, size_t len_rd, return 0; } -BT_SETTINGS_DEFINE(dis, dis_set, NULL, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(bt_dis, "bt/dis", NULL, dis_set, NULL, NULL); + #endif /* CONFIG_BT_GATT_DIS_SETTINGS && CONFIG_BT_SETTINGS*/