Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/include/*.h @nrfconnect/ncs-bm
/include/bm/ @nrfconnect/ncs-bm
/include/bm/bluetooth/ @nrfconnect/ncs-bm
/include/bm/settings/ @nrfconnect/ncs-eris

# Libraries
/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm
Expand Down Expand Up @@ -88,6 +89,7 @@
/subsys/logging/ @nrfconnect/ncs-bm
/subsys/mgmt/mcumgr/ @nrfconnect/ncs-eris
/subsys/nfc/ @nrfconnect/ncs-bm
/subsys/settings/ @nrfconnect/ncs-eris
/subsys/softdevice/ @nrfconnect/ncs-bm
/subsys/softdevice_handler/ @nrfconnect/ncs-bm
/subsys/storage/bm_storage/ @nrfconnect/ncs-bm
Expand Down
58 changes: 58 additions & 0 deletions applications/firmware_loader/ble_mcumgr/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <zephyr/sys/reboot.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/settings/settings.h>
#include <bm/settings/bluetooth_name.h>
#include <zephyr/retention/retention.h>

LOG_MODULE_REGISTER(app, CONFIG_APP_LOG_LEVEL);

Expand Down Expand Up @@ -214,6 +217,19 @@ int main(void)

LOG_INF("Bluetooth enabled");

#if CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME
/* Initialize setting subsystem with SRAM retention backend
* for fetching ADV device name provided by the application.
*/
err = settings_subsys_init();

if (err) {
LOG_ERR("Failed to enable settings, err %d", err);
}

settings_load();
#endif

nrf_err = ble_mcumgr_init(&mcumgr_cfg);

if (nrf_err) {
Expand All @@ -240,13 +256,55 @@ int main(void)
return 0;
}

#if CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME
const char *custom_advertising_name;
uint8_t custom_advertising_name_size;
ble_gap_conn_sec_mode_t sec_mode = {0};

custom_advertising_name = bluetooth_name_value_get();
custom_advertising_name_size = strlen(custom_advertising_name);

if (custom_advertising_name_size > 0) {
/* Change advertising name to one from application */
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err = sd_ble_gap_device_name_set(&sec_mode, custom_advertising_name,
custom_advertising_name_size);

if (err) {
LOG_ERR("Failed to change advertising name, err %d", err);
return 0;
}

err = ble_adv_data_encode(&ble_adv_cfg.adv_data, ble_adv.enc_adv_data[0],
&ble_adv.adv_data.adv_data.len);

if (err) {
LOG_ERR("Failed to update advertising data, err %d", err);
return 0;
}

/* Clear settings after device name has been set so it does not persist */
err = retention_clear(DEVICE_DT_GET(DT_CHOSEN(zephyr_settings_partition)));

if (err) {
LOG_ERR("Failed to clear retention area, err %d", err);
return 0;
}
}
#endif /* CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME */

nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST);
if (nrf_err) {
LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err);
return 0;
}

#if CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME
LOG_INF("Advertising as %s", (custom_advertising_name_size > 0 ? custom_advertising_name :
CONFIG_BLE_ADV_NAME));
#else
LOG_INF("Advertising as %s", CONFIG_BLE_ADV_NAME);
#endif /* CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME */

while (notification_sent == false && device_disconnected == false) {
while (LOG_PROCESS()) {
Expand Down
31 changes: 31 additions & 0 deletions doc/nrf-bm/app_dev/dfu/dfu_name.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. _ug_dfu_name:

Setting up DFU Device Bluetooth name remotely
#############################################

The Device Firmware Update (DFU) over Bluetooth® Low Energy in the single bank solution uses the loader application for firmware download support.
The firmware loader is separate application to which the remote Bluetooth LE DFU client connects to perform the firmware update.
To identify the firmware loader application over Bluetooth LE, it uses a specific advertising name provided by the remote client to the application.

You can configure the name at application runtime using the MCUmgr settings command group.

Write the name using the MCUmgr write setting request for ``fw_loader/adv_name`` key and export the key value to retention memory using the MCUmgr save settings request.
Once the device is rebooted into the firmware loader application, the name can be read back from the retention memory and used as the advertising name of the firmware loader.

Enabling the feature
********************

To enable this feature for a sysbuild project, use the :kconfig:option:`SB_CONFIG_BM_APP_CAN_SETUP_FIRMWARE_LOADER_NAME` Kconfig option.
Otherwise, enable the following Kconfig options in both the application and the firmware loader configuration:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Otherwise, enable the following Kconfig options in both the application and the firmware loader configuration:
Alternatively, enable the following Kconfig options in both the application and the firmware loader configuration:


* :kconfig:option:`CONFIG_RETAINED_MEM` - Enables the use of retained memory.
* :kconfig:option:`CONFIG_RETENTION` - Allows the retention of data across device reboots.
* :kconfig:option:`CONFIG_SETTINGS`- Enables the settings management subsystem.
* :kconfig:option:`CONFIG_SETTINGS_RETENTION`- Enables retention backend implementation of settings subsystem.
* :kconfig:option:`CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME`- Enables setting handlers required for Bluetooth name sharing support.

Additionally, the application must enable the MCUmgr settings group using the following Kconfig options:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Additionally, the application must enable the MCUmgr settings group using the following Kconfig options:
Additionally, the application must enable the MCUmgr settings group using the following Kconfig options:

* :kconfig:option:`CONFIG_MCUMGR_GRP_SETTINGS`- Enables the MCUmgr settings group.
* :kconfig:option:`CONFIG_SETTINGS_RUNTIME`- Allows runtime modification of settings.

This feature is used in the :ref:`ble_mcuboot_recovery_entry_sample`.
1 change: 1 addition & 0 deletions doc/nrf-bm/app_dev/dfu/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ This chapter provides an overview of the Device Firmware Update (DFU) capabiliti
single_bank_dfu
bootloader_keys
ug_dfu
dfu_name
14 changes: 14 additions & 0 deletions include/bm/settings/bluetooth_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <stdint.h>

/**
* @brief Retrieve the variable that holds the desired device advertising name.
*
* @retval Address of device name setting.
*/
const char *bluetooth_name_value_get(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit.) should probably have settings in the name also

2 changes: 2 additions & 0 deletions samples/boot/mcuboot_recovery_entry/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ CONFIG_NRF_SDH_BLE_GATT_MAX_MTU_SIZE=498
CONFIG_BLE_CONN_PARAMS_MAX_CONN_INTERVAL=24
CONFIG_BLE_CONN_PARAMS_SUP_TIMEOUT=20
CONFIG_BLE_CONN_PARAMS_MAX_SUP_TIMEOUT_DEVIATION=20

CONFIG_MCUMGR_GRP_SETTINGS=y
13 changes: 12 additions & 1 deletion samples/boot/mcuboot_recovery_entry/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>

#include <zephyr/settings/settings.h>

LOG_MODULE_REGISTER(app, CONFIG_APP_LOG_LEVEL);

Expand Down Expand Up @@ -187,6 +187,17 @@ int main(void)
return 0;
}

#if CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME
/* Initialize setting subsystem with SRAM retention backend
* for setup ADV device name to the firmware loader
*/
err = settings_subsys_init();

if (err) {
LOG_ERR("Failed to enable settings: %d", err);
}
#endif

LOG_INF("Bluetooth enabled");

nrf_err = ble_mcumgr_init(&mcumgr_cfg);
Expand Down
1 change: 1 addition & 0 deletions samples/boot/mcuboot_recovery_entry/sysbuild.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SB_CONFIG_BM_BOOTLOADER_MCUBOOT_FIRMWARE_LOADER_ENTRANCE_BOOT_MODE=y
SB_CONFIG_BM_APP_CAN_SETUP_FIRMWARE_LOADER_NAME=y
2 changes: 2 additions & 0 deletions scripts/ci/license_allow_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Apache-2.0: |
^nrf-bm/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig
^nrf-bm/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt
^nrf-bm/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig
^nrf-bm/subsys/mgmt/mcumgr/grp/settings_mgmt/CMakeLists.txt
^nrf-bm/subsys/mgmt/mcumgr/grp/settings_mgmt/Kconfig
^nrf-bm/subsys/mgmt/mcumgr/mgmt/CMakeLists.txt
^nrf-bm/subsys/mgmt/mcumgr/mgmt/Kconfig
^nrf-bm/subsys/mgmt/mcumgr/smp/CMakeLists.txt
Expand Down
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ add_subdirectory(nfc)
add_subdirectory(storage)
add_subdirectory_ifdef(CONFIG_NCS_BM_MCUMGR mgmt/mcumgr)
add_subdirectory_ifdef(CONFIG_NRF_SDH softdevice_handler)
add_subdirectory_ifdef(CONFIG_SETTINGS settings)
add_subdirectory_ifdef(CONFIG_SOFTDEVICE softdevice)
# zephyr-keep-sorted-stop
1 change: 1 addition & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rsource "fs/Kconfig"
rsource "logging/Kconfig"
rsource "mgmt/mcumgr/Kconfig"
rsource "nfc/Kconfig"
rsource "settings/Kconfig"
rsource "softdevice/Kconfig"
rsource "softdevice_handler/Kconfig"
rsource "storage/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions subsys/mgmt/mcumgr/grp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

add_subdirectory_ifdef(CONFIG_MCUMGR_GRP_IMG img_mgmt)
add_subdirectory_ifdef(CONFIG_MCUMGR_GRP_OS os_mgmt)
add_subdirectory_ifdef(CONFIG_MCUMGR_GRP_SETTINGS settings_mgmt)
2 changes: 2 additions & 0 deletions subsys/mgmt/mcumgr/grp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
rsource "img_mgmt/Kconfig"

rsource "os_mgmt/Kconfig"

rsource "settings_mgmt/Kconfig"
18 changes: 18 additions & 0 deletions subsys/mgmt/mcumgr/grp/settings_mgmt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2023 Nordic Semiconductor ASA
# Copyright (c) 2025 Nordic Semiconductor ASA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was copied from zephtr-rtos. What time stamp should be there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was copied from zephtr-rtos. What time stamp should be there.

Up to you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be changed

#
# SPDX-License-Identifier: Apache-2.0
#

# Settings management group public API is exposed by MCUmgr API
# interface, when settings management is enabled.
zephyr_library()
zephyr_library_sources(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/grp/settings_mgmt/src/settings_mgmt.c)

if(CONFIG_MCUMGR_GRP_SETTINGS AND NOT CONFIG_MCUMGR_GRP_SETTINGS_ACCESS_HOOK)
message(WARNING "Note: MCUmgr settings management is enabled but settings access hooks are "
"disabled, this is an insecure configuration and not recommended for production "
"use, as all settings on the device can be manipulated by a remote device. See "
"https://docs.zephyrproject.org/latest/services/device_mgmt/mcumgr_callbacks.html "
"for details on enabling and using MCUmgr hooks.")
endif()
68 changes: 68 additions & 0 deletions subsys/mgmt/mcumgr/grp/settings_mgmt/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright Nordic Semiconductor ASA 2023. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

menuconfig MCUMGR_GRP_SETTINGS
bool "MCUmgr handlers for settings management"
depends on SETTINGS
depends on SETTINGS_RUNTIME
select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2
select MCUMGR_SMP_CBOR_MIN_ENCODING_LEVEL_2 if ZCBOR_CANONICAL
select MCUMGR_SMP_CBOR_MIN_ENCODING_LEVEL_1
help
Enables MCUmgr handlers for settings manipulation.

if MCUMGR_GRP_SETTINGS

choice MCUMGR_GRP_SETTINGS_BUFFER_TYPE
prompt "Buffer type"
default MCUMGR_GRP_SETTINGS_BUFFER_TYPE_STACK
help
Selects if the stack or heap will be used for variables that are
needed when processing requests.

config MCUMGR_GRP_SETTINGS_BUFFER_TYPE_STACK
bool "Stack (fixed size)"
help
Use a fixed size stack buffer, any user-supplied values longer than
this will be rejected.

Note that stack usage for parameter storage alone will be
MCUMGR_GRP_SETTINGS_NAME_LEN + MCUMGR_GRP_SETTINGS_VALUE_LEN,
therefore the MCUmgr stack should be appropriately sized.

config MCUMGR_GRP_SETTINGS_BUFFER_TYPE_HEAP
bool "Heap (dynamic size)"
depends on COMMON_LIBC_MALLOC_ARENA_SIZE > 0
help
Use dynamic heap memory allocation through malloc, if there is
insufficient heap memory for the allocation then the request will be
rejected.

endchoice

config MCUMGR_GRP_SETTINGS_NAME_LEN
int "Maximum setting name length"
default 32
help
Maximum length of a key to lookup, this will be the size of the
variable if placed on the stack or the maximum allocated size of the
variable if placed on the heap.

config MCUMGR_GRP_SETTINGS_VALUE_LEN
int "Maximum setting value length"
default 32
help
Maximum length of a value to read, this will be the size of the
variable if placed on the stack or the allocated size of the
variable if placed on the heap (settings does not support getting
the size of a value prior to looking it up).

config MCUMGR_GRP_SETTINGS_ACCESS_HOOK
bool "Settings access hook"
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
help
Allows applications to control settings management access by
registering for a callback which is then triggered whenever a
settings read or write attempt is made.

endif
7 changes: 7 additions & 0 deletions subsys/settings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

zephyr_sources_ifdef(CONFIG_NCS_BM_SETTINGS_BLUETOOTH_NAME src/bluetooth_name.c)
17 changes: 17 additions & 0 deletions subsys/settings/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2025 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Settings"
depends on SETTINGS

config NCS_BM_SETTINGS_BLUETOOTH_NAME
bool "Bluetooth name [EXPERIMENTAL]"
select EXPERIMENTAL
help
If enabled, settings handlers for support BLE advertising name
sharing under `fw_loader/adv_name` key are included into the build.

endmenu
Loading