Hi Nordic Team,
I am using W25Q64JV external flash memory which is of 8MB for both http application update and full modem update.
The mcuboot secondary is in external flash.
My environment
Device: nrf9160dk customized one
NCS: v1.9.1
After downloading the app_update.bin file, we are rebooting the system.
During boot the device tries to install the new update but fails to update to new version.
It reverts to previous version. I am not able to rectify why it is reverting.
I have searched the devzone for the similar problem tickets, unfortunately that could not helped me.
Here is my configuration.
borads/im830_nrf9160_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; }; }; &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 = <67108864>; //8MBytes spi-max-frequency = <80000000>; reg = <0>; jedec-id = [ ef 40 17 ]; wp-gpios = <&gpio0 29 0>; hold-gpios = <&gpio0 26 0>; }; };
child_image/mcuboot.conf
# SPI operation CONFIG_SPI=y CONFIG_SPI_NOR=y CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096 CONFIG_MULTITHREADING=y CONFIG_BOOT_MAX_IMG_SECTORS=256 # Verbose mcuboot logs CONFIG_LOG=y CONFIG_LOG_OVERRIDE_LEVEL=4 # Increase the size of MCUboot to fit debug build with USB drivers CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000 # MCUboot requires a large stack size, otherwise an MPU fault will occur CONFIG_MAIN_STACK_SIZE=10240 # Enable flash operations CONFIG_FLASH=y CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32 CONFIG_SIZE_OPTIMIZATIONS=y
child_image/mcuboot/boards/im830_nrf9160.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;
};
};
&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 = <67108864>; //8MBytes
spi-max-frequency = <80000000>;
reg = <0>;
jedec-id = [ ef 40 17 ];
wp-gpios = <&gpio0 29 0>;
hold-gpios = <&gpio0 26 0>;
};
};
prj.confCONFIG_TRUSTED_EXECUTION_NONSECURE=y
# General config
CONFIG_REBOOT=y
CONFIG_RING_BUFFER=y
# LOGGNG
CONFIG_LOG=n
# Console
CONFIG_PRINTK=n
CONFIG_UART_CONSOLE=n
CONFIG_SHELL=y
CONFIG_KERNEL_SHELL=y
CONFIG_DEVICE_SHELL=y
CONFIG_POSIX_CLOCK=y
CONFIG_DATE_SHELL=y
CONFIG_SHELL_STACK_SIZE=1536
CONFIG_SHELL_BACKEND_SERIAL=n
CONFIG_THREAD_MONITOR=y
CONFIG_INIT_STACKS=y
CONFIG_BOOT_BANNER=n
CONFIG_THREAD_NAME=y
#enable RTT shell
CONFIG_USE_SEGGER_RTT=n
# UART
CONFIG_UART_ASYNC_API=y
# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_MODEM_INFO=y
CONFIG_MODEM_KEY_MGMT=y
CONFIG_DOWNLOAD_CLIENT=y
# AT libraries
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n
# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_LOCK_BANDS=y
CONFIG_LTE_LOCK_BAND_MASK="0000000001000000000000000000"
# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
# PDN library
CONFIG_PDN=y
#CONFIG_PDN_SYS_INIT=y
CONFIG_PDN_SYS_INIT=n
CONFIG_PDN_DEFAULTS_OVERRIDE=y
CONFIG_PDN_DEFAULT_APN="apn"
CONFIG_PDN_DEFAULT_FAM_IPV4=y
CONFIG_PDN_DEFAULT_AUTH_CHAP=y
CONFIG_PDN_DEFAULT_USERNAME="username"
CONFIG_PDN_DEFAULT_PASSWORD="pwd"
# Stacks and heaps
CONFIG_AGPS_OFFLINE_FLG=y
CONFIG_HEAP_MEM_POOL_SIZE=29696
# for debug
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_PRIVILEGED_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
# Flash
CONFIG_SPI=y
CONFIG_FLASH=y
# I2C
CONFIG_I2C_NRFX=y
CONFIG_I2C=y
#IMU
CONFIG_SENSOR=y
CONFIG_ICM42605=y
CONFIG_ICM42605_TRIGGER_NONE=y
# json
CONFIG_JSON_LIBRARY=y
# for Zmod library
CONFIG_FPU=y
CONFIG_FPU_SHARING=y
CONFIG_FP_HARDABI=y
CONFIG_CPU_LOAD=y
CONFIG_DATE_TIME=y
CONFIG_APP_VERSION="v0.0.4"
CONFIG_DEVELOP_MODE=y
CONFIG_STAGING_FLG=y
CONFIG_CJSON_LIB=y
# appication fota update configuration
CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_SOCKET_RETRIES=5
#DFU
CONFIG_DFU_TARGET=y
# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y
# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y
# Download client
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2048
CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS=n
CONFIG_DOWNLOAD_CLIENT_TCP_SOCK_TIMEO_MS=600000
# DFU Target
CONFIG_DFU_TARGET_STREAM=y
CONFIG_DFU_TARGET_FULL_MODEM=y
# Full modem firmware from external flash support
CONFIG_FMFU_FDEV=y
CONFIG_CDDL_GEN=y
#SPI NOR
CONFIG_SPI_NOR=y
#Stream flash
CONFIG_STREAM_FLASH=y
CONFIG_STREAM_FLASH_ERASE=y
#libmodem
CONFIG_NRF_MODEM_LIB_SYS_INIT=n
#Prevalidation is not yet supported by the modem firmware, so skip it for now.
CONFIG_FMFU_FDEV_SKIP_PREVALIDATION=n
CONFIG_NCS_SAMPLES_DEFAULTS=n
# Crypto
CONFIG_OBERON_BACKEND=y
CONFIG_NORDIC_SECURITY_BACKEND=y
# Disable all non-used crypto
CONFIG_NRF_SECURITY_RNG=n
CONFIG_MBEDTLS_AES_C=n
CONFIG_MBEDTLS_CHACHA20_C=n
CONFIG_MBEDTLS_POLY1305_C=n
CONFIG_MBEDTLS_ECP_C=n
CONFIG_MBEDTLS_RSA_C=n
CONFIG_MBEDTLS_DHM_C=n
CONFIG_MBEDTLS_SHA1_C=n
CONFIG_MBEDTLS_SHA384_C=n
CONFIG_MBEDTLS_SHA512_C=n
CONFIG_MBEDTLS_GCM_C=n
# This is the one we need
CONFIG_MBEDTLS_SHA256_C=y
# EXTERNAL MCUBOOT SECONDARY
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_STREAM_FLASH=y
CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=32
# Enable mcumgr.
CONFIG_MCUMGR=y
# Enable most core commands.
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
pm_static.ymlEMPTY_0:
address: 0xc000
end_address: 0x10000
placement:
before:
- mcuboot_pad
region: flash_primary
size: 0x4000
app:
address: 0x20200
end_address: 0x100000
region: flash_primary
size: 0xdfe00
external_flash:
address: 0x0
end_address: 0x600000
region: external_flash
size: 0x600000
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: 0x100000
orig_span: &id001
- app
- spm
- mcuboot_pad
region: flash_primary
size: 0xf0000
span: *id001
mcuboot_primary_app:
address: 0x10200
end_address: 0x100000
orig_span: &id002
- app
- spm
region: flash_primary
size: 0xefe00
span: *id002
mcuboot_secondary:
address: 0x600000
device: W25Q64JV
end_address: 0x6f0000
placement:
align:
start: 0x4
region: external_flash
share_size:
- mcuboot_primary
size: 0xf0000
unused_external_flash:
address: 0x6f0000
device: W25Q64JV
end_address: 0x800000
region: external_flash
size: 0x110000
CMakesLists.txt# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
set(mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(my_project)
target_sources(app
PRIVATE
src/main.c
src/common.c
src/setting.c
src/shell_cmd.c
src/logger.c
src/thread/ui/ui_thread.c
src/thread/lte/lte_thread.c
src/thread/sensor/sensor_thread.c
src/thread/wdt/wdt_thread.c
src/thread/mloca/mloca_thread.c
src/thread/mloca/mc_api.c
src/thread/gnss/gnss_thread.c
src/thread/logger/logger_thread.c
src/thread/buzzer/buzzer_thread.c
src/thread/update/update_thread.c
src/device/gpio/gpio.c
src/device/gnss/gnss.c
src/device/serialLED/serialLED.c
src/device/imu/imu.c
src/device/imu/imu_filter.c
src/device/temp_humi/temp_humi.c
src/device/buzzer/buzzer.c
src/device/flash/flash.c
src/device/lte/lte.c
src/device/carrier_certs/carrier_certs.c
src/device/lte/esm.c
src/device/uart/uart.c
)
target_include_directories(app
PRIVATE
inc
certs
)
target_compile_options(app PRIVATE -DSDK_UPDATE_1_9_1)
build folder / partitions.ymlEMPTY_0:
address: 0xc000
end_address: 0x10000
placement:
before:
- mcuboot_pad
region: flash_primary
size: 0x4000
app:
address: 0x20200
end_address: 0x100000
region: flash_primary
size: 0xdfe00
external_flash:
address: 0x0
end_address: 0x600000
region: external_flash
size: 0x600000
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: 0x100000
orig_span: &id001
- app
- spm
- mcuboot_pad
region: flash_primary
size: 0xf0000
span: *id001
mcuboot_primary_app:
address: 0x10200
end_address: 0x100000
orig_span: &id002
- app
- spm
region: flash_primary
size: 0xefe00
span: *id002
mcuboot_secondary:
address: 0x600000
device: W25Q64JV
end_address: 0x6f0000
placement:
align:
start: 0x4
region: external_flash
share_size:
- mcuboot_primary
size: 0xf0000
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
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
unused_external_flash:
address: 0x6f0000
device: W25Q64JV
end_address: 0x800000
region: external_flash
size: 0x110000
build folder / regions.ymlexternal_flash:
base_address: 0x0
device: W25Q64JV
dynamic_partition: null
name: external_flash
placement_strategy: start_to_end
size: 0x800000
flash_primary:
base_address: 0x0
device: NRF_FLASH_DRV_NAME
dynamic_partition: null
name: flash_primary
placement_strategy: complex
size: 0x100000
otp:
base_address: 0xff8108
device: ''
dynamic_partition: null
name: otp
placement_strategy: start_to_end
size: 0x2f4
sram_primary:
base_address: 0x20000000
device: ''
dynamic_partition: sram_primary
name: sram_primary
placement_strategy: complex
size: 0x40000
Checklist
1. I am calling the boot_write_img_confirmed() in the main top.
2. I am using the same pm_static.yml file for both the old version and new updates.
I think that when the application FOTA fails, it is reverted by Zephyr OS.
I would like to know under what circumstances (under what conditions) it will be reverted?
My configurations are correct? Am I missing something?
EDITED
What are the steps to be carried out when creating new version update file (app_update.bin file)?
do we need to use same computer for creating old version build and new version build?
NOTE:
-> I have also noticed that, the fota update is successful sometime, and most of the times it is reverted. (ratio is like 19 (fail) : 1 (success))
-> I have also noticed that, when debugger is connected, it works without any issue.
-> I have also noticed that LTE-ACT LED is turned off in the board
-> We are using A-GPS, we are downloading - U-BLOX file online using download client after every boot.
Best Regards
Praveen Deshmane