[MCU BOOT] `RAM' overflowed

Hello, 

I'm trying to implement the MCU BOOT in order to introduce the Firmware uptdate but I get the following error: 

c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.exe: zephyr\zephyr_pre0.elf section `bss' will not fit in region `RAM'
c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `RAM' overflowed by 246080 bytes
collect2.exe: error: ld returned 1 exit status

I'm trying to reduce the RAM usage but with no succes.

When I build my program without the MCU BOOT I get this following build report: 

[0/418] Performing build step for 'tfm'
ninja: warning: premature end of file; recovering
[8/18] Linking C executable zephyr\zephyr_pre0.elf

[11/18] Linking C executable zephyr\zephyr_pre1.elf

[16/18] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      186748 B       256 KB     71.24%
             RAM:       51044 B        64 KB     77.89%
           SRAM1:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB         2 KB      0.00%

[401/414] Linking CXX executable zephyr\zephyr_pre0.elf

[405/414] Linking CXX executable zephyr\zephyr_pre1.elf

[411/414] Linking CXX executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      240064 B       992 KB     23.63%
             RAM:       96280 B       416 KB     22.60%
        IDT_LIST:          0 GB         2 KB      0.00%

In my _cpuapp_common.dts

/ {

	reserved-memory {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		sram0_image: image@20000000 {
			/* Zephyr image(s) memory */
		};

		sram0_s: image_s@20000000 {
			/* Secure image memory */
		};

		sram0_ns: image_ns@20040000 {
			/* Non-Secure image memory */
		};
	};
};

In my cpuapp_partition_conf.dts : 

&slot0_partition {
	reg = <0x00010000 0x40000>;
};

&slot0_ns_partition {
	reg = <0x00050000 0x30000>;
};

&slot1_partition {
	reg = <0x00080000 0x40000>;
};

&slot1_ns_partition {
	reg = <0x000c0000 0x30000>;
};

&sram0_image {
	reg = <0x20000000 DT_SIZE_K(448)>;
};

&sram0_s {
	reg = <0x20000000 0x40000>;
};    

&sram0_ns {
	reg = <0x20040000 0x30000>;
};

I'm using the TF-M image for the moment (using the board file with ns at the end), I'm not quite sur to understand the use of secure and non secure partition for flash and RAM.

Is thoses partition needed even If I use only secured or only non secured image ? 

Thanks in advance.

Best regards. 
Martin

EDIT:

I have an external flash that I can use for the second image, but I've not configured the partition and the program to use it yet.

Since the error is linked to RAM I though it was not useful to implement it at the moment.

  • I'm not using any overlay since I use my custom board files.

    And yes I use QSPI external flash feature.

    #File system on external flash
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_FCB=y
    CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=n
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x00800000

    Edit:

    Since I want to use QSPI external flash I think I need to put 

            nordic,pm-ext-flash = &mx25r64;

    But I need to defined the PM behavior for this flash otherwise it use it as a image space and then I get 

    c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.exe: zephyr\zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
    c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `FLASH' overflowed by 4988 bytes
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.

    Do you have a Idea how can I do so ? 

  • So I've try using a static partition : 

    external_flash:
      address: 0x800000
      region: external_flash
      device: mx25r6435f
      size: 0x0
    littlefs_storage:
      address: 0x00000000
      region: external_flash
      device: mx25r6435f
    size: 0x00800000
    app:
      address: 0x14000
      end_address: 0x84000
      region: flash_primary
      size: 0x70000
    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: 0x4000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0xc000
      end_address: 0x84000
      orig_span: &id001
      - tfm
      - app
      - mcuboot_pad
      region: flash_primary
      sharers: 0x1
      size: 0x78000
      span: *id001
    mcuboot_primary_app:
      address: 0xc200
      end_address: 0x84000
      orig_span: &id002
      - app
      - tfm
      region: flash_primary
      size: 0x77e00
      span: *id002
    mcuboot_secondary:
      address: 0x84000
      end_address: 0xfc000
      placement:
        after:
        - mcuboot_primary
        align:
          start: 0x4000
        align_next: 0x4000
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id003
      - tfm_sram
      region: sram_primary
      size: 0x8000
      span: *id003
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    sram_nonsecure:
      address: 0x20008000
      end_address: 0x20080000
      orig_span: &id004
      - sram_primary
      region: sram_primary
      size: 0x78000
      span: *id004
    sram_primary:
      address: 0x20008000
      end_address: 0x20080000
      region: sram_primary
      size: 0x78000
    sram_secure:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id005
      - tfm_sram
      region: sram_primary
      size: 0x8000
      span: *id005
    tfm:
      address: 0xc200
      end_address: 0x14000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x7e00
    tfm_nonsecure:
      address: 0x14000
      end_address: 0x84000
      orig_span: &id006
      - app
      region: flash_primary
      size: 0x70000
      span: *id006
    tfm_secure:
      address: 0xc000
      end_address: 0x14000
      orig_span: &id007
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x8000
      span: *id007
    tfm_sram:
      address: 0x20000000
      end_address: 0x20008000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000
    

    But I get the same error : 

    -- Found partition manager static configuration: C:/Users/dev/dev/BPI/Concentrateur/pm_static.yml
    Traceback (most recent call last):
      File "C:/ncs/v2.3.0/nrf/scripts/partition_manager.py", line 1978, in <module>
        main()
      File "C:/ncs/v2.3.0/nrf/scripts/partition_manager.py", line 1018, in main
        static_config = load_static_configuration(args, pm_config) if args.static_config else dict()
      File "C:/ncs/v2.3.0/nrf/scripts/partition_manager.py", line 980, in load_static_configuration
        fix_syntactic_sugar(static_config)
      File "C:/ncs/v2.3.0/nrf/scripts/partition_manager.py", line 948, in fix_syntactic_sugar
        if 'region' not in v:
    TypeError: argument of type 'int' is not iterable
    CMake Error at C:/ncs/v2.3.0/nrf/cmake/partition_manager.cmake:304 (message):
      Partition Manager failed, aborting.  Command:
      C:/ncs/toolchains/v2.3.0/opt/bin/python.exe;C:/ncs/v2.3.0/nrf/scripts/partition_manager.py;--input-files;C:/Users/dev/dev/BPI/Concentrateur/build_release/mcuboot/zephyr/include/generated/pm.yml;C:/Users/dev/dev/BPI/Concentrateur/build_release/mcuboot/modules/nrf/subsys/partition_manager/pm.yml.pcd;C:/Users/dev/dev/BPI/Concentrateur/build_release/zephyr/include/generated/pm.yml;C:/Users/dev/dev/BPI/Concentrateur/build_release/modules/nrf/subsys/partition_manager/pm.yml.file_system;C:/Users/dev/dev/BPI/Concentrateur/build_release/modules/nrf/subsys/partition_manager/pm.yml.rpmsg_nrf53;--regions;sram_primary;otp;flash_primary;external_flash;--output-partitions;C:/Users/dev/dev/BPI/Concentrateur/build_release/partitions.yml;--output-regions;C:/Users/dev/dev/BPI/Concentrateur/build_release/regions.yml;--static-config;C:/Users/dev/dev/BPI/Concentrateur/pm_static.yml;--sram_primary-size;0x80000;--sram_primary-base-address;0x20000000;--sram_primary-placement-strategy;complex;--sram_primary-dynamic-partition;sram_primary;--otp-size;764;--otp-base-address;0xff8100;--otp-placement-strategy;start_to_end;--flash_primary-size;0x100000;--flash_primary-base-address;0x0;--flash_primary-placement-strategy;complex;--flash_primary-device;flash_controller;--flash_primary-default-driver-kconfig;CONFIG_SOC_FLASH_NRF;--external_flash-size;8388608;--external_flash-base-address;0;--external_flash-placement-strategy;start_to_end;--external_flash-device;DT_CHOSEN(nordic_pm_ext_flash);--external_flash-default-driver-kconfig;CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
    Call Stack (most recent call first):
      C:/ncs/v2.3.0/zephyr/cmake/modules/kernel.cmake:246 (include)
      C:/ncs/v2.3.0/zephyr/cmake/modules/zephyr_default.cmake:117 (include)
      C:/ncs/v2.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      C:/ncs/v2.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Configuring incomplete, errors occurred!

  • I managed to make it work the issues was that I have to set the proper configuration for both files: 

    • In mcuboot.conf
      CONFIG_HW_CC3XX=n
      CONFIG_NRF_CC3XX_PLATFORM=n
      CONFIG_NORDIC_QSPI_NOR=n
    • In the prj.conf
      CONFIG_BOOTLOADER_MCUBOOT=y
      CONFIG_MCUBOOT_IMAGE_VERSION="0.0.1+0"
      CONFIG_TFM_PROFILE_TYPE_MINIMAL=y
      CONFIG_IMG_MANAGER=y
      CONFIG_PARTITION_MANAGER_ENABLED=y
      
      CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
      CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x7FFFFF
      CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
      
      #Flash
      CONFIG_FLASH=y
      CONFIG_FLASH_MAP=y
      CONFIG_FLASH_PAGE_LAYOUT=y
      CONFIG_STREAM_FLASH=y
      
      #QSPI External flash
      CONFIG_NORDIC_QSPI_NOR=y
      CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
      
      #File system
      CONFIG_FILE_SYSTEM=y
      CONFIG_FILE_SYSTEM_LITTLEFS=y
      CONFIG_SETTINGS=y
      CONFIG_SETTINGS_FS=y
      CONFIG_FS_LITTLEFS_NUM_FILES=15
      
      CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
      CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x7FFFFF
      CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
      
      

    What I've understand is that 

    CONFIG_NORDIC_QSPI_NOR
    was enable by default in the mcuboot.conf making the partition manager create a partition for the image 2, this will introduce a conflict with the LittleFs image since 
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x7FFFFF
    .

    Edit:

    As discussed above the chosen  

    nordic,pm-ext-flash = &mx25r64;
    has to be set too.

    Thanks for the help.

    Kinds regards.

    Martin

  • Hi,

    Apologies for the long response time, I've been out of office. I will go through your information today and come back with a response

    What I see immediately is that your static partition is a bit wrong, the "size" part of your littlefs_storage region needs to be aligned with the rest of the parameters for that partition:

    You will most likely get the flash overflow error again, but could you fix this and see if you do?

    Kind regards,
    Andreas

  • Oh and I see you just replied with another update! Happy to hear that you resolved it with those configurations, and thank you very much for sharing your progress!

    Kind regards,
    Andreas

Related