External Flash OTA + Littlefs storage

Hello All,

I am using nrf9160 based custom board with external flash. I am trying to build an application with mcuboot, primary image in internal flash and secondary image in external flash.

Now I defined about memory layout in pm_static.yml file, where primary image will be in internal flash, secondary image & littlefs storage will be in external flash.

But even though mcuboot fail's to boot the application image.

[00:00:00.258,331] <wrn> mcuboot: Failed reading sectors; BOOT_MAX_IMG_SECTORS=2048 - too small?
[00:00:00.258,331] <wrn> mcuboot: Cannot upgrade: not a compatible amount of sectors

dts file

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
        pinctrl-0 = <&spi3_default>;
        pinctrl-1 = <&spi3_sleep>;
        pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;

	w25q32jv: w25q32jv@0 {
		compatible = "jedec,spi-nor";
		status = "okay";
		label = "W25Q32JV";
		reg = <0>;
		spi-max-frequency = <8000000>;
		wp-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
		hold-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;
		size = <0x4000000>;
		has-dpd;
		t-enter-dpd = <3000>;
		t-exit-dpd = <30000>;
		jedec-id = [ef 40 17];

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

			storage_partition: partition@0 {
				label = "storage";
				reg = <0x00000000 DT_SIZE_M(7)>;
			};
		};
	};
};

&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>;
		};
	};
};

pm_static.yml file

mcuboot:
  address: 0x0
  size: 0x10000
  region: flash_primary
mcuboot_pad:
  address: 0x10000
  size: 0x200
  region: flash_primary
spm:
  address: 0x10200
  region: flash_primary
  size: 0xc000
app:
  address: 0x1c200
  region: flash_primary
  size: 0xd3e00
mcuboot_primary:
  orig_span: &id001
  - mcuboot_pad
  - spm
  - app
  span: *id001
  address: 0x10000
  size: 0xe0000
  region: flash_primary
mcuboot_primary_app:
  orig_span: &id002
  - spm
  - app
  span: *id002
  address: 0x10200
  size: 0xdfe00
  region: flash_primary
mcuboot_secondary:
  address: 0x0
  size: 0xe0000
  device: W25Q32JV 
  region: external_flash
littlefs_storage:
  address: 0xe0000
  device: W25Q32JV
  region: external_flash
  size: 0x720000

mcuboot.conf

CONFIG_SPEED_OPTIMIZATIONS=y

# Disable memory guard to avoid false faults in application after boot
CONFIG_HW_STACK_PROTECTION=n

#CONFIG_SYSTEM_CLOCK_DISABLE=y

CONFIG_TIMESLICING=n
CONFIG_CBPRINTF_NANO=y

CONFIG_MAIN_STACK_SIZE=10240
CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"

CONFIG_BOOT_BOOTSTRAP=n

CONFIG_BOOT_ENCRYPT_RSA=n
CONFIG_BOOT_SIGNATURE_TYPE_RSA=n
CONFIG_BOOT_ECDSA_CC310=y
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
CONFIG_BOOT_SIGNATURE_KEY_FILE="root-ec-p256.pem"

# Flash
CONFIG_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_BOOT_ERASE_PROGRESSIVELY=y
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y

# Logger
CONFIG_LOG=y

# External flash
CONFIG_MULTITHREADING=y
CONFIG_BOOT_MAX_IMG_SECTORS=2048

CONFIG_NORDIC_QSPI_NOR=n

CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_SPI_NOR_SFDP_DEVICETREE=n
CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32
#CONFIG_SPI_NOR_SFDP_RUNTIME=y
# Size optimization for release build
CONFIG_BOOT_BANNER=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_USE_SEGGER_RTT=n
CONFIG_ERRNO=n
CONFIG_PRINTK=y
CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_I2C=n

Any hint to set the correct partition layout and chain the application from mcuboot?

Parents
  • Hello,

    what is the NCS version? Can you show the prj.conf and overlay file?

  • NCS version: v2.1.99-dev2

    prj.conf

    CONFIG_GPIO=y
    
    # General config
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    CONFIG_REBOOT=y
    
    # NEWLIB C
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_NATIVE=n
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_NETWORK_MODE_LTE_M=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    # AT Host
    CONFIG_UART_INTERRUPT_DRIVEN=n
    CONFIG_AT_HOST_LIBRARY=n
    
    # Date Time library
    CONFIG_DATE_TIME=y
    
    # Modem information
    CONFIG_MODEM_INFO=y
    
    # Modem key management
    CONFIG_MODEM_KEY_MGMT=y
    CONFIG_MODEM_KEY_MGMT_LOG_LEVEL_ERR=y
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=32768
    CONFIG_MAIN_STACK_SIZE=16384
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
    
    # CJSON
    CONFIG_CJSON_LIB=y
    
    # Littlefs
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    # External Flash
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_SPI_NOR_SFDP_DEVICETREE=n
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    
    # No of Opened Files
    CONFIG_FS_LITTLEFS_NUM_FILES=8
    
    # ADXL372 Sensor
    CONFIG_SPI=y
    CONFIG_SENSOR=y
    CONFIG_ADXL372=y
    
    CONFIG_ADXL372_MEASUREMENT_MODE=y
    CONFIG_ADXL372_TRIGGER_OWN_THREAD=y
    CONFIG_ADXL372_PEAK_DETECT_MODE=n
    
    CONFIG_ADXL372_ACTIVITY_THRESHOLD=2000
    CONFIG_ADXL372_ACTIVITY_TIME=1
    
    CONFIG_ADXL372_INACTIVITY_THRESHOLD=1000
    CONFIG_ADXL372_INACTIVITY_TIME=5
    
    CONFIG_ADXL372_TRIGGER_GLOBAL_THREAD=y
    
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    # LIS3DH Sensor
    CONFIG_LIS2DH=y
    CONFIG_LIS2DH_ACCEL_RANGE_16G=y
    
    CONFIG_LIS2DH_OPER_MODE_LOW_POWER=y
    CONFIG_LIS2DH_ODR_9_LOW=y
    
    # Temperature Sensor
    CONFIG_I2C=y
    CONFIG_SHTCX=y
    
    # ADC
    CONFIG_ADC=y
    CONFIG_NRFX_SAADC=y
    
    # LOG Level
    CONFIG_SWITCH_APP_LOG_LEVEL_DBG=y 
    
    # WatchDog Timer
    CONFIG_WATCHDOG=y
    CONFIG_WDT_DISABLE_AT_BOOT=n
    
    CONFIG_HTTP_CLIENT=y
    
    # Bootloader MCUBOOT
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_MCUBOOT_IMG_MANAGER=y
    
    # AWS IoT library
    CONFIG_AWS_IOT=y
    CONFIG_AWS_IOT_CLIENT_ID_APP=y
    CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=1
    CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
    CONFIG_AWS_IOT_LAST_WILL=y
    #CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
    #CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y
    
    # MQTT - Maximum MQTT keepalive timeout specified by AWS IoT Core
    CONFIG_MQTT_KEEPALIVE=1200
    
    # Image manager
    CONFIG_IMG_MANAGER=y
    CONFIG_FLASH=y
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    
    # AWS FOTA
    CONFIG_AWS_FOTA=y
    CONFIG_FOTA_DOWNLOAD=y
    CONFIG_DFU_TARGET=y
    
    # CJSON
    CONFIG_CJSON_LIB=y
    
    # Download client (needed by AWS FOTA)
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    
    # Heap
    CONFIG_NRF_MODEM_LIB_HEAP_SIZE=4096
    
    # Power Management
    CONFIG_PM_DEVICE=y
    
    # Debug Console
    CONFIG_SERIAL=y
    CONFIG_UART_CONSOLE=y
    CONFIG_CONSOLE=y
    
    CONFIG_APP_WIPE_STORAGE=n
    
    CONFIG_SHELL=n
    
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

    There is no overlay file. I defined board related info in dts file itself.

    Generated build/partition.yml file

    app:
      address: 0x28200
      end_address: 0x100000
      region: flash_primary
      size: 0xd7e00
    external_flash:
      address: 0x800000
      end_address: 0x800000
      region: external_flash
      size: 0x0
    littlefs_storage:
      address: 0xe0000
      device: W25Q32JV
      end_address: 0x800000
      region: external_flash
      size: 0x720000
    mcuboot:
      address: 0x0
      end_address: 0x10000
      region: flash_primary
      size: 0x10000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xf0000
      orig_span: &id001
      - mcuboot_pad
      - spm
      - app
      region: flash_primary
      size: 0xe0000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xf0000
      orig_span: &id002
      - spm
      - app
      region: flash_primary
      size: 0xdfe00
      span: *id002
    mcuboot_secondary:
      address: 0x0
      device: W25Q32JV
      end_address: 0xe0000
      region: external_flash
      size: 0xe0000
    nrf_modem_lib_ctrl:
      address: 0x20008000
      end_address: 0x200084e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - tfm_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: 0x1c200
      region: flash_primary
      size: 0xc000
    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
      - tfm_sram
      region: sram_primary
      size: 0x8000
      span: *id005
    tfm:
      address: 0x1c200
      end_address: 0x28200
      placement:
        before:
        - app
      region: flash_primary
      size: 0xc000
    tfm_nonsecure:
      address: 0x28200
      end_address: 0x100000
      orig_span: &id006
      - app
      region: flash_primary
      size: 0xd7e00
      span: *id006
    tfm_secure:
      address: 0x1c200
      end_address: 0x28200
      orig_span: &id007
      - tfm
      region: flash_primary
      size: 0xc000
      span: *id007
    tfm_sram:
      address: 0x20000000
      end_address: 0x20008000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000

  • You can try adding the configs

    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_SINGLE_IMAGE=y

  • Hi Hakon,

    Thanks for the input. But still getting the same error.

    [00:00:00.256,622] <inf> mcuboot: Starting bootloader
    [00:00:00.256,835] <wrn> mcuboot: Failed reading sectors; BOOT_MAX_IMG_SECTORS=2048 - too small?
    [00:00:00.256,866] <wrn> mcuboot: Cannot upgrade: not a compatible amount of sectors
    [00:00:00.256,866] <err> mcuboot: Unable to find bootable image

  • Can you check build/mcuboot/.config and confirm that the page size is actually set to 4096? You can also do the same for the app image.

  • yes the page size is set to 4096, for both the mcuboot/.config & zephyr/.config.

    CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

Reply Children
Related