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.

Fullscreen
1
2
3
4
5
*** 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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Checked the partition with west build -t partition_manager_report .

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
+------------------------------------------+
| 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) |
+--------------------------------------------------+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My configuration as follows:

child_image\mcuboot\boards\nrf9160dk_nrf9160_mcuboot.overlay

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/ {
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>;
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

child_image\mcuboot\prj_mcuboot.conf

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

nrf9160dk_nrf9160_ns.overlay

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/ {
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>;
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

pm_static.yml

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
#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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

prj.conf

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# 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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    external_flash:
    address: 0x0
    device: mx25r6435f
    region: external_flash
    size: 0x800000
    mcuboot_secondary:
    address: 0x0
    device: mx25r6435f
    region: external_flash
    size: 0x70000
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    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.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    *** 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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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 reproduced the same issue, and it is related to the trusted firmware m (tfm) module. It currently has a bug in the handling of the mcuboot secondary slot, which we are addressing with this pull-request:

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

     

    For now, I would recommend that you add this to your prj.conf to use SPM for the time being:

    Fullscreen
    1
    2
    CONFIG_BUILD_WITH_TFM=n
    CONFIG_SPM=y
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Could you test with this and see if this runs as expected?

     

    Kind regards,

    Håkon

  • Hi,

    I got a build error after applying your suggestion.

    Please advise. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [193/205] Building C object zephyr/kernel/CMakeFiles/kernel.dir/work.c.obj
    [194/205] Linking C static library zephyr\kernel\libkernel.a
    [195/205] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\v2.0.2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/Users/TDCAdmin/Workspace/azure_fota_exFlash/build/mcuboot/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/lib/posix/liblib__posix.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/boards/boards/arm/nrf9160dk_nrf9160/libboards__arm__nrf9160dk_nrf9160.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/spi/libdrivers__spi.a zephyr/drivers/flash/libdrivers__flash.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a modules/nrf/lib/fprotect/lib..__nrf__lib__fprotect.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a modules/mcuboot/boot/bootutil/zephyr/libmcuboot_util.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"c:/ncs/toolchains/v2.0.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v8-m.main+fp/hard" -LC:/Users/TDCAdmin/Workspace/azure_fota_exFlash/build/mcuboot/zephyr -lgcc zephyr/arch/common/libisr_tables.a -no-pie -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfpu=fpv5-sp-d16 -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn C:/ncs/v2.0.2/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m33/hard-float/no-interrupts/libnrf_cc310_platform_0.9.14.a C:/ncs/v2.0.2/nrfxlib/crypto/nrf_cc310_bl/lib/cortex-m33/hard-float/no-interrupts/libnrf_cc310_bl_0.9.12.a && cmd.exe /C "cd /D C:\Users\TDCAdmin\Workspace\azure_fota_exFlash\build\mcuboot\zephyr && C:\ncs\toolchains\v2.0.2\opt\bin\cmake.exe -E echo ""
    c:/ncs/toolchains/v2.0.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: zephyr\zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
    c:/ncs/toolchains/v2.0.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `FLASH' overflowed by 1108 bytes
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    [15/287] No configure step for 'spm_subimage'
    FAILED: modules/mcuboot/mcuboot_subimage-prefix/src/mcuboot_subimage-stamp/mcuboot_subimage-build mcuboot/zephyr/zephyr.hex mcuboot/zephyr/zephyr.elf
    cmd.exe /C "cd /D C:\Users\TDCAdmin\Workspace\azure_fota_exFlash\build\mcuboot && C:\ncs\toolchains\v2.0.2\opt\bin\cmake.exe --build . --"
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.0.2\opt\bin\cmake.EXE' --build 'c:\Users\TDCAdmin\Workspace\azure_fota_exFlash\build'
    * The terminal process terminated with exit code: 1.
    * Terminal will be reused by tasks, press any key to close it.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • It looks like mcuboot is failing to compile due to a flash overflow (ie. too large image).

    Try commenting out this line in child_image/mcuboot.conf:

    CONFIG_DEBUG_OPTIMIZATIONS=y

    Kind regards,

    Håkon

  • Hi,

    Try commenting out this line in child_image/mcuboot.conf:

    CONFIG_DEBUG_OPTIMIZATIONS=y

    Build can run without error, but I got a forever loop error after flash the firmware to the board.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    *** Booting Zephyr OS build v3.0.99-ncs1-1 ***
    I: Starting bootloader
    W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
    E: ***** MPU FAULT *****
    E: Instruction Access Violation
    E: r0/a1: 0x00000000 r1/a2: 0x00000000 r2/a3: 0x2000c8e4
    E: r3/a4: 0x00000020 r12/ip: 0xb0f7f9b5 r14/lr: 0x00000ddf
    E: xpsr: 0x69100000
    E: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
    E: s[ 4]: 0x00000000 s[ 5]: 0x00000000 s[ 6]: 0x00000000 s[ 7]: 0x00000000
    E: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0x00000000
    E: s[12]: 0x00000000 s[13]: 0x00000000 s[14]: 0x00000000 s[15]: 0x00000000
    E: fpscr: 0x0000960c
    E: Faulting instruction address (r15/pc): 0xb0f7f9b4
    E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    E: Current thread: 0x2000c7e8 (unknown)
    E: Device id 00 00 00 does not match config c2 28 17
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Wandering the return data indicates that the device id does not match because [00 00 00].

    By the way, I already confirm the device id [c2 28 17] is can use or not.

    I have been tested with the spi_flash example, it can read/write in normally with the device id [c2 28 17].

    Then change the device to [00 00 00] in overlay file.

    Program runs as normally, can connect to the azure IoT hub and can start to do FOTA task.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    *** 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=bad, swap_type=0x0, copy_done=0x2, image_ok=0x2
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    *** Booting Zephyr OS build v3.0.99-ncs1-1 ***
    Flash regions Domain Permissions
    00 03 0x00000 0x20000 Secure rwxl
    04 31 0x20000 0x100000 Non-Secure rwxl
    Non-secure callable region 0 placed in flash region 3 with size 32.
    SRAM region Domain Permissions
    00 03 0x00000 0x08000 Secure rwxl
    04 31 0x08000 0x40000 Non-Secure rwxl
    Peripheral Domain Status
    00 NRF_P0 Non-Secure OK
    01 NRF_CLOCK Non-Secure OK
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    But after download complete the err is occur as below:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [00:30:05.155,761] <inf> download_client: Downloaded 214000/221979 bytes (96%)
    [00:30:09.566,833] <inf> download_client: Downloaded 215000/221979 bytes (96%)
    [00:30:19.423,309] <inf> download_client: Downloaded 216000/221979 bytes (97%)
    [00:30:25.094,177] <inf> download_client: Downloaded 217000/221979 bytes (97%)
    [00:30:29.169,219] <inf> download_client: Downloaded 218000/221979 bytes (98%)
    [00:30:33.812,316] <inf> download_client: Downloaded 219000/221979 bytes (98%)
    [00:30:36.030,792] <inf> download_client: Downloaded 220000/221979 bytes (99%)
    [00:30:40.307,739] <inf> download_client: Downloaded 221000/221979 bytes (99%)
    [00:30:42.945,892] <inf> download_client: Downloaded 221979/221979 bytes (100%)
    [00:30:42.956,359] <inf> download_client: Download complete
    [00:30:42.994,049] <err> dfu_target_mcuboot: boot_request_upgrade for image-0 error -14
    [00:30:43.003,540] <err> fota_download: dfu_target_done error: -14
    [00:30:43.011,047] <err> azure_fota: FOTA download failed
    [00:30:43.017,883] <err> azure_iot_hub: AZURE_FOTA_EVT_ERROR
    Unknown Azure IoT Hub event type: 22
    AZURE_IOT_HUB_EVT_TWIN_RESULT_SUCCESS, ID: 1843024
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Please assist me in solving this issue.

    Again, my propose is update firmware via FOTA using external flash with the ncs 2.0.2 or newer version.

    Since the TF-M is still trying to solve the problem, I agree to work with the SPM.

    By the way, please let me know if there are any TF-M updates.

    Appreciate your help.

  • Hi,

     

    Rung said:

    By the way, I already confirm the device id [c2 28 17] is can use or not.

    I have been tested with the spi_flash example, it can read/write in normally with the device id [c2 28 17].

    Then change the device to [00 00 00] in overlay file.

    This is the jedec id for your external flash, which can be read out from the datasheet of your used external flash.

    For the MX25R64 mounted on the nRF9160-DK, it is c2 28 17, and if you read all zeros, then it has issues connecting to your flash.

    For the nRF9160-DK, you must switch in the pins for communicating with the flash, as explained in this post:

     RE: Full modem update configuration 

     

    Note that this is for the board controller, ie. nrf9160dk_nrf52840, so it is important that you set the switch into "NRF52" position before programming the above snippet.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Rung said:

    By the way, I already confirm the device id [c2 28 17] is can use or not.

    I have been tested with the spi_flash example, it can read/write in normally with the device id [c2 28 17].

    Then change the device to [00 00 00] in overlay file.

    This is the jedec id for your external flash, which can be read out from the datasheet of your used external flash.

    For the MX25R64 mounted on the nRF9160-DK, it is c2 28 17, and if you read all zeros, then it has issues connecting to your flash.

    For the nRF9160-DK, you must switch in the pins for communicating with the flash, as explained in this post:

     RE: Full modem update configuration 

     

    Note that this is for the board controller, ie. nrf9160dk_nrf52840, so it is important that you set the switch into "NRF52" position before programming the above snippet.

     

    Kind regards,

    Håkon

Children
  • 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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    [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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    west build -t partition_manager_report

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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) |
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    prj.conf

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #
    # 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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    circuitdojo_feather_nrf9160_ns.overlay

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    // 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;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    child_image/mcuboot.conf

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    child_image/mcuboot/boards/circuitdojo_feather_nrf9160.overlay

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /*
    * 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;
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    the image is loading into external flash

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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 |........ ........|
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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:

    Fullscreen
    1
    DEVICE "DT_CHOSEN(nordic_pm_ext_flash)"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    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