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. 

  • 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. 
  • "Can you confirm that your application is a multi-image build?"

    Yes, I believe it is a multi-image build. It has the SPM and our own application which uses the LTE modem. No bootloader yet, though. But we will most likely only use an immutable bootloader.

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

    It started out as an attempt to create a storage space in the internal flash and read/write over it using NVS. I took the NVS sample and tried to adapt it, but failed.

    The rationale for using the NVS storage is that our application (running as non-secure) is required to support the change of symmetric encryption keys during a communication session with a remote client. We cannot store them in the KMU because the application is non-secure, the only options are either to store them in plaintext in the internal flash or encrypted in an external flash.

    The use of NVS seemed simpler and faster than accessing an external flash. Recently one your colleagues suggested here that I could use a customized SPM for accessing secure resources from a non-secure app.

    But even if a customized SPM will solve our key storage problems, I still don't understand why this is needed in the device tree definition:

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

    if the Partition Manager is used and the device tree partitions are ignored. As soon as I remove it, my application crashes immediately.

    EDIT: here are the config and board files I am currently using board_and_config_files.zip

Related