do not open flash nor area partition

Hi Support,

I'm working on a project where I need to copy the contents of the internal flash from slot_0 to an external NOR flash partition. However, I'm currently unable to access the partition named fota-body. After building the project, I get the following errors when trying to access it:

Memory region         Used Size  Region Size  %age Used
           FLASH:       38948 B        48 KB     79.24%
             RAM:       22736 B       448 KB      4.96%
        IDT_LIST:          0 GB        32 KB      0.00%
[171/189] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj 
ccache /opt/nordic/ncs/toolchains/15b490767d/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -I/opt/nordic/ncs/v2.6.2/zephyr/include -I/Users/babos/Documents/github_fota_project/hexdump_slot_0/build/zephyr/include/generated -I/opt/nordic/ncs/v2.6.2/zephyr/soc/arm/nordic_nrf/nrf53 -I/opt/nordic/ncs/v2.6.2/zephyr/soc/common/nordic_nrf/. -I/opt/nordic/ncs/v2.6.2/zephyr/soc/arm/nordic_nrf/common/. -I/opt/nordic/ncs/v2.6.2/nrf/include -I/opt/nordic/ncs/v2.6.2/nrf/tests/include -I/opt/nordic/ncs/v2.6.2/modules/hal/cmsis/CMSIS/Core/Include -I/opt/nordic/ncs/v2.6.2/zephyr/modules/cmsis/. -I/opt/nordic/ncs/v2.6.2/modules/hal/nordic/nrfx -I/opt/nordic/ncs/v2.6.2/modules/hal/nordic/nrfx/drivers/include -I/opt/nordic/ncs/v2.6.2/modules/hal/nordic/nrfx/mdk -I/opt/nordic/ncs/v2.6.2/zephyr/modules/hal_nordic/nrfx/. -I/opt/nordic/ncs/v2.6.2/modules/lib/zcbor/include -isystem /opt/nordic/ncs/v2.6.2/zephyr/lib/libc/common/include -isystem /opt/nordic/ncs/v2.6.2/nrfxlib/crypto/nrf_cc312_platform/include -fno-strict-aliasing -Os -imacros /Users/babos/Documents/github_fota_project/hexdump_slot_0/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=/opt/nordic/ncs/toolchains/15b490767d/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros /opt/nordic/ncs/v2.6.2/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/Users/babos/Documents/github_fota_project/hexdump_slot_0=CMAKE_SOURCE_DIR -fmacro-prefix-map=/opt/nordic/ncs/v2.6.2/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/opt/nordic/ncs/v2.6.2=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c /Users/babos/Documents/github_fota_project/hexdump_slot_0/src/main.c
In file included from /opt/nordic/ncs/v2.6.2/zephyr/include/zephyr/storage/flash_map.h:275,
                 from /Users/babos/Documents/github_fota_project/hexdump_slot_0/src/main.c:3:
/Users/babos/Documents/github_fota_project/hexdump_slot_0/src/main.c: In function 'main':
/opt/nordic/ncs/v2.6.2/nrf/include/flash_map_pm.h:43:22: error: 'PM_fota_body_ID' undeclared (first use in this function); did you mean 'fa_fota_body'?
   43 | #define PM_ID(label) PM_##label##_ID
      |                      ^~~
/opt/nordic/ncs/v2.6.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)
      |                                   ^~~~~
/opt/nordic/ncs/v2.6.2/nrf/include/flash_map_pm.h:49:30: note: in expansion of macro 'FIXED_PARTITION_ID'
   49 | #define FLASH_AREA_ID(label) FIXED_PARTITION_ID(label)
      |                              ^~~~~~~~~~~~~~~~~~
/Users/babos/Documents/github_fota_project/hexdump_slot_0/src/main.c:82:29: note: in expansion of macro 'FLASH_AREA_ID'
   82 |       err = flash_area_open(FLASH_AREA_ID(fota_body), &fa_fota_body);
      |                             ^~~~~~~~~~~~~
/opt/nordic/ncs/v2.6.2/nrf/include/flash_map_pm.h:43:22: note: each undeclared identifier is reported only once for each function it appears in
   43 | #define PM_ID(label) PM_##label##_ID
      |                      ^~~
/opt/nordic/ncs/v2.6.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)
      |                                   ^~~~~
/opt/nordic/ncs/v2.6.2/nrf/include/flash_map_pm.h:49:30: note: in expansion of macro 'FIXED_PARTITION_ID'
   49 | #define FLASH_AREA_ID(label) FIXED_PARTITION_ID(label)
      |                              ^~~~~~~~~~~~~~~~~~
/Users/babos/Documents/github_fota_project/hexdump_slot_0/src/main.c:82:29: note: in expansion of macro 'FLASH_AREA_ID'
   82 |       err = flash_area_open(FLASH_AREA_ID(fota_body), &fa_fota_body);
      |                             ^~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/15b490767d/bin/cmake --build /Users/babos/Documents/github_fota_project/hexdump_slot_0/build

 *  The terminal process terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

It seems like the partition fota-body is not being defined properly in the build, or it's missing from the partition manager configuration. I've tried using FLASH_AREA_ID(FOTA_BODY_PARTITION_ID) but get compilation errors because PM_FOTA_BODY_ID (or whatever index it resolves to) is undefined.

My goal is to build a 'delta FOTA' system where I can generate and write only the differences between the current firmware and a new image to slot_1, stored in external flash, before performing a firmware swap. This approach is intended to reduce write time and flash wear. However, I'm currently blocked by this partition access issue and can't proceed.

I'm attaching a demo project that reproduces the issue. Any help would be greatly appreciated.

When I comment this code, it correctly reads part of the slot_0 without any issues.
I suspect the fota_body partition is either not properly defined in the partition manager (.yml) or it’s not being exposed with the expected PM_ macro during build.

   // Get information about the slot_0 partition using the flash_map API
   // If I comment out the line below, the project compiles successfully, but I’m still unable to open the fota_body area.
   // =======================================================================================
   const struct flash_area *fa_fota_body;
   err = flash_area_open(FLASH_AREA_ID(fota_body), &fa_fota_body);
   if (err)
   {
      LOG_ERR("Errore nell'apertura della partizione QSPI (fota_body): %d", err);
      flash_area_close(fa);
      return -1;



Best regards,
Babos

ToolChain 2.8.0
SDK 2.6.2

Archivio.zip


Parents
  • Hello Babos,

    Please check the generated pm_config.h header in your build folder to find the symbols generated for your pm static file (build/zephyr/include/generated). Also, the external_flash flash region does not specify which Q/SPI flash device you are using which is required, see https://github.com/nrfconnect/sdk-connectedhomeip/blob/e6a1e8e9a010c641c9998e197e65bea15cce8c11/examples/all-clusters-app/nrfconnect/configuration/nrf7002dk_nrf5340_cpuapp/pm_static_dfu.yml#L51 

    Best regards,

    Vidar

  • Hi Vidar,

    now the pm_static.yml:

    ### EXTERNAL FLASH PARTITION TABLE ###
    
    external_flash:
      address: 0x0
      device: MX25R64
      end_address: 0x800000
      region: external_flash
      size: 0x800000 # 8MB
    
    fota_header: # Padding di 32kB con informazioni sulla versione
      address: 0x0
      device: MX25R64
      region: external_flash
      size: 0x8000 # 32kB
    
    fota_body: # Fota Body
      address: 0x8000
      device: MX25R64
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0x78000 # 480 kB
    
    custom_array: # Firmware BHI360
      address: 0x80000
      device: MX25R64
      region: external_flash
      size: 0x80000 # 512 kB
    
    configurations: # Configurazioni
      address: 0x100000
      device: MX25R64
      region: external_flash
      size: 0x40000 # 256 kB
    
    EMPTY_1: # I restanti
      address: 0x140000
      device: MX25R64
      region: external_flash
      size: 0x6C0000 # 6.75 MB


    then, pm_config.h:
    /* File generated by /opt/nordic/ncs/v2.6.2/nrf/scripts/partition_manager_output.py, do not modify */
    #ifndef PM_CONFIG_H__
    #define PM_CONFIG_H__
    #define PM_APP_OFFSET 0x0
    #define PM_APP_ADDRESS 0x0
    #define PM_APP_END_ADDRESS 0x100000
    #define PM_APP_SIZE 0x100000
    #define PM_APP_NAME app
    #define PM_APP_ID 0
    #define PM_app_ID PM_APP_ID
    #define PM_app_IS_ENABLED 1
    #define PM_0_LABEL APP
    #define PM_APP_DEV flash_controller
    #define PM_APP_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
    #define PM_OTP_OFFSET 0x0
    #define PM_OTP_ADDRESS 0xff8100
    #define PM_OTP_END_ADDRESS 0xff83fc
    #define PM_OTP_SIZE 0x2fc
    #define PM_OTP_NAME otp
    #define PM_SRAM_PRIMARY_OFFSET 0x0
    #define PM_SRAM_PRIMARY_ADDRESS 0x20000000
    #define PM_SRAM_PRIMARY_END_ADDRESS 0x20080000
    #define PM_SRAM_PRIMARY_SIZE 0x80000
    #define PM_SRAM_PRIMARY_NAME sram_primary
    #define PM_NUM 1
    #define PM_ALL_BY_SIZE "otp sram_primary app"
    #define PM_ADDRESS 0x0
    #define PM_SIZE 0x100000
    #define PM_SRAM_ADDRESS 0x20000000
    #define PM_SRAM_SIZE 0x80000
    #endif /* PM_CONFIG_H__ */


    are all right for you ?
    I don't see external flash section

    Thx's always,

    Babos

  • maybe this was missing in the overlay:
    / {
    chosen {
    nordic,pm-ext-flash = &mx25r64;
    };

    };

    after add:
    /* File generated by /opt/nordic/ncs/v2.6.2/nrf/scripts/partition_manager_output.py, do not modify */
    #ifndef PM_CONFIG_H__
    #define PM_CONFIG_H__
    #define PM_APP_OFFSET 0x0
    #define PM_APP_ADDRESS 0x0
    #define PM_APP_END_ADDRESS 0x100000
    #define PM_APP_SIZE 0x100000
    #define PM_APP_NAME app
    #define PM_APP_ID 0
    #define PM_app_ID PM_APP_ID
    #define PM_app_IS_ENABLED 1
    #define PM_0_LABEL APP
    #define PM_APP_DEV flash_controller
    #define PM_APP_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
    #define PM_EXTERNAL_FLASH_OFFSET 0x0
    #define PM_EXTERNAL_FLASH_ADDRESS 0x0
    #define PM_EXTERNAL_FLASH_END_ADDRESS 0x800000
    #define PM_EXTERNAL_FLASH_SIZE 0x800000
    #define PM_EXTERNAL_FLASH_NAME external_flash
    #define PM_EXTERNAL_FLASH_ID 1
    #define PM_external_flash_ID PM_EXTERNAL_FLASH_ID
    #define PM_external_flash_IS_ENABLED 1
    #define PM_1_LABEL EXTERNAL_FLASH
    #define PM_EXTERNAL_FLASH_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_EXTERNAL_FLASH_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_FOTA_HEADER_OFFSET 0x0
    #define PM_FOTA_HEADER_ADDRESS 0x0
    #define PM_FOTA_HEADER_END_ADDRESS 0x8000
    #define PM_FOTA_HEADER_SIZE 0x8000
    #define PM_FOTA_HEADER_NAME fota_header
    #define PM_FOTA_HEADER_ID 2
    #define PM_fota_header_ID PM_FOTA_HEADER_ID
    #define PM_fota_header_IS_ENABLED 1
    #define PM_2_LABEL FOTA_HEADER
    #define PM_FOTA_HEADER_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_FOTA_HEADER_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_FOTA_BODY_OFFSET 0x8000
    #define PM_FOTA_BODY_ADDRESS 0x8000
    #define PM_FOTA_BODY_END_ADDRESS 0x80000
    #define PM_FOTA_BODY_SIZE 0x78000
    #define PM_FOTA_BODY_NAME fota_body
    #define PM_FOTA_BODY_ID 3
    #define PM_fota_body_ID PM_FOTA_BODY_ID
    #define PM_fota_body_IS_ENABLED 1
    #define PM_3_LABEL FOTA_BODY
    #define PM_FOTA_BODY_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_FOTA_BODY_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_CUSTOM_ARRAY_OFFSET 0x80000
    #define PM_CUSTOM_ARRAY_ADDRESS 0x80000
    #define PM_CUSTOM_ARRAY_END_ADDRESS 0x100000
    #define PM_CUSTOM_ARRAY_SIZE 0x80000
    #define PM_CUSTOM_ARRAY_NAME custom_array
    #define PM_CUSTOM_ARRAY_ID 4
    #define PM_custom_array_ID PM_CUSTOM_ARRAY_ID
    #define PM_custom_array_IS_ENABLED 1
    #define PM_4_LABEL CUSTOM_ARRAY
    #define PM_CUSTOM_ARRAY_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_CUSTOM_ARRAY_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_CONFIGURATIONS_OFFSET 0x100000
    #define PM_CONFIGURATIONS_ADDRESS 0x100000
    #define PM_CONFIGURATIONS_END_ADDRESS 0x140000
    #define PM_CONFIGURATIONS_SIZE 0x40000
    #define PM_CONFIGURATIONS_NAME configurations
    #define PM_CONFIGURATIONS_ID 5
    #define PM_configurations_ID PM_CONFIGURATIONS_ID
    #define PM_configurations_IS_ENABLED 1
    #define PM_5_LABEL CONFIGURATIONS
    #define PM_CONFIGURATIONS_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_CONFIGURATIONS_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_EMPTY_1_OFFSET 0x140000
    #define PM_EMPTY_1_ADDRESS 0x140000
    #define PM_EMPTY_1_END_ADDRESS 0x800000
    #define PM_EMPTY_1_SIZE 0x6c0000
    #define PM_EMPTY_1_NAME EMPTY_1
    #define PM_EMPTY_1_ID 6
    #define PM_empty_1_ID PM_EMPTY_1_ID
    #define PM_empty_1_IS_ENABLED 1
    #define PM_6_LABEL EMPTY_1
    #define PM_EMPTY_1_DEV DT_CHOSEN(nordic_pm_ext_flash)
    #define PM_EMPTY_1_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    #define PM_OTP_OFFSET 0x0
    #define PM_OTP_ADDRESS 0xff8100
    #define PM_OTP_END_ADDRESS 0xff83fc
    #define PM_OTP_SIZE 0x2fc
    #define PM_OTP_NAME otp
    #define PM_SRAM_PRIMARY_OFFSET 0x0
    #define PM_SRAM_PRIMARY_ADDRESS 0x20000000
    #define PM_SRAM_PRIMARY_END_ADDRESS 0x20080000
    #define PM_SRAM_PRIMARY_SIZE 0x80000
    #define PM_SRAM_PRIMARY_NAME sram_primary
    #define PM_NUM 7
    #define PM_ALL_BY_SIZE "otp fota_header configurations fota_body custom_array sram_primary app EMPTY_1 external_flash"
    #define PM_ADDRESS 0x0
    #define PM_SIZE 0x100000
    #define PM_SRAM_ADDRESS 0x20000000
    #define PM_SRAM_SIZE 0x80000
    #endif /* PM_CONFIG_H__ */


    thank you so much
    Babos
  • Thanks for the update Yes, the pm-ext-flash property must be set as well (External flash memory partitions)

Reply Children
No Data
Related