<?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>Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91247/update-firmware-bootloader-and-application-from-external-flash</link><description>I am using the nRF52840-dk with the nRF Connect SDK v2.0.0 and for the development itself I use Visual Studio Code. 
 My Goal: Both the bootloader and the actual application should be upgradeable, with firmware updates stored on an external flash. Supposedly</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Aug 2022 08:25:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91247/update-firmware-bootloader-and-application-from-external-flash" /><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/384072?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 08:25:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35bda4c7-bd89-4b7d-9ae0-ad89624a9f88</guid><dc:creator>Simon</dc:creator><description>[quote user="Talisca"]But now I would like to know if there is any setting for the build process, so that this is set directly in the image trailer of the firmware? That would not only be very convinient in my eyes, but also a necessity. What would be the point of uploading a firmware that is not recognized as an upgrade by the bootloader? An uploaded firmware is always an upgrade in my use case.[/quote]
&lt;p&gt;First I would like to inform you that it might be smart to confirm the image from within the image itself, this is how the NCS samples are doing it. For example, take a look at the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.2/samples/nrf9160/http_update/application_update/src/main.c#L60"&gt;http application update sample&lt;/a&gt;&amp;nbsp;and the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.2/applications/asset_tracker_v2/src/modules/cloud_module.c#L705"&gt;asset tracker v2 application&lt;/a&gt;. The reason for this is to avoid bricking the device. For example if you perform a DFU update with an unconfirmed image, and a fault happens during the Zephyr init process, the chip will reset (and not reach the point where it confirms itself), and it will swap back to the old image. If it&amp;#39;s already confirmed, mcuboot will keep running that image and the device is bricked (unless you have added a possibility to let mcuboot perform the DFU update).&lt;/p&gt;
&lt;p&gt;However, to answer your question, I&amp;nbsp;think it should be feasible to confirm the image in the buil process. If you look under &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/mcuboot/imgtool.html#signing-images"&gt;Image tool --&amp;gt; signing images&lt;/a&gt;, you can see that imagetool sign has a --confirm option. Try using that.&lt;/p&gt;
&lt;p&gt;The app_update.bin file is created &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.2/modules/mcuboot/CMakeLists.txt#L310-L319"&gt;here&lt;/a&gt;&amp;nbsp;and &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.2/modules/mcuboot/CMakeLists.txt#L151-L158"&gt;here&lt;/a&gt;&amp;nbsp;I believe, so try modifying that fail and&amp;nbsp;append --confirm.&lt;/p&gt;
&lt;p&gt;Of course, you can also use app_to_sign.bin (see &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/mcuboot/readme-ncs.html#using-mcuboot-in-nrf-connect-sdk"&gt;Using MCUboot in nRF Connect SDK&lt;/a&gt;) and sign it yourself following the guide&amp;nbsp;&lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/mcuboot_manual_sign"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/mcuboot_manual_sign&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/384034?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 05:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:886a8e90-42b8-49ad-aa13-30f161a189bf</guid><dc:creator>Talisca</dc:creator><description>&lt;p&gt;I have found the solution by chance.&lt;br /&gt;As already written, I had debugged mcuboot and had the assumption that you still have to somehow tell the bootloader that it is an upgrade.&lt;br /&gt;I found the confirmation at &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/design.html#new-swaps-non-resumes"&gt;developer.nordicsemi.com/.../design.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then I remembered that I had read in some articles that the application itself can confirm the swap with &amp;quot;boot_write_img_confirmed()&amp;quot;. Somehow I had the suspicion that there must be a function to set the swap type. And indeed. All I needed for the last two weeks was a call to the function &amp;quot;boot_request_upgrade()&amp;quot; with &amp;quot;BOOT_UPGRADE_PERMANENT or BOOT_UPGRADE_TEST&amp;quot;.&lt;/p&gt;
&lt;p&gt;But now I would like to know if there is any setting for the build process, so that this is set directly in the image trailer of the firmware? That would not only be very convinient in my eyes, but also a necessity. What would be the point of uploading a firmware that is not recognized as an upgrade by the bootloader? An uploaded firmware is always an upgrade in my use case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/383958?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 13:56:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54b77c44-d40a-4d88-9718-4c3c29e40dc5</guid><dc:creator>Talisca</dc:creator><description>&lt;p&gt;Hello Simon,&lt;/p&gt;
&lt;p&gt;I followed the instructions for DFU over Bluetooth and that works fine.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Only my use case is quite different, in that I write the firmware&amp;nbsp;with my own method into the flash. mcumgr, smp etc. is not used at all in our case.&lt;/p&gt;
&lt;p&gt;The firmware is in the right place, I have already checked that. When I debug mcuboot, I also see that it reads the header information correctly and also checks if both image slots are compatible.&lt;br /&gt;At the end in the function &amp;quot;boot_prepare_image_for_update&amp;quot; in loader.c the swap type is set to none and that&amp;#39;s it.&lt;br /&gt;The macro &amp;quot;BOOT_IS_UPGRADE&amp;quot; checks only for BOOT_SWAP_TYPE_TEST, BOOT_SWAP_TYPE_REVERT and BOOT_SWAP_TYPE_PERM. This apparently makes mcuboot think that there is no upgrade and simply ignores the firmware. It&amp;#39;s almost like you have to set another flag somewhere so that mcuboot knows about the upgrade.&lt;br /&gt;I don&amp;#39;t have time to debug this extensively, so far I&amp;#39;ve already lost too much time because of this &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/383930?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 13:02:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ff4d205-a530-4f01-b5e5-7b531c76a040</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello, I didn&amp;#39;t get time to read detailed through this whole message, but I&amp;#39;ll just answer quick before I leave work today.&lt;/p&gt;
[quote user="Talisca"]&lt;p&gt;But now I would like to attempt the application firmware update: This simply does not work at all. Even with a minimal project from the internal flash mcuboot refuses to do anyhing.&lt;/p&gt;
&lt;p&gt;For testing I copied the following small project:&amp;nbsp;&lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nsib_mcuboot_smp"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nsib_mcuboot_smp&lt;/a&gt;&lt;/p&gt;[/quote]
&lt;p&gt;It does not seem like this project was made to update the main application, only mcuboot. To update the main application, check out&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/ncs-dfu"&gt;Add DFU support to your application&lt;/a&gt;. It was made for NCS v1.8.0, but I think it should work with NCS v2.0.0 as well.&lt;/p&gt;
&lt;p&gt;Let me know if that guide is not suficcient, and I will assist you tomorrow.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/383813?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 08:20:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97982d50-e58d-4640-ae59-cebb7cd1c29a</guid><dc:creator>Talisca</dc:creator><description>&lt;p&gt;First of all, thanks for the reply. I have looked at the sample projects, continued to read through various posts and now have wasted another week with more attempts.&lt;/p&gt;
&lt;p&gt;I just don&amp;#39;t get it at all.&lt;/p&gt;
&lt;p&gt;In the meantime I have managed to update mcuboot, but not the way I would like.&lt;br /&gt;It seems that mcuboot can only be &amp;quot;updated&amp;quot; via the internal flash, which in the Immutable Bootloader can be done simply &lt;br /&gt;by booting the image with the largest version.&lt;br /&gt;If this is the case, then I can live with that. I just have to develop my own routine, which copies the image&amp;nbsp;from the external flash to the internal flash.&lt;/p&gt;
&lt;p&gt;For now I would declare the topic &amp;quot;updateable bootloader&amp;quot; as finished for me. Unless someone has additional information.&lt;/p&gt;
&lt;p&gt;But now I would like to attempt the application firmware update: This simply does not work at all. Even with a minimal project from the internal flash mcuboot refuses to do anyhing.&lt;/p&gt;
&lt;p&gt;For testing I copied the following small project:&amp;nbsp;&lt;a id="" href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nsib_mcuboot_smp"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nsib_mcuboot_smp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Since this project cannot be built with nRF Connect SDK v.2.0.0,&amp;nbsp;see my changes:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/CMakeLists.txt b/nsib_mcuboot_smp/CMakeLists.txt
index ecb7d24..9010aa2 100644
--- a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/CMakeLists.txt
+++ b/nsib_mcuboot_smp/CMakeLists.txt
@@ -2,6 +2,10 @@

 cmake_minimum_required(VERSION 3.20.0)

+set(mcuboot_CONF_FILE
+   ${CMAKE_CURRENT_SOURCE_DIR}/child_image/mcuboot.conf
+)
+
 find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
 project(hello_world)
 
diff --git a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/prj.conf b/nsib_mcuboot_smp/prj.conf
index 4d50428..3e8e5eb 100644
--- a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/prj.conf
+++ b/nsib_mcuboot_smp/prj.conf
@@ -1,13 +1,11 @@
-CONFIG_BOOTLOADER_MCUBOOT=y
 CONFIG_MCUMGR=y
-CONFIG_MCUMGR_SMP_UART=y
-CONFIG_MCUMGR_CMD_IMG_MGMT=y
+CONFIG_BOOTLOADER_MCUBOOT=y

 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
 CONFIG_FLASH=y

 CONFIG_SECURE_BOOT=y
-CONFIG_SB_SIGNING_KEY_FILE=&amp;quot;nsib_priv.pem&amp;quot;
+CONFIG_SB_SIGNING_KEY_FILE=&amp;quot;private.pem&amp;quot;
 CONFIG_BUILD_S1_VARIANT=y
 # Need to lower the number of counter slots to be able to update several times. Do not know the best number yet.
 CONFIG_SB_NUM_VER_COUNTER_SLOTS=120
 
diff --git a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/src/main.c b/nsib_mcuboot_smp/src/main.c
index 1d885f2..39c9e4d 100644
--- a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/src/main.c
+++ b/nsib_mcuboot_smp/src/main.c
@@ -6,10 +6,9 @@

 #include &amp;lt;zephyr.h&amp;gt;
 #include &amp;lt;sys/printk.h&amp;gt;
-#include &amp;quot;img_mgmt/img_mgmt.h&amp;quot;

 void main(void)
 {
-    img_mgmt_register_group();
-       printk(&amp;quot;Change this to see change\n&amp;quot;);
+       printk(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
+       printk(&amp;quot;My Version is %s\n&amp;quot;, CONFIG_MCUBOOT_IMAGE_VERSION);
 }
 
diff --git a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/child_image/mcuboot.conf b/nsib_mcuboot_smp/child_image/mcuboot.conf
index 24ccbac..4d4ea08 100644
--- a/samples_for_nrf_connect_sdk-main/bootloader_samples/nsib_mcuboot_smp/child_image/mcuboot.conf
+++ b/nsib_mcuboot_smp/child_image/mcuboot.conf
@@ -2,3 +2,6 @@ CONFIG_LOG=y
 CONFIG_LOG_MODE_MINIMAL=y

 CONFIG_FW_INFO_FIRMWARE_VERSION=5
+
+CONFIG_FLASH=y
+CONFIG_MAIN_STACK_SIZE=10240
\ No newline at end of file&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With these changes the project can be built finally.&lt;/p&gt;
&lt;p&gt;As you can read in various guides, after the initial build I put the build/partitions.yml file as&amp;nbsp;pm_static.yml in the root directory.&lt;/p&gt;
&lt;p&gt;I get the following partition report:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  flash_primary (0x100000 - 1024kB):
+--------------------------------------------------+
+---0x0: b0_container (0x9000 - 36kB)--------------+
| 0x0: b0 (0x8000 - 32kB)                          |
| 0x8000: provision (0x1000 - 4kB)                 |
+---0x9000: s0 (0xc200 - 48kB)---------------------+
| 0x9000: s0_pad (0x200 - 512B)                    |
+---0x9200: s0_image (0xc000 - 48kB)---------------+
| 0x9200: mcuboot (0xc000 - 48kB)                  |
+--------------------------------------------------+
| 0x15200: EMPTY_0 (0xe00 - 3kB)                   |
+---0x16000: s1 (0xc200 - 48kB)--------------------+
| 0x16000: s1_pad (0x200 - 512B)                   |
| 0x16200: s1_image (0xc000 - 48kB)                |
+--------------------------------------------------+
| 0x22200: EMPTY_1 (0xe00 - 3kB)                   |
+---0x23000: mcuboot_primary (0x6e000 - 440kB)-----+
| 0x23000: mcuboot_pad (0x200 - 512B)              |
+---0x23200: app_image (0x6de00 - 439kB)-----------+
+---0x23200: mcuboot_primary_app (0x6de00 - 439kB)-+
| 0x23200: app (0x6de00 - 439kB)                   |
+--------------------------------------------------+
| 0x91000: mcuboot_secondary (0x6e000 - 440kB)     |
| 0xff000: EMPTY_2 (0x1000 - 4kB)                  |
+--------------------------------------------------+

  sram_primary (0x40000 - 256kB):
+--------------------------------------------+
| 0x20000000: sram_primary (0x40000 - 256kB) |
+--------------------------------------------+&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If I flash the merged.hex after the initial build and restart the mcu, I get the following output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.0.99-ncs1  ***
Attempting to boot slot 0.
Attempting to boot from address 0x9200.
Verifying signature against key 0.
Hash: 0xea...6a
Firmware signature verified.
Firmware version 5
*** Booting Zephyr OS build v3.0.99-ncs1  ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Bootloader chainload address offset: 0x23000
*** Booting Zephyr OS build v3.0.99-ncs1  ***
Hello World! nrf52840dk_nrf52840
My Version is 1.1.1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And again the question, what is mcuboot doing here? Why do the lines &amp;quot;Primary image&amp;quot; and &amp;quot;Secondary image&amp;quot; appear twice?&amp;nbsp;Why is magic always unset?&lt;br /&gt;If I change CONFIG_MCUBOOT_IMAGE_VERSION in prj.conf of my application and build again, I get the file app_update.bin. I have read often enough that this should be&amp;nbsp;the binary of my application for the update process. A look into the paritition table tells me that mcuboot_secondary starts at 0x91000.&lt;br /&gt;So for me this is the start address where the firmware has to be written in.&lt;br /&gt;Using my own Python script, I convert the .bin file to Intel Hex format with address offset 0x91000.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;:020000040009F1
:101000003DB8F3960000000000020000EC62000012
:1010100000000000010105000000000000000000C9
:10102000FFFFFFFFFFFFFFFFFFFFFFFFFFD0
:10103000FFFFFFFFFFFFFFFFFFFFFFFFC0
...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I flash this file successfully with nrfjprog.&lt;br /&gt;If I now reset the mcu, I get the following output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.0.99-ncs1  ***
Attempting to boot slot 0.
Attempting to boot from address 0x9200.
Verifying signature against key 0.
Hash: 0xea...6a
Firmware signature verified.
Firmware version 5
*** Booting Zephyr OS build v3.0.99-ncs1  ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Bootloader chainload address offset: 0x23000
*** Booting Zephyr OS build v3.0.99-ncs1  ***
Hello World! nrf52840dk_nrf52840
My Version is 1.1.1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Notice that the output &amp;quot;I: Swap type: none&amp;quot; before &amp;quot;I: Bootloader chainload address offset: 0x23000&amp;quot;&amp;nbsp;is suddenly missing. But otherwise there are no changes.&lt;/p&gt;
&lt;p&gt;So what am I doing wrong? Or is mcuboot no longer functional by now?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update Firmware (Bootloader and Application) from external flash</title><link>https://devzone.nordicsemi.com/thread/382959?ContentTypeID=1</link><pubDate>Tue, 23 Aug 2022 17:32:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb788c67-22b6-494a-ac70-585ead598cd8</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure if updating mcuboot on the 52840 is supported, see&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/84007/does-mcuboot-have-a-mechanisms-to-update-the-bootloader-itself/350956#350956"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/84007/does-mcuboot-have-a-mechanisms-to-update-the-bootloader-itself/350956#350956&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, I found this ticket:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85539/update-mcuboot-with-smp"&gt;Update mcuboot with SMP&lt;/a&gt;. In that ticket, it seems like my colleague was able to update MCUboot. Test the sample he linked to and see if you&amp;#39;re able to do it. He also gives some pointers to some samples that supports putting the update in external flash.&lt;/p&gt;
&lt;p&gt;If this didn&amp;#39;t help, please let me know and I&amp;#39;ll take a closer look at it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>