nRF9160dk FOTA using external flash, ncs 2.0.2

Hi, 

I am using nRf9160dk with mcuboot secondary image on external flash base on AZURE_FOTA example, ncs 2.0.2.

Found the bootloader cannot runs primary image.

So, I need advice on how to set up the mcuboot secondary with SPI flash.

*** Booting Zephyr OS build v3.0.99-ncs1-1  ***
I: Starting bootloader
W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=128 - too small?
E: Image in the primary slot is not valid!
E: Unable to find bootable image

Checked the partition with west build -t partition_manager_report .

+------------------------------------------+
| 0x0: external_flash (0x800000 - 8192kB)  |
| 0x0: mcuboot_secondary (0x70000 - 448kB) |
+------------------------------------------+

  flash_primary (0x100000 - 1024kB):
+--------------------------------------------------+
| 0x0: mcuboot (0xc000 - 48kB)                     |
| 0xc000: EMPTY_0 (0x4000 - 16kB)                  |
+---0x10000: mcuboot_primary (0xe8000 - 928kB)-----+
+---0x10000: tfm_secure (0xc200 - 48kB)------------+
| 0x10000: mcuboot_pad (0x200 - 512B)              |
+---0x10200: mcuboot_primary_app (0xe7e00 - 927kB)-+
| 0x10200: tfm (0xc000 - 48kB)                     |
+---0x1c200: tfm_nonsecure (0xdbe00 - 879kB)-------+
| 0x1c200: app (0xdbe00 - 879kB)                   |
+---0xf8000: nonsecure_storage (0x8000 - 32kB)-----+
| 0xf8000: settings_storage (0x2000 - 8kB)         |
| 0xfa000: littlefs_storage (0x6000 - 24kB)        |
+--------------------------------------------------+

  otp (0x2f4 - 756B):
+------------------------------+
| 0xff8108: otp (0x2f4 - 756B) |
+------------------------------+

  sram_primary (0x40000 - 256kB):
+--------------------------------------------------+
+---0x20000000: sram_secure (0x10000 - 64kB)-------+
| 0x20000000: tfm_sram (0x10000 - 64kB)            |
+---0x20010000: sram_nonsecure (0x30000 - 192kB)---+
+---0x20010000: nrf_modem_lib_sram (0x44e8 - 17kB)-+
| 0x20010000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
| 0x200104e8: nrf_modem_lib_tx (0x2000 - 8kB)      |
| 0x200124e8: nrf_modem_lib_rx (0x2000 - 8kB)      |
+--------------------------------------------------+
| 0x200144e8: sram_primary (0x2bb18 - 174kB)       |
+--------------------------------------------------+

My configuration as follows:

child_image\mcuboot\boards\nrf9160dk_nrf9160_mcuboot.overlay

/ {
	chosen {
		nordic,pm-ext-flash = &mx25r64;
	};
};

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi3_default_alt>;
	pinctrl-1 = <&spi3_sleep_alt>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
	mx25r64: mx25r6435f@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <80000000>;
		label = "MX25R64";
		jedec-id = [c2 28 17];
		size = <67108864>;
	};
};

&pinctrl {
	spi3_default_alt: spi3_default_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 13)>,
				<NRF_PSEL(SPIM_MOSI, 0, 11)>,
				<NRF_PSEL(SPIM_MISO, 0, 12)>;
		};
	};

	spi3_sleep_alt: spi3_sleep_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 13)>,
				<NRF_PSEL(SPIM_MOSI, 0, 11)>,
				<NRF_PSEL(SPIM_MISO, 0, 12)>;
			low-power-enable;
		};
	};

};

child_image\mcuboot\prj_mcuboot.conf

CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

CONFIG_MULTITHREADING=y

# MCUboot requires a large stack size, otherwise an MPU fault will occur
CONFIG_MAIN_STACK_SIZE=10240

CONFIG_DEBUG_OPTIMIZATIONS=y

# Enable flash operations
CONFIG_FLASH=y

# This must be increased to accommodate the bigger images.
CONFIG_BOOT_MAX_IMG_SECTORS=256

nrf9160dk_nrf9160_ns.overlay

/ {
    	chosen {
    		nordic,pm-ext-flash = &mx25r64;
    	};
};

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi3_default_alt>;
	pinctrl-1 = <&spi3_sleep_alt>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
	mx25r64: mx25r6435f@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <80000000>;
		label = "MX25R64";
		jedec-id = [c2 28 17];
		size = <67108864>;
	};
};

&pinctrl {
	spi3_default_alt: spi3_default_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 13)>,
				<NRF_PSEL(SPIM_MOSI, 0, 11)>,
				<NRF_PSEL(SPIM_MISO, 0, 12)>;
		};
	};

	spi3_sleep_alt: spi3_sleep_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 13)>,
				<NRF_PSEL(SPIM_MOSI, 0, 11)>,
				<NRF_PSEL(SPIM_MISO, 0, 12)>;
			low-power-enable;
		};
	};

};

pm_static.yml

#include <autoconf.h>
#include <devicetree_legacy_unfixed.h>

external_flash:
  address: 0x0
  device: mx25r6435f
  region: external_flash
  size: 0x800000 
mcuboot_secondary:
  address: 0x0
  device: mx25r6435f
  region: external_flash
  size: 0x70000

prj.conf

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# General config
CONFIG_REBOOT=y

# Log
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=n
CONFIG_LTE_NETWORK_MODE_NBIOT=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# MQTT
CONFIG_MQTT_KEEPALIVE=900

# Azure IoT Hub library
CONFIG_AZURE_IOT_HUB=y
CONFIG_AZURE_IOT_HUB_DEVICE_ID="nordic_960074368"
# Host name must be configured if DPS is not used
CONFIG_AZURE_IOT_HUB_HOSTNAME=""
# Change the security tag to the tag where relevant certificates are provisioned
CONFIG_AZURE_IOT_HUB_SEC_TAG=11
# Uncomment to get more verbose logging when debugging
# CONFIG_AZURE_IOT_HUB_LOG_LEVEL_DBG=y

# Uncomment and configure the options below to use DPS for device provisioning
CONFIG_AZURE_IOT_HUB_DPS=y
CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE="0ne0053A4FD"


# Azure FOTA
CONFIG_CJSON_LIB=y
CONFIG_AZURE_FOTA=y
CONFIG_AZURE_FOTA_APP_VERSION_AUTO=n
CONFIG_AZURE_FOTA_APP_VERSION="v0.0.1"
CONFIG_AZURE_FOTA_TLS=y
# Change the security tag to the tag where the certificates are provisioned
# for the server where the FOTA image is hosted
CONFIG_AZURE_FOTA_SEC_TAG=10
# Uncomment the below line to get more debug logging
# CONFIG_AZURE_FOTA_LOG_LEVEL_DBG=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=6144
CONFIG_MAIN_STACK_SIZE=1536

# Settings, needed for Azure Device Provisioning Service
CONFIG_FLASH=y
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_FCB=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n

# Modem library
CONFIG_NRF_MODEM_LIB=y

# newlibc
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# FOTA Download
CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT=y
CONFIG_AZURE_FOTA_FILE_PATH_MAX_LEN=200

# Download Client
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_INF=y
CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2300

# DFU Target
CONFIG_DFU_TARGET=y

# Application update support
CONFIG_BOOTLOADER_MCUBOOT=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

#################################################
# Config using external flash memory and littleFS.
#################################################
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
# Need this when storage is on flash
# CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

Parents
  • Hi,

     

    child_image\mcuboot\prj_mcuboot.conf

    You have two choices wrt. configuring a child_image:

    child_image/$image.conf

    This overrides the original default configuration for the child_image.

    Or:

    Replace the default configuration by setting:

    child_image/$image/prj.conf

     

    This approach will not use the default configuration for the image, and will require larger configuration files (ie. def_config + your wanted local configs)

     

    I would recommend that you move this file to:

    child_image\mcuboot.conf

     

    child_image\mcuboot\boards\nrf9160dk_nrf9160_mcuboot.overlay

    This should be child_image\mcuboot\boards\nrf9160dk_nrf9160.overlay

     

    The algorithm here must follow the following rule:

    child_image/$image/boards/$BOARD

     

    Note that mcuboot runs in secure, so it will be "nrf9160dk_nrf9160" that is the board chosen for this child image.

     

    pm_static.yml

    You have overlapping sections in this file:

    external_flash:
      address: 0x0
      device: mx25r6435f
      region: external_flash
      size: 0x800000 
    mcuboot_secondary:
      address: 0x0
      device: mx25r6435f
      region: external_flash
      size: 0x70000

     

    You should define "external_flash" with a start address after the end_addr of mcuboot_secondary.

     

    Since you've already setup the corresponding "nordic,pm-ext-flash" section in device-tree, you can remove (or move the pm_static.yml to a backed up location) and rely on the generated build\partitions.yml file instead.

     

    Kind regards,

    Håkon

  • Hi,

    My code is struck in an infinite loop when booting the mcuboot_primary slot.

    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000

    I am taking your advice and doing:

    I would recommend that you move this file to:

    child_image\mcuboot.conf

    Rounding the mcuboot.conf as your recommend.

    This should be child_image\mcuboot\boards\nrf9160dk_nrf9160.overlay

    This suggestion has also been implemented in my project.

    Since you've already setup the corresponding "nordic,pm-ext-flash" section in device-tree, you can remove (or move the pm_static.yml to a backed up location) and rely on the generated build\partitions.yml file instead.

    Remove pm_static.yml since I have define "nordic.pm-ext-flash"

    Could you provide me some advice and confirm my configuration from my initial post is the root cause of the issue?

  • Hi  

    I want to know if the TFM issue has been resolved.

    If so, could you describe how to use it?

  • Hi,

     

    Yes, this issue was resolved with this PR:

    https://github.com/nrfconnect/sdk-nrf/pull/8363

    It is present in ncs v2.1.0.

     

    Rung said:
    If so, could you describe how to use it?

    Based on your previously used project, you take away the SPM config:

    CONFIG_BUILD_WITH_TFM=y
    # CONFIG_SPM=n

     

    Could you try this and see if this works as expected?

     

    Kind regards,

    Håkon

  • Hi   I'm having a similar problem, for the last couple of weeks. 

    NCS 2.1.0

    I'm using the HTTP application update, and it works OK when using FOTA and internal flash however it doesn't work when using external flash. 

    I get an error 

    Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
    Cannot upgrade: not a compatible amount of sectors

    [00:00:00.*** Booting Zephyr OS build v3.1.99-ncs1 ***
    HTTP application update sample started
    Using version 1

    [00:00:00.368,041] <dbg> os: k_sched_unlock: scheduler unlocked (0x2000cce0:0)
    [00:00:05.556,610] <inf> mcuboot: Starting bootloader
    [00:00:05.556,640] <dbg> os: setup_thread_stack: stack 0x2000ebb8 for thread 0x2000c708: obj_size=768 buf_start=0x2000c97d  buf_size 768 stack_ptr=0x2000c97f
    [00:00:05.556,915] <wrn> mcuboot: Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
    [00:00:05.556,945] <wrn> mcuboot: Cannot upgrade: not a compatible amount of sectors
    [00:00:00.*** Booting Zephyr OS build v3.1.99-ncs1  ***
    HTTP application update sample started
    Using version 1

     

    west build -t partition_manager_report

      external_flash (0x400000 - 4096kB):
    +---------------------------------------------+
    | 0x0: mcuboot_secondary (0xf0000 - 960kB)    |
    | 0xf0000: external_flash (0x310000 - 3136kB) |
    +---------------------------------------------+
    
      flash_primary (0x100000 - 1024kB):
    +--------------------------------------------------+
    | 0x0: mcuboot (0x10000 - 64kB)                    |
    +---0x10000: mcuboot_primary (0xf0000 - 960kB)-----+
    +---0x10000: tfm_secure (0xc200 - 48kB)------------+
    | 0x10000: mcuboot_pad (0x200 - 512B)              |
    +---0x10200: mcuboot_primary_app (0xefe00 - 959kB)-+
    | 0x10200: tfm (0xc000 - 48kB)                     |
    +---0x1c200: tfm_nonsecure (0xe3e00 - 911kB)-------+
    | 0x1c200: app (0xe3e00 - 911kB)                   |
    +--------------------------------------------------+
    
      otp (0x2f4 - 756B):
    +------------------------------+
    | 0xff8108: otp (0x2f4 - 756B) |
    +------------------------------+
    
      sram_primary (0x40000 - 256kB):
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x8000 - 32kB)--------+
    | 0x20000000: tfm_sram (0x8000 - 32kB)             |
    +---0x20008000: sram_nonsecure (0x38000 - 224kB)---+
    +---0x20008000: nrf_modem_lib_sram (0x44e8 - 17kB)-+
    | 0x20008000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200084e8: nrf_modem_lib_tx (0x2000 - 8kB)      |
    | 0x2000a4e8: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x2000c4e8: sram_primary (0x33b18 - 206kB)       |
    +--------------------------------------------------+

    prj.conf

    #
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    # General config
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    CONFIG_REBOOT=y
    CONFIG_NEWLIB_LIBC=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_NATIVE=n
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    CONFIG_NRF_MODEM_LIB_SYS_INIT=n
    
    # Shell configurations
    CONFIG_SHELL=y
    CONFIG_SHELL_WILDCARD=n
    CONFIG_SHELL_CMD_BUFF_SIZE=128
    
    # Library for buttons and LEDs
    CONFIG_DK_LIBRARY=y
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    CONFIG_MAIN_STACK_SIZE=8192
    
    # Image manager
    CONFIG_IMG_MANAGER=y
    CONFIG_FLASH=y
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    
    # GPIO
    CONFIG_GPIO=y
    
    # FOTA library
    CONFIG_FOTA_DOWNLOAD=y
    
    # Download client
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    
    # DFU Target
    CONFIG_DFU_TARGET=y
    
    # Modem key management
    CONFIG_MODEM_KEY_MGMT=y
    
    # Application Upgrade support
    CONFIG_BOOTLOADER_MCUBOOT=y
    
    # Sample configuration
    CONFIG_DOWNLOAD_HOST="nrfconnectsdk.s3.eu-central-1.amazonaws.com"
    
    CONFIG_DOWNLOAD_FILE_V2="app_update.bin"
    CONFIG_DOWNLOAD_FILE_V1="app_downgrade.bin"
    CONFIG_APPLICATION_VERSION=1
    
    
    
    CONFIG_NRFX_SPIM3=y
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_NORDIC_QSPI_NOR=n
    
    
    
    
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_STREAM_FLASH=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_DEFERRED=y
    CONFIG_LOG_DEFAULT_LEVEL=4
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_STREAM_FLASH_LOG_LEVEL_DBG=y
    CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=2048
    CONFIG_IMG_MANAGER_LOG_LEVEL_DBG=y
    #turn off compiler optimisations so we can debug it
    #CONFIG_NO_OPTIMIZATIONS=y
    
    CONFIG_BUILD_WITH_TFM=y
    

    circuitdojo_feather_nrf9160_ns.overlay

    // To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
    
    // You can also use the buttons in the sidebar to perform actions on nodes.
    // Actions currently available include:
    
    // * Enabling / disabling the node
    // * Adding the bus to a bus
    // * Removing the node
    // * Connecting ADC channels
    
    // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
    // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &is25lp032d;
    	};
    
    	aliases {
    		spi-flash0 = &is25lp032d;
            led0 = &blue_led;
            led1 = &blue_led;
        
        };
    
        leds {
            compatible = "gpio-leds";
            blue_led: led_0 {
                gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
                label = "Blue LED (D7)";
            };
        };
    
    };
    
    &uart0 {
    	status = "okay";
    	current-speed = <115200>;
    };
    
    
    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    
    
    	/delete-node/ w25q32jv@0;
    
    
    	cs-gpios = < &gpio0 7 GPIO_ACTIVE_LOW >;
    	is25lp032d: is25lp032d@0 {
    		compatible = "jedec,spi-nor";
    		label = "IS25LP032D";
    		reg = < 0 >;
    		spi-max-frequency = < 40000000 >;
    		wp-gpios = < &gpio0 8 GPIO_ACTIVE_LOW >;
    		hold-gpios = < &gpio0 10 GPIO_ACTIVE_LOW >;
    		size = < 0x2000000 >;
    		has-dpd;
    		t-enter-dpd = < 3000 >;
    		t-exit-dpd = < 30000 >;
    		jedec-id = [ 9d 60 16  ];
    
    	};
        
    };
    
    
    
    
    

    child_image/mcuboot.conf

    CONFIG_NORDIC_QSPI_NOR=n
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_NRFX_SPIM3=y
    
    CONFIG_MULTITHREADING=y
    
    # MCUboot requires a large stack size, otherwise an MPU fault will occur
    CONFIG_MAIN_STACK_SIZE=10240
    
    
    
    # Enable flash operations
    CONFIG_FLASH=y
    
    
    # This must be increased to accommodate the bigger images.
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    
    CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
    
    
    # Size of mcuboot partition
    CONFIG_SIZE_OPTIMIZATIONS=y
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    
    CONFIG_MCUBOOT_SERIAL=n #make sure this is set to n if you want to log stuff.
    
    CONFIG_LOG_MODE_MINIMAL=n
    CONFIG_LOG_DEFAULT_LEVEL=4
    CONFIG_LOG_MODE_DEFERRED=y
    
    CONFIG_LOG_OVERRIDE_LEVEL=4
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_UART_CONSOLE=y
    CONFIG_CONSOLE=y
    CONFIG_BOOT_ERASE_PROGRESSIVELY=y
    CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32
    #CONFIG_MCUBOOT_OVERWRITE_ONLY=y
    
    #turn off compiler optimisations so we can debug it
    #CONFIG_NO_OPTIMIZATIONS=y
    
    

    child_image/mcuboot/boards/circuitdojo_feather_nrf9160.overlay

    /*
     * Copyright (c) 2021 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
     //MKB added this entire file in the child image directory to try and enable external flash as
     //the second slot, so that we can get more primary flash for a larger application.
     //https://devzone.nordicsemi.com/f/nordic-q-a/91180/nrf9160dk-fota-using-external-flash-ncs-2-0-2
    
     //note that the file name is thingy91_nrf9160.overlay (no "ns" in the file name) as mcuboot runs secure.
    
     / {
    	chosen {
    		nordic,pm-ext-flash = &is25lp032d;
    		
    	};
    
    	aliases {
    		spi-flash0 = &is25lp032d;
        };
    
    
    };
    
    &uart0 {
    	status = "okay";
    	current-speed = <115200>;
    };
    
    
    
    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    
    
    	/delete-node/ w25q32jv@0;
    
    	cs-gpios = < &gpio0 7 GPIO_ACTIVE_LOW >;
    	is25lp032d: is25lp032d@0 {
    		compatible = "jedec,spi-nor";
    		label = "IS25LP032D";
    		reg = < 0 >;
    		spi-max-frequency = < 40000000 >;
    		wp-gpios = < &gpio0 8 GPIO_ACTIVE_LOW >;
    		hold-gpios = < &gpio0 10 GPIO_ACTIVE_LOW >;
    		size = < 0x2000000 >;
    		has-dpd;
    		t-enter-dpd = < 3000 >;
    		t-exit-dpd = < 30000 >;
    		jedec-id = [ 9d 60 16  ];
    
    	};
    };
    

    the image is loading into external flash

    uart:~$ mcuboot
    swap type: test
    confirmed: 0
    
    primary area (3):
      version: 0.0.0+0
      image size: 192552
      magic: unset
      swap type: none
      copy done: unset
      image ok: unset
    
    secondary area (1):
      version: 0.0.0+0
      image size: 192432
      magic: good
      swap type: test
      copy done: unset
      image ok: unset
    uart:~$ [00:00:35.131,164] <inf> mcuboot_util: Swap type: test
    [00:00:35.131,164] <inf> mcuboot_util: Swap type: test

    shell read of flash - not sure if this is a valid result, but it looks promising.

    uart:~$ flash read IS25LP032D 0 0x1000
    00000000: 3d b8 f3 96 00 00 00 00  00 02 00 00 b0 ef 02 00 |=....... ........|
    00000010: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........|
    00000020: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000030: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000040: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000050: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000060: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000070: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000080: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000090: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000A0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000B0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000C0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000D0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000E0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000000F0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000100: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000110: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000120: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000130: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000140: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000150: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000160: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000170: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000180: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000190: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001A0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001B0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001C0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001D0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001E0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    000001F0: ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff |........ ........|
    00000200: 00 0c 00 20 45 03 01 00  c7 03 01 00 61 12 01 00 |... E... ....a...|
    00000210: 6b 12 01 00 75 12 01 00  89 12 01 00 7f 12 01 00 |k...u... ........|
    00000220: 00 00 00 00 00 00 00 00  00 00 00 00 95 20 01 00 |........ ..... ..|
    00000230: e3 03 01 00 00 00 00 00  59 20 01 00 eb 03 01 00 |........ Y ......|
    00000240: 00 00 00 00 00 00 00 00  00 00 00 00 ef 03 01 00 |........ ........|
    00000250: 00 00 00 00 f3 03 01 00  00 00 00 00 00 00 00 00 |........ ........|
    00000260: f7 03 01 00 fb 03 01 00  ff 03 01 00 03 04 01 00 |........ ........|
    00000270: 00 00 00 00 07 04 01 00  0b 04 01 00 0f 04 01 00 |........ ........|
    00000280: 13 04 01 00 17 04 01 00  00 00 00 00 00 00 00 00 |........ ........|
    00000290: 1b 04 01 00 1f 04 01 00  00 00 00 00 00 00 00 00 |........ ........|
    000002A0: 23 04 01 00 00 00 00 00  00 00 00 00 27 04 01 00 |#....... ....'...|

    I'd really appreciate a bit of help its driving me nuts. 

    This is me as well..... 

    https://devzone.nordicsemi.com/f/nordic-q-a/93387/fota-to-external-flash

    Thanks

    Marshall

  • Hi  and  

     

    My deepest apologies for the inconvenience.

    Unfortunately, there is another breaking change in NCS v2.1.0, that blocks for using SPI based flash ("spi_nor") in mcuboot.

    You will need in total 2 changes:

    1. in your child_image/mcuboot.conf, you will need to add this symbol when using SPI and flash:

    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

     

    2. In addition, there is a bug with the flash_device that mcuboot picks up through the "partition manager" script system.

    This line in ncs_v2.1.0/nrf/cmake/partition_manager.cmake:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.1.2/cmake/partition_manager.cmake#L215

     

    Shall be changed to:

        DEVICE "DT_CHOSEN(nordic_pm_ext_flash)"

     

    The second point is handled in this PR, but due to release-note changes as well, it is not easy to cherry pick directly:

    https://github.com/nrfconnect/sdk-nrf/pull/9169

     

    Could you try these two steps and report back if this helps the scenario?

     

    Kind regards,

    Håkon

  • Oh my goodness..... IT WORKS

    Thanks so much for the support. 

    Regards

    Marshall

Reply Children
  • Hi Marshall,

     

    I'm glad to hear that it is working at your end now.

    I'll pursue this issue internally, and make sure it is handled.

     

    Kind regards,

    Håkon

  • Hi ,

    Thanks for your support and sorry for my late reply.

    I works properly with the example.

    By the way, my external flash needs to be portioned.

    I created a static partition for the external flash using the "pm static.yml" file.

    #include <autoconf.h>
    EMPTY_0:
      address: 0xc000
      end_address: 0x10000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x4000
    EMPTY_1:
      address: 0xf0000
      end_address: 0xf8000
      placement:
        after:
        - mcuboot_secondary
      region: flash_primary
      size: 0x8000
    app:
      address: 0x1c200
      end_address: 0x80000
      region: flash_primary
      size: 0x63e00
    littlefs_storage:
      address: 0xfa000
      align:
        start: 0x8000
      end_address: 0xfb000
      inside:
      - nonsecure_storage
      placement:
        before:
        - end
      region: flash_primary
      size: 0x1000
    nvs_storage:
      address: 0xfb000
      align:
        start: 0xb000
      end_address: 0xfc000
      inside:
      - nonsecure_storage
      placement:
        before:
        - end
      region: flash_primary
      size: 0x1000
    reserved_storage:
      address: 0xfc000
      align:
        start: 0x8000
      end_address: 0x10000
      inside:
      - nonsecure_storage
      placement:
        before:
        - end
      region: flash_primary
      size: 0x4000    
    mcuboot:
      address: 0x0
      end_address: 0xc000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xc000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x8000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0x80000
      orig_span: &id001
      - tfm
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size: 0x70000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0x80000
      orig_span: &id002
      - app
      - tfm
      region: flash_primary
      size: 0x6fe00
      span: *id002
    # mcuboot_secondary:
    #   address: 0x80000
    #   end_address: 0xf0000
    #   placement:
    #     after:
    #     - mcuboot_primary
    #     align:
    #       start: 0x8000
    #   region: flash_primary
    #   share_size:
    #   - mcuboot_primary
    #   size: 0x70000
    nonsecure_storage:
      address: 0xf8000
      end_address: 0x100000
      orig_span: &id003
      - settings_storage
      region: flash_primary
      size: 0x8000
      span: *id003
    nrf_modem_lib_ctrl:
      address: 0x2000b000
      end_address: 0x2000b4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - tfm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x2000d4e8
      end_address: 0x2000f4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x2000b000
      end_address: 0x2000f4e8
      orig_span: &id004
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x44e8
      span: *id004
    nrf_modem_lib_tx:
      address: 0x2000b4e8
      end_address: 0x2000b4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2000
    otp:
      address: 0xff8108
      end_address: 0xff83fc
      region: otp
      size: 0x2f4
    settings_storage:
      address: 0xf8000
      end_address: 0xfa000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_nonsecure:
      address: 0x2000b000
      end_address: 0x20040000
      orig_span: &id005
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x35000
      span: *id005
    sram_primary:
      address: 0x2000f4e8
      end_address: 0x20040000
      region: sram_primary
      size: 0x30b18
    sram_secure:
      address: 0x20000000
      end_address: 0x200B0000
      orig_span: &id006
      - tfm_sram
      region: sram_primary
      size: 0x0B000
      span: *id006
    tfm:
      address: 0x10200
      end_address: 0x1c200
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0xc000
    tfm_nonsecure:
      address: 0x1c200
      end_address: 0x80000
      orig_span: &id007
      - app
      region: flash_primary
      size: 0x63e00
      span: *id007
    tfm_secure:
      address: 0x10000
      end_address: 0x1c200
      orig_span: &id008
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0xc200
      span: *id008
    tfm_sram:
      address: 0x20000000
      end_address: 0x2000B000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x0B000
    external_flash:
      address: 0x0
      device: MX25R64
      end_address: 0x800000
      region: external_flash
      size: 0x800000
    mcuboot_secondary:
      address: 0x00
      region: external_flash
      size: 0xF0000
    lte_modem_fw:
      address: 0xF0000
      region: external_flash
      size: 0x4F000
    abc_fw:
      address: 0x13F000
      region: external_flash
      size: 0xF5000 
    def_fw:
      address: 0x234000
      region: external_flash
      size: 0xF5000   
    datalogger_storage:
      address: 0x329000
      region: external_flash
      size: 0x450000
     

    The system can download successfully, however after rebooting to the bootloader, it displays that it cannot upgrade.

    [00:07:47.032,867] <inf> download_client: Downloaded 209000/214490 bytes (97%)
    [00:07:48.711,853] <inf> download_client: Downloaded 210000/214490 bytes (97%)
    [00:07:50.662,628] <inf> download_client: Downloaded 211000/214490 bytes (98%)
    [00:07:52.616,790] <inf> download_client: Downloaded 212000/214490 bytes (98%)
    [00:07:54.151,000] <inf> download_client: Downloaded 213000/214490 bytes (99%)
    [00:07:55.528,106] <inf> download_client: Downloaded 214000/214490 bytes (99%)
    [00:07:57.320,892] <inf> download_client: Downloaded 214490/214490 bytes (100%)
    [00:07:57.338,562] <inf> download_client: Download complete
    [00:07:57.444,396] <inf> dfu_target_mcuboot: MCUBoot image-0 upgrade scheduled. Reset device to apply
    AZURE_IOT_HUB_EVT_FOTA_DONE
    The device will reboot in 5 seconds to apply update
    AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 477&$version=23ersion=9
    *** Booting Zephyr OS build v3.1.99-ncs1-1  ***
    I: Starting bootloader
    W: Cannot upgrade: not a compatible amount of sectors
    I: Bootloader chainload address offset: 0x10000
    *** Booting Zephyr OS build v3.1.99-ncs1-1  ***
    Azure FOTA sample started
    This may take a while if a modem firmware update is pending
    [00:00:00.497,985] <inf> azure_fota: Current firmware version: v0.0.1Ext
    Connecting to LTE network
    DNS correctly set
    +CEREG: 2,"C008","024BB1A1",9
    LTE cell changed: Cell ID: 38515105, Tracking area: 49160
    +CSCON: 1
    RRC mode: Connected
    +CEREG: 1,"C008","024BB1A1",9,,,"11100000","00010010"
    Network registration status: Connected - home network
    AZUREPSM parameter update: TAU: 10800, Active time: -1
    _IOT_HUB_EVT_CONNECTING
    AZURE_IOT_HUB_EVT_CONNECTED
    AZURE_IOT_HUB_EVT_READY
    [00:00:15.965,881] <wrn> azure_fota: FOTA image was not applied, rolled back
    [00:00:15.976,013] <wrn> azure_fota: Update job (ID: 3) was already attempted, aborting
    AZURE_IOT_HUB_EVT_TWIN_RECEIVED
    AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 159&$version=24
    +CSCON: 0
    RRC mode: Idle

    Can we do the FOTA utilizing the external flash static partition?

  • Hi,

    Rung said:
    I works properly with the example.

    Ok, good, so that means that you have implemented the formerly mentioned fix for ncs v2.1.0.

     

    Which image are you downloading?

    When updating, it is important that the original static partition is kept for all update-images as well, to ensure that mcuboot recognizes the image properly.

     

    Kind regards,

    Håkon

  • Hi,

    Which image are you downloading?

    Like with the "azure_fota" sample I tested, I used the "app_update.bin" file.

    However, the "Cannot upgrade: not a compatible amount of sectors" error, I have divided the external flash memory by add the "pm_static.yml" file.

    When updating, it is important that the original static partition is kept for all update-images as well, to ensure that mcuboot recognizes the image properly.

    What is the "original static partition is kept for all-images as well" means?

    Did you mean we cannot costume the external flash partition by using the static partition, pm_static.yml file.

    If so, could you provide me some advise on how to partition the external flash?

  • Hi,

     

    Rung said:

    What is the "original static partition is kept for all-images as well" means?

    Did you mean we cannot costume the external flash partition by using the static partition, pm_static.yml file.

    If so, could you provide me some advise on how to partition the external flash?

    In order to successfully update, your "app_update.bin" must be provided with the same pm_static.yml as your original project.

    This is to ensure that the image is setup with the same flash address offset as mcuboot was configured to.

    Did you add this to your configuration? 

    Håkon Alseth said:
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

    And also changed this line:

        DEVICE "DT_CHOSEN(nordic_pm_ext_flash)"

    In file:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.1.2/cmake/partition_manager.cmake#L215

     

    Note that you should delete the build and regenerate the project.

     

    Kind regards,

    Håkon

Related