Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ CONFIG_DESKTOP_BLE_LOW_LATENCY_LOCK=y

CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y
CONFIG_DESKTOP_CONFIG_CHANNEL_OUT_REPORT=y
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y

CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y
CONFIG_CAF_INIT_LOG_BLE_SMP_TRANSFER_EVENTS=n

# Temporarily disable unsupported features.
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=n

################################################################################
# Zephyr Configuration

Expand Down Expand Up @@ -124,6 +122,10 @@ CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4096
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y

CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Configure Zephyr system power management
CONFIG_PM=y
CONFIG_PM_S2RAM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ CONFIG_DESKTOP_BLE_NEW_PEER_SCAN_ON_BOOT=y
CONFIG_DESKTOP_BLE_PEER_ERASE=y

CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y

# Temporarily disable unsupported features.
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=n
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y

################################################################################
# Zephyr Configuration
Expand Down Expand Up @@ -85,6 +83,10 @@ CONFIG_BT_PRIVACY=y

CONFIG_BT_BUF_ACL_TX_SIZE=35

CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Configure Zephyr system power management
CONFIG_PM=y
CONFIG_PM_S2RAM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ CONFIG_DESKTOP_FAILSAFE_ENABLE=y

CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y
CONFIG_DESKTOP_CONFIG_CHANNEL_OUT_REPORT=y
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y

CONFIG_DESKTOP_DFU_MCUMGR_ENABLE=y

# Temporarily disable unsupported features.
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=n

################################################################################
# Zephyr Configuration

Expand Down Expand Up @@ -118,6 +116,10 @@ CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4096
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y

CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Configure Zephyr system power management
CONFIG_PM=y
CONFIG_PM_S2RAM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ CONFIG_DESKTOP_WATCHDOG_ENABLE=y
CONFIG_DESKTOP_FAILSAFE_ENABLE=y

CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y

# Temporarily disable unsupported features.
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=n
CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y

################################################################################
# Zephyr Configuration
Expand Down Expand Up @@ -84,6 +82,10 @@ CONFIG_BT_PRIVACY=y

CONFIG_BT_BUF_ACL_TX_SIZE=35

CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Configure Zephyr system power management
CONFIG_PM=y
CONFIG_PM_S2RAM=y
Expand Down
65 changes: 44 additions & 21 deletions applications/nrf_desktop/src/modules/dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,55 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_LOG_LEVEL);
#error Missing partition definitions.
#endif
#elif CONFIG_BOOTLOADER_MCUBOOT
BUILD_ASSERT(IS_ENABLED(CONFIG_PARTITION_MANAGER_ENABLED),
"MCUBoot bootloader supported only with Partition Manager");
#include <pm_config.h>
#include <zephyr/dfu/mcuboot.h>
#if CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_MCUBOOT_DIRECT_XIP
#define BOOTLOADER_NAME "MCUBOOT+XIP"
#else
#define BOOTLOADER_NAME "MCUBOOT"
#endif

#ifdef PM_MCUBOOT_SECONDARY_PAD_SIZE
BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE);
#endif

#if CONFIG_BUILD_WITH_TFM
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE + PM_TFM_SIZE)
#if CONFIG_PARTITION_MANAGER_ENABLED
#include <pm_config.h>

#ifdef PM_MCUBOOT_SECONDARY_PAD_SIZE
BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE);
#endif

#if CONFIG_BUILD_WITH_TFM
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE + PM_TFM_SIZE)
#else
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE)
#endif

#define MCUBOOT_PRIMARY_ID PM_MCUBOOT_PRIMARY_ID
Copy link
Contributor

Choose a reason for hiding this comment

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

MCUBOOT_PRIMARY_PARTITION_ID? (previously PARTITION word was part of the PM_ prefix)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe MCUBOOT_PRIMARY_SLOT_ID (for consistency with DFU_SLOT_ID)?

#define MCUBOOT_SECONDARY_ID PM_MCUBOOT_SECONDARY_ID

#if (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_PRIMARY_ADDRESS
#define DFU_SLOT_ID MCUBOOT_SECONDARY_ID
#elif (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_SECONDARY_ADDRESS
#define DFU_SLOT_ID MCUBOOT_PRIMARY_ID
#else
#error Missing partition definitions.
#endif
#elif CONFIG_USE_DT_CODE_PARTITION
#include <zephyr/devicetree.h>

#define CODE_PARTITION_NODE DT_CHOSEN(zephyr_code_partition)
#define MCUBOOT_PRIMARY_NODE DT_NODELABEL(slot0_partition)
#define MCUBOOT_SECONDARY_NODE DT_NODELABEL(slot1_partition)
Comment on lines +102 to +103
Copy link
Contributor

Choose a reason for hiding this comment

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

You could consider checking if both partitions exist (DT_FIXED_PARTITION_EXISTS) and start at different addresses


#define MCUBOOT_PRIMARY_ID DT_FIXED_PARTITION_ID(MCUBOOT_PRIMARY_NODE)
#define MCUBOOT_SECONDARY_ID DT_FIXED_PARTITION_ID(MCUBOOT_SECONDARY_NODE)

#if DT_REG_ADDR(CODE_PARTITION_NODE) == DT_REG_ADDR(MCUBOOT_PRIMARY_NODE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using DT_FIXED_PARTITION_ADDR (to improve readability)

Copy link
Contributor

Choose a reason for hiding this comment

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

btw. It would be good to also test IronSide with our fwupd plugin at some point (to ensure it works there)

#define DFU_SLOT_ID MCUBOOT_SECONDARY_ID
#elif DT_REG_ADDR(CODE_PARTITION_NODE) == DT_REG_ADDR(MCUBOOT_SECONDARY_NODE)
#define DFU_SLOT_ID MCUBOOT_PRIMARY_ID
#else
#error Missing partition definitions in DTS.
#endif
#else
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE)
#endif

#if (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_PRIMARY_ADDRESS
#define DFU_SLOT_ID PM_MCUBOOT_SECONDARY_ID
#elif (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_SECONDARY_ADDRESS
#define DFU_SLOT_ID PM_MCUBOOT_PRIMARY_ID
#else
#error Missing partition definitions.
#error Unsupported partitioning scheme.
#endif
#else
#error Bootloader not supported.
Expand Down Expand Up @@ -732,12 +755,12 @@ static void handle_image_info_request(uint8_t *data, size_t *size)
uint8_t flash_area_id;
uint8_t bank_header_area_id;

if (DFU_SLOT_ID == PM_MCUBOOT_SECONDARY_ID) {
if (DFU_SLOT_ID == MCUBOOT_SECONDARY_ID) {
flash_area_id = 0;
bank_header_area_id = PM_MCUBOOT_PRIMARY_ID;
bank_header_area_id = MCUBOOT_PRIMARY_ID;
} else {
flash_area_id = 1;
bank_header_area_id = PM_MCUBOOT_SECONDARY_ID;
bank_header_area_id = MCUBOOT_SECONDARY_ID;
}

int err = boot_read_bank_header(bank_header_area_id, &header,
Expand Down