NCS 1.7.1 DFU target reset issue

Good day!

There is now way to restart dfu_mcuboot with

CONFIG_DFU_TARGET_STREAM_SAVE_PROGRESS

Checkout:

dfu_target.c

int dfu_target_reset(void)
{
	if (current_target != NULL) {
		int err = current_target->done(false);

		if (err != 0) {
			LOG_ERR("Unable to clean up dfu_target");
			return err;
		}
	}
	current_target = NULL;
	return 0;
}

next dfu_target_mcu_boot.c

int dfu_target_mcuboot_done(bool successful)
{
	int err = 0;

	err = dfu_target_stream_done(successful);
	if (err != 0) {
		LOG_ERR("dfu_target_stream_done error %d", err);
		return err;
	}

	if (successful) {
		err = stream_flash_erase_page(dfu_target_stream_get_stream(),
					      MCUBOOT_SECONDARY_LAST_PAGE_ADDR);
		if (err != 0) {
			LOG_ERR("Unable to delete last page: %d", err);
			return err;
		}
		err = boot_request_upgrade(BOOT_UPGRADE_TEST);
		if (err != 0) {
			LOG_ERR("boot_request_upgrade error %d", err);
			return err;
		}

		LOG_INF("MCUBoot image upgrade scheduled. "
			"Reset device to apply");
	} else {
		LOG_INF("MCUBoot image upgrade aborted.");
	}

	return err;
}

and finally we appear here in dfu_target_stream_flash.c

int dfu_target_stream_done(bool successful)
{
	int err = 0;

	if (successful) {
		err = stream_flash_buffered_write(&stream, NULL, 0, true);
		if (err != 0) {
			LOG_ERR("stream_flash_buffered_write error %d", err);
		}
#ifdef CONFIG_DFU_TARGET_STREAM_SAVE_PROGRESS
		/* Delete state so that a new call to 'init' will
		 * start with offset 0.
		 */
		err = settings_delete(current_name_key);
		if (err != 0) {
			LOG_ERR("setting_delete error %d", err);
		}

	} else {
		/* The stream has not completed, store the progress so that
		 * a new call to 'init' will pick up where we left off.
		 */
		err = store_progress();
		if (err != 0) {
			LOG_ERR("Unable to reset write progress: %d", err);
		}
#endif
	}

	current_id = NULL;

	return err;
}

It will be useful to have same interface to restart selected dfu type

  • Hi,

      

    I am not sure I follow what the issue is. Could you please describe your use-case and what the issue is?

    Saving the progress is in case your device resets mid-process, so that you can continue where you left off.

     

    Kind regards,

    Håkon

  • I apologize for the misunderstanding. I read source twice and figured that dfu_reset reset whole subsystem and I looked for a function to reset current download. For example if I started to download wrong file - there is only one way to restart and reconfigure is to use dfu_target_stream_done(true) and this is little bit confusing

  • Hi,

     

    ipshiv said:
    I apologize for the misunderstanding. I read source twice and figured that dfu_reset reset whole subsystem and I looked for a function to reset current download.

    No worries, I was just afraid that there was an issue in the module and wanted to make sure I understood the scenario.

     

    ipshiv said:
    or example if I started to download wrong file - there is only one way to restart and reconfigure is to use dfu_target_stream_done(true) and this is little bit confusing

    This is true, the reset function is essentially a _done call with a unsuccessful input parameter. If the stored input data is not directed to you, then it seems that this is the only way to reset the progress.

     

    Kind regards,

    Håkon

Related