Place mcuboot_secondary in winbond W25Q64JV extenal flash memory for FOTA using NCS 1.9.1, nrf9160dk

Hi Nordic Team,

I would like to place mcuboot_secondary in winbond W25Q64JV extenal flash memory for FOTA. I would like perform HTTP application and full modem fota.
As my app_update.bin size is very huge and internal flash memory is alomost 90% full, I could not able to do fota update.

Envrionment Details 

SDK : NCS 1.9.1 
Device :  nrf9160dk - customized one
External flash memory - winbond W25Q64JV 8MB

I have followed many devzone tickets, I could not able to place mcuboot_secondary in winbond W25Q64JV extenal flash memory. 

Prj.conf

CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_REBOOT=y

#MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_IMG_MANAGER=y

# SPI
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# QSPI
CONFIG_NORDIC_QSPI_NOR=n

# FLASH
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=6144
CONFIG_MAIN_STACK_SIZE=10240


child_image/mcuboot.conf

# SPI
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR=n

# MULTITHREAD
CONFIG_MULTITHREADING=y

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

CONFIG_BOOT_MAX_IMG_SECTORS=256

# Enable flash operations
CONFIG_FLASH=y

# This must be increased to accommodate the bigger images.
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000

# Size of mcuboot partition
CONFIG_SIZE_OPTIMIZATIONS=y

CONFIG_BOOT_ERASE_PROGRESSIVELY=y


child_image/mcuboot/boards/im830_nrf1960.overlay

/ {
    board-control {
        external_flash_pins_routing: switch-ext-mem-ctrl {
          compatible = "nordic,nrf9160dk-optional-routing";
          control-gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
          status = "okay";
        };
    };

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

};


boards/im830_nrf1960_ns.overlay

/ {
    board-control {
        external_flash_pins_routing: switch-ext-mem-ctrl {
          compatible = "nordic,nrf9160dk-optional-routing";
          control-gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
          status = "okay";
        };
    };

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


boards/im830_nrf1960_common.dts

/ {
	model = "IM-830 NRF9160";
	compatible = "im830-nrf9160";


	/* These aliases are provided for compatibility with samples */
	aliases {
		led-pwm = &pwm0;
		buzzer-pwm = &pwm1;
	};
};

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

/* PWM0 is intended for LED(PWM Serial) control */
&pwm0 {
	status = "okay";
	ch0-pin = <12>;
};

/* PWM1 is intended for buzzer control */
&pwm1 {
	status = "okay";
	ch0-pin = <1>;
	ch1-pin = <0>;
	ch1-inverted;
};


&uart0 {
	current-speed = <9600>;
	compatible = "nordic,nrf-uarte";
	status = "okay";
	tx-pin = <15>;
	rx-pin = <16>;
};


&i2c1 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <4>;
	scl-pin = <3>;
	clock-frequency = <100000>;
};


&spi2 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <8>;
	mosi-pin = <10>;
	miso-pin = <9>;
	miso-pull-up;
	cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
	icm42605@0 {
		compatible = "invensense,icm42605";
		label = "ICM-42605";
		spi-max-frequency = <1000000>;
		accel-hz = <100>;
		gyro-hz = <100>;
		accel-fs = <2>;
		reg = <0>;
		int-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>;
	};
};


&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <27>;
	mosi-pin = <28>;
	miso-pin = <30>;
	cs-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
	w25q64jv: w25q64jv@0 {
		compatible = "jedec,spi-nor";
		label = "W25Q64JV";
		size = <0x8000000>; //8MBytes
		spi-max-frequency = <40000000>;
		reg = <0>;
		jedec-id = [ ef 40 17 ]; 
		wp-gpios = <&gpio0 29 0>;
		hold-gpios = <&gpio0 26 0>;
	};
};

&timer0 {
	status = "okay";
};

&timer1 {
	status = "okay";
};

&timer2 {
	status = "okay";
};

&flash0 {

	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
		};
		slot0_ns_partition: partition@50000 {
			label = "image-0-nonsecure";
		};
		slot1_partition: partition@80000 {
			label = "image-1";
		};
		slot1_ns_partition: partition@c0000 {
			label = "image-1-nonsecure";
		};
		scratch_partition: partition@f0000 {
			label = "image-scratch";
			reg = <0x000f0000 0xa000>;
		};
		storage_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00006000>;
		};
	};
};

/ {

	reserved-memory {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		sram0_s: image_s@20000000 {
			/* Secure image memory */
		};

		sram0_modem: image_modem@20016000 {
			/* Modem (shared) memory */
		};

		sram0_ns: image_ns@20020000 {
			/* Non-Secure image memory */
		};
	};
};

/* Include partition configuration file */
#include "im830_nrf9160_partition_conf.dts"


boards/im830_nrf9160_partition_conf.dts

&slot0_partition {
	reg = <0x00010000 0x40000>;
};

&slot0_ns_partition {
	reg = <0x00050000 0x30000>;
};

&slot1_partition {
	reg = <0x00080000 0x40000>;
};

&slot1_ns_partition {
	reg = <0x000c0000 0x30000>;
};

&sram0_s {
	reg = <0x20000000 DT_SIZE_K(88)>;
};

&sram0_modem {
	reg = <0x20016000 DT_SIZE_K(40)>;
};

&sram0_ns {
	reg = <0x20020000 DT_SIZE_K(128)>;
};


boards/im830_nrf9160_ns_defconfig

# SPDX-License-Identifier: Apache-2.0

CONFIG_SOC_SERIES_NRF91X=y
CONFIG_SOC_NRF9160_SICA=y
CONFIG_BOARD_IM830_NRF9160_NS=y
# Enable MPU
CONFIG_ARM_MPU=y

# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y

# Enable TrustZone-M
CONFIG_ARM_TRUSTZONE_M=y

# This Board implies building Non-Secure firmware
CONFIG_TRUSTED_EXECUTION_NONSECURE=y

# enable GPIO
CONFIG_GPIO=y
CONFIG_PWM=y

# Enable uart driver
CONFIG_SERIAL=y

# enable console
CONFIG_CONSOLE=y

CONFIG_SPI_NOR=y


CMakeLists.txt

# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
set(mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/child_image/mcuboot/boards/im830_nrf9160.overlay")
set(mcuboot_CONF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/child_image/mcuboot.conf")

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(IM830_Poc)

target_sources(app PRIVATE src/main.c)

target_compile_options(app PRIVATE -DSDK_UPDATE_1_9_1)


I am getting this build error.

error

Please tell me why I am getting this error. My configurations are correct? How to do it in a proper way?
Its been two weeks I have gone through all the related tickets in devzone, about placing mcuboot_secondary in external flash memory for fota unfortunately none of them worked for me.

Here is my test code.

 im830.rar

Please help me to resolve this issue. Your help will be greately appreciated.

NOTE:

I request to you please dont give any solutions that are done with 
MX25R64 external flash memory and SDK version more than 1.9.1. I want it in NCS 1.9.1 SDK.

Best Regards

Praveen Deshmane

Parents
  • Hi, have you tried setting CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y in your prj.conf?

  • Hello BenKrug,

    Thank you for your reply.

    if I add CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y, It will look like this




    I will get a build time error.

     - Praveen

  • The error seems kind of weird to me, did you try making it a pm.yml file instead of pm_static?

  • I changed it to pm.yml, i got this error

    I think my pm.yml/pm_static.yml mcuboot_secondary and external_flash configuration is wrong.

    -praveen

  • my pm.yml file is like this and it works for me:

    mcuboot:
        address: 0x0
        size: 0xc000
        region: flash_primary
    mcuboot_pad:
        address: 0xc000
        size: 0xc200
    app:
        address: 0xc200
        size: 0xf1e00
    mcuboot_primary:
        orig_span: &id001
            - mcuboot_pad
            - app
        span: *id001
        address: 0xc000
        size: 0xf2000
        region: flash_primary
    mcuboot_primary_app:
        orig_span: &id002
            - app
        span: *id002
        address: 0xc200
        size: 0xf1e00
    settings_storage:
        address: 0xfe000
        size: 0x2000
        region: flash_primary
    
    
    
    mcuboot_secondary:
        address: 0x0
        size: 0xf2000
        device: MX25R16
        region: external_flash    
    littlefs_storage:
        address: 0xf2000
        size: 0xd000
        device: MX25R16
        region: external_flash 
    external_flash:
       address: 0xff000
       size: 0x707000
       device: MX25R16
       region: external_flash 

  • I modified your pm.yml with my device name

    pm.yml

    mcuboot:
        address: 0x0
        size: 0xc000
        region: flash_primary
    mcuboot_pad:
        address: 0xc000
        size: 0xc200
    app:
        address: 0xc200
        size: 0xf1e00
    mcuboot_primary:
        orig_span: &id001
            - mcuboot_pad
            - app
        span: *id001
        address: 0xc000
        size: 0xf2000
        region: flash_primary
    mcuboot_primary_app:
        orig_span: &id002
            - app
        span: *id002
        address: 0xc200
        size: 0xf1e00
    settings_storage:
        address: 0xfe000
        size: 0x2000
        region: flash_primary
    mcuboot_secondary:
        address: 0x0
        size: 0xf2000
        device: W25Q64JV
        region: external_flash    
    littlefs_storage:
        address: 0xf2000
        size: 0xd000
        device: W25Q64JV
        region: external_flash 
    external_flash:
       address: 0xff000
       size: 0x707000
       device: W25Q64JV
       region: external_flash 

    end up with failed message

    - praveen

  • when i normally build my application without external flash settings my partition.yml from build folder will be like this

    partition.yml

    EMPTY_0:
      address: 0xc000
      end_address: 0x10000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x4000
    app:
      address: 0x20200
      end_address: 0x88000
      region: flash_primary
      size: 0x67e00
    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: 0x88000
      orig_span: &id001
      - app
      - spm
      - mcuboot_pad
      region: flash_primary
      sharers: 0x1
      size: 0x78000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0x88000
      orig_span: &id002
      - app
      - spm
      region: flash_primary
      size: 0x77e00
      span: *id002
    nrf_modem_lib_ctrl:
      address: 0x20008000
      end_address: 0x200084e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - spm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x2000a4e8
      end_address: 0x2000c4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x20008000
      end_address: 0x2000c4e8
      orig_span: &id003
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x44e8
      span: *id003
    nrf_modem_lib_tx:
      address: 0x200084e8
      end_address: 0x2000a4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2000
    otp:
      address: 0xff8108
      end_address: 0xff83fc
      region: otp
      size: 0x2f4
    spm:
      address: 0x10200
      end_address: 0x20200
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x10000
    spm_sram:
      address: 0x20000000
      end_address: 0x20008000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000
    sram_nonsecure:
      address: 0x20008000
      end_address: 0x20040000
      orig_span: &id004
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x38000
      span: *id004
    sram_primary:
      address: 0x2000c4e8
      end_address: 0x20040000
      region: sram_primary
      size: 0x33b18
    sram_secure:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id005
      - spm_sram
      region: sram_primary
      size: 0x8000
      span: *id005
    mcuboot_secondary:
      address: 0x88000
      end_address: 0x100000
      placement:
        after: 
          - mcuboot_primary
        align: 
          start: 0x8000
        align_next: 0x8000
      region: flash_primary 
      share_size:
        - mcuboot_primary
      size: 0x78000

Reply
  • when i normally build my application without external flash settings my partition.yml from build folder will be like this

    partition.yml

    EMPTY_0:
      address: 0xc000
      end_address: 0x10000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x4000
    app:
      address: 0x20200
      end_address: 0x88000
      region: flash_primary
      size: 0x67e00
    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: 0x88000
      orig_span: &id001
      - app
      - spm
      - mcuboot_pad
      region: flash_primary
      sharers: 0x1
      size: 0x78000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0x88000
      orig_span: &id002
      - app
      - spm
      region: flash_primary
      size: 0x77e00
      span: *id002
    nrf_modem_lib_ctrl:
      address: 0x20008000
      end_address: 0x200084e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - spm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x2000a4e8
      end_address: 0x2000c4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x20008000
      end_address: 0x2000c4e8
      orig_span: &id003
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x44e8
      span: *id003
    nrf_modem_lib_tx:
      address: 0x200084e8
      end_address: 0x2000a4e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2000
    otp:
      address: 0xff8108
      end_address: 0xff83fc
      region: otp
      size: 0x2f4
    spm:
      address: 0x10200
      end_address: 0x20200
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x10000
    spm_sram:
      address: 0x20000000
      end_address: 0x20008000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000
    sram_nonsecure:
      address: 0x20008000
      end_address: 0x20040000
      orig_span: &id004
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x38000
      span: *id004
    sram_primary:
      address: 0x2000c4e8
      end_address: 0x20040000
      region: sram_primary
      size: 0x33b18
    sram_secure:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id005
      - spm_sram
      region: sram_primary
      size: 0x8000
      span: *id005
    mcuboot_secondary:
      address: 0x88000
      end_address: 0x100000
      placement:
        after: 
          - mcuboot_primary
        align: 
          start: 0x8000
        align_next: 0x8000
      region: flash_primary 
      share_size:
        - mcuboot_primary
      size: 0x78000

Children
  • do you know at what step it's giving the error messages?

  • I suspect on spi driver, spm child image




    c:/users/ift_praveen/ncs/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spim.c.obj):(.rodata.__compound_literal.0+0x0): undefined reference to `__device_dts_ord_67'
    c:/users/ift_praveen/ncs/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spim.c.obj):(.rodata.__compound_literal.1+0x0): undefined reference to `__device_dts_ord_67'
    c:/users/ift_praveen/ncs/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/flash/libdrivers__flash.a(spi_nor.c.obj):(.data.__compound_literal.0+0x0): undefined reference to `__device_dts_ord_67'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    [17/214] Completed 'mcuboot_subimage'
    FAILED: modules/nrf/samples/spm_subimage-prefix/src/spm_subimage-stamp/spm_subimage-build spm/zephyr/zephyr.hex spm/zephyr/zephyr.elf spm/libspmsecureentries.a
    cmd.exe /C "cd /D C:\Users\ift_praveen\Downloads\im830\build\spm && C:\Users\ift_praveen\ncs\v1.9.1\toolchain\opt\bin\cmake.exe --build . --"
    ninja: build stopped: subcommand failed.

  • when you set the file as pm_static.yml, does the step where the error occur happen after or before this step 17? That would be important for us to know if you're actually fixing anything when you set the file as pm_static.yml

  • this error was there
    1. even before we are added missing .overlay file in the boards folder

    - Added pm_static.yml
     
    re occurred on 
    2. after changing the pm_static.yml to pm.yml  


    Again, now i switched from pm.yml to pm_static.yml, I am gettng the same error. Kind of weird. 

    Even though i deleted build folder before build. 

  • I think it might be a problem that happens earlier than the pm.yml build then. So it might be something else, I'm trying to look for similar errors.

Related