Saving a fota progress is in case the device resets mid-process,

Hi

I am working on FOTA on the nrf9160dk board with ncs2.2.0 and started with the application_update example then I also tried it on the AT2 app. I tested some cases and noticed that a fota process can continue downloading after lte connection break down and recover also it seems any case unless the device is not restarted.  But in a case, if the device is restarted, the fota process does not continue downloading where it left off. I need the application to skip the blocks that are already downloaded

So Can you please shed some light on how I can implement this feature in the application_update or the at2 app.

As I learned from my investigations, 

DFU Library is responsible to write downloaded image data to flash memory, right? image data written in flash memory cannot vanish after reboot, right? 

if so,

according to dfu app flow, I need to invoke this API   dfu_target_offset_get() allows me to ask for the offset of already downloaded blocks. But I do not know what kind of parameters I need to store to start downloading where the app left off after booting. Basically,  I stored an offset data value of 14336 bytes and set it in the code block below in the fota_download.c after booting. So I expected to start downloading at an offset value of 14336 but it did not work.

err = dfu_target_offset_get(&offset);
			if (err != 0) {
				LOG_DBG("unable to get dfu target offset err: "
					"%d", err);
				send_error_evt(FOTA_DOWNLOAD_ERROR_CAUSE_DOWNLOAD_FAILED);
			}
			printk("offfseett1 %d\n", offset);
			offset = 14336;
			if (offset != 0) {
				/* Abort current download procedure, and
				 * schedule new download from offset.
				 */
				(void)download_client_disconnect(&dlc);
				k_work_schedule(&dlc_with_offset_work,
						K_SECONDS(1));
				LOG_INF("Refuse fragment, restart with offset");

				return -1;
			}

Related