Issue with flash partitions in NCS 1.7.0 on nRF9160

Hi,

I've been trying to modify the flash partitions in the nvs example provided in ncs 1.7.0, namely, I want to greatly increase the size of the storage partition so I can log data there. I had been working in ncs 1.499, and I used the method that most others ask about on this forum to change partition sizes, which is to add a pm_static.yml file in the project directory that overrides any board-defined partitions.

The issue is, when I add any pm_static.yml file in the nvs 1.7 example, it is not able to build. Also, I do not have a good starting point for formatting the pm_static.yml file because this sample does not generate partitions.yml or regions.yml files in the build directory on a successful build. It looks like in this log, the partition manager script is running, but it is creating errors when I try to create a static partition definition. Has the recommended way to create static partitions changed in ncs 1.7.0?

Building example_nvs
west build --build-dir c:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs\build c:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs

[0/1] Re-running CMake...
Including boilerplate (Zephyr base (cached)): C:/Users/jwhite/ncs/v1.7.0/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs
-- Zephyr version: 2.6.99 (C:/Users/jwhite/ncs/v1.7.0/zephyr), build: v2.6.99-ncs1
-- Found west (found suitable version "0.11.1", minimum required is "0.7.1")
-- Board: nrf9160dk_nrf9160, Revision: 0.7.0
-- Cache files will be written to: C:/Users/jwhite/ncs/v1.7.0/zephyr/.cache
-- Found dtc: C:/Users/jwhite/ncs/v1.7.0/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (c:/Users/jwhite/ncs/v1.7.0/toolchain/opt)
-- Found BOARD.dts: C:/Users/jwhite/ncs/v1.7.0/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
-- Generated zephyr.dts: C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/zephyr/dts.cmake
Parsing C:/Users/jwhite/ncs/v1.7.0/zephyr/Kconfig
Loaded configuration 'C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/zephyr/.config'
-- Configuring incomplete, errors occurred!
See also "C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/jwhite/Desktop/L20/FW/1.7.0/example_nvs/build/CMakeFiles/CMakeError.log".
FAILED: build.ninja 
C:\Users\jwhite\ncs\v1.7.0\toolchain\opt\bin\cmake.exe --regenerate-during-build -SC:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs -BC:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs\build

warning: ENTROPY_CC3XX (defined at C:\Users\jwhite\ncs\v1.7.0\nrf\drivers\entropy\Kconfig:7) has direct dependencies (CRYPTOCELL_USABLE || SPM || BUILD_WITH_TFM) && ENTROPY_GENERATOR with value n, but is currently being y-selected by the following symbols:
 - SPM (defined at C:\Users\jwhite\ncs\v1.7.0\nrf\subsys\spm\Kconfig:9), with value y, direct dependencies !BUILD_WITH_TFM (value: y), and select condition !BUILD_WITH_TFM (value: y)

warning: ARM_FIRMWARE_USES_SECURE_ENTRY_FUNCS (defined at C:\Users\jwhite\ncs\v1.7.0\zephyr\arch\arm\core\aarch32\cortex_m\tz\Kconfig:57) has direct dependencies ARM_NONSECURE_FIRMWARE && (ARM_SECURE_FIRMWARE || ARM_NONSECURE_FIRMWARE) && ARM_TRUSTZONE_M && CPU_CORTEX_M && ARM with value n, but is currently being y-selected by the following symbols:
 - SPM_SECURE_SERVICES (defined at C:\Users\jwhite\ncs\v1.7.0\nrf\subsys\spm\Kconfig:82), with value y, direct dependencies IS_SPM || SPM (value: y), and select condition SPM && (IS_SPM || SPM) (value: y)

error: Aborting due to Kconfig warnings

CMake Error at C:\Users\jwhite\ncs\v1.7.0\zephyr\cmake\kconfig.cmake:268 (message):
  command failed with return code: 1
Call Stack (most recent call first):
  C:\Users\jwhite\ncs\v1.7.0\zephyr\cmake\app\boilerplate.cmake:554 (include)
  C:\Users\jwhite\ncs\v1.7.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:24 (include)
  C:\Users\jwhite\ncs\v1.7.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:40 (include_boilerplate)
  c:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs\build\CMakeLists.txt:11 (find_package)


ninja: error: rebuilding 'build.ninja': subcommand failed
FATAL ERROR: command exited with status 1: 'c:\Users\jwhite\ncs\v1.7.0\toolchain\opt\bin\cmake.EXE' --build 'c:\Users\jwhite\Desktop\L20\FW\1.7.0\example_nvs\build'

Thanks,

Jacob

  • Hi Jacob,

    I managed to get this working on my nRF52832.  There were some minor changes to the example code that I needed to make to initialise my flash storage correctly, and be able to access the sections of flash I wanted to.  I'm using the v2.0.0 of the SDK though, so not sure if this will apply to your situation

    I put in a static partition that looks like this (this is basically my pm_static.yml file)

    user_storage:
      address: 0x7a000
      size: 0x2000
      placement:
        before: 
        - file_storage
      region: flash_primary
    file_storage:
      address: 0x7c000
      size: 0x2000
      placement:
        before: 
        - settings_storage
      region: flash_primary
    settings_storage:
      address: 0x7e000
      size: 0x2000
      placement:
        before:
        - end
      region: flash_primary
    

    The user_storage is where I'm storing my data.  The file_storage is for some future work (trying to implement a littlefs structure in flash) and the settings_storage is where all the BLE, etc stuff gets stored.  This all fits into the area designated as "storage" in the .dts for my board (from 0x7a000 to 0x80000)

    This is how I then initialise everything:

    #define STORAGE_NODE_LABEL storage
    #define NVS_SECTOR_COUNT 2
    
    struct flash_pages_info info;
    static struct nvs_fs fs;
    
    int16_t flash_initialise(void)
    {
        int16_t rc;
    
    	fs.flash_device = FLASH_AREA_DEVICE(STORAGE_NODE_LABEL);
    	if (!device_is_ready(fs.flash_device)) {
    		#ifdef DEBUG_NVS
    			printk("Flash device %s is not ready\n", fs.flash_device->name);
    		#endif
    		return -EINVAL;
    	}
    
    	fs.offset = FLASH_AREA_OFFSET(user_storage);
    	rc = flash_get_page_info_by_offs(fs.flash_device, fs.offset, &info);
    	if (rc !=0) 
    	{
    		#ifdef DEBUG_NVS		
    			printk("Unable to get page info\n");
    		#endif
    		return rc = -EINVAL;
    	}
    
    	fs.sector_size = info.size;
    	fs.sector_count = NVS_SECTOR_COUNT;
    
    	if(fs.sector_size*fs.sector_count > (FLASH_AREA_SIZE(user_storage)))
    	{
    		#ifdef DEBUG_NVS
    		printk("ERROR: Area used by NVS is larger than user storage\n");
    		#endif
    	}
    
    	rc = nvs_mount(&fs);
    	if (rc !=0) 
    	{
    		#ifdef DEBUG_NVS
    			printk("Flash Init failed\n");
    		#endif
    		return rc;
    	}
    
    	// Check if data is stored in flash
    	rc = check_for_nvs_key();
    	return rc;
    	
    }

    Not sure why, but I had to ditch the use of:

    const struct device *flash_dev;

    from what the original sample code had employed, and then utilise the .flash_device element of the fs directly.

    Where I've called: 

    fs.offset = FLASH_AREA_OFFSET(user_storage);

    you may need to adjust this to point to the area in flash you actually want to use.

    This all works perfectly for me...to a point.  I'm having issues where if I try and write more than about 2000 bytes of data to my user_storage partition, I get errors indicating I've run out of room, even though I have 2 sectors, each of ~ 4000 bytes available.  Still trying to work that one out.

    Cheers,

    Mike

Related