NRF52840: mcuboot (ota) and external flash / Compilation Problem

Hye everyone, thanks for the project
i have a problem on NRF52840 on a project using mcuboot (ota) and an external flash used independently by the app (not for ota)

prj.conf:

...
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

myboard.dts:

...
&zd25wq32 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;
        
        storagenor_part: partition@0 {
            label = "storagenor";
            reg = <0x000000 0x400000>; /* 0x00100000 -> 4MB */
        };
    };
};

storage.c

...
#define STORAGE_PARTITION storagenor_part
#define STORAGE_PARTITION_ID FIXED_PARTITION_ID(STORAGE_PARTITION)

my code build when CONFIGBOOTLOADER_MCUBOOT=n
but i get a compilation error when CONFIG_BOOTLOADER_MCUBOOT=y

[15/363] Building C object CMakeFiles/app.dir/src/drivers/storage.c.obj
FAILED: CMakeFiles/app.dir/src/drivers/storage.c.obj
...
In file included from /opt/nordic/ncs/v2.5.2/zephyr/include/zephyr/storage/flash_map.h:275,
from ../src/drivers/storage.c:19:
../src/drivers/storage.c: In function 'setup_flash':
/opt/nordic/ncs/v2.5.2/nrf/include/flash_map_pm.h:43:22: error: 'PM_storagenor_part_ID' undeclared (first use in this function)
43 | #define PM_ID(label) PM##label##_ID
| ^
/opt/nordic/ncs/v2.5.2/nrf/include/flash_map_pm.h:48:35: note: in expansion of macro 'PM_ID'
48 | #define FIXED_PARTITION_ID(label) PM_ID(label)
| ^
../src/drivers/storage.c:12:41: note: in expansion of macro 'FIXED_PARTITION_ID'
12 | #define STORAGE_PARTITION_ID FIXED_PARTITION_ID(STORAGE_PARTITION)
| ^~~~
../src/drivers/storage.c:36:36: note: in expansion of macro 'STORAGE_PARTITION_ID'
36 | mnt->storage_dev = (void *)STORAGE_PARTITION_ID;
| ^~~~~~~~

tried a lot but i can't pass through this
same pb with toolchain 2.4.2 and 2.5.2.
any advice ?!

  • Hi,

    Glad to hear that you were able to compile it using a pm_static.

    However, did you ever uncover why it didn't compile when using CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL and the equivalent config for NVS on external flash? I'm curious if there are any faults that might still be present that causes the issue?

    W.r.t hte build fault you're getting. Could you describe the flashing procedure you're doing? Is it for a custom board or are you flashing a DK through the VS Code extension?

    There are some slightly older cases that indicates that this could be caused by a wide range of causes, let me know if any of these seems to be relevant

     Issue with flashing and debugging firmware on nRF52833 microcontroller with nRF Connect SDK and Visual Studio Code  RE: nrfjprog failures  

     Serial wire programming in production - advise needed  

    Kind regards,
    Andreas

  • hye, 

    for CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL, my project wasn't looked to use external flash for settings but just for a filesystem, so i did not push away inverstigation...

    but my compilation problem  was more generaly due to the fact that using mcuboot on my project was overriding (in fact remove) in partitions.yml the external flash partition declared in dts (?)... raison why using pm_static.yml and put my own "storagenor_part" entry solved the compilation. I also use a part of the external flash for mcuboot_secondary as we discussed...

    My current flashing problem is on a custom board with VSCode used very classicaly through the nrf extension since the beginning of the project...  i continue to look on it...

    Thanks for the links, i'll check this more deeply soon.

  • i did go through the flashing problem for now but by disabling the mcuboot_secondary on the external flash using then:

    app:
      address: 0xc200
      end_address: 0x85000
      region: flash_primary
      size: 0x78e00
    mcuboot:
      address: 0x0
      end_address: 0xc000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xc000
    mcuboot_pad:
      address: 0xc000
      end_address: 0xc200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0xc000
      end_address: 0x85000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size: 0x79000
      span: *id001
    mcuboot_primary_app:
      address: 0xc200
      end_address: 0x85000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0x78e00
      span: *id002
    mcuboot_secondary:
      address: 0x85000
      end_address: 0xfe000
      placement:
        after:
        - mcuboot_primary
        align:
          start: 0x1000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size: 0x79000
    storagenor_part:
      address: 0x000000
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x400000
      placement:
        align:
          start: 0x4
      region: external_flash
      size: 0x400000
    settings_storage:
      address: 0xfe000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000

    sadly i now have an address error mounting the fs:

    [00:00:00.042,236] <inf> flashdisk: Initialize device NAND
    [00:00:00.042,266] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 4194304
    [00:00:00.042,755] <err> flashdisk: Error -22 getting page info at offset 100000
    [00:00:00.042,785] <err> storage: Failed to mount filesystem

    the mounting code base is the same as in 

    /cfs-file/__key/communityserver-discussions-components-files/4/chat_5F00_support_5F00_case.zip

    referenced at https://devzone.nordicsemi.com/f/nordic-q-a/99806/flashdisk_init_runtime-error--22-while-getting-page-info-usb_msc-mass_storage_init-storage-init-error---aborting-usb-init

    maybe the flashing problem using mcuboot_secondary on external flash or simply mounting the flash ar correlated ?

  • Hi Pierre

    I see that your fs log says that you're trying to initialize a NAND device. Unfortunately the QSPI peripheral on the nRF52/53 series isn't designed to be used with NAND flash devices, and our QSPI drivers/libraries doesn't support it either, so you will have a hard time getting it up and running. Depending on what NAND device you're using, it might be possible, but it's not something we support or will be able to help you out with setting up I'm afraid. The QSPI peripheral and libraries only support the NOR flashes.

    Best regards,

    Simon

  • Thanks, i pass the problem with littlefs.

    I always have a pb with mcuboot_secondary partition on external drive at flashing step.

    i will post any solution i could found.

Related