<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102575/dfu-process-in-nrf-connect-sdk-for-nrf52840</link><description>Hi, I am currently working with latest Nrf Connect SDK for my development purposes on NRF52840 Dev Kit. Previously I have worked on Nrf sdk 17.0.1 for development of DFU process. 
 DFU process followed in Nrf SDK 17.0.1 
 
 Generate the combined hex </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Aug 2023 13:31:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102575/dfu-process-in-nrf-connect-sdk-for-nrf52840" /><item><title>RE: DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/thread/441405?ContentTypeID=1</link><pubDate>Tue, 15 Aug 2023 13:31:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae285984-448a-41ec-9b0c-7a53b4576969</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Sarvesh"]&lt;p&gt;As I will get the start and end address from these about two, can I use the APIs from following for writing the image data in flash on given address ?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/dfu/dfu_multi_image.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/dfu/dfu_multi_image.html&lt;/a&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This API is for multi image DFU, so if your application consists of several separate images you can use it. For single image, you can use zcbor directly without the added DFU multi-image API on top. &lt;/p&gt;
[quote user="Sarvesh"]And how do I do this, it would be great if you can help me with these[/quote]
&lt;p&gt;You can send a SMP confirmed command similar to how it is done in&amp;nbsp;send_smp_confirm() here: &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/main/bootloader_samples/client_smp/smp_client_ble/src/main.c#L993"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/main/bootloader_samples/client_smp/smp_client_ble/src/main.c#L993&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also use the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/zephyr/services/device_mgmt/dfu.html"&gt;Device Firmware Upgrade&lt;/a&gt; API, which might be simpler if you want to handle it locally on the device. When you have written the DFU image to the device you will have two images, one primary image in slot 0 and one secondary image in slot 1. The primary is the current running application, and the secondary is the new DFU image. With boot_request_upgrade() you can mark the image in slot 1, the secondary image, as pending. This means that the device will boot into this image on a reboot. The parameter of boot_request_upgrade() decides if it is a test image or permanent.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;boot_request_upgrade&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&lt;span&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&lt;span&gt;permanent&lt;/span&gt;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;dl&gt;
&lt;dt&gt;
&lt;blockquote&gt;Parameters&lt;span&gt;:&lt;/span&gt;&lt;/blockquote&gt;
&lt;/dt&gt;
&lt;dd&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;permanent&lt;/strong&gt; – Whether the image should be used permanently or only tested once: &lt;br /&gt;BOOT_UPGRADE_TEST=run image once, then confirm or revert. &lt;br /&gt;BOOT_UPGRADE_PERMANENT=run image forever.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/thread/440172?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 15:02:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11ca6a44-d159-4d6b-bf0c-22a67e27e00e</guid><dc:creator>Sarvesh</dc:creator><description>&lt;p&gt;HI Marte, Thanks for reply , It cleared lots of my doubts, but still I have some quires ,&lt;/p&gt;
[quote userid="92402" url="~/f/nordic-q-a/102575/dfu-process-in-nrf-connect-sdk-for-nrf52840/440137"]You will get some generated configurations for the bootloader which you can use. In this case, PM_MCUBOOT_SECONDARY_ADDRESS and PM_MCUBOOT_SECONDARY_END_ADDRESS will be the start and end addresses of the secondary partition/bank, [/quote]
&lt;p&gt;As I will get the start and end address from these about two, can I use the APIs from following for writing the image data in flash on given address ?&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/dfu/dfu_multi_image.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/dfu/dfu_multi_image.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="92402" url="~/f/nordic-q-a/102575/dfu-process-in-nrf-connect-sdk-for-nrf52840/440137"]If you mark the new firmware image as a test image or confirmed, then MCUboot should handle this for you so the device automatically boots into the new image on a reboot.[/quote]
&lt;p&gt;And how do I do this, it would be great if you can help me with these&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/thread/440137?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 13:47:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8e6f2de-c731-4382-a063-ee94aebc1e2b</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Sarvesh"]what should I add in my application code to know where to write the new received firmware file over UART[/quote]
&lt;p&gt;You will get some generated configurations for the bootloader which you can use. In this case, PM_MCUBOOT_SECONDARY_ADDRESS and PM_MCUBOOT_SECONDARY_END_ADDRESS will be the start and end addresses of the secondary partition/bank, so this is where you want to write the image. &lt;br /&gt;One of the unofficial examples I mentioned in my previous response shows how to implement a SMP Client, &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/client_smp/smp_client_ble"&gt;Bluetooth: Central SMP Client DFU&lt;/a&gt;. This is showing DFU over Bluetooth LE, but a lot of the code can be reused for UART. The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/zephyr/samples/subsys/mgmt/mcumgr/smp_svr/README.html"&gt;SMP Server&lt;/a&gt; sample mentioned can be used for DFU over serial as well.&lt;/p&gt;
&lt;p&gt;The part that is relevant for how and where to store the firmware is in the send_upload2() function here: &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/main/bootloader_samples/client_smp/smp_client_ble/src/main.c#L840"&gt;smp_client_ble/src/main.c#L840&lt;/a&gt;.&lt;/p&gt;
[quote user="Sarvesh"]And completion of writing , how would I boot from that location[/quote]
&lt;p&gt;If you mark the new firmware image as a test image or confirmed, then MCUboot should handle this for you so the device automatically boots into the new image on a reboot. &lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/thread/439930?ContentTypeID=1</link><pubDate>Fri, 04 Aug 2023 13:05:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f38d5a5-3657-4832-894a-61c489e93f3e</guid><dc:creator>Sarvesh</dc:creator><description>&lt;p&gt;Hi Marte, Thanks for reply&lt;/p&gt;
&lt;p&gt;I have added this line&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BOOTLOADER_MCUBOOT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;in prj.conf file, now I am able to do the BLE DFU that is working fine. But I want to know following&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;what should I add in my application code to know where to write the new received firmware file over UART&lt;/li&gt;
&lt;li&gt;And completion of writing , how would I boot from that location&lt;/li&gt;
&lt;li&gt;I have read the sample Bootloader code as well given in nrf connect SDK , but did not understand what it will do&lt;/li&gt;
&lt;li&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;pm_config.h&amp;gt;
#include &amp;lt;fw_info.h&amp;gt;
#include &amp;lt;fprotect.h&amp;gt;
#include &amp;lt;bl_storage.h&amp;gt;
#include &amp;lt;bl_boot.h&amp;gt;
#include &amp;lt;bl_validation.h&amp;gt;
#include &amp;lt;nrfx_nvmc.h&amp;gt;

#if defined(CONFIG_HW_UNIQUE_KEY_LOAD)
#include &amp;lt;zephyr/init.h&amp;gt;
#include &amp;lt;hw_unique_key.h&amp;gt;

#define HUK_FLAG_OFFSET 0xFFC /* When this word is set, expect HUK to be written. */

int load_huk(void)
{
	if (!hw_unique_key_is_written(HUK_KEYSLOT_KDR)) {
		uint32_t huk_flag_addr = PM_HW_UNIQUE_KEY_PARTITION_ADDRESS + HUK_FLAG_OFFSET;

		if (*(uint32_t *)huk_flag_addr == 0xFFFFFFFF) {
			printk(&amp;quot;First boot, expecting app to write HUK.\n&amp;quot;);
			nrfx_nvmc_word_write(huk_flag_addr, 0);
			return 0;
		}
		printk(&amp;quot;Error: Hardware Unique Key not present.\n&amp;quot;);
		k_panic();
		return -1;

	}

	hw_unique_key_load_kdr();

	return 0;
}

SYS_INIT(load_huk, PRE_KERNEL_2, 0);
#endif


static void validate_and_boot(const struct fw_info *fw_info, uint16_t slot)
{
	printk(&amp;quot;Attempting to boot slot %d.\r\n&amp;quot;, slot);

	if (fw_info == NULL) {
		printk(&amp;quot;No fw_info struct found.\r\n&amp;quot;);
		return;
	}

	printk(&amp;quot;Attempting to boot from address 0x%x.\n\r&amp;quot;,
		fw_info-&amp;gt;address);

	if (!bl_validate_firmware_local(fw_info-&amp;gt;address,
					fw_info)) {
		printk(&amp;quot;Failed to validate, permanently invalidating!\n\r&amp;quot;);
		fw_info_invalidate(fw_info);
		return;
	}

	printk(&amp;quot;Firmware version %d\r\n&amp;quot;, fw_info-&amp;gt;version);

	uint16_t stored_version;
	int err = get_monotonic_version(&amp;amp;stored_version);

	if (err) {
		printk(&amp;quot;Failed to read the monotonic counter!\n\r&amp;quot;);
		printk(&amp;quot;We assume this is due to the firmware version not being enabled.\n\r&amp;quot;);

		/*
		 * Errors in reading the firmware version are assumed to be
		 * due to the firmware version not being enabled. When the
		 * firmware version is disabled, no version checking should
		 * be done. The version is then set to 0 as it is not permitted
		 * in fwinfo and will therefore pass all version checks.
		 */
		stored_version = 0;
	}

	if (fw_info-&amp;gt;version &amp;gt; stored_version) {
		int err = set_monotonic_version(fw_info-&amp;gt;version, slot);

		if (err) {
			/*
			 * Errors in writing the firmware version are assumed to be
			 * due to the firmware version not being enabled. When the
			 * firmware version is disabled, no version updates should
			 * be done and this case can be ignored.
			 *
			 * The body of this if-statement is intentionally empty.
			 * It is left here solely for documentation purposes,
			 * describing why we ignore the error.
			 */
		}
	}

	bl_boot(fw_info);
}

#define BOOT_SLOT_0 0
#define BOOT_SLOT_1 1

int main(void)
{
	int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);

	if (err) {
		printk(&amp;quot;Failed to protect B0 flash, cancel startup.\n\r&amp;quot;);
		return 0;
	}

	uint32_t s0_addr = s0_address_read();
	uint32_t s1_addr = s1_address_read();
	const struct fw_info *s0_info = fw_info_find(s0_addr);
	const struct fw_info *s1_info = fw_info_find(s1_addr);

	if (!s1_info || (s0_info-&amp;gt;version &amp;gt;= s1_info-&amp;gt;version)) {
		validate_and_boot(s0_info, BOOT_SLOT_0);
		validate_and_boot(s1_info, BOOT_SLOT_1);
	} else {
		validate_and_boot(s1_info, BOOT_SLOT_1);
		validate_and_boot(s0_info, BOOT_SLOT_0);
	}

	printk(&amp;quot;No bootable image found. Aborting boot.\n\r&amp;quot;);
	return 0;
}
&lt;/pre&gt;&lt;br /&gt;This is main.c file code written there&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU process in Nrf connect SDK for Nrf52840</title><link>https://devzone.nordicsemi.com/thread/439924?ContentTypeID=1</link><pubDate>Fri, 04 Aug 2023 12:57:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d870e6d-a47c-4482-a45b-ae83a34e7643</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The process in nRF Connect SDK is different, but a lot of it is done automatically.&lt;/p&gt;
&lt;p&gt;To enable bootloader and DFU in your application, you only need to set CONFIG_BOOTLOADER_MCUBOOT=y in your project config file (prj.conf). With this, the bootloader firmware will automatically be built as a child image of your application. It also enabled the partition manager, which creates partitions. Please be aware that if you have a bootloader, you &lt;span style="text-decoration:underline;"&gt;&lt;/span&gt;must create your own static partitions, and not use the dynamic partitions.&lt;/p&gt;
&lt;p&gt;The DFU image is automatically generated when you build the application, so you do not need to generate settings or merge the hex files.&lt;/p&gt;
&lt;p&gt;We have a lot of information about bootloaders, DFU, partition manager, etc. in our documentation, so I recommend that you read through that. I will link to the most relevant ones.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/nrf/app_dev/bootloaders_and_dfu/index.html"&gt;Bootloaders and Device Firmware Updates&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/nrf/scripts/partition_manager/partition_manager.html"&gt;Partition Manager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/mcuboot/wrapper.html"&gt;MCUboot documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.1/nrf/app_dev/build_and_config_system/index.html#build-and-configuration-system"&gt;Build and configuration system&lt;/a&gt; (mainly the sections about building FOTA images, output build files, and MCUboot output build files).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I also recommend taking a look at the bootloader samples made by a colleague: &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples&lt;/a&gt;. They are not official samples, so they have not been tested thoroughly and might not be the latest version of nRF Connect SDK, but you will find some very good explanations and samples there.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>