Using internal flash with custom partitions and BT OTA DFU and MCUboot enabled

Hello

I'm using nRF Connect SDK v2.5.0 and have defined a pm_static and the corresponding partitions in the dts with the same address ranges (BTW: is there a way to sync them?). DFU over Bluetooth is working as expected.

pm_static and dts partitions (the strange cryptic node name is just for testing):

app:
  address: 0x7200
  region: flash_primary
  size: 0x39e00

mcuboot:
  address: 0x0
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0x7000

mcuboot_pad:
  address: 0x7000
  placement:
    align:
      start: 0x1000
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200

mcuboot_primary:
  address: 0x7000
  orig_span: &id001
  - mcuboot_pad
  - app
  region: flash_primary
  size: 0x3a000
  span: *id001

mcuboot_primary_app:
  address: 0x7200
  orig_span: &id002
  - app
  region: flash_primary
  size: 0x39e00
  span: *id002

mcuboot_secondary:
  address: 0x41000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
    align_next: 0x1000
  region: flash_primary
  size: 0x3a000

align_dummy_1:
  address: 0x7b000
  placement:
    after:
    - mcuboot_secondary
    align:
      start: 0x1000
  region: flash_primary
  size: 0x1000

appdata:
  address: 0x7c000
  placement:
    after:
    - align_dummy_1
    align:
      start: 0x1000
  region: flash_primary
  size: 0x4000




flash_primary (0x80000 - 512kB): 
+-------------------------------------------------+
| 0x0: mcuboot (0x7000 - 28kB)                    |
+---0x7000: mcuboot_primary (0x3a000 - 232kB)-----+
| 0x7000: mcuboot_pad (0x200 - 512B)              |
+---0x7200: mcuboot_primary_app (0x39e00 - 231kB)-+
| 0x7200: app (0x39e00 - 231kB)                   |
+-------------------------------------------------+
| 0x41000: mcuboot_secondary (0x3a000 - 232kB)    |
| 0x7b000: align_dummy_1 (0x1000 - 4kB)           |
| 0x7c000: appdata (0x4000 - 16kB)                |
+-------------------------------------------------+





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

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x0 0x7000>;
		};
		slot0_partition: partition@7000 {
			label = "image-0";
			reg = <0x7000 0x3a000>;
		};
		slot1_partition: partition@41000 {
			label = "image-1";
			reg = <0x41000 0x3a000>;
		};
		myadt_partition: partition@7c000 {
			label = "appdata";
			reg = <0x7c000 0x4000>;
		};
	};
};

Then I added the code from the soc_flash_nrf sample, and adapted the dts node:

#define DATAPART_DT_LABEL  myadt_partition
#define DATAPART_OFFSET    FIXED_PARTITION_OFFSET(DATAPART_DT_LABEL)
#define DATAPART_DT_DEVICE FIXED_PARTITION_DEVICE(DATAPART_DT_LABEL)

But it can't get compiled:

C:/ncs/v2.5.0/nrf/include/flash_map_pm.h:52:18: error: 'PM_PM_PM_myadt_partition_ID_LABEL_OFFSET' undeclared (first use in this function)
   52 |         UTIL_CAT(PM_, UTIL_CAT(UTIL_CAT(PM_, UTIL_CAT(PM_ID(label), _LABEL)), x))
... (many macro expansion notes)
../flash.c:49:25: note: in expansion of macro 'FIXED_PARTITION_OFFSET'
   49 | #define DATAPART_OFFSET FIXED_PARTITION_OFFSET(DATAPART_DT_LABEL)

I tested it with an additional prj_nodfu.conf, whith is the same as the one used in my project but with disabled DFU:

CONFIG_BOOTLOADER_MCUBOOT=n
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=n

then it compiles and the flash operations work as expected. But I obviously have no DFU.

I also looked in to the diff of the two .conf files in the two build directories and added them to the no-dfu config:

CONFIG_BOOTLOADER_MCUBOOT=n
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=n

# to have the same flash stuff config as with MCUboot
CONFIG_USE_DT_CODE_PARTITION=y
CONFIG_PARTITION_MANAGER_ENABLED=y
CONFIG_FLASH_MAP_CUSTOM=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_STREAM_FLASH_ERASE=y

Then also the no-dfu config raises the same compiler errors as the actual project config.

How can I configure my project, so that flash_write, flash_read and flash_erase can be used on my internal data partition with MCUboot and DFU enabled?

Best regards

Related