Skip to content

Commit 25c3197

Browse files
committed
mcumgr/grp/os_mgmt: hook for disabling BT on nrf54Lx
Added hook implementation for disabling Bluetooth in the hook of MCUmgr OS reboot command. Disabling of bluetooth allow to restart it properly after the warm boot. Ref: NCSDK-36564 Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 5a56574 commit 25c3197

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# Copyright (c) 2024-2025 Nordic Semiconductor ASA
33
#
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
@@ -8,3 +8,8 @@ if(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT)
88
zephyr_library_amend()
99
zephyr_library_sources(src/os_mgmt_b0_active_slot.c)
1010
endif()
11+
12+
if(CONFIG_MCUMGR_GRP_OS_REBOOT_BT)
13+
zephyr_library_amend()
14+
zephyr_library_sources(src/os_mgmt_reboot_bt.c)
15+
endif()

subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# Copyright (c) 2024-2025 Nordic Semiconductor ASA
33
#
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
@@ -19,4 +19,13 @@ config MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT
1919
Enables a bootloader info command for `active_b0_slot` which will return the active b0
2020
image slot number, and can be used to determine which update image should be loaded.
2121

22+
config MCUMGR_GRP_OS_REBOOT_BT
23+
bool
24+
default y
25+
depends on MCUMGR_GRP_OS
26+
depends on (BT || MPSL)
27+
depends on SOC_SERIES_NRF54LX
28+
select MCUMGR_MGMT_NOTIFICATION_HOOKS
29+
select MCUMGR_GRP_OS_RESET_HOOK
30+
2231
endmenu
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zcbor_common.h>
8+
#include <zcbor_encode.h>
9+
#include <pm_config.h>
10+
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
11+
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
12+
#include <zephyr/logging/log.h>
13+
14+
#ifdef CONFIG_BT
15+
#include <zephyr/bluetooth/bluetooth.h>
16+
#endif
17+
#ifdef CONFIG_MPSL
18+
#include <mpsl.h>
19+
#endif
20+
21+
LOG_MODULE_REGISTER(os_mgmt_reboot_bt, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL);
22+
23+
static enum mgmt_cb_return reboot_bt_hook(uint32_t event, enum mgmt_cb_return prev_status,
24+
int32_t *rc, uint16_t *group, bool *abort_more,
25+
void *data, size_t data_size)
26+
{
27+
int err_rc;
28+
struct os_mgmt_reset_data *reboot_data = (struct os_mgmt_reset_data *)data;
29+
30+
if (event != MGMT_EVT_OP_OS_MGMT_RESET || data_size != sizeof(*reboot_data)) {
31+
*rc = MGMT_ERR_EUNKNOWN;
32+
return MGMT_CB_ERROR_RC;
33+
}
34+
35+
#ifdef CONFIG_BT
36+
err_rc = bt_disable();
37+
if (err_rc) {
38+
LOG_ERR("BT disable failed before reboot: %d", err_rc);
39+
}
40+
#endif
41+
#ifdef CONFIG_MPSL
42+
mpsl_uninit();
43+
#endif
44+
45+
return MGMT_CB_OK;
46+
}
47+
48+
static struct mgmt_callback cmd_reboot_bt_info_cb = {
49+
.callback = reboot_bt_hook,
50+
.event_id = MGMT_EVT_OP_OS_MGMT_RESET,
51+
};
52+
53+
static int os_mgmt_register_reboot_bt(void)
54+
{
55+
mgmt_callback_register(&cmd_reboot_bt_info_cb);
56+
return 0;
57+
}
58+
59+
SYS_INIT(os_mgmt_register_reboot_bt, APPLICATION, 0);

0 commit comments

Comments
 (0)