Debug build

Hello,

I created a copy of the nRF Cloud CoAP Device Message sample application for the Thingy 91 X.  It builds using the default optimization level.  However it fails to build when I select "Optimize for debugging (-Og)".

The tfm_s section is too small for the generated code.

Here is a copy of the build output.

-- Build files have been written to: D:/Work/nrf_cloud_coap_device_message/build/nrf_cloud_coap_device_message/tfm
[17/493] Performing build step for 'tfm'
[149/153] Linking C executable bin\tfm_s.axf
FAILED: bin/tfm_s.axf
cmd.exe /C "cd . && C:\ncs\toolchains\fd21892d0f\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -mcpu=cortex-m33 -g -mcpu=cortex-m33 --entry=Reset_Handler -specs=nano.specs -specs=nosys.specs -Wl,-check-sections -Wl,-fatal-warnings -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -Wl,-Map=D:/Work/nrf_cloud_coap_device_message/build/nrf_cloud_coap_device_message/tf                                                                                                                                                    fm/bin/tfm_s.map -mfloat-abi=hard -mfpu=fpv5-sp-d16 -Wl,--cmse-implib,--out-implib=D:/Work/nrf_cloud_coap_device_message/build/nrf_cloud_coap_device_message/tfm/secure_fw/s_veneers.o -T D:/Work/nrf_clo                                                                                                                                                    oud_coap_device_message/build/nrf_cloud_coap_device_message/tfm/platform/target/nrf91/nrf_common/CMakeFiles/tfm_s_scatter.dir/./__/__/__/__/generated/platform/ext/common/gcc/tfm_common_s.ld @CMakeFiles                                                                                                                                                    s\tfm_s.rsp -o bin\tfm_s.axf  && cd ."
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3971b of bin\tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3c520 of bin\tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3fc40 of bin\tfm_s.axf section `.gnu.sgstubs' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: bin\tfm_s.axf section `.TFM_DATA' will not fit in region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3971b of bin\tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3c520 of bin\tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x3fc40 of bin\tfm_s.axf section `.gnu.sgstubs' is not within region `FLASH'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `FLASH' overflowed by 32236 bytes
Memory region         Used Size  Region Size  %age Used
           FLASH:       64492 B      32256 B    199.94%
             RAM:       14560 B        16 KB     88.87%
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

-----------------------------

I tried copying partitions.yml from the build folder to the root folder and modified to increase the tfm section.  Unfortunately the build process does not seem to recognize the memory map.

I tried naming it pm.yml and pm_static.yml.

Neither seem to be accepted.

Here is the options selected for the build configuration.

Here is the generated partitions.yml file.

app:
  address: 0x38000
  end_address: 0x100000
  region: flash_primary
  size: 0xc8000
app_image:
  address: 0x30200
  end_address: 0x100000
  region: flash_primary
  size: 0xcfe00
  span:
  - tfm
  - app
b0:
  address: 0x0
  end_address: 0x8000
  region: flash_primary
  size: 0x8000
b0_container:
  address: 0x0
  end_address: 0x8000
  region: flash_primary
  size: 0x8000
  span:
  - b0
external_flash:
  address: 0x4d2000
  end_address: 0x2000000
  region: external_flash
  size: 0x1b2e000
fmfu_storage:
  address: 0xd0000
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0x4d0000
  region: external_flash
  size: 0x400000
mcuboot:
  address: 0x8200
  end_address: 0x1c000
  region: flash_primary
  size: 0x13e00
mcuboot_pad:
  address: 0x30000
  end_address: 0x30200
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0x30000
  end_address: 0x100000
  region: flash_primary
  size: 0xd0000
  span:
  - mcuboot_pad
  - app
  - tfm
mcuboot_primary_app:
  address: 0x30200
  end_address: 0x100000
  region: flash_primary
  size: 0xcfe00
  span:
  - tfm
  - app
mcuboot_secondary:
  address: 0x0
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0xd0000
  region: external_flash
  share_size:
  - mcuboot_primary
  size: 0xd0000
mcuboot_sram:
  address: 0x20000000
  end_address: 0x20040000
  orig_span: &id001
  - sram_primary
  - nrf_modem_lib_rx
  - nrf_modem_lib_tx
  - nrf_modem_lib_ctrl
  - tfm_sram
  region: sram_primary
  size: 0x40000
  span: *id001
nrf_modem_lib_ctrl:
  address: 0x20004000
  end_address: 0x200044e8
  inside:
  - sram_nonsecure
  placement:
    after:
    - tfm_sram
    - start
  region: sram_primary
  size: 0x4e8
nrf_modem_lib_rx:
  address: 0x20006568
  end_address: 0x20008568
  inside:
  - sram_nonsecure
  placement:
    after:
    - nrf_modem_lib_tx
  region: sram_primary
  size: 0x2000
nrf_modem_lib_sram:
  address: 0x20004000
  end_address: 0x20008568
  orig_span: &id002
  - nrf_modem_lib_ctrl
  - nrf_modem_lib_tx
  - nrf_modem_lib_rx
  region: sram_primary
  size: 0x4568
  span: *id002
nrf_modem_lib_tx:
  address: 0x200044e8
  end_address: 0x20006568
  inside:
  - sram_nonsecure
  placement:
    after:
    - nrf_modem_lib_ctrl
  region: sram_primary
  size: 0x2080
otp:
  address: 0xff8388
  end_address: 0xff83fc
  region: otp
  size: 0x74
provision:
  address: 0xff8108
  end_address: 0xff8388
  region: otp
  size: 0x280
s0:
  address: 0x8000
  end_address: 0x1c000
  region: flash_primary
  size: 0x14000
  span:
  - mcuboot
  - s0_pad
s0_image:
  address: 0x8200
  end_address: 0x1c000
  region: flash_primary
  size: 0x13e00
  span:
  - mcuboot
s0_pad:
  address: 0x8000
  end_address: 0x8200
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
s1:
  address: 0x1c000
  end_address: 0x30000
  region: flash_primary
  size: 0x14000
  span:
  - s1_pad
  - s1_image
s1_image:
  address: 0x1c200
  end_address: 0x30000
  region: flash_primary
  share_size:
  - mcuboot
  size: 0x13e00
s1_pad:
  address: 0x1c000
  end_address: 0x1c200
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
settings_storage:
  address: 0x4d0000
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0x4d2000
  region: external_flash
  size: 0x2000
sram_nonsecure:
  address: 0x20004000
  end_address: 0x20040000
  orig_span: &id003
  - sram_primary
  - nrf_modem_lib_ctrl
  - nrf_modem_lib_tx
  - nrf_modem_lib_rx
  region: sram_primary
  size: 0x3c000
  span: *id003
sram_primary:
  address: 0x20008568
  end_address: 0x20040000
  region: sram_primary
  size: 0x37a98
sram_secure:
  address: 0x20000000
  end_address: 0x20004000
  orig_span: &id004
  - tfm_sram
  region: sram_primary
  size: 0x4000
  span: *id004
tfm:
  address: 0x30200
  end_address: 0x38000
  region: flash_primary
  size: 0x7e00
tfm_nonsecure:
  address: 0x38000
  end_address: 0x100000
  region: flash_primary
  size: 0xc8000
  span:
  - app
tfm_secure:
  address: 0x30000
  end_address: 0x38000
  region: flash_primary
  size: 0x8000
  span:
  - mcuboot_pad
  - tfm
tfm_sram:
  address: 0x20000000
  end_address: 0x20004000
  inside:
  - sram_secure
  placement:
    after:
    - start
  region: sram_primary
  size: 0x4000

Can someone help me work this out?

Parents
  • Hi,

    Assuming the intention is not to debug TF-M, I would recommend anohther approach, where you only build the application itself with debug optimization, and not TF-M (or other images). The most straight forward way to do this is as explained in this post. When using the nRF Cloud CoAP device message sample and using a build folder called "build", the path to the file you should edit is nrf/samples/cellular/nrf_cloud_coap_device_message/build/nrf_cloud_coap_device_message/zephyr/.config.

  • Your assumption is correct.

    I added the following line to the prj.conf file in the projects root folder

    CONFIG_SIZE_OPTIMIZATIONS=y

    Regarding

    "One way around this is to configure your project with CONFIG_SIZE_OPTIMIZATIONS, and afterwards go into menuconfig and change the application's optimization level. "

    where do I find menuconfig?

    I do not see a build option in "nRF Kconfig GUI" for app optimization level.

  • The debug information is not being included as the code with not run to a break point in main().

    Is there a way to increase the size of the tfm section?

  • For clarification I am using a Serger debug probe.

  • Hi,

    You want to debug the non-secure application, right? Then reserving more space for TF-M to make room for a debug build of that will not give any benefit. Can you check that the code size (which is printed after the build) of the non-secure application is larger when you build the debug build compared to when not? That would confirm that it worked (I verified this on my end).

    Note that some optimization is still performed with debug build (it is not the same as building with CONFIG_NO_OPTIMIZATIONS=y). So you will not be able to set a breakpoint on every line with CONFIG_DEBUG_OPTIMIZATIONS=y, but it normally gives a good compromise.

  • When targeting the nRF9151 DK I am able you use "Optimize for debugging  (-Og)" as it allocates 64k for TF-M.

    I need to be able to set break points when developing code.

    The benefit is that I can build the rest of my application with the -Og options.  Which is huge.

    Normal build

    [148/152] Linking C executable bin\tfm_s.axf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       31704 B      32256 B     98.29%
                 RAM:       10432 B        16 KB     63.67%
    [19/493] Performing install step for 'tfm'
    -- Install configuration: "MinSizeRel"
    ----- Installing platform NS -----
    [493/493] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      235512 B       800 KB     28.75%
                 RAM:       85264 B     227992 B     37.40%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from D:/Work/CommBrick/nrf_cloud_coap_device_message/build/nrf_cloud_coap_device_message/zephyr/zephyr.elf for board: thingy91x
    image.py: sign the payload
    image.py: sign the payload
    [6/215] Generating include/generated/zephyr/version.h
    -- Zephyr version: 4.2.99 (C:/ncs/v3.2.3/zephyr), build: ncs-v3.2.3
    [215/215] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       43532 B      81408 B     53.47%
                 RAM:       34856 B       256 KB     13.30%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from D:/Work/CommBrick/nrf_cloud_coap_device_message/build/mcuboot/zephyr/zephyr.elf for board: thingy91x
    [4/155] Generating include/generated/zephyr/version.h
    -- Zephyr version: 4.2.99 (C:/ncs/v3.2.3/zephyr), build: ncs-v3.2.3
    [155/155] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:         27 KB        32 KB     84.38%
                 RAM:       37336 B     227992 B     16.38%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from D:/Work/CommBrick/nrf_cloud_coap_device_message/build/b0/zephyr/zephyr.elf for board: thingy91x
    [6/215] Generating include/generated/zephyr/version.h
    -- Zephyr version: 4.2.99 (C:/ncs/v3.2.3/zephyr), build: ncs-v3.2.3
    [215/215] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       43532 B      81408 B     53.47%
                 RAM:       34856 B     227992 B     15.29%
            IDT_LIST:          0 GB        32 KB      0.00%

    Build with 

    # CONFIG_SIZE_OPTIMIZATIONS is not set
    CONFIG_DEBUG_OPTIMIZATIONS=y

    [117/121] Linking C executable bin\tfm_s.axf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       31704 B      32256 B     98.29%
                 RAM:       10432 B        16 KB     63.67%
    [474/474] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      289884 B       800 KB     35.39%
                 RAM:       85288 B     227992 B     37.41%
            IDT_LIST:          0 GB        32 KB      0.00%

  • Hi.

    I see. You can increase the TF-M partition with this partition layout. You can for instance put it in a pm_static_thingy91x_nrf9151_ns in the project root folder and point to it using "-DPM_STATIC_YML_FILE=pm_static_thingy91x_nrf9151_ns" as an extra CMake argument in the build configuration:

    b0:
      address: 0x0
      size: 0x8000
      region: flash_primary
    b0_container:
      address: 0x0
      size: 0x8000
      region: flash_primary
      span: [b0]
    s0:
      address: 0x8000
      size: 0x14000
      span: [mcuboot, s0_pad]
      region: flash_primary
    s0_pad:
      address: 0x8000
      size: 0x200
      share_size: [mcuboot_pad]
      region: flash_primary
    s0_image:
      address: 0x8200
      size: 0x13e00
      span: [mcuboot]
      region: flash_primary
    mcuboot:
      address: 0x8200
      size: 0x13e00
      region: flash_primary
    s1:
      address: 0x1c000
      size: 0x14000
      span: [s1_pad, s1_image]
      region: flash_primary
    s1_pad:
      address: 0x1c000
      size: 0x200
      region: flash_primary
      share_size: [mcuboot_pad]
    s1_image:
      address: 0x1c200
      size: 0x13e00
      share_size: [mcuboot]
      region: flash_primary
    mcuboot_primary:
      address: 0x30000
      size: 0xD0000
      span: [mcuboot_pad, app, tfm]
      region: flash_primary
    tfm_secure:
      address: 0x30000
      size: 0x10000
      span: [mcuboot_pad, tfm]
      region: flash_primary
    mcuboot_pad:
      address: 0x30000
      size: 0x200
      region: flash_primary
    mcuboot_primary_app:
      address: 0x30200
      size: 0xcfe00
      span: [tfm, app]
      region: flash_primary
    app_image:
      address: 0x30200
      size: 0xcfe00
      span: [tfm, app]
      region: flash_primary
    tfm:
      address: 0x30200
      size: 0xFE00
      region: flash_primary
    tfm_nonsecure:
      address: 0x40000
      size: 0xC0000
      span: [app]
      region: flash_primary
    app:
      address: 0x40000
      size: 0xC0000
      region: flash_primary
    
    mcuboot_secondary:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x0
      size: 0xD0000
      share_size: [mcuboot_primary]
      region: external_flash
    fmfu_storage:
      address: 0xD0000
      device: DT_CHOSEN(nordic_pm_ext_flash)
      region: external_flash
      size: 0x400000
    settings_storage:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x4D0000
      size: 0x2000
      region: external_flash
    

    With this, the TF-M partition is 64 kB and I see that the project builds with debug optimization enabled for all images. However, I do not have a Thingy91x at hand now, so I have not been able to test it.

Reply
  • Hi.

    I see. You can increase the TF-M partition with this partition layout. You can for instance put it in a pm_static_thingy91x_nrf9151_ns in the project root folder and point to it using "-DPM_STATIC_YML_FILE=pm_static_thingy91x_nrf9151_ns" as an extra CMake argument in the build configuration:

    b0:
      address: 0x0
      size: 0x8000
      region: flash_primary
    b0_container:
      address: 0x0
      size: 0x8000
      region: flash_primary
      span: [b0]
    s0:
      address: 0x8000
      size: 0x14000
      span: [mcuboot, s0_pad]
      region: flash_primary
    s0_pad:
      address: 0x8000
      size: 0x200
      share_size: [mcuboot_pad]
      region: flash_primary
    s0_image:
      address: 0x8200
      size: 0x13e00
      span: [mcuboot]
      region: flash_primary
    mcuboot:
      address: 0x8200
      size: 0x13e00
      region: flash_primary
    s1:
      address: 0x1c000
      size: 0x14000
      span: [s1_pad, s1_image]
      region: flash_primary
    s1_pad:
      address: 0x1c000
      size: 0x200
      region: flash_primary
      share_size: [mcuboot_pad]
    s1_image:
      address: 0x1c200
      size: 0x13e00
      share_size: [mcuboot]
      region: flash_primary
    mcuboot_primary:
      address: 0x30000
      size: 0xD0000
      span: [mcuboot_pad, app, tfm]
      region: flash_primary
    tfm_secure:
      address: 0x30000
      size: 0x10000
      span: [mcuboot_pad, tfm]
      region: flash_primary
    mcuboot_pad:
      address: 0x30000
      size: 0x200
      region: flash_primary
    mcuboot_primary_app:
      address: 0x30200
      size: 0xcfe00
      span: [tfm, app]
      region: flash_primary
    app_image:
      address: 0x30200
      size: 0xcfe00
      span: [tfm, app]
      region: flash_primary
    tfm:
      address: 0x30200
      size: 0xFE00
      region: flash_primary
    tfm_nonsecure:
      address: 0x40000
      size: 0xC0000
      span: [app]
      region: flash_primary
    app:
      address: 0x40000
      size: 0xC0000
      region: flash_primary
    
    mcuboot_secondary:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x0
      size: 0xD0000
      share_size: [mcuboot_primary]
      region: external_flash
    fmfu_storage:
      address: 0xD0000
      device: DT_CHOSEN(nordic_pm_ext_flash)
      region: external_flash
      size: 0x400000
    settings_storage:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x4D0000
      size: 0x2000
      region: external_flash
    

    With this, the TF-M partition is 64 kB and I see that the project builds with debug optimization enabled for all images. However, I do not have a Thingy91x at hand now, so I have not been able to test it.

Children
No Data
Related