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

Signed-off-by: Jan Zyczkowski <[email protected]>
  • Loading branch information
zycz committed May 28, 2024
1 parent 5f4c331 commit 9afedc6
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 4 deletions.
3 changes: 3 additions & 0 deletions applications/nrf_desktop/Kconfig.sysbuild
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ config SECURE_BOOT_APPCORE
config PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY
default y if BOARD_NRF52840DK_NRF52840

config SUIT_ENVELOPE
default y if BOARD_NRF54H20DK

source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
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 @@ -106,3 +106,41 @@ CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_PRINTK=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=1024

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

CONFIG_SUIT=y
CONFIG_SUIT_DFU_CANDIDATE_PROCESSING_MINIMAL=y
CONFIG_ZCBOR=y
CONFIG_ZCBOR_CANONICAL=y
CONFIG_SSF_SUIT_SERVICE_ENABLED=y
CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y

CONFIG_MGMT_SUITFU=y
CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR=y

# Enable the Bluetooth MCUmgr transport (unauthenticated).
CONFIG_MCUMGR=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

# Extended SUIT commands over USER group
CONFIG_MGMT_SUITFU_GRP_SUIT=y
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,41 @@ CONFIG_BT_CONN_TX_MAX=4
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

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

CONFIG_SUIT=y
CONFIG_SUIT_DFU_CANDIDATE_PROCESSING_MINIMAL=y
CONFIG_ZCBOR=y
CONFIG_ZCBOR_CANONICAL=y
CONFIG_SSF_SUIT_SERVICE_ENABLED=y
CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y

CONFIG_MGMT_SUITFU=y
CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR=y

# Enable the Bluetooth MCUmgr transport (unauthenticated).
CONFIG_MCUMGR=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

# Extended SUIT commands over USER group
CONFIG_MGMT_SUITFU_GRP_SUIT=y
28 changes: 24 additions & 4 deletions applications/nrf_desktop/src/modules/Kconfig.dfu_mcumgr
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ 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 FLASH
depends on BOOTLOADER_MCUBOOT
help
This option enables an alternative method of performing DFU using the
MCUmgr module.
Expand All @@ -43,6 +39,30 @@ 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 MCUMGR_GRP_IMG
select MCUBOOT_BOOTUTIL_LIB
select IMG_MANAGER
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
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
29 changes: 29 additions & 0 deletions applications/nrf_desktop/src/modules/dfu_mcumgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
* 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>
#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 @@ -127,6 +134,7 @@ 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 defined CONFIG_DESKTOP_DFU_BACKEND_MCUBOOT
if (!IS_ENABLED(CONFIG_DESKTOP_DFU_MCUMGR_MCUBOOT_DIRECT_XIP)) {
int err = boot_write_img_confirmed();

Expand All @@ -136,6 +144,27 @@ static bool app_event_handler(const struct app_event_header *aeh)
}

LOG_INF("MCUboot image version: %s", CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION);
#elif defined CONFIG_DESKTOP_DFU_BACKEND_SUIT
/* Manifest class ID
* nRF Desktop uses default SUIT manifest file (default namespace and name).

Check warning on line 149 in applications/nrf_desktop/src/modules/dfu_mcumgr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

applications/nrf_desktop/src/modules/dfu_mcumgr.c:149 Block comments should align the * on each line
*/
const suit_manifest_class_id_t manifest_class_id = {{
/* RFC4122 uuid5(uuid5(uuid.NAMESPACE_DNS, 'nordicsemi.com'),
* 'nRF54H20_sample_root')

Check warning on line 153 in applications/nrf_desktop/src/modules/dfu_mcumgr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

applications/nrf_desktop/src/modules/dfu_mcumgr.c:153 Block comments should align the * on each line
*/
0x3f, 0x6a, 0x3a, 0x4d, 0xcd, 0xfa, 0x58, 0xc5,
0xac, 0xce, 0xf9, 0xf5, 0x84, 0xc4, 0x11, 0x24
}};
unsigned int seq_num = 0;

int err = suit_get_installed_manifest_info((suit_manifest_class_id_t *)&manifest_class_id,

Check warning on line 160 in applications/nrf_desktop/src/modules/dfu_mcumgr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

applications/nrf_desktop/src/modules/dfu_mcumgr.c:160 line length of 114 exceeds 100 columns
&seq_num, NULL, NULL, NULL, NULL);
if (!err) {
LOG_INF("SUIT image version: %d", seq_num);
} else {
LOG_ERR("suit_read_manifest_data failed (err: %d)", err);
}
#endif
k_work_init_delayable(&dfu_timeout, dfu_timeout_handler);

mgmt_callback_register(&cmd_recv_cb);
Expand Down

0 comments on commit 9afedc6

Please sign in to comment.