Help with BLE DFU FOTA on External Flash (nRF52840, NCS 2.5.2)

I am trying to get DFU FOTA over BLE to work using external flash on an nRF52840 DK with NCS 2.5.2. I followed multiple sources, but I am unsure about the correct configuration.

1. Configuration Steps

I started by adding these to prj.conf

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

This already causes compilation errors, but I will get back to that later.
You can get the same errors by modifying the fs_sample and adding:

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

2. Partition configuration

I have seen projects using pm_static.yml and others defining partitions in overlay, but I am not sure what the difference is.

Here is my pm_static.yml

external_flash:
  address: 0xf4000
  end_address: 0x800000
  region: external_flash
  size: 0x70c000

mcuboot_secondary:
  address: 0x00000
  device: MX25R64
  end_address: 0xf4000
  region: external_flash
  size: 0xf4000

At the same time, my overlay file contains:

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

        /* 8MB external storage partition */
        external_partition: partition@0 {
            reg = <0x00000000 0x0800000>;
        };
    };
};

/ {
    msc_disk0 {
        status = "okay";
        compatible = "zephyr,flash-disk";
        partition = <&external_partition>;
        disk-name = "NAND";
        /* cache-size == page erase size */
        cache-size = <4096>;
    };
};

Then I add this at the end of the overlay file:
/ {
    chosen {
        nordic,pm-ext-flash = &mx25r64;
    };
};
Does this conflict with pm_static.yml?
3. MCUBoot configuration
Inside child_image/mcuboot.conf I added
CONFIG_FLASH=y
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_BOOT_MAX_IMG_SECTORS=256
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y 
CONFIG_MCUBOOT_LOG_LEVEL_WRN=y
CONFIG_CBPRINTF_NANO=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
4. Compilation errors
When compiling, I get these errors:
/opt/nordic/ncs/v2.5.2/zephyr/drivers/disk/flashdisk.c:484:1: error: return type defaults to 'int' [-Werror=implicit-int]
484 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/nordic/ncs/v2.5.2/zephyr/drivers/disk/flashdisk.c:524:39: error: 'DEFINE_FLASHDISKS_DEVICE' undeclared (first use in this function)
524 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_DEVICE)
| ^~~~~~~~~~~~~~~~~~~~~~~~
5. Questions
1. Should I use pm_static.yml or overlay or both?
 - Are my external flash partitions conflicting between these two files
2. Why does MCUBoot fail to compile with these errors?
 - Is there a missing configuration option for flash-disk or QSPI

Parents
  • Hello,

    While checking the shared pm_static file and the overlay, there are some mismatches in the definition, which could be the cause of the issue you are seeing.

    In the pm_static.yml file, you defined mcuboot_secondary as 0x00000–0xf4000, which overlaps with the external flash region defined as 0xf4000–0x800000. This will cause MCUboot to fail. Additionally, in the pm_static file, external_flash starts after mcuboot_secondary, at 0xf4000, and extends to 0x800000, but external_partition starts at 0x00000000 inside the overlay file.

    I recommend that you take a look at this old DevZone case, which discusses a similar issue and contains some useful reference links.

    You can use both pm_static.yml and .overlay files, but they must not conflict. I recommend using the  pm_static.yml alone first, if you only need to define a simple set of partitions like MCUBoot, application and storage.

    Kind Regards,

    Abhijith

Reply
  • Hello,

    While checking the shared pm_static file and the overlay, there are some mismatches in the definition, which could be the cause of the issue you are seeing.

    In the pm_static.yml file, you defined mcuboot_secondary as 0x00000–0xf4000, which overlaps with the external flash region defined as 0xf4000–0x800000. This will cause MCUboot to fail. Additionally, in the pm_static file, external_flash starts after mcuboot_secondary, at 0xf4000, and extends to 0x800000, but external_partition starts at 0x00000000 inside the overlay file.

    I recommend that you take a look at this old DevZone case, which discusses a similar issue and contains some useful reference links.

    You can use both pm_static.yml and .overlay files, but they must not conflict. I recommend using the  pm_static.yml alone first, if you only need to define a simple set of partitions like MCUBoot, application and storage.

    Kind Regards,

    Abhijith

Children
Related