extxip_smp_srv fails compiling for nrf5340dk non-secure target

Hello,

Working on Ubuntu 22.04 with nRF Connect SDK 2.6.1 for the target nrf5340dk_nrf5340_cpuapp_ns (= with TF-M).

My application image became too large. I want to split the app image over internal and external memory. I'm using extxip_smp_svr as example. It compiles & runs for the target nrf5340dk_nrf5340_cpuapp.

When building this sample for the nrf5340dk_nrf5340_cpuapp_ns target (with TF-M), compilation fails:

In file included from /home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/zephyr/include/sysflash/sysflash.h:10,
                 from /home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/bootutil/src/bootutil_priv.h:33,
                 from /home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/bootutil/src/tlv.c:24:
/home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h: In function '__flash_area_ids_for_slot':
/home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h:49:37: error: 'PM_MCUBOOT_PRIMARY_2_ID' undeclared (first use in this function); did you mean 'PM_MCUBOOT_PRIMARY_1_ID'?
   49 | #define FLASH_AREA_IMAGE_2_SLOTS    PM_MCUBOOT_PRIMARY_2_ID, PM_MCUBOOT_SECONDARY_2_ID
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~
/home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h:59:29: note: in expansion of macro 'FLASH_AREA_IMAGE_2_SLOTS'
   59 |                             FLASH_AREA_IMAGE_2_SLOTS
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/nrf-official/v2.6.1/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h:67:9: note: in expansion of macro 'ALL_AVAILABLE_SLOTS'
   67 |         ALL_AVAILABLE_SLOTS
      |         ^~~~~~~~~~~~~~~~~~~

What do I need to change in this sample to make it compile for the non-secure target?

(PS my current project fails compiling with the same error when trying to add support for a split application image. That's why I looked into Nordic's sample to find how that is configured differently. Unfortunately it fails too. I saw the same error in the past when experimenting with CONFIG_BOOT_UPGRADE_ONLY=n in a multi-image build)

Thank you!

Kind regards,
francis

Parents
  • Hello,

    I could solve the error described above by copying the files:
    - boards/nrf5340dk_nrf5340_cpuapp.overlay
    - boards/nrf5340dk_nrf5340_cpuapp.conf

    as
    - boards/nrf5340dk_nrf5340_cpuapp_ns.overlay
    - boards/nrf5340dk_nrf5340_cpuapp_ns.conf

    During linking I now run into this error:
    /home/dev/ncs/toolchains/2be090971e/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `bss' will not fit in region `RAM'
    /home/dev/ncs/toolchains/2be090971e/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `RAM' overflowed by 277336 bytes
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.

    Is this due to the static pm_static.yml? Any suggestion on how to fix this?
    Do _ns targets (TF-M) really need this amount (270k) of additional RAM (or is this a code segment overwriting the RAM segment by a large amount)?

    - I've tried to move the entries from build/partitions.yml (there are new entries related to tfm) into the pm_static.yml. But the error is still the same; the RAM is still overflowed by the same amount of bytes (277336).

    - I've checked the bss segment in the zephyr_pre0.elf; only 2831h

      [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
      [32] bss               NOBITS          200029e8 021a38 002831 00  WA  0   0  8


    Thank you!

    Kind regards,
    francis

  • Hi, 

    I suggest that you start by looking at Memory optimization and try to reduce some buffers to see if the error reports a smaller overflow. Please be aware that the nrf5340dk_nrf5340_cpuapp_ns is not listed in the Requirements of the SMP Server with external XIP sample. That means it might not be supported. 

    Regards,
    Amanda H. 

  • Hello Amanda,

    Should I open a new ticket with a question regarding the "Unable to find bootable image"?

    Thank you. Kind regards,
    francis

  • Are you still using pm_static.yml with removed RAM section or all generated?

  • Hello Amanda,

    Sorry for coming back late ...

    You are right, there is the original pm_static.yml that is reused for the "ns" target.
    If I move that aside, and thereby fall-back on the generated build/partition.yml, the build fails (I guess you're seeing this as well).
    At first eye-sight there are considerable differences between the resulting build/partition.yml and that original pm_static.yml for the "ns" target case.
    Until now, I've not changed this pm_static.yml (e.g. removed the RAM section). I only added CONFIG_MCUBOOT_USE_ALL_AVAILABLE_RAM=y to boards/nrf5340dk_nrf5340_cpuapp_ns.conf.



    1. I try to see if I can make sense out of these two files and reconcile these.

    2. I would assume that the generated build/partition.yml should not make the build fail. Might this be an issue internal to the NCS and require an internal ticket?

    Kind regards,
    francis

  • Hello Amanda,

    I've tried to reconcile the pm_static.yml (the one included in the sample) with the build/partiontion.yml (after compiling for non-secure). Here is that new version:

    ###
    ### Ext. flash
    ###
    
    # The app update image
    mcuboot_secondary:
      address: 0x0
      device: MX25R64   # Is this better: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xe0000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xe0000    # TODO check size mcuboot_primary
    
    # The network update image
    mcuboot_secondary_1:
      address: 0xe0000
      device: MX25R64 # Is this better: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x120000
      region: external_flash
      size: 0x40000
    
    # Since verything is aligned, do see the purpose of this EMPTY_1 partition
    # EMPTY_1:
    #   address: 0x114000
    #   device: MX25R64
    #   end_address: 0x120000
    #   region: external_flash
    #   size: 0xc000
    
    mcuboot_primary_2:      # for app part running in ext. flash
      address: 0x120000
      device: MX25R64
      end_address: 0x160000
      region: external_flash
      size: 0x40000
    
    mcuboot_secondary_2:    # for the app part in ext. flash update
      address: 0x160000
      device: MX25R64
      end_address: 0x1a0000
      region: external_flash
      size: 0x40000
    
    external_flash:
      address: 0x1a0000
      device: MX25R64
      end_address: 0x800000
      region: external_flash
      size: 0x660000
    
    
    ###
    ### Int. flash (primary)
    ###
    
    # The bootloader
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    
    # Everything except the bootloader & settings storage space
    mcuboot_primary:
      address: 0x10000
      end_address: 0xf0000
      orig_span: &id001
      - mcuboot_pad
      - tfm
      - app
      region: flash_primary
      size: 0xe0000
      span: *id001
    
    tfm_secure:
      address: 0x10000
      end_address: 0x20000
      orig_span: &id007
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x10000
      span: *id007
    
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x4000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xf0000
      orig_span: &id002
      - tfm
      - app
      region: flash_primary
      size: 0xdfe00
      span: *id002
    
    tfm:
      address: 0x10200
      end_address: 0x20000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0xfe00
      
    tfm_nonsecure:
      address: 0x20000
      end_address: 0xf0000
      orig_span: &id006
      - app
      region: flash_primary
      size: 0xd0000
      span: *id006
    
    app:
      address: 0x20000
      end_address: 0xf0000   # in NCS doc ex. this does not complete uses all space (until 0xe4000)
      region: flash_primary
      size: 0xd0000
    
    settings_storage:
      address: 0xf0000
      end_address: 0x100000
      region: flash_primary
      size: 0x10000
    
    
    ###
    ### OTP
    ###
    
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    
    
    ###
    ### RAM flash
    ###
    
    ram_flash:
      address: 0x40000
      end_address: 0x40000
      region: ram_flash
      size: 0x0
    
    mcuboot_primary_1:    # for the network core update
      address: 0x0
      device: nordic_ram_flash_controller
      end_address: 0x40000
      region: ram_flash
      size: 0x40000
    
    
    ###
    ### SRAM
    ###
    
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20080000
      orig_span: &id003
      - pcd_sram
      - tfm_sram
      - sram_primary
      - rpmsg_nrf53_sram
      region: sram_primary
      size: 0x80000
      span: *id003
    
    sram_secure:
      address: 0x20000000
      end_address: 0x2000a000
      orig_span: &id005
      - pcd_sram
      - tfm_sram
      region: sram_primary
      size: 0xa000
      span: *id005
    pcd_sram:
      address: 0x20000000
      end_address: 0x20002000
      placement:
        before:
        - tfm_sram
      region: sram_primary
      size: 0x2000
    tfm_sram:
      address: 0x20002000
      end_address: 0x2000a000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000
    
    sram_nonsecure:
      address: 0x2000a000
      end_address: 0x20080000
      orig_span: &id004
      - sram_primary
      - rpmsg_nrf53_sram
      region: sram_primary
      size: 0x76000
      span: *id004
    sram_primary:
      address: 0x2000a000
      end_address: 0x20070000
      region: sram_primary
      size: 0x66000
    rpmsg_nrf53_sram:
      address: 0x20070000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0x10000
    
    

    The linker_arm_extxip.ld is not changed as the offset in ext. flash did not change. The resulting memory report:

      external_flash (0x800000 - 8192kB): 
    +-------------------------------------------------+
    | 0x0: mcuboot_secondary (0xe0000 - 896kB)        |
    | 0xe0000: mcuboot_secondary_1 (0x40000 - 256kB)  |
    | 0x120000: mcuboot_primary_2 (0x40000 - 256kB)   |
    | 0x160000: mcuboot_secondary_2 (0x40000 - 256kB) |
    | 0x1a0000: external_flash (0x660000 - 6528kB)    |
    +-------------------------------------------------+
    
      flash_primary (0x100000 - 1024kB): 
    +--------------------------------------------------+
    | 0x0: mcuboot (0x10000 - 64kB)                    |
    +---0x10000: mcuboot_primary (0xe0000 - 896kB)-----+
    +---0x10000: tfm_secure (0x10000 - 64kB)-----------+
    | 0x10000: mcuboot_pad (0x200 - 512B)              |
    +---0x10200: mcuboot_primary_app (0xdfe00 - 895kB)-+
    | 0x10200: tfm (0xfe00 - 63kB)                     |
    +---0x20000: tfm_nonsecure (0xd0000 - 832kB)-------+
    | 0x20000: app (0xd0000 - 832kB)                   |
    +--------------------------------------------------+
    | 0xf0000: settings_storage (0x10000 - 64kB)       |
    +--------------------------------------------------+
    
      otp (0x2fc - 764B): 
    +------------------------------+
    | 0xff8100: otp (0x2fc - 764B) |
    +------------------------------+
    
      ram_flash (0x40000 - 256kB): 
    +------------------------------------------+
    | 0x0: mcuboot_primary_1 (0x40000 - 256kB) |
    | 0x40000: ram_flash (0x0 - 0B)            |
    +------------------------------------------+
    
      sram_primary (0x80000 - 512kB): 
    +------------------------------------------------+
    +---0x20000000: mcuboot_sram (0x80000 - 512kB)---+
    +---0x20000000: sram_secure (0xa000 - 40kB)------+
    | 0x20000000: pcd_sram (0x2000 - 8kB)            |
    | 0x20002000: tfm_sram (0x8000 - 32kB)           |
    +---0x2000a000: sram_nonsecure (0x76000 - 472kB)-+
    | 0x2000a000: sram_primary (0x66000 - 408kB)     |
    | 0x20070000: rpmsg_nrf53_sram (0x10000 - 64kB)  |
    +------------------------------------------------+
    
     CPUNET flash_primary (0x40000 - 256kB): 
    +--------------------------------------------+
    +---0x1000000: b0n_container (0x8800 - 34kB)-+
    | 0x1000000: b0n (0x8580 - 33kB)             |
    | 0x1008580: provision (0x280 - 640B)        |
    +---0x1008800: app (0x37800 - 222kB)---------+
    | 0x1008800: hci_ipc (0x37800 - 222kB)       |
    +--------------------------------------------+
    
     CPUNET sram_primary (0x10000 - 64kB): 
    +-------------------------------------------+
    | 0x21000000: sram_primary (0x10000 - 64kB) |
    +-------------------------------------------+

    Unfortunately I still end up with the mcuboot error:

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    I: MCUBOOT main!
    I: Starting bootloader ...
    I: Image index: 0, Swap type: none
    I: Image index: 1, Swap type: none
    I: Image index: 2, Swap type: none
    E: Unable to find bootable image
    

    Could you have a look what might be wrongly configured? Thank you.

    For bothe the secure and non-secure variants, I have a question on the app image that goes on the external flash. Is this the qspi_flash.hex? When I open this with the desktop programmer, it only shows 9232 bytes while the pm_static.yml seems to reserve 256k. Is there something wrong? (the programmer is showing the correct address 0x1012.0200)

    Kind regards,
    francis

Reply
  • Hello Amanda,

    I've tried to reconcile the pm_static.yml (the one included in the sample) with the build/partiontion.yml (after compiling for non-secure). Here is that new version:

    ###
    ### Ext. flash
    ###
    
    # The app update image
    mcuboot_secondary:
      address: 0x0
      device: MX25R64   # Is this better: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xe0000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xe0000    # TODO check size mcuboot_primary
    
    # The network update image
    mcuboot_secondary_1:
      address: 0xe0000
      device: MX25R64 # Is this better: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x120000
      region: external_flash
      size: 0x40000
    
    # Since verything is aligned, do see the purpose of this EMPTY_1 partition
    # EMPTY_1:
    #   address: 0x114000
    #   device: MX25R64
    #   end_address: 0x120000
    #   region: external_flash
    #   size: 0xc000
    
    mcuboot_primary_2:      # for app part running in ext. flash
      address: 0x120000
      device: MX25R64
      end_address: 0x160000
      region: external_flash
      size: 0x40000
    
    mcuboot_secondary_2:    # for the app part in ext. flash update
      address: 0x160000
      device: MX25R64
      end_address: 0x1a0000
      region: external_flash
      size: 0x40000
    
    external_flash:
      address: 0x1a0000
      device: MX25R64
      end_address: 0x800000
      region: external_flash
      size: 0x660000
    
    
    ###
    ### Int. flash (primary)
    ###
    
    # The bootloader
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    
    # Everything except the bootloader & settings storage space
    mcuboot_primary:
      address: 0x10000
      end_address: 0xf0000
      orig_span: &id001
      - mcuboot_pad
      - tfm
      - app
      region: flash_primary
      size: 0xe0000
      span: *id001
    
    tfm_secure:
      address: 0x10000
      end_address: 0x20000
      orig_span: &id007
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x10000
      span: *id007
    
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x4000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xf0000
      orig_span: &id002
      - tfm
      - app
      region: flash_primary
      size: 0xdfe00
      span: *id002
    
    tfm:
      address: 0x10200
      end_address: 0x20000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0xfe00
      
    tfm_nonsecure:
      address: 0x20000
      end_address: 0xf0000
      orig_span: &id006
      - app
      region: flash_primary
      size: 0xd0000
      span: *id006
    
    app:
      address: 0x20000
      end_address: 0xf0000   # in NCS doc ex. this does not complete uses all space (until 0xe4000)
      region: flash_primary
      size: 0xd0000
    
    settings_storage:
      address: 0xf0000
      end_address: 0x100000
      region: flash_primary
      size: 0x10000
    
    
    ###
    ### OTP
    ###
    
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    
    
    ###
    ### RAM flash
    ###
    
    ram_flash:
      address: 0x40000
      end_address: 0x40000
      region: ram_flash
      size: 0x0
    
    mcuboot_primary_1:    # for the network core update
      address: 0x0
      device: nordic_ram_flash_controller
      end_address: 0x40000
      region: ram_flash
      size: 0x40000
    
    
    ###
    ### SRAM
    ###
    
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20080000
      orig_span: &id003
      - pcd_sram
      - tfm_sram
      - sram_primary
      - rpmsg_nrf53_sram
      region: sram_primary
      size: 0x80000
      span: *id003
    
    sram_secure:
      address: 0x20000000
      end_address: 0x2000a000
      orig_span: &id005
      - pcd_sram
      - tfm_sram
      region: sram_primary
      size: 0xa000
      span: *id005
    pcd_sram:
      address: 0x20000000
      end_address: 0x20002000
      placement:
        before:
        - tfm_sram
      region: sram_primary
      size: 0x2000
    tfm_sram:
      address: 0x20002000
      end_address: 0x2000a000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000
    
    sram_nonsecure:
      address: 0x2000a000
      end_address: 0x20080000
      orig_span: &id004
      - sram_primary
      - rpmsg_nrf53_sram
      region: sram_primary
      size: 0x76000
      span: *id004
    sram_primary:
      address: 0x2000a000
      end_address: 0x20070000
      region: sram_primary
      size: 0x66000
    rpmsg_nrf53_sram:
      address: 0x20070000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0x10000
    
    

    The linker_arm_extxip.ld is not changed as the offset in ext. flash did not change. The resulting memory report:

      external_flash (0x800000 - 8192kB): 
    +-------------------------------------------------+
    | 0x0: mcuboot_secondary (0xe0000 - 896kB)        |
    | 0xe0000: mcuboot_secondary_1 (0x40000 - 256kB)  |
    | 0x120000: mcuboot_primary_2 (0x40000 - 256kB)   |
    | 0x160000: mcuboot_secondary_2 (0x40000 - 256kB) |
    | 0x1a0000: external_flash (0x660000 - 6528kB)    |
    +-------------------------------------------------+
    
      flash_primary (0x100000 - 1024kB): 
    +--------------------------------------------------+
    | 0x0: mcuboot (0x10000 - 64kB)                    |
    +---0x10000: mcuboot_primary (0xe0000 - 896kB)-----+
    +---0x10000: tfm_secure (0x10000 - 64kB)-----------+
    | 0x10000: mcuboot_pad (0x200 - 512B)              |
    +---0x10200: mcuboot_primary_app (0xdfe00 - 895kB)-+
    | 0x10200: tfm (0xfe00 - 63kB)                     |
    +---0x20000: tfm_nonsecure (0xd0000 - 832kB)-------+
    | 0x20000: app (0xd0000 - 832kB)                   |
    +--------------------------------------------------+
    | 0xf0000: settings_storage (0x10000 - 64kB)       |
    +--------------------------------------------------+
    
      otp (0x2fc - 764B): 
    +------------------------------+
    | 0xff8100: otp (0x2fc - 764B) |
    +------------------------------+
    
      ram_flash (0x40000 - 256kB): 
    +------------------------------------------+
    | 0x0: mcuboot_primary_1 (0x40000 - 256kB) |
    | 0x40000: ram_flash (0x0 - 0B)            |
    +------------------------------------------+
    
      sram_primary (0x80000 - 512kB): 
    +------------------------------------------------+
    +---0x20000000: mcuboot_sram (0x80000 - 512kB)---+
    +---0x20000000: sram_secure (0xa000 - 40kB)------+
    | 0x20000000: pcd_sram (0x2000 - 8kB)            |
    | 0x20002000: tfm_sram (0x8000 - 32kB)           |
    +---0x2000a000: sram_nonsecure (0x76000 - 472kB)-+
    | 0x2000a000: sram_primary (0x66000 - 408kB)     |
    | 0x20070000: rpmsg_nrf53_sram (0x10000 - 64kB)  |
    +------------------------------------------------+
    
     CPUNET flash_primary (0x40000 - 256kB): 
    +--------------------------------------------+
    +---0x1000000: b0n_container (0x8800 - 34kB)-+
    | 0x1000000: b0n (0x8580 - 33kB)             |
    | 0x1008580: provision (0x280 - 640B)        |
    +---0x1008800: app (0x37800 - 222kB)---------+
    | 0x1008800: hci_ipc (0x37800 - 222kB)       |
    +--------------------------------------------+
    
     CPUNET sram_primary (0x10000 - 64kB): 
    +-------------------------------------------+
    | 0x21000000: sram_primary (0x10000 - 64kB) |
    +-------------------------------------------+

    Unfortunately I still end up with the mcuboot error:

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    I: MCUBOOT main!
    I: Starting bootloader ...
    I: Image index: 0, Swap type: none
    I: Image index: 1, Swap type: none
    I: Image index: 2, Swap type: none
    E: Unable to find bootable image
    

    Could you have a look what might be wrongly configured? Thank you.

    For bothe the secure and non-secure variants, I have a question on the app image that goes on the external flash. Is this the qspi_flash.hex? When I open this with the desktop programmer, it only shows 9232 bytes while the pm_static.yml seems to reserve 256k. Is there something wrong? (the programmer is showing the correct address 0x1012.0200)

    Kind regards,
    francis

Children
No Data
Related