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 Jun 3, 2024
1 parent 0cae535 commit 82b4b6f
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 17 deletions.
3 changes: 3 additions & 0 deletions applications/nrf_desktop/Kconfig.sysbuild
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,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 @@ -107,3 +107,30 @@ 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_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,30 @@ 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_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,7 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ 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
42 changes: 33 additions & 9 deletions applications/nrf_desktop/src/modules/Kconfig.dfu_mcumgr
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ 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 +38,35 @@ 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 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
50 changes: 42 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 "desktop_suit.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,11 @@ 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
suit_dfu_cleanup();
#endif
#endif /* CONFIG_DESKTOP_DFU_LOCK */
}

Expand Down Expand Up @@ -110,6 +122,35 @@ 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;

int err = suit_get_installed_manifest_seq_num(&seq_num);
if (!err) {

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

View workflow job for this annotation

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

LINE_SPACING

applications/nrf_desktop/src/modules/dfu_mcumgr.c:144 Missing a blank line after declarations
LOG_INF("SUIT sequence number: %d", seq_num);
} else {
LOG_ERR("suit_read_manifest_data 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 +168,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
3 changes: 3 additions & 0 deletions applications/nrf_desktop/src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ endif()
target_sources_ifdef(CONFIG_DESKTOP_ADV_PROV_UUID16_ALL
app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bt_le_adv_prov_uuid16.c)

target_sources_ifdef(CONFIG_DESKTOP_DFU_BACKEND_SUIT
app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/desktop_suit.c)

target_sources_ifdef(CONFIG_DESKTOP_DFU_LOCK
app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dfu_lock.c)

Expand Down
29 changes: 29 additions & 0 deletions applications/nrf_desktop/src/util/desktop_suit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>
#include "desktop_suit.h"
#include <sdfw/sdfw_services/suit_service.h>

int suit_get_installed_manifest_seq_num(unsigned int *seq_num)
{
/* Manifest class ID
* nRF Desktop uses default SUIT manifest file (default namespace and name).
*/
const suit_manifest_class_id_t manifest_class_id = {{
/* RFC4122 uuid5(uuid5(uuid.NAMESPACE_DNS, 'nordicsemi.com'),
* 'nRF54H20_sample_root')
*/
0x3f, 0x6a, 0x3a, 0x4d, 0xcd, 0xfa, 0x58, 0xc5,
0xac, 0xce, 0xf9, 0xf5, 0x84, 0xc4, 0x11, 0x24
}};

int err = suit_get_installed_manifest_info((
suit_manifest_class_id_t *)&manifest_class_id,
seq_num, NULL, NULL, NULL, NULL);

return err;
}
12 changes: 12 additions & 0 deletions applications/nrf_desktop/src/util/desktop_suit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef _DESKTOP_SUIT_H_
#define _DESKTOP_SUIT_H_

int suit_get_installed_manifest_seq_num(unsigned int *seq_num);

#endif /* _DESKTOP_SUIT_H_ */

0 comments on commit 82b4b6f

Please sign in to comment.