NCS 2.6.1
nRF5340
My project is based on coap_client, and I am trying to get DFU to work on an off-the-shelf dongle, which has no external flash. I have looked at this ticket:
how to implement simultaneous dfu on 5340 ncs2.4 without external flash
I am aware of the flash limitations, but have managed to get it to fit.
pm_static.yml
app: address: 0x10200 end_address: 0x76000 region: flash_primary size: 0x65e00 mcuboot: address: 0x0 end_address: 0x10000 placement: before: - mcuboot_primary region: flash_primary size: 0x10000 mcuboot_pad: address: 0x10000 end_address: 0x10200 placement: before: - mcuboot_primary_app region: flash_primary size: 0x200 mcuboot_primary: address: 0x10000 end_address: 0x76000 orig_span: &id001 - mcuboot_pad - app region: flash_primary sharers: 0x1 size: 0x66000 span: *id001 mcuboot_primary_app: address: 0x10200 end_address: 0x76000 orig_span: &id002 - app region: flash_primary size: 0x65e00 span: *id002 mcuboot_secondary: address: 0x76000 end_address: 0xdc000 placement: after: - mcuboot_primary align: start: 0x1000 region: flash_primary share_size: - mcuboot_primary size: 0x66000 mcuboot_primary_1: address: 0x0 size: 0x20000 device: flash_ctrl region: ram_flash ram_flash_empty: address: 0x20000 size: 0x5a000 device: flash_ctrl region: ram_flash mcuboot_secondary_1: address: 0xdc000 end_address: 0xfc000 placement: align: start: 0x1000 region: flash_primary size: 0x20000 otp: address: 0xff8100 end_address: 0xff83fc region: otp size: 0x2fc pcd_sram: address: 0x20000000 end_address: 0x20002000 placement: after: - start region: sram_primary size: 0x2000 ram_flash: address: 0x40000 end_address: 0x40000 region: ram_flash size: 0x0 rpmsg_nrf53_sram: address: 0x20070000 end_address: 0x20080000 placement: before: - end region: sram_primary size: 0x10000 settings_storage: address: 0xfc000 end_address: 0x100000 placement: align: start: 0x1000 before: - end region: flash_primary size: 0x4000 sram_primary: address: 0x20002000 end_address: 0x20070000 region: sram_primary size: 0x6e000
I copied board files from the 5340DK modified them as necessary for the hardware. I have included a node for the phantom flash controller in then rf5340_common_cpuapp.dts file.
mcuboot/prj.conf
########################################## ### Configure required bootloader settings ########################################## CONFIG_MULTITHREADING=y CONFIG_BOOT_MAX_IMG_SECTORS=256 # From: https://github.com/simon-iversen/sdk-zephyr/blob/serial_dfu_ext_flash_hello_world/samples/hello_world/child_image/mcuboot/prj.conf # In order to provide board specific configurations to the MCUboot child image # we also need to provide a base configuration for MCUboot. This file contains # the basic configurations needed to successfully build and run MCUboot. # MCUboot requires a large stack size, otherwise an MPU fault will occur CONFIG_MAIN_STACK_SIZE=10240 CONFIG_DEBUG_OPTIMIZATIONS=y CONFIG_SIZE_OPTIMIZATIONS=y # Enable flash operations CONFIG_FLASH=y # This must be increased to accommodate the bigger images. CONFIG_BOOT_MAX_IMG_SECTORS=256 CONFIG_LOG=y CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL ### Ensure Zephyr logging changes don't use more resources CONFIG_LOG_DEFAULT_LEVEL=3 ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y CONFIG_CBPRINTF_NANO=y # Must match the board yaml file: pm_static_nrf5340.yml CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000 CONFIG_PM_PARTITION_SIZE_MCUBOOT_SCRATCH=0x10000 CONFIG_MCUBOOT_INDICATION_LED=y CONFIG_PINCTRL=y CONFIG_BOOT_WATCHDOG_FEED=y # Public key, ECDSA CONFIG_BOOT_SIGNATURE_KEY_FILE="d:/myproject/child_image/mcuboot/myproject_priv.pem" CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y # Simultaneous updates (cpuapp, cpunet) # See: https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf53/simultaneous_multi_image_dfu_nrf5340.html # Enable flash simulator #CONFIG_FPROTECT=y CONFIG_PCD_APP=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 CONFIG_NRF53_MULTI_IMAGE_UPDATE=y CONFIG_UPDATEABLE_IMAGE_NUMBER=2 CONFIG_BOOT_UPGRADE_ONLY=y CONFIG_BOOT_IMAGE_ACCESS_HOOK_NRF5340=y CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y
overlay-dfu_support.conf
# # Copyright (c) 2021 Nordic Semiconductor # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # # Enable MCUboot bootloader CONFIG_BOOTLOADER_MCUBOOT=y CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y # MCU Manager and SMP configuration CONFIG_ZCBOR=y 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 # Reduce GAP event length to avoid heavy BLE traffic generated during DFU #CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT=3000 # Enable minimal logging implementation to decrease memory footprint #CONFIG_LOG_MODE_MINIMAL=y # Added to match DTS CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x4000 CONFIG_SETTINGS_NVS_SECTOR_COUNT=4 # NCS2 additions # Image manager CONFIG_IMG_MANAGER=y CONFIG_FLASH=y CONFIG_FLASH_MAP=y CONFIG_STREAM_FLASH=y CONFIG_IMG_ERASE_PROGRESSIVELY=y #CONFIG_MCUMGR_GRP_IMG=y #CONFIG_MCUMGR_GRP_OS=y # Enable statistics and statistic names. #CONFIG_STATS=y #CONFIG_STATS_NAMES=y #CONFIG_MCUMGR_GRP_STAT=y # DFU Target #CONFIG_DFU_TARGET=y CONFIG_IEEE802154_NRF5_RX_STACK_SIZE=1000 # nRF5340 CONFIG_UPDATEABLE_IMAGE_NUMBER=2
The project compiles, and the images seem to be loaded in the correct areas of flash.
D:\myproject\bld_usb40n\zephyr>nrfjprog --verify app_signed.hex
[ #################### ] 2.789s | Verify file - Done verifying
However, the bootloader fails to find a bootable image, and halts here, with fig_rc = -1:
I note that in build\mcuboot\zephyr\.config,
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
Is the bootloader looking for bootable images in external flash?
If I set CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n in overlay-dfu_support, mcuboot won't compile, and reports this error:
error: 'PM_MCUBOOT_PRIMARY_1_ID' undeclared
How can I get this to work?
Mary