This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zephyr FOTA doesn't work with CONFIG_DFU_TARGET_MCUBOOT_SAVE_PROGRESS parameter

Hi,

I connected MCUBoot and FOTA to my project. I checked that the download is working, but not stable. I saw in the documentation that you can enable the continuation of the firmware download after restarting the device.
I set the parameters:

CONFIG_SETTINGS=y
CONFIG_DFU_TARGET_MCUBOOT_SAVE_PROGRESS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT=y

Initialized the file system to the internal flash memory:

FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
static struct fs_mount_t lfs_storage_mnt = {
	.type = FS_LITTLEFS,
	.fs_data = &cstorage,
	.storage_dev = (void *)FLASH_AREA_ID(storage),
	.mnt_point = "/settings",
};

err = fs_mount(&lfs_storage_mnt);
if (err != 0)
{
	LOG_ERR("mounting littlefs error: [%d]\n", err);
}

However, the download continuation system does not work.
I started to study the source code of the program, I found that the settings of the loaded firmware are written correctly and read also correctly.
However, the function that loads them makes them empty (file dfu_target_mcuboot.c):

/**
 * @brief Function used by settings_load() to restore the flash_img variable.
 *	  See the Zephyr documentation of the settings subsystem for more
 *	  information.
 */
static int settings_set(const char *key, size_t len_rd,
			settings_read_cb read_cb, void *cb_arg)
{
	if (!strcmp(key, FILE_FLASH_IMG)) {
		size_t bytes_written = flash_img_bytes_written(&flash_img);
		ssize_t len = read_cb(cb_arg, &bytes_written,
				      sizeof(bytes_written));

		if (len != sizeof(bytes_written)) {
			LOG_ERR("Can't read flash_img from storage");
			return len;
		}
	}

	return 0;
}

It turns out that the program loaded the bytes_written parameter correctly, but does not use it anywhere and just exits this function, and the firmware download starts from byte 0

Am I misunderstanding something or is it a library bug?

regards

Parents
  • Hello, 

    I have reached out to our NCS team. 

    Kind regards,
    Øyvind

  • There was indeed a bug in the library, according to our developers. Her is a link to a PR which fixes the issue: https://github.com/nrfconnect/sdk-nrf/pull/2829 

    Kind regads,
    Øyvind

  • My first solution was to do exactly the same, but it didn't work. For some reason, my program crashes when it starts downloading the firmware with an offset.

    So this solution doesn't work

    [00:00:18.082,763] <inf> download_client: Downloading: app_update.bin [0]
    [00:00:18.090,942] <dbg> download_client.get_request_send: Sending HTTP request
    [00:00:18.100,311] <dbg> download_client.download_thread: Receiving up to 4096 bytes at 0x20020fe4...
    [00:00:23.510,223] <dbg> download_client.download_thread: Read 421 bytes from socket
    [00:00:23.519,439] <dbg> download_client.header_parse: GET header size: 421
    [00:00:23.527,740] <dbg> download_client.header_parse: File size = 329616
    [00:00:23.535,888] <dbg> download_client.download_thread: Awaiting full fragment (0)
    [00:00:23.545,013] <dbg> download_client.download_thread: Receiving up to 4096 bytes at 0x20020fe4...
    [00:00:23.864,501] <dbg> download_client.download_thread: Read 708 bytes from socket
    [00:00:23.873,687] <dbg> download_client.download_thread: Awaiting full fragment (708)
    [00:00:23.883,026] <dbg> download_client.download_thread: Receiving up to 3388 bytes at 0x200212a8...
    [00:00:24.304,504] <dbg> download_client.download_thread: Read 708 bytes from socket
    [00:00:24.313,659] <dbg> download_client.download_thread: Awaiting full fragment (1416)
    [00:00:24.323,089] <dbg> download_client.download_thread: Receiving up to 2680 bytes at 0x2002156c...
    [00:00:24.650,329] <dbg> download_client.download_thread: Read 708 bytes from socket
    [00:00:24.659,484] <dbg> download_client.download_thread: Awaiting full fragment (2124)
    [00:00:24.668,914] <dbg> download_client.download_thread: Receiving up to 1972 bytes at 0x20021830...
    [00:00:25.199,615] <dbg> download_client.download_thread: Read 708 bytes from socket
    [00:00:25.208,801] <dbg> download_client.download_thread: Awaiting full fragment (2832)
    [00:00:25.218,261] <dbg> download_client.download_thread: Receiving up to 1264 bytes at 0x20021af4...
    [00:00:25.519,348] <dbg> download_client.download_thread: Read 708 bytes from socket
    [00:00:25.528,503] <dbg> download_client.download_thread: Awaiting full fragment (3540)
    [00:00:25.537,963] <dbg> download_client.download_thread: Receiving up to 556 bytes at 0x20021db8...
    [00:00:25.904,327] <dbg> download_client.download_thread: Read 556 bytes from socket
    [00:00:25.913,482] <inf> download_client: Downloaded 4096/329616 bytes (1%)
    [00:00:25.921,905] <err> fs: failed to create directory (-17)
    [00:00:25.948,608] <dbg> settings.settings_call_set_handler: set-value OK. key: dfu/mcuboot/flash_img
    [00:00:25.959,564] <inf> fota_download: Refuse fragment, restart with offset
    [00:00:25.967,926] <inf> download_client: Fragment refused, download stopped.
    [00:00:26.959,655] <inf> download_client: Downloading: app_update.bin [81920]
    [00:00:26.968,200] <dbg> download_client.get_request_send: Sending HTTP request
    [00:00:26.976,959] <err> os: ***** USAGE FAULT *****
    [00:00:26.983,062] <err> os:   Illegal load of EXC_RETURN into PC
    [00:00:26.990,386] <err> os: r0/a1:  0x20030d88  r1/a2:  0x000559b1  r2/a3:  0x2002caac
    [00:00:26.999,786] <err> os: r3/a4:  0x00000001 r12/ip:  0x20030d98 r14/lr:  0x000638f9
    [00:00:27.009,216] <err> os:  xpsr:  0x00000000
    [00:00:27.014,831] <err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
    [00:00:27.026,092] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000002
    [00:00:27.037,414] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
    [00:00:27.048,645] <err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
    [00:00:27.059,936] <err> os: fpscr:  0x00000040
    [00:00:27.065,612] <err> os: Faulting instruction address (r15/pc): 0x0002d84c
    [00:00:27.074,157] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:27.082,611] <err> os: Current thread: 0x20024238 (idle 00)
    [00:00:27.089,965] <err> fatal_error: Resetting system
    

Reply Children
Related