Skip to content

Commit

Permalink
[nrfconnect] Added support for multi-image Device Firmware Upgrade (#…
Browse files Browse the repository at this point in the history
…10105)

Currently lock-app and lighting-app examples support performinf
Device Firmware Upgrade over Bluetooth LE on nRF52840 DK
and nRF5340 DK devices. However they do support only upgrading
application firmware, while nRF5340 has also second core running
network firmware.

* Added additional config files allowing to support multi-image
Device Firmware Upgrade on nRF5340DK.
* Moved mcuboot.conf files from child_image to configuration,
as they are no longer attached automatically by the nrfconnect
toolchain.
* Aligned READMEs and DFU guide.
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Nov 26, 2021
1 parent 837f100 commit 2271384
Show file tree
Hide file tree
Showing 25 changed files with 744 additions and 71 deletions.
53 changes: 53 additions & 0 deletions config/nrfconnect/app/overlay-multi_image_dfu_support.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_UPDATEABLE_IMAGE_NUMBER=2

# QSPI configuration
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16

# External flash memory configuration
CONFIG_PM_EXTERNAL_FLASH_SUPPORT_LEGACY=y
CONFIG_PM_EXTERNAL_FLASH=y
CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="MX25R64"
CONFIG_PM_EXTERNAL_FLASH_SIZE=0x800000
CONFIG_PM_EXTERNAL_FLASH_BASE=0

# MCU Manager and SMP configuration
CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_BUF_COUNT=6

# Increase BT MTU and RX buffer for big size DFU messages
CONFIG_BT_L2CAP_TX_MTU=260
CONFIG_BT_BUF_ACL_RX_SIZE=264

# Increase system workqueue size, as SMP is processed within it
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2800

# FLASH nop device is enabled to prevent bus faults when mcumgr tries to access
# simulated partition with network core image data.
CONFIG_FLASH_NOP_DEVICE=y

# Enable custom SMP request to erase settings partition.
CONFIG_MCUMGR_GRP_ZEPHYR_BASIC=y
CONFIG_MCUMGR_GRP_BASIC_CMD_STORAGE_ERASE=y
78 changes: 73 additions & 5 deletions docs/guides/nrfconnect_examples_software_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Complete the following steps to perform DFU using mcumgr:
3. Observe that the LED on the device is flashing (short flash on), which means
that the Bluetooth LE advertising has started. See the user interface
section in the example documentation to check the LED number.
4. Upload the firmware image to the device by running the following command in
your example directory:
4. Upload the application firmware image to the device by running the following
command in your example directory:

$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image upload build/zephyr/app_update.bin
$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image upload build/zephyr/app_update.bin -n 0

The operation can take few minutes. Wait until the progress bar reaches
The operation can take a few minutes. Wait until the progress bar reaches
100%.

5. Obtain the list of images present in the device memory by running following
Expand Down Expand Up @@ -118,11 +118,79 @@ Complete the following steps to perform DFU using mcumgr:
hash: cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1
Split status: N/A (0)

7. Reset the device with the following command to let the bootloader swap
> **_NOTE:_** If you are using the nRF5340DK board, that supports multi-image
> device firmware upgrade, complete Steps 7-9. If not using one, go straight to
> the step 10.
7. Upload the network core firmware image to the device by running the
following command in your example directory:

$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image upload build/zephyr/net_core_app_update.bin -n 1

The operation can take a few minutes. Wait until the progress bar reaches
100%.

8. Obtain the list of images present in the device memory by running following
command:

$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image list

The displayed output contains the old application image in slot 0 that is
currently active, the new application image in slot 1 in pending state, and
the new network image which is in slot 1 and not active yet (flags field
empty):

Images:
image=0 slot=0
version: 0.0.0
bootable: true
flags: active confirmed
hash: 7bb0e909a846e833465cbb44c581cf045413a5446c6953a30a3dcc2c3ad51764
image=0 slot=1
version: 0.0.0
bootable: true
flags: pending
hash: cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1
image=1 slot=1
version: 0.0.0
bootable: true
flags:
hash: d9e31e73cb7a959c26411250c2b3028f3510ae88a4549ae3f2f097c3e7530f48
Split status: N/A (0)

9. Swap the firmware images by calling the following method with `image-hash`
replaced by the image present in the slot 1 hash (for example,
`d9e31e73cb7a959c26411250c2b3028f3510ae88a4549ae3f2f097c3e7530f48`):

$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image test image-hash

You can observe that the `flags:` field in the image for slot 1 changes
value to `pending`:

Images:
image=0 slot=0
version: 0.0.0
bootable: true
flags: active confirmed
hash: 7bb0e909a846e833465cbb44c581cf045413a5446c6953a30a3dcc2c3ad51764
image=0 slot=1
version: 0.0.0
bootable: true
flags: pending
hash: cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1
image=1 slot=1
version: 0.0.0
bootable: true
flags: pending
hash: d9e31e73cb7a959c26411250c2b3028f3510ae88a4549ae3f2f097c3e7530f48
Split status: N/A (0)

10. Reset the device with the following command to let the bootloader swap
images:

$ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' reset


The device is reset and the following notifications appear in its console:

*** Booting Zephyr OS build zephyr-v2.5.0-1101-ga9d3aef65424 ***
Expand Down
8 changes: 7 additions & 1 deletion examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ endif()

option(BUILD_WITH_DFU "Build target with Device Firmware Upgrade support" OFF)
if(BUILD_WITH_DFU)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-dfu_support.conf)
if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_multi_image_dfu.conf CACHE INTERNAL "")
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_single_image_dfu.conf CACHE INTERNAL "")
endif()
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static.yml)
endif()

Expand Down
36 changes: 27 additions & 9 deletions examples/lighting-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,36 @@ Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):

$ west build -b build-target -- -DBUILD_WITH_DFU=1

> **Note**:
>
> There are two types of Device Firmware Upgrade modes: single-image DFU and
> multi-image DFU. Single-image mode supports upgrading only one firmware image,
> the application image, and should be used for single-core nRF52840 DK devices.
> Multi-image mode allows to upgrade more firmware images and is suitable for
> upgrading the application core and network core firmware in two-core nRF5340
> DK devices.
#### Changing Device Firmware Upgrade configuration

To change the default DFU configuration, edit the
`overlay-single_image_dfu_support.conf` or
`overlay-multi_image_dfu_support.conf` overlay files depending on whether the
build target device supports multi-image DFU (nRF5340 DK) or single-image DFU
(nRF52840 DK). The files are located in the `config/nrfconnect/app` directory.
You can also define the desired options in your example's `prj.conf` file.

#### Changing bootloader configuration

To change the default MCUboot configuration, edit the `overlay-dfu_support.conf`
overlay file that contains bootloader configuration options. The file is located
in the `config/nrfconnect/app` directory. You can also define the desired
options in your example's `prj.conf` file.
To change the default MCUboot configuration, edit the
`mcuboot_single_image_dfu.conf` or `mcuboot_multi_image_dfu.conf` overlay files
depending on whether the build target device supports multi-image DFU (nRF5340
DK) or single-image DFU (nRF52840 DK). The files are located in the
`configuration` directory.

Make sure to apply the same configuration changes in the
`child_image/mcuboot.conf` file. This is necessary for the configuration to
work, as the bootloader image is a separate application from the user
application and it has its own configuration file. The contents of this file
must be consistent with the application configuration.
Make sure to keep the configuration consistent with changes made to the
application configuration. This is necessary for the configuration to work, as
the bootloader image is a separate application from the user application and it
has its own configuration file.

#### Changing flash memory settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,50 @@
};
};

soc {
/* Add a flash controller which has the compatible
* 'zephyr,sim-flash'. This will ensure that the flash
* simulator can use it. None of the other properties in this
* node is used for anything.
*/
nordic_ram_flash_controller: nordic_ram-flash-controller@0 {
compatible = "zephyr,sim-flash";
reg = <0x00000000 DT_SIZE_K(40)>;
#address-cells = <1>;
#size-cells = <1>;
erase-value = <0xff>;
label = "nordic_ram_flash_flash_controller";

/* This node label must match that used in the flash
* simulator.
*/
flash_sim0: flash_sim@0 {
status = "okay";
compatible = "soc-nv-flash";
label = "simulated_flash";
erase-block-size = <4096>;
write-block-size = <4>;
reg = <0x00000000 DT_SIZE_K(256)>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

/* This partition must be defined for
* MCUboot to find the partition ID
* of the primary slot for image 1,
* which is stored in this partition.
*/
slot2_partition: partition@0 {
label = "image-2";
reg = <0x00000000 0x00000A000>;
};
};
};
};
};

};

&pwm0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# QSPI configuration
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16

CONFIG_MULTITHREADING=y
CONFIG_BOOT_MAX_IMG_SECTORS=256

# External flash memory configuration
CONFIG_PM_EXTERNAL_FLASH_SUPPORT_LEGACY=y
CONFIG_PM_EXTERNAL_FLASH=y
CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="MX25R64"
CONFIG_PM_EXTERNAL_FLASH_SIZE=0x800000
CONFIG_PM_EXTERNAL_FLASH_BASE=0

# The following configurations are required to support simultaneous multi image update
CONFIG_PCD_APP=y
CONFIG_UPDATEABLE_IMAGE_NUMBER=2
CONFIG_BOOT_UPGRADE_ONLY=y
# The network core cannot access external flash directly. The flash simulator must be used to
# provide a memory region that is used to forward the new firmware to the network core.
CONFIG_FLASH_SIMULATOR=y
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
CONFIG_FLASH_SIMULATOR_STATS=n

# Enable custom command to erase settings partition.
CONFIG_ENABLE_MGMT_PERUSER=y
CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE=y
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
mcuboot:
address: 0x0
size: 0xc000
size: 0x10000
region: flash_primary
mcuboot_pad:
address: 0xc000
address: 0x10000
size: 0x200
app:
address: 0xc200
size: 0xebe00
address: 0x10200
size: 0xe7e00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0xc000
size: 0xec000
address: 0x10000
size: 0xe8000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0xc200
size: 0xebe00
address: 0x10200
size: 0xe7e00
settings_storage:
address: 0xf8000
size: 0x8000
region: flash_primary
mcuboot_primary_1:
address: 0x0
size: 0x40000
device: flash_ctrl
region: ram_flash
mcuboot_secondary:
address: 0x0
size: 0xec000
size: 0xe8000
device: MX25R64
region: external_flash
mcuboot_secondary_1:
address: 0xe8000
size: 0x40000
device: MX25R64
region: external_flash
external_flash:
address: 0xec000
size: 0x714000
address: 0x128000
size: 0x6d8000
device: MX25R64
region: external_flash
pcd_sram:
address: 0x20000000
size: 0x2000
region: sram_primary
8 changes: 7 additions & 1 deletion examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ endif()

option(BUILD_WITH_DFU "Build target with Device Firmware Upgrade support" OFF)
if(BUILD_WITH_DFU)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-dfu_support.conf)
if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_multi_image_dfu.conf CACHE INTERNAL "")
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_single_image_dfu.conf CACHE INTERNAL "")
endif()
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static.yml)
endif()

Expand Down
Loading

0 comments on commit 2271384

Please sign in to comment.