Use external flash (AT45DB0) with MCUBOOT

I am using nRF Connect SDK v2.2.0 with nRF52810 on a custom board. 
We have included OTA updates in our project, and it works successfully and downloads the firmware via MQTT and writes it using developer.nordicsemi.com/.../dfu_target.html.
Because the internal flash nRF52810 is not enough for us, we want to use the external flash AT45DB0 to store the firmware image.
As an example I used tests\modules\mcuboot\external_flash.
As a result of the build, I get an error:
 
I made a child_image\boards .overlay file:
/ {
	led {
		compatible = "gpio-leds";
		but_led_1: but_led {
			gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
			label = "Permission to turn off the device";
		};
	};

	aliases {
		mcuboot-led0 = &but_led_1;
	};

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

&gpio0 {
	status = "okay";
};

&spi2 {
	status = "okay";
	pinctrl-0 = <&spi2_default>;
	pinctrl-1 = <&spi2_sleep>;
	pinctrl-names = "default", "sleep";
	cs-gpios = < &gpio0 29 GPIO_ACTIVE_LOW >;

	at45db0: at45db161d@0 {
		compatible = "atmel,at45";
		reg = <0>;
		spi-max-frequency = <15000000>;
		label = "AT45DB0";
		jedec-id = [1f 26 00];
		size = <16777216>;
		sector-size = <131072>;
		block-size = <4096>;
		page-size = <512>;
		use-udpd;
		enter-dpd-delay = <2000>;
		exit-dpd-delay = <35000>;
		status = "okay";
	};
};

I made a child mcuboot.config file:
#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
CONFIG_MAIN_STACK_SIZE=10240
#CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000 
#CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"

CONFIG_MCUBOOT_INDICATION_LED=y

CONFIG_FLASH=y
CONFIG_FPROTECT=y
CONFIG_PM=n

CONFIG_FW_INFO=y

#CONFIG_BOOT_ENCRYPT_EC256=n
#CONFIG_BOOT_ENCRYPT_RSA=n
#CONFIG_BOOT_ENCRYPT_X25519=n
#CONFIG_BOOT_SWAP_SAVE_ENCTLV=n

#CONFIG_BOOT_BOOTSTRAP=n
#CONFIG_BOOT_UPGRADE_ONLY=n

### Minimal Configurations ###
#CONFIG_ASSERT=n
#CONFIG_BOOT_BANNER=n
#CONFIG_CLOCK_CONTROL=n
#CONFIG_KERNEL_MEM_POOL=n
#CONFIG_MINIMAL_LIBC_CALLOC=n
#CONFIG_MINIMAL_LIBC_MALLOC=n
#CONFIG_MINIMAL_LIBC_REALLOCARRAY=n
#CONFIG_NCS_SAMPLES_DEFAULTS=n
#CONFIG_NO_RUNTIME_CHECKS=y
#CONFIG_REBOOT=n
#CONFIG_RESET_ON_FATAL_ERROR=n
#CONFIG_SIZE_OPTIMIZATIONS=y
#CONFIG_SYS_CLOCK_EXISTS=n

# Config logger
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
### Ensure Zephyr logging changes don't use more resources
CONFIG_LOG_DEFAULT_LEVEL=3
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
CONFIG_CBPRINTF_NANO=y

CONFIG_CONSOLE=y
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y

Added pm_static.yml file static partition to the root of the project:
app:
  address: 0xc200
  end_address: 0xfa000
  region: flash_primary
  size: 0xede00
external_flash:
  address: 0xee000
  end_address: 0x800000
  region: external_flash
  size: 0x712000
littlefs_storage:
  address: 0xfa000
  end_address: 0x100000
  placement:
    before:
    - end
  region: flash_primary
  size: 0x6000
mcuboot:
  address: 0x0
  end_address: 0xc000
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0xc000
mcuboot_pad:
  address: 0xc000
  end_address: 0xc200
  placement:
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0xc000
  end_address: 0xfa000
  orig_span: &id001
  - mcuboot_pad
  - app
  region: flash_primary
  size: 0xee000
  span: *id001
mcuboot_primary_app:
  address: 0xc200
  end_address: 0xfa000
  orig_span: &id002
  - app
  region: flash_primary
  size: 0xede00
  span: *id002
mcuboot_secondary:
  address: 0x0
  device: AT45DB0
  end_address: 0xee000
  placement:
    align:
      start: 0x4
  region: external_flash
  size: 0xee000
sram_primary:
  address: 0x20000000
  end_address: 0x20040000
  region: sram_primary
  size: 0x40000

I spent a lot of time to understand why it doesn't work. I hope you can help me. 
I can provide you with the source files of my project if you need them.
 
Parents
  • Hi, 

    Try to remove the pm_static.yml, and add CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y to child_image/mcuboot.conf.

    Regards,
    Amanda H.

  • I need "mcuboot_secondary" to be on external flash (AT45DB0).

  • Hi, 

    Please run the following command under build folder:

    ninja partition_manager_report

    And then post the memory layout. Let's see whether the "mcuboot_secondary" is on the external flash or not. 

    -Amanda H.

  • Hi, 

    You need to add the overlay with pm-ext-flash to both the application and MCUboot. See this post

    To use SPI external memory, it needs the following configs

    for child_image\mcuboot\boards\*board.config

    # MCUboot requires a large stack size, otherwise an MPU fault will occur
    CONFIG_MAIN_STACK_SIZE=10240
    
    CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
    
    # Enable flash operations
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    # This must be increased to accommodate the bigger images.
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y 
    
    ### Ensure Zephyr logging changes don't use more resources
    CONFIG_LOG_DEFAULT_LEVEL=0
    
    ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
    CONFIG_CBPRINTF_NANO=y
    
    CONFIG_NORDIC_QSPI_NOR=n
    
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    # If you don't add this when setting CONFIG_SPI=y, you'll get a lot of undefined references from the nrfx spim driver
    # E.G. "undefined reference to `z_impl_k_sleep'"
    CONFIG_MULTITHREADING=y
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

    for application external_flash\boards\*board.conf

    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    ################################################################################
    
    # SPI Flash
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    ################################################################################
    # Enable flash operations.
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    # Enable the LittleFS file system.
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x7000

    -Amanda H.

Reply
  • Hi, 

    You need to add the overlay with pm-ext-flash to both the application and MCUboot. See this post

    To use SPI external memory, it needs the following configs

    for child_image\mcuboot\boards\*board.config

    # MCUboot requires a large stack size, otherwise an MPU fault will occur
    CONFIG_MAIN_STACK_SIZE=10240
    
    CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
    
    # Enable flash operations
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    # This must be increased to accommodate the bigger images.
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y 
    
    ### Ensure Zephyr logging changes don't use more resources
    CONFIG_LOG_DEFAULT_LEVEL=0
    
    ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
    CONFIG_CBPRINTF_NANO=y
    
    CONFIG_NORDIC_QSPI_NOR=n
    
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    # If you don't add this when setting CONFIG_SPI=y, you'll get a lot of undefined references from the nrfx spim driver
    # E.G. "undefined reference to `z_impl_k_sleep'"
    CONFIG_MULTITHREADING=y
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

    for application external_flash\boards\*board.conf

    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    ################################################################################
    
    # SPI Flash
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    ################################################################################
    # Enable flash operations.
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    # Enable the LittleFS file system.
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x7000

    -Amanda H.

Children
Related