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 Reply Children
Related