section `rodata' will not fit in region `FLASH'

Summary: I get an error that section `rodata' will not fit in region `FLASH' when building a Matter custom template device and I am unsure what configuration changes I should make. I am using NRF Connect SDK 2.5.0. I am first trying to build for the NRF5340-DK, but I also have my own custom board (with same external flash, mx25r64, as the Nordic DK board). I am not sure what is the best way to increase the FLASH region so that I can build my program. Welcome your advice and guidance. Thanks! Dan.

Here is the error I get when building for the nrf5340-DK:

/opt/nordic/ncs/toolchains/20d68df7e5/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 `rodata' will not fit in region `FLASH'
/opt/nordic/ncs/toolchains/20d68df7e5/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `FLASH' overflowed by 248 bytes
collect2: error: ld returned 1 exit status

I've looked at the related tickets, but am not sure if the root cause is the same:

 https://devzone.nordicsemi.com/f/nordic-q-a/105338/section-rodata-will-not-fit-in-region-flash 

 https://devzone.nordicsemi.com/f/nordic-q-a/106910/section-rodata-will-not-fit-in-region-flash-bin-ld-exe-region-flash-overflowed-by-6134-bytes  

Here is my pm_static_dfu.yml

mcuboot:
  address: 0x0
  size: 0x8000
  region: flash_primary
mcuboot_pad:
  address: 0x8000
  size: 0x200
app:
  address: 0x8200
  size: 0xeee00
mcuboot_primary:
  orig_span: &id001
  - mcuboot_pad
  - app
  span: *id001
  address: 0x8000
  size: 0xef000
  region: flash_primary
mcuboot_primary_app:
  orig_span: &id002
  - app
  span: *id002
  address: 0x8200
  size: 0xeee00
factory_data:
  address: 0xf7000
  size: 0x1000
  region: flash_primary
settings_storage:
  address: 0xf8000
  size: 0x8000
  region: flash_primary
mcuboot_primary_1:
  address: 0x0
  size: 0x40000
  device: flash_ctrl
  region: ram_flash
mcuboot_secondary:
  address: 0x0
  size: 0xef000
  device: MX25R64
  region: external_flash
mcuboot_secondary_1:
  address: 0xef000
  size: 0x40000
  device: MX25R64
  region: external_flash
external_flash:
  address: 0x12f000
  size: 0x6D1000
  device: MX25R64
  region: external_flash
pcd_sram:
  address: 0x20000000
  size: 0x2000
  region: sram_primary

and my prj.conf:

#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# This sample uses Kconfig.defaults to set options common for all
# samples. This file should contain only options specific for this sample
# or overrides of default values.

# Enable CHIP
CONFIG_CHIP=y
CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y
CONFIG_CHIP_PROJECT_CONFIG="src/chip_project_config.h"
# 32768 == 0x8000 (example Product ID added temporaly,
# but it must be changed with proper PID from the list:
# https://github.com/project-chip/connectedhomeip/blob/482e6fd03196a6de45465a90003947ef4b86e0b1/docs/examples/discussion/PID_allocation_for_example_apps.md)
CONFIG_CHIP_DEVICE_PRODUCT_ID=32768
CONFIG_STD_CPP14=y

# Add support for LEDs and buttons on Nordic development kits
CONFIG_DK_LIBRARY=y

# Bluetooth Low Energy configuration
CONFIG_BT_DEVICE_NAME="MatterTemplate"

# Other settings
CONFIG_THREAD_NAME=y
CONFIG_MPU_STACK_GUARD=y
CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_CHIP_LIB_SHELL=y

#enable CoAP
CONFIG_COAP=y
CONFIG_COAP_UTILS=y

# Disable NFC commissioning
CONFIG_CHIP_NFC_COMMISSIONING=n

# Reduce application size
CONFIG_USE_SEGGER_RTT=n

CONFIG_CHIP_APP_LOG_LEVEL=0
CONFIG_MATTER_LOG_LEVEL_ERR=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_DEBUG_OPTIMIZATIONS=y

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV6=y


CONFIG_DNS_RESOLVER=y
# google IPV6 DNS server
CONFIG_DNS_SERVER1="2001:4860:4860::8888"


CONFIG_I2C=y
#CONFIG_BOARD_ENABLE_DCDC_APP=n
#CONFIG_BOARD_ENABLE_DCDC_NET=n
#CONFIG_BOARD_ENABLE_DCDC_HV=n

As an aside, during the build, the memory regions seem to be within the capacity available:

[139/139] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       23410 B      34176 B     68.50%
             RAM:        3500 B        64 KB      5.34%
           SRAM1:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB         2 KB      0.00%
[272/282] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
[273/282] Creating data to be provisioned to the Bootloader, storing to provision.hex
[275/282] Completed 'b0n_subimage'
[277/282] Generating zephyr/b0n_container.hex
[278/282] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      212184 B       222 KB     93.34%
             RAM:       53704 B        64 KB     81.95%
           SRAM1:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB         2 KB      0.00%
[279/282] Generating zephyr/app.hex

  • I am running into a similar issue. My board was building and then I updated the SDK from 2.4.1 to 2.5.2. Now I get an error similar to yours saying the rodata won't fit in FLASH.

    I tried editing the pm_static_dfu.yml file. I am not clear on whether to only have the 4 lines for the factory_data section or if I have to have the modified version of the file with all the 9's you changed and then put factory_data at the end or ???

    Can you please clarify for me? What exactly should my .yml file look like?

    Also, did you end up using that patch that Sigurd gave you?

    Are there maybe other changes I need to make to my project itself going from 2.4.1 to 2.5.2?

  • I just reverted back to 2.4.1 and now I don't get that build error.

    What should I do to upgrade my project to 2.5.2?

  • Hi  - I was OOO and just saw your message now. I ended up just specifying the factory_data section as follows, and did not add any other sections in the .yml file, and this worked (I did not use the patch Sigurd provided). I am building in SDK v.2.5.0:

    factory_data:
    address: 0xff000
    size: 0x1000
    region: flash_primary
  • Thank you.

    In my yml file (if I am looking at the right thing), there are a lot of things. Are you saying I take all of those out and just have the factory_data section or so I make a yml file that overrides just that setting?

  • Hi Tony

    Tony said:
    In my yml file (if I am looking at the right thing), there are a lot of things.

    From my previous answer i this ticket:

    "There are two reasons to use static partitioning as far as I see it:
    1. Freezing the partitioning on release so you do not mess up DFU. See Static partition requirement for DFU.
    2. Add custom partitions."

    Do you use pm_static.yml for any of those two reasons?
    Eventually, do you have another reason to use pm_static?

    If not any of those two, I suggest that you only define factory_data in pm_static.yml when developing, and then copy partitions.yml into pm_static.yml for the release (and use the same for all further code for those devices).

    Does that make sense?

Related