FOTA update failure for custom development

I am currently developing software of the nrf9160 and am having trouble with a firmware upgrade.  The firmware data is received via UART.  All of the functions work as expected but when the device reboots, the new firmware doesn't run.

int firmware_update_demo(char *URL)
{
	char *demo_pointer = NULL;
	const void *buf;
	size_t len;

	size_t firmware_update_len;

	int response = 0;
	

	uint8_t mcubuf[1000];
	dfu_target_mcuboot_set_buf(mcubuf, sizeof(mcubuf));

	int set_buf = dfu_target_mcuboot_init((size_t)file_size,0, NULL);

	LOG_WRN("Dfu target init: %d", set_buf);

         // 
         
         CODE TO COLLECT THE DATA OVER SERIAL IS HERE
         
         
         //
         

		int offset_get = dfu_target_mcuboot_offset_get(&fota_offset);
		LOG_INF("Offset get: %d", offset_get);
		LOG_INF("offset: %d", fota_offset);

		int dfu_write = dfu_target_mcuboot_write(firmware_block, content_len);
		LOG_INF("dfu write: %d", dfu_write);


	int download_done = dfu_target_mcuboot_done(true);
	LOG_INF("DOWNLOAD DONE: %d", download_done);
	// Set back variables to default values
	fota_offset = 0;
	start_range = 0;


	int schedule_update = dfu_target_mcuboot_schedule_update(0);
	LOG_ERR("Update Scheduled: %d", schedule_update);

	k_sleep(K_MSEC(10000));
	sys_reboot(1);
	;
	return 0;
}

My PRJ file is as follows:

# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_ASSERT=y
CONFIG_REBOOT=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y

# Sensors
CONFIG_SPI=y
CONFIG_SENSOR=y

# LwM2M and IPSO
CONFIG_LWM2M=y
CONFIG_LWM2M_COAP_BLOCK_SIZE=512
CONFIG_LWM2M_COAP_MAX_MSG_SIZE=1280
CONFIG_LWM2M_ENGINE_MAX_OBSERVER=15
CONFIG_LWM2M_ENGINE_MAX_MESSAGES=15
CONFIG_LWM2M_ENGINE_MAX_PENDING=15
CONFIG_LWM2M_ENGINE_MAX_REPLIES=15
CONFIG_LWM2M_DNS_SUPPORT=y
CONFIG_LWM2M_RW_JSON_SUPPORT=n
CONFIG_LWM2M_SERVER_DEFAULT_PMIN=1
CONFIG_LWM2M_SERVER_DEFAULT_PMAX=300
CONFIG_LWM2M_CLIENT_UTILS=y
CONFIG_LWM2M_CLIENT_UTILS_LOCATION_OBJ_SUPPORT=n
CONFIG_LWM2M_IPSO_SUPPORT=y

# DTLS settings
CONFIG_LWM2M_DTLS_SUPPORT=y

# Modem key management
CONFIG_MODEM_KEY_MGMT=y

# Default app to debug logging
CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_DBG=y

# Support HEX style PSK values (double the size + NULL char)
CONFIG_LWM2M_SECURITY_KEY_SIZE=33

# extend CoAP retry timing to 4 seconds for LTE/LTE-M
CONFIG_COAP_INIT_ACK_TIMEOUT_MS=4000

# Enable CoAP extended option length
CONFIG_COAP_EXTENDED_OPTIONS_LEN=y
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40

# Enable settings storage
CONFIG_SETTINGS=y
CONFIG_FCB=y
CONFIG_SETTINGS_FCB=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y

# Modem library
CONFIG_NRF_MODEM_LIB=y

# Modem info
CONFIG_MODEM_INFO=y
CONFIG_MODEM_INFO_ADD_DATE_TIME=n

# Enable shell
CONFIG_LWM2M_SHELL=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_LWM2M_ENGINE_STACK_SIZE=3072
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Allow FOTA downloads using download-client
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
CONFIG_FOTA_DOWNLOAD=y

# Application version
CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="1.0.0"

# Set LwM2M Server IP address here
CONFIG_LWM2M_CLIENT_UTILS_SERVER="coaps://leshan.eclipseprojects.io:5684"

# Application Event Manager
CONFIG_APP_EVENT_MANAGER=y

# Date-Time library
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS=86400

# Enable LwM2M Queue Mode
CONFIG_LWM2M_QUEUE_MODE_ENABLED=y

# Enable TLS session caching to prevent doing a full TLS handshake for every send.
CONFIG_LWM2M_TLS_SESSION_CACHING=y

# Socket close is skipped at RX off idle state which optimize power consumption
# Socket close call will enable RCC connection for send Alert message to server
# Alert is now send right before opening a new connection.
CONFIG_LWM2M_RD_CLIENT_SUSPEND_SOCKET_AT_IDLE=y

# Sets the duration that the lwm2m engine will be polling for data after transmission before
# the socket is closed.
# Adjust so that we can detach from network in 30 seconds
CONFIG_LWM2M_QUEUE_MODE_UPTIME=30

# Set lifetime of 12 hours
CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=43200

# Do registration update after 5400 seconds (90 minutes)
CONFIG_LWM2M_UPDATE_PERIOD=5400
CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=60

# Configure PSM mode
CONFIG_LTE_PSM_REQ=y
# Request periodic TAU of 3600 seconds (60 minutes)
CONFIG_LTE_PSM_REQ_RPTAU="00000110"

# Set Requested Active Time (RAT) to 30 seconds. Preferably a little bit longer than the
# configured LWM2M_QUEUE_MODE_UPTIME. Due to NAT/firewall UDP connections are usually
# closed within 30-60 seconds so there is in general no point in setting a longer
# Queue mode uptime / LTE PSM active time.
CONFIG_LTE_PSM_REQ_RAT="00001111"

# Request eDRX mode
CONFIG_LTE_EDRX_REQ=y

# Request eDRX cycle length of 10.24 seconds for LTE-M
CONFIG_LTE_EDRX_REQ_VALUE_LTE_M="0001"

# Request eDRX cycle length of 20.48 seconds for NB-IoT
CONFIG_LTE_EDRX_REQ_VALUE_NBIOT="0010"

# Request Paging time window of 1.28 seconds for LTE-M
CONFIG_LTE_PTW_VALUE_LTE_M="0000"

# Request Paging time window of 2.56 seconds for NB-IoT
CONFIG_LTE_PTW_VALUE_NBIOT="0000"

# Get notification before Tracking Area Update (TAU). Notification triggers registration
# update and TAU will be sent with the update which decreases power consumption.
CONFIG_LTE_LC_TAU_PRE_WARNING_NOTIFICATIONS=y

# Optimize powersaving by using tickless mode in LwM2M engine
CONFIG_NET_SOCKETPAIR=y
CONFIG_LWM2M_TICKLESS=y




# NBIOT Usage
CONFIG_LTE_NETWORK_MODE_NBIOT=y
CONFIG_PDN=y
CONFIG_PDN_DEFAULTS_OVERRIDE=y
CONFIG_PDN_DEFAULT_APN="nbiot.vodacom.za"
CONFIG_LTE_NETWORK_MODE_NBIOT=y


CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=n



# Enable LwM2M Queue Mode
CONFIG_LWM2M_QUEUE_MODE_ENABLED=y

# Enable TLS session caching to prevent doing a full TLS handshake for every send.
CONFIG_LWM2M_TLS_SESSION_CACHING=y

# Socket close is skipped at RX off idle state which optimize power consumption
# Socket close call will enable RCC connection for send Alert message to server
# Alert is now send right before opening a new connection.
CONFIG_LWM2M_RD_CLIENT_SUSPEND_SOCKET_AT_IDLE=y

# Sets the duration that the lwm2m engine will be polling for data after transmission before
# the socket is closed.
# Adjust so that we can detach from network in 30 seconds
CONFIG_LWM2M_QUEUE_MODE_UPTIME=45

# Set lifetime of 12 hours
CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=3600

# Do registration update after 5400 seconds (90 minutes)
CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=3000



# Request eDRX cycle length of 20.48 seconds for NB-IoT
CONFIG_LTE_EDRX_REQ_VALUE_NBIOT="0010"






# Sensors
CONFIG_I2C=y
CONFIG_SPI=n
CONFIG_SENSOR=n

#Enable/Disable RTT or UART Logging
CONFIG_CONSOLE=y
CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_DBG=y

CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n


# Set LwM2M Server IP address here
# CONFIG_LWM2M_CLIENT_UTILS_SERVER="coaps://leshan.eclipseprojects.io:5684"
CONFIG_LWM2M_CLIENT_UTILS_SERVER="coaps://dev.lwm2m.automatechcloud.co.za:5683"








# Configure lwm2m version
CONFIG_LWM2M_VERSION_1_1=y
CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1=y

CONFIG_JSON_LIBRARY=y
CONFIG_BASE64=y
CONFIG_LWM2M_RW_SENML_JSON_SUPPORT=y

# w1 sensor interface configuration
CONFIG_SENSOR=y
CONFIG_W1=y

# Enabling RTC
CONFIG_COUNTER=y
CONFIG_PCF85063A=y

# Battery measurement
CONFIG_ADC=y

# Power saving
CONFIG_PM_DEVICE=y

# Configure internal flash


CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y



CONFIG_LTE_NETWORK_USE_FALLBACK=n
CONFIG_LTE_NETWORK_TIMEOUT=60



CONFIG_WATCHDOG=y


CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=n

CONFIG_MODBUS=y
CONFIG_MODBUS_ROLE_CLIENT=y
CONFIG_MODBUS_RAW_ADU=y

CONFIG_UART_USE_RUNTIME_CONFIGURE=y

CONFIG_LWM2M_CLIENT_UTILS_DOWNLOADER_SEC_TAG=35724861
CONFIG_LWM2M_CLIENT_UTILS_SERVER_TLS_TAG=35724861

CONFIG_DFU_TARGET=y

CONFIG_LWM2M_CLIENT_UTILS_RAI=y

CONFIG_AT_MONITOR_HEAP_SIZE=1024

CONFIG_SERIAL=y

# DEMO

CONFIG_BOOTLOADER_MCUBOOT=y

CONFIG_DFU_TARGET=y
CONFIG_DFU_TARGET_MCUBOOT=y
CONFIG_FLASH=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

On Startup i am also calling:

int err = boot_write_img_confirmed();

 LOG_INF("Is image confirmed: %d", err);
How do i determine if the new image ever attempted to run?
Parents
  • Hello,

    Which SDK version are you using? What does the log say? Are there any error messages?

    The firmware data is received via UART. 

    Could you clarify the setup further? I'm a bit confused. The title mentions FOTA, but the image is being received via UART.

    Kind Regards,

    Abhijith

  • Hi Menon

    We are running a program in an nrf9160 but everything network related is being done on an external chip.  So were using AT commands over UART to perform FOTA and everything else.  My question is that when the update is downloaded everything until the reboot works perfectly.  There are no obvious erros.  The image type is "Test". However on reboot, nothing happens.  What can i do to log what happens after the reboot.  How can i tell if the update ever runs.  NB: i am currently using custom partitions. Can this be a factor ?

  • Hello,

    Can you configure MCUboot to provide logging information? This will give insights into whether the new image is being validated or rejected at startup. See this step. You mentioned that the image is marked as 'test,' which means the image will be booted only once unless confirmed. If, for any reason, boot_write_img_confirmed() is not called after a successful boot, the bootloader will revert to the previous image

    Hkhan7861 said:
    NB: i am currently using custom partitions. Can this be a factor ?

    This can be an issue if MCUboot is looking for a specific image slot, and it doesn't exist or is improperly sized. In such cases, it might not boot the new image. Ensure that both the primary and secondary slots in the partition layout are configured properly for MCUboot.

    Kind Regards,

    Abhijith

Reply
  • Hello,

    Can you configure MCUboot to provide logging information? This will give insights into whether the new image is being validated or rejected at startup. See this step. You mentioned that the image is marked as 'test,' which means the image will be booted only once unless confirmed. If, for any reason, boot_write_img_confirmed() is not called after a successful boot, the bootloader will revert to the previous image

    Hkhan7861 said:
    NB: i am currently using custom partitions. Can this be a factor ?

    This can be an issue if MCUboot is looking for a specific image slot, and it doesn't exist or is improperly sized. In such cases, it might not boot the new image. Ensure that both the primary and secondary slots in the partition layout are configured properly for MCUboot.

    Kind Regards,

    Abhijith

Children
No Data
Related