This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to configure flash and RAM partitions

Hello,

I am trying to partition the RAM and the internal flash of the nRF9160, and I am blocked. 

I began by defining the partitions in the board device tree, based on the examples from the SDK. One of the partitions in flash is labeled "storage",

which I will use for storing application specific data. However when I compiled the code, I got an error saying that the label "storage" does not exist.

Digging through the forum, I found out that I should use the Partition Manager instead of the device tree. So I remove the partition definitions

from the device tree and wrote a pm_static.yml with the partitions I need. However now the firmware crashes immediately on startup.

I am suspecting that Zephyr requires the partitions to be defined in the device tree, even though this particular device tree information is ignored

when the firmware image is build. If this is correct, then I have to keep the partition information in two different places: the device tree and the 

pm_static.yml file. Am I correct ? Because this seems absurd to me.

Quite frankly I am very confused and discouraged with the nrf9160. 

Parents
  • Hi!

    If your application has more than one image (for example including SPM or MCUboot) then you need to use the Partition Manager to partition the memory region. 

    The way to add a static configuration to a multi-image is to define the partitions of the child images in a pm.yml file in every child image (for example MCUboot or SPM). Then when you build the main application with all the child images, the resulting partition configuration can be found in $BUILD_DIR/partitions.yml. Take this file and rename it "pm_static.yml" and place it in the application directory (doc: Configuring static partitions).

    The documentation mentions you can build this pm_static.yml file from scratch, but we really don't recommend doing that. It's much easier to use the one that the build creates for you. 

    Let me know if you have any more questions!

    Best regards,

    Heidi

  • Hello Heidi,

    I was confused by how the NVS sample application works. 

    It seems that "CONFIG_NVS=y" adds the "nvs_storage" flash partition, but I only found out after much head banging. And because the partitions defined in the device tree are ignored, no matter the changes I made to the label or size, nothing would work.

    Thanks for the tip on how to create a pm_static.yml file. I was trying to do it by hand, but going nowhere.

    Regarding the partitions defined in the device tree, I believe they are needed by Zephyr. So, I still need to defined the flash and RAM partitions in the device tree files. Correct ? 

  • Hi

    No, you don't need to add the partitions to the device tree. They're defined in partitions.yml which is enough.

  • Ok, but then this section in the device tree (from the nrf910dk_nrf9160ns.dts):

    chosen {
    zephyr,flash = &flash0;
    zephyr,sram = &sram0_ns;
    zephyr,code-partition = &slot0_ns_partition;
    };

    it is not needed ? 

Reply Children
  • Hi!

    As Didrik mentions here, NCS uses the Partition Manager to partition the flash and RAM, and not the device tree.

    Therefore, any devicetree configuration of flash or RAM partitions is ignored by the Partition Manager script.

    This script is used by the build system to properly allocate space for multi-image builds and is thus used for most nRF9160 applications, as all applications using the modem library require SPM as a child image and are therefore multi-image builds.

  • Heidi,

    The problem is that if I remove the partition definitions from the device tree, the code compiles but crashes immediately (hard fault).

    Among the board files is Kconfig.defconfig (which must be present) wich for the nrf9160dk_nrf9160ns board is: 

    # nRF9160 DK NRF9160 board configuration
    
    # Copyright (c) 2018-2020 Nordic Semiconductor ASA
    # SPDX-License-Identifier: Apache-2.0
    
    if BOARD_NRF9160DK_NRF9160 || BOARD_NRF9160DK_NRF9160NS
    
    config BOARD
    	default "nrf9160dk_nrf9160"
    
    # For the secure version of the board the firmware is linked at the beginning
    # of the flash, or into the code-partition defined in DT if it is intended to
    # be loaded by MCUboot. If the secure firmware is to be combined with a non-
    # secure image (TRUSTED_EXECUTION_SECURE=y), the secure FW image shall always
    # be restricted to the size of its code partition.
    # For the non-secure version of the board, the firmware
    # must be linked into the code-partition (non-secure) defined in DT, regardless.
    # Apply this configuration below by setting the Kconfig symbols used by
    # the linker according to the information extracted from DT partitions.
    
    # Workaround for not being able to have commas in macro arguments
    DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
    
    config FLASH_LOAD_SIZE
    	default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
    	depends on BOARD_NRF9160DK_NRF9160 && TRUSTED_EXECUTION_SECURE
    
    if BOARD_NRF9160DK_NRF9160NS
    
    config FLASH_LOAD_OFFSET
    	default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
    
    config FLASH_LOAD_SIZE
    	default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
    
    endif # BOARD_NRF9160DK_NRF9160NS
    
    config BT_WAIT_NOP
    	default BT && $(dt_nodelabel_enabled,nrf52840_reset)
    
    # Workaround for not being able to have commas in macro arguments
    DT_COMPAT_NXP_PCAL6408A := nxp,pcal6408a
    
    config I2C
    	default $(dt_compat_on_bus,$(DT_COMPAT_NXP_PCAL6408A),i2c)
    
    endif # BOARD_NRF9160DK_NRF9160 || BOARD_NRF9160DK_NRF9160NS

    This is a reference to the device tree partitions: DT_CHOSEN_Z_CODE_PARTITION.

    Or am I reading it wrong ? 

  • Why are you removing the partitions? 

    We don't recommend editing the board directories and the relevant partitions in the devicetree will just be ignored.

  • I am trying to understand how the board definition files are used, because I would like create the definitions for our custom board. And I am using the nrf9160dk_nrf9160 board as a starting point. And if I going to copy existing definitions, at least I would like to understand what I am copying.

    The use of the partition definitions in the board files is very confusing, because:

    1. the definitions are ignored

    2. the definitions cannot be edited out (even though they are ignored)

    So is it correct to say that the partition definitions have to be the same on the partition manager *and* the device tree ? 

  • Hi!

    NelsonGoncalves said:
    So is it correct to say that the partition definitions have to be the same on the partition manager *and* the device tree ? 

     No. When using the Partition Manager, the partitions in the device tree are ignored.

    I don't think that you're actually using the Partition Manager here. Can you confirm that your application is a multi-image build?

    Could you give me some more details on specifically what you're trying to do? 

    pm_static.yaml is only supposed to be used when a product is out in the field and you can't move the partitions anymore. During development, you should always use the dynamic solution. 
Related