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

MCU boot with external Flash littles partition and Secondary image partition

Hello ALL,

I am trying to use MCU boot with my application. I am using NRF916DK and it has external Flash similar to NR52840DK board. Now when I am creating a partition on external Flash and point LittleFs to that storage partition, after compiling when I see the partition.yml in the build folder, the LittleFs always in the primary Flash. I have tried few options as seen in the code but nothing is working. Can somebody please guide me on how I can enable these partitions and point secondary Image and littlefs to those partitions.

Here is my overlay file


/ {
	chosen {
		zephyr,bt-uart=&uart0;
	};
};

/delete-node/ &storage_partition;

&i2c2 {
    compatible = "nordic,nrf-twim";
    status = "okay";
    sda-pin = <26>;
    scl-pin = <27>;

    pcf85263a@51 {
        compatible = "nxp,pcf85263a";
        label = "PCF85063A";
        reg = <0x51>;
    };

};

&uart1 {
	status = "okay";
	current-speed = <9600>;
	tx-pin = <06>;
	rx-pin = <07>;
};


&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <13>;
	mosi-pin = <11>;
	miso-pin = <12>;
	cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
	mx25r6435f: mx25r6435f@0 {
		compatible = "jedec,spi-nor";
		label = "MX25R6435F";
		reg = <0>;
		spi-max-frequency = <40000000>;
		wp-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
		hold-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
		jedec-id = [c2 28 14];
  		size = <0x0800000>; /* flash capacity in bits */
  		has-be32k;
  		has-dpd;
  		t-enter-dpd = <10000>;
  		t-exit-dpd = <35000>;
	};
};


&mx25r6435f {
 	partitions {
  		compatible = "fixed-partitions";
  		#address-cells = <1>;
  		#size-cells = <1>;
		storage_partition: partition@40000 {
   			label = "storage";
   			reg = <0x00040000 0x00020000>;
  		};
 	};
};

Here is prj.conf

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_ASSERT=y
CONFIG_REBOOT=y

# Logging config
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_LOG_IMMEDIATE=y
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y

# Console
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_HANDLER=y
CONFIG_CONSOLE_GETCHAR=y

# PWM
CONFIG_PWM=y
CONFIG_PWM_LOG_LEVEL_DBG=y

# I2C
CONFIG_I2C=y

# RTC
CONFIG_PCF85263A=y

# UART
CONFIG_UART_ASYNC_API=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n
CONFIG_UART_1_NRF_HW_ASYNC=n
CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
CONFIG_NRFX_TIMER2=y
CONFIG_NRFX_UARTE1=y

CONFIG_NRFX_SPIM=y
CONFIG_NRFX_SPIM3=y

# CONFIG_NRFX_SPI=y
# CONFIG_NRFX_SPI0=y
CONFIG_BSD_LIBRARY_TRACE_ENABLED=n

# SPI Flash
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# Enable flash operations.
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y



# Nordic specific external flash stuff
CONFIG_PM_EXTERNAL_FLASH=y
CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="MX25R6435F"
CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
CONFIG_PM_EXTERNAL_FLASH_SIZE=0x0800000

# Enable the LittleFS file system.
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
# CONFIG_APP_WIPE_STORAGE=n

# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

Here is my main.c

 

#include <zephyr.h>
#include <logging/log.h>
#include <drivers/uart.h>

#include <fs/fs.h>
#include <fs/littlefs.h>
#include <storage/flash_map.h>

#if (CONFIG_SPI_NOR - 0) || DT_NODE_HAS_STATUS(DT_INST(0, jedec_spi_nor), okay)
#define FLASH_DEVICE DT_LABEL(DT_INST(0, jedec_spi_nor))
#define FLASH_NAME "JEDEC SPI-NOR"
#elif (CONFIG_NORDIC_QSPI_NOR - 0) || DT_NODE_HAS_STATUS(DT_INST(0, nordic_qspi_nor), okay)
#define FLASH_DEVICE DT_LABEL(DT_INST(0, nordic_qspi_nor))
#define FLASH_NAME "JEDEC QSPI-NOR"
#else
#error Unsupported flash driver
#endif

LOG_MODULE_REGISTER(app);

/* Matches LFS_NAME_MAX */
#define MAX_PATH_LEN 255

FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(lfsstorage);
static struct fs_mount_t lfs_storage_mnt = {
		.type = FS_LITTLEFS,
		.fs_data = &lfsstorage,
		//.storage_dev = (void *)DT_FLASH_AREA_STORAGE_ID,
		.storage_dev = (void *)FLASH_AREA_ID(storage),
		//.storage_dev = (void *)FLASH_AREA_ID(external_flash),
		.mnt_point = "/lfs",
};

here is the partition.yml that is generated in the build folder after compilation

EMPTY_0:
  address: 0xc000
  placement:
    before:
    - mcuboot_pad
  region: flash_primary
  size: 0x4000
app:
  address: 0x1c200
  region: flash_primary
  size: 0x68e00
external_flash:
  address: 0x0
  region: external_flash
  size: 0x800000
littlefs_storage:
  address: 0xfa000
  placement:
    before:
    - end
  region: flash_primary
  size: 0x6000
mcuboot:
  address: 0x0
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0xc000
mcuboot_pad:
  address: 0x10000
  placement:
    align:
      start: 0x8000
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0x10000
  orig_span: &id001
  - spm
  - mcuboot_pad
  - app
  region: flash_primary
  sharers: 0x1
  size: 0x75000
  span: *id001
mcuboot_primary_app:
  address: 0x10200
  orig_span: &id002
  - app
  - spm
  region: flash_primary
  size: 0x74e00
  span: *id002
mcuboot_secondary:
  address: 0x85000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x75000
otp:
  address: 0xff8108
  region: otp
  size: 0x2f4
spm:
  address: 0x10200
  inside:
  - mcuboot_primary_app
  placement:
    before:
    - app
  region: flash_primary
  size: 0xc000
spm_sram:
  address: 0x20000000
  inside:
  - sram_secure
  placement:
    after:
    - start
  region: sram_primary
  size: 0x10000
sram_primary:
  address: 0x20010000
  region: sram_primary
  size: 0x30000
sram_secure:
  address: 0x20000000
  orig_span: &id003
  - spm_sram
  region: sram_primary
  size: 0x10000
  span: *id003

  • Hi Håkon,

    I have did the changes that you suggest of adding 

    external_flash:
    address: 0x800000
    region: external_flash
    size: 0x0

    in the partition file but still I am getting build errors. here is the screen shot of error and my code

    This is my pm_static.yml

    external_flash:
      address: 0x800000
      region: external_flash
      size: 0x0
      
    littlefs_storage:
      address: 0x0
      device: mx25r6435f
      region: external_flash
      size: 0x800000

    This is mcuboot.conf

    # Nordic specific external flash stuff
    CONFIG_PM_EXTERNAL_FLASH=y
    CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="MX25R6435F"
    CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
    CONFIG_PM_EXTERNAL_FLASH_SIZE=0x2000000
    

    This is main file and the source of the error is line 27 which is  that pm_littlefs_storage_ID not found. 

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <logging/log.h>
    #include <drivers/uart.h>
    
    #include <fs/fs.h>
    #include <fs/littlefs.h>
    #include <storage/flash_map.h>
    #include "wmbus.h"
    
    LOG_MODULE_REGISTER(app);
    
    
    /* Matches LFS_NAME_MAX */
    #define MAX_PATH_LEN 255
    
    FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
    static struct fs_mount_t lfs_storage_mnt = {
    		.type = FS_LITTLEFS,
    		.fs_data = &storage,
    		// .storage_dev = (void *)FLASH_AREA_ID(littlefs_storage),
    		.storage_dev = (void *)FLASH_AREA_ID(storage),
    		//.storage_dev = (void *)FLASH_AREA_ID,
    		.mnt_point = "/lfs",
    };
    

    Here is the spm.conf

    # Configuration copied from the nRF Secure Partition Manager (SPM) sample:
    CONFIG_IS_SPM=y
    CONFIG_FW_INFO=y
    CONFIG_GPIO=n
    
    # Make watchdog timers non-secure (so they can be used in the non-secure image).
    # CONFIG_SPM_NRF_WDT_NS=y
    

    Here is the cmakelist.txt

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.13.1)
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/spm.conf")
      set(spm_CONF_FILE
        prj.conf
        ${CMAKE_CURRENT_LIST_DIR}/spm.conf
      )
    endif()
    
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf")
        list(APPEND mcuboot_OVERLAY_CONFIG
          "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf"
          )
    endif()
    
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/nrf9160dk_nrf9160ns.overlay")
      set(mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/nrf9160dk_nrf9160ns.overlay")
      set(spm_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/nrf9160dk_nrf9160ns.overlay")
    endif()
    set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/pm_static.yml)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(NB_IOT_MBUS_GW)
    
    zephyr_include_directories(include)
    
    
    target_sources(app PRIVATE src/main.c src/wmbus.c)
    
    add_subdirectory(drivers)

    Here is the overlay file

    / {
    	chosen {
    		zephyr,bt-uart=&uart0;
    	};
    };
    
    &i2c2 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        sda-pin = <26>;
        scl-pin = <27>;
    
        pcf85263a@51 {
            compatible = "nxp,pcf85263a";
            label = "PCF85063A";
            reg = <0x51>;
        };
    
    };
    
    &uart1 {
    	status = "okay";
    	current-speed = <9600>;
    	tx-pin = <06>;
    	rx-pin = <07>;
    };
    
    
    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <13>;
    	mosi-pin = <11>;
    	miso-pin = <12>;
    	cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    	mx25r6435f: mx25r6435f@0 {
    		compatible = "jedec,spi-nor";
    		label = "MX25R6435F";
    		reg = <0>;
    		spi-max-frequency = <40000000>;
    		wp-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
    		hold-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
    		jedec-id = [c2 28 17];
    		size = <67108864>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <35000>;
    	};
    };

  • Hi,

     

    I cannot see anything wrong with your setup. The symbol you are failing on shall be defined in your-build-folder/pm.config (values might differ from your config, but the defines should be in this file):

    $ cat pm.config | grep little -i
    PM_LITTLEFS_STORAGE_ADDRESS=0x0
    PM_LITTLEFS_STORAGE_END_ADDRESS=0x6000
    PM_LITTLEFS_STORAGE_SIZE=0x6000
    PM_LITTLEFS_STORAGE_NAME=littlefs_storage
    PM_LITTLEFS_STORAGE_ID=0
    PM_littlefs_storage_ID=PM_LITTLEFS_STORAGE_ID
    PM_littlefs_storage_IS_ENABLED=1
    PM_0_LABEL=LITTLEFS_STORAGE
    PM_ALL_BY_SIZE="external_flash mcuboot_pad otp EMPTY_0 littlefs_storage mcuboot spm spm_sram sram_secure sram_primary sram_nonsecure mcuboot_secondary app mcuboot_primary_app mcuboot_primary"

     

    When changing anything in the partition scheme, I would strongly recommend that you delete your build folder, then regenerate your project. Could you try this?

     

    Kind regards,

    Håkon 

  • yes I did multiple times and I physically checked this file there is no ID. but I not down one thing while doing configuration. this log message is appeared. 

    Dropping partition 'littlefs_storage' since it is statically defined.
    -- Configuring done
    -- Generating done
    -- Build files have been written to

    and I can see there is nothing in the build.pm.config

    PM_MCUBOOT_ADDRESS=0x0
    PM_MCUBOOT_SIZE=0xc000
    PM_MCUBOOT_NAME=mcuboot
    PM_MCUBOOT_ID=0
    PM_mcuboot_ID=PM_MCUBOOT_ID
    PM_0_LABEL=MCUBOOT
    PM_EMPTY_0_ADDRESS=0xc000
    PM_EMPTY_0_SIZE=0x4000
    PM_EMPTY_0_NAME=EMPTY_0
    PM_EMPTY_0_ID=1
    PM_empty_0_ID=PM_EMPTY_0_ID
    PM_1_LABEL=EMPTY_0
    PM_MCUBOOT_PAD_ADDRESS=0x10000
    PM_MCUBOOT_PAD_SIZE=0x200
    PM_MCUBOOT_PAD_NAME=mcuboot_pad
    PM_MCUBOOT_PAD_ID=2
    PM_mcuboot_pad_ID=PM_MCUBOOT_PAD_ID
    PM_2_LABEL=MCUBOOT_PAD
    PM_MCUBOOT_PRIMARY_ADDRESS=0x10000
    PM_MCUBOOT_PRIMARY_SIZE=0x78000
    PM_MCUBOOT_PRIMARY_NAME=mcuboot_primary
    PM_MCUBOOT_PRIMARY_ID=3
    PM_mcuboot_primary_ID=PM_MCUBOOT_PRIMARY_ID
    PM_3_LABEL=MCUBOOT_PRIMARY
    PM_MCUBOOT_PRIMARY_SPAN="mcuboot_pad app spm"
    PM_MCUBOOT_PRIMARY_APP_ADDRESS=0x10200
    PM_MCUBOOT_PRIMARY_APP_SIZE=0x77e00
    PM_MCUBOOT_PRIMARY_APP_NAME=mcuboot_primary_app
    PM_MCUBOOT_PRIMARY_APP_ID=4
    PM_mcuboot_primary_app_ID=PM_MCUBOOT_PRIMARY_APP_ID
    PM_4_LABEL=MCUBOOT_PRIMARY_APP
    PM_MCUBOOT_PRIMARY_APP_SPAN="app spm"
    PM_SPM_ADDRESS=0x10200
    PM_SPM_SIZE=0xc000
    PM_SPM_NAME=spm
    PM_SPM_ID=5
    PM_spm_ID=PM_SPM_ID
    PM_5_LABEL=SPM
    PM_APP_ADDRESS=0x1c200
    PM_APP_SIZE=0x6be00
    PM_APP_NAME=app
    PM_APP_ID=6
    PM_app_ID=PM_APP_ID
    PM_6_LABEL=APP
    PM_MCUBOOT_SECONDARY_ADDRESS=0x88000
    PM_MCUBOOT_SECONDARY_SIZE=0x78000
    PM_MCUBOOT_SECONDARY_NAME=mcuboot_secondary
    PM_MCUBOOT_SECONDARY_ID=7
    PM_mcuboot_secondary_ID=PM_MCUBOOT_SECONDARY_ID
    PM_7_LABEL=MCUBOOT_SECONDARY
    PM_OTP_ADDRESS=0xff8108
    PM_OTP_SIZE=0x2f4
    PM_OTP_NAME=otp
    PM_SPM_SRAM_ADDRESS=0x20000000
    PM_SPM_SRAM_SIZE=0x10000
    PM_SPM_SRAM_NAME=spm_sram
    PM_SRAM_SECURE_ADDRESS=0x20000000
    PM_SRAM_SECURE_SIZE=0x10000
    PM_SRAM_SECURE_NAME=sram_secure
    PM_SRAM_SECURE_SPAN="spm_sram"
    PM_SRAM_PRIMARY_ADDRESS=0x20010000
    PM_SRAM_PRIMARY_SIZE=0x30000
    PM_SRAM_PRIMARY_NAME=sram_primary
    PM_NUM=8
    PM_ALL_BY_SIZE="mcuboot_pad otp EMPTY_0 mcuboot spm spm_sram sram_secure sram_primary app mcuboot_primary_app mcuboot_secondary mcuboot_primary"

  • Hi,

     

    Your setup doesn't seem to catch the littlefs partition.

    I took your former example, and edited it. It does seem to successfully register littlefs in pm, as well as the external flash region:

    2021_04_13_app_program_nordic.zip

     

    Kind regards,

    Håkon

Related