Skip to content

Commit

Permalink
applications: nrf_desktop: Add SMP SUIT DFU support for nrf54h20
Browse files Browse the repository at this point in the history
Add SMP SUIT DFU support for nrf_desktop application.

JIRA: NCSDK-26998
      NCSDK-25024

Signed-off-by: Jan Zyczkowski <[email protected]>
  • Loading branch information
zycz committed Jun 4, 2024
1 parent 0cae535 commit 3c7b671
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@
};
};
};

&cpuapp_rw_partitions {
dfu_partition: partition@13c000 {
label = "dfu_partition";
reg = <0x13c000 DT_SIZE_K(676)>;
};
};

&cpusec_cpuapp_ipc {
status = "okay";
};

&cpusec_bellboard {
status = "okay";
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CONFIG_CAF_CLICK_DETECTOR=y

CONFIG_CAF_LEDS=y

CONFIG_CAF_INIT_LOG_BLE_SMP_TRANSFER_EVENTS=n

# The LLPM must be explicitly enabled, as the Bluetooth Controller
# is not part of the main application.
CONFIG_CAF_BLE_USE_LLPM=y
Expand Down Expand Up @@ -107,3 +109,31 @@ CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_PRINTK=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=1024

# Enable MCUmgr Bluetooth transport
CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y
CONFIG_MCUMGR_TRANSPORT_BT=y
CONFIG_MCUMGR_TRANSPORT_BT_AUTHEN=n

# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=498
CONFIG_BT_BUF_ACL_RX_SIZE=502
CONFIG_BT_BUF_ACL_TX_SIZE=251

# Enable the MCUmgr Packet Reassembly feature over Bluetooth and its configuration dependencies.
# MCUmgr buffer size is optimized to fit one SMP packet divided into five Bluetooth Write Commands,
# transmitted with the maximum possible MTU value: 498 bytes.
CONFIG_MCUMGR_TRANSPORT_BT_REASSEMBLY=y
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=2475
CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4096

# Allow a DFU host to retrieve information about the number and size of MCUmgr buffers.
# The nRF Connect Device Manager uses this information to speed up the DFU.
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y

################################################################################
# DFU configuration

CONFIG_SUIT=y
CONFIG_SUIT_DFU_CANDIDATE_PROCESSING_MINIMAL=y
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,31 @@ CONFIG_BT_CONN_TX_MAX=4
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# Enable MCUmgr Bluetooth transport
CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y
CONFIG_MCUMGR_TRANSPORT_BT=y
CONFIG_MCUMGR_TRANSPORT_BT_AUTHEN=n

# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=498
CONFIG_BT_BUF_ACL_RX_SIZE=502
CONFIG_BT_BUF_ACL_TX_SIZE=251

# Enable the MCUmgr Packet Reassembly feature over Bluetooth and its configuration dependencies.
# MCUmgr buffer size is optimized to fit one SMP packet divided into five Bluetooth Write Commands,
# transmitted with the maximum possible MTU value: 498 bytes.
CONFIG_MCUMGR_TRANSPORT_BT_REASSEMBLY=y
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=2475
CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4096

# Allow a DFU host to retrieve information about the number and size of MCUmgr buffers.
# The nRF Connect Device Manager uses this information to speed up the DFU.
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y

################################################################################
# DFU configuration

CONFIG_SUIT=y
CONFIG_SUIT_DFU_CANDIDATE_PROCESSING_MINIMAL=y
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ CONFIG_THREAD_NAME=y

CONFIG_IPC_RADIO_BT=y
CONFIG_IPC_RADIO_BT_HCI_IPC=y

# Allow for large Bluetooth data packets.
CONFIG_BT_BUF_ACL_RX_SIZE=502
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ CONFIG_UART_CONSOLE=n

CONFIG_IPC_RADIO_BT=y
CONFIG_IPC_RADIO_BT_HCI_IPC=y

# Allow for large Bluetooth data packets.
CONFIG_BT_BUF_ACL_RX_SIZE=502
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
43 changes: 33 additions & 10 deletions applications/nrf_desktop/src/modules/Kconfig.dfu_mcumgr
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ menuconfig DESKTOP_DFU_MCUMGR_ENABLE
select EXPERIMENTAL
select CAF_BLE_SMP_TRANSFER_EVENTS if MCUMGR_TRANSPORT_BT
select MCUMGR
select MCUMGR_GRP_IMG
select MCUMGR_GRP_OS
select MCUMGR_MGMT_NOTIFICATION_HOOKS
select MCUMGR_GRP_IMG_MUTEX if DESKTOP_DFU_LOCK
select MCUMGR_SMP_COMMAND_STATUS_HOOKS
select NET_BUF
select ZCBOR
select CRC
select IMG_MANAGER
select MCUBOOT_BOOTUTIL_LIB
select STREAM_FLASH
select FLASH_MAP
select NET_BUF
select FLASH
depends on BOOTLOADER_MCUBOOT
select FLASH_MAP
select ZCBOR
help
This option enables an alternative method of performing DFU using the
MCUmgr module.
Expand All @@ -43,6 +36,36 @@ config DESKTOP_DFU_MCUMGR_MCUBOOT_DIRECT_XIP
boots the image with a higher version. The module does not confirm the
newly updated image after a successful boot.

choice DESKTOP_DFU_MCUMGR_BACKEND
prompt "Choose DFU backend"
default DESKTOP_DFU_BACKEND_MCUBOOT if BOOTLOADER_MCUBOOT
default DESKTOP_DFU_BACKEND_SUIT if SUIT

config DESKTOP_DFU_BACKEND_MCUBOOT
bool "Use MCUboot as DFU backend"
select MCUBOOT_BOOTUTIL_LIB
select IMG_MANAGER
select MCUMGR_GRP_IMG
select MCUMGR_GRP_IMG_MUTEX if DESKTOP_DFU_LOCK
select MCUMGR_GRP_OS
select STREAM_FLASH
depends on BOOTLOADER_MCUBOOT
help
This option enables the MCUboot bootloader as the backend for the MCUmgr DFU module.

config DESKTOP_DFU_BACKEND_SUIT
bool "Use SUIT as DFU backend"
select MCUMGR_SMP_LEGACY_RC_BEHAVIOUR
select MGMT_SUITFU
select MGMT_SUITFU_GRP_SUIT
select SSF_SUIT_SERVICE_ENABLED
select ZCBOR_CANONICAL
depends on SUIT
help
This option enables the SUIT as the backend for the MCUmgr DFU module.

endchoice

module = DESKTOP_DFU_MCUMGR
module-str = DFU MCUmgr
source "subsys/logging/Kconfig.template.log_config"
Expand Down
61 changes: 53 additions & 8 deletions applications/nrf_desktop/src/modules/dfu_mcumgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>

#if defined CONFIG_DESKTOP_DFU_BACKEND_MCUBOOT
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt.h>
#elif defined CONFIG_DESKTOP_DFU_BACKEND_SUIT
#include <sdfw/sdfw_services/suit_service.h>
#include <dfu/suit_dfu.h>
#endif

#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
#include <zephyr/sys/math_extras.h>
Expand Down Expand Up @@ -37,7 +45,16 @@ static void dfu_lock_owner_changed(const struct dfu_lock_owner *new_owner)
/* The function declaration is not included in MCUmgr's header file if the mutex locking
* of the image management state object is disabled.
*/
#if defined CONFIG_DESKTOP_DFU_BACKEND_MCUBOOT
img_mgmt_reset_upload();
#elif defined CONFIG_DESKTOP_DFU_BACKEND_SUIT
int err = suit_dfu_cleanup();

if (err) {
module_set_state(MODULE_STATE_ERROR);
LOG_ERR("Failed to cleanup SUIT DFU: %d", err);
}
#endif
#endif /* CONFIG_DESKTOP_DFU_LOCK */
}

Expand Down Expand Up @@ -110,6 +127,41 @@ static struct mgmt_callback cmd_recv_cb = {
.event_id = MGMT_EVT_OP_CMD_RECV,
};

#if CONFIG_DESKTOP_DFU_BACKEND_MCUBOOT
static void dfu_backend_init(void)
{
if (!IS_ENABLED(CONFIG_DESKTOP_DFU_MCUMGR_MCUBOOT_DIRECT_XIP)) {
int err = boot_write_img_confirmed();

if (err) {
LOG_ERR("Cannot confirm a running image: %d", err);
}
}

LOG_INF("MCUboot image version: %s", CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION);
}
#elif CONFIG_DESKTOP_DFU_BACKEND_SUIT
static void dfu_backend_init(void)
{
unsigned int seq_num = 0;
suit_ssf_manifest_class_info_t class_info;

int err = suit_get_supported_manifest_info(SUIT_MANIFEST_APP_ROOT, &class_info);

if (!err) {
err = suit_get_installed_manifest_info(&(class_info.class_id),
&seq_num, NULL, NULL, NULL, NULL);
}
if (!err) {
LOG_INF("SUIT sequence number: %d", seq_num);
} else {
LOG_ERR("suit retrieve manifest seq num failed (err: %d)", err);
}
}
#else
#error "The DFU backend choice is not supported"
#endif /* CONFIG_DESKTOP_DFU_BACKEND_MCUBOOT */

static bool app_event_handler(const struct app_event_header *aeh)
{
if (IS_ENABLED(CONFIG_MCUMGR_TRANSPORT_BT) &&
Expand All @@ -127,15 +179,8 @@ static bool app_event_handler(const struct app_event_header *aeh)
cast_module_state_event(aeh);

if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
if (!IS_ENABLED(CONFIG_DESKTOP_DFU_MCUMGR_MCUBOOT_DIRECT_XIP)) {
int err = boot_write_img_confirmed();

if (err) {
LOG_ERR("Cannot confirm a running image: %d", err);
}
}
dfu_backend_init();

LOG_INF("MCUboot image version: %s", CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION);
k_work_init_delayable(&dfu_timeout, dfu_timeout_handler);

mgmt_callback_register(&cmd_recv_cb);
Expand Down

0 comments on commit 3c7b671

Please sign in to comment.