<?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>MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93060/mcuboot-update-hooks---rejects-any-mcuboot-updates-when-used-with-immutable-bootlader</link><description>Dear nordic, 
 state of your MCUBoot + Immutable bootloader is just awful. 
 Please fix this hook, when enabled it disables updates of the mcuboot bootloader when used with immutable bootloader. This issue is detected upon next mcuboot update, however</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Nov 2022 13:23:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93060/mcuboot-update-hooks---rejects-any-mcuboot-updates-when-used-with-immutable-bootlader" /><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/393477?ContentTypeID=1</link><pubDate>Tue, 01 Nov 2022 13:23:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69e07aaf-f5b8-4b10-bd9b-40a61561ae03</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Just as a note: I will get ti the rest of the things you ask about also, I just started in an end to get more insight into this case.&lt;/p&gt;
&lt;p&gt;If the bootloader does not support the revert feature, can you try to use &amp;quot;confirm&amp;quot; instead of &amp;quot;test&amp;quot;?&lt;br /&gt;Then maybe you will no longer get the following error:&lt;/p&gt;
[quote user="optical"]This leads to bricking the device due to mcumgr not able to erase image marked as test and the update procedure will not unmark(test) the image in the secondary slot.[/quote]
&lt;p&gt;For your question:&lt;/p&gt;
[quote user="optical"]I&amp;#39;m asking for application note or documentation, which exactly describes procedure for updating the MCUBoot Bootloader using Mcumgr.&amp;nbsp;[/quote]
&lt;p&gt;It is unofficial, but I made a sample to test updatable bootloaders at &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/updatable_bootloader/nsib_mcuboot_smp"&gt;Sample on how to use NSIB(b0) to update MCUBoot feat. SMP Server&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Is this the kind of thing you are asking for, or do you want something more detailed?&lt;/p&gt;
[quote user="optical"]Do you experience this issue as well ?[/quote]
&lt;p&gt;When I test my sample linked above, I am able to do v1(s0) -&amp;gt; v2(s1) -&amp;gt; v3(s0)-&amp;gt;v4(s1)-&amp;gt;v5(s0). I stopped there cause I guess that proves that it workes for me.&lt;br /&gt;This is what you wanted me to test right?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/393378?ContentTypeID=1</link><pubDate>Tue, 01 Nov 2022 08:36:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f07a80a-f1b5-48cf-9f0a-db99dc1ec6a2</guid><dc:creator>optical</dc:creator><description>&lt;p&gt;The procedure for updating bootloader does not support the revert feature. By my opinion. Because this is handled by the immutable bootloader.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I&amp;#39;m asking for application note or documentation, which exactly describes procedure for updating the MCUBoot Bootloader using Mcumgr.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/393298?ContentTypeID=1</link><pubDate>Mon, 31 Oct 2022 15:19:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21acc9bf-2ef8-4def-a92a-982ed6b74670</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user="optical"]What is the correct procedure for updating the bootloader ? We are currently using mcumgr upload -&amp;gt; test -&amp;gt; restart. This is works the main down fall of this method is that after second update(v1(s0) -&amp;gt; v2(s1) -&amp;gt; v3(s0)) the image swaped out from the s0 image will be marked as Test. This leads to bricking the device due to mcumgr not able to erase image marked as test and the update procedure will not unmark(test) the image in the secondary slot.&lt;br /&gt;[/quote]
&lt;p&gt;Usually when using TEST with MCUboot, the image will revert after unless you are confirming the image, right.&lt;/p&gt;
&lt;p&gt;Do you confirm the image in MCUboot when you do this?&lt;/p&gt;
&lt;p&gt;If not, do the MCUboot image revert each time you reset?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/393056?ContentTypeID=1</link><pubDate>Fri, 28 Oct 2022 13:51:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce31b575-d93a-4180-90de-a4d02966773f</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Simon is out of office.&lt;br /&gt;Therefore I will continue handling this case.&lt;/p&gt;
&lt;p&gt;I will need to take some time to get into what this is about, but I will return with an answer on Monday.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/392014?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2022 06:14:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ddf0509-1865-4439-b24e-a03cec116f56</guid><dc:creator>optical</dc:creator><description>&lt;p&gt;&lt;em&gt;This hook is not specific to the Nordic downstream MCUboot version, it exist in the upstream MCUboot version as well (see&amp;nbsp;&lt;a href="https://github.com/mcu-tools/mcuboot/blob/main/boot/zephyr/hooks_sample.c"&gt;https://github.com/mcu-tools/mcuboot/blob/main/boot/zephyr/hooks_sample.c&lt;/a&gt;). Can you create an issue in&amp;nbsp;&lt;a href="https://github.com/mcu-tools/mcuboot/issues"&gt;https://github.com/mcu-tools/mcuboot/issues&lt;/a&gt;&amp;nbsp;if there are any issues with this hook?&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The issue is caused by configuration done by nordic. The mainstream sample prevent the secondary Image(Bootloader) (BootImages compiled into the mcuboot. 0 - App, 1 - Bootloader). The hooks automaticly rejects the secondary image. This should be fixed in the nordic repository to prevent any issue for the end user. &lt;br /&gt;The procedure to test all updates when releasing new version is very tiresome and can lead to user error. We exactly encountered this issue.&lt;br /&gt;&lt;br /&gt;I suggest inclusion of following patch to the ncs branch to prevent any future confusion for the users.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0001_2D00_fix_2D00_Boot_2D00_sample_2D00_hooks_2D00_modified_2D00_to_2D00_prevent_2D00_any_2D00_furthe.patch"&gt;devzone.nordicsemi.com/.../0001_2D00_fix_2D00_Boot_2D00_sample_2D00_hooks_2D00_modified_2D00_to_2D00_prevent_2D00_any_2D00_furthe.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The main problem is that this will appear after another bootloader version release, which is not common&lt;/p&gt;
&lt;p&gt;.&amp;nbsp;&lt;br /&gt;Is there a supported way from nordic how to verify that the configured bootloader will perform another update ? Some kind of integration or unit tests ? This is by my opinion a &lt;strong&gt;crucial part&lt;/strong&gt; of the development of critical application part such as bootloader.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;Are you using nRF9160 with MCUboot+immutable bootloader+external flash?&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Yes, we are.&amp;nbsp; For ilustration the partition manager flash map. We are also using Mcuboot scratch partition for the swap operation. We encountered using the default method that when the bootloader expands to the last sector the &lt;strong&gt;update process fails. This should be checked by the compilation. It is not. &lt;/strong&gt;This creates a false notion for the user that he has larger flash area to work with. This will for some users endu fatal during NCS updates of the bootloader.&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;  external_flash (0x200000 - 2048kB): 
+-----------------------------------------------+
| 0x0: mcuboot_secondary (0xa8000 - 672kB)      |
| 0xa8000: mcuboot_scratch (0x8000 - 32kB)      |
| 0xb0000: external_storage (0x148000 - 1312kB) |
| 0x1f8000: external_settings (0x8000 - 32kB)   |
| 0x200000: external_flash (0x0 - 0B)           |
+-----------------------------------------------+

  flash_primary (0x100000 - 1024kB): 
+--------------------------------------------------+
+---0x0: b0_container (0x8000 - 32kB)--------------+
| 0x0: b0 (0x8000 - 32kB)                          |
+---0x8000: s0 (0x20200 - 128kB)-------------------+
| 0x8000: s0_pad (0x200 - 512B)                    |
+---0x8200: s0_image (0x20000 - 128kB)-------------+
| 0x8200: mcuboot (0x20000 - 128kB)                |
+--------------------------------------------------+
| 0x28200: EMPTY_0 (0x7e00 - 31kB)                 |
+---0x30000: s1 (0x20200 - 128kB)------------------+
| 0x30000: s1_pad (0x200 - 512B)                   |
| 0x30200: s1_image (0x20000 - 128kB)              |
+--------------------------------------------------+
| 0x50200: EMPTY_1 (0x7e00 - 31kB)                 |
+---0x58000: mcuboot_primary (0xa8000 - 672kB)-----+
| 0x58000: mcuboot_pad (0x200 - 512B)              |
+---0x58200: app_image (0xa7e00 - 671kB)-----------+
+---0x58200: mcuboot_primary_app (0xa7e00 - 671kB)-+
| 0x58200: spm (0x8000 - 32kB)                     |
| 0x60200: app (0x9fe00 - 639kB)                   |
+--------------------------------------------------+&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Patch needed for user to be able to define scratch partition using pm_static.yml file inside external flash.&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0001_2D00_feat_2D00_Adding_2D00_option_2D00_to_2D00_specify_2D00_user_2D00_scratch_2D00_partition.patch"&gt;devzone.nordicsemi.com/.../0001_2D00_feat_2D00_Adding_2D00_option_2D00_to_2D00_specify_2D00_user_2D00_scratch_2D00_partition.patch&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;Can you try this patch on MCUboot associated with NCS v2.1.0? Let me know if it works or not.&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;We are still using the v2.0.0, we will update to the NCS v2.1.0 during following months. However, we are reluctant with the updates due to lack of test for the update process from our side.&lt;br /&gt;&lt;br /&gt;We are currently using this patch, which is verified to work.&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0001_2D00_fix_2D00_MCUBoot_2D00_Fixed_2D00_immutable_2D00_bootloader_2D00_when_2D00_external.patch"&gt;devzone.nordicsemi.com/.../0001_2D00_fix_2D00_MCUBoot_2D00_Fixed_2D00_immutable_2D00_bootloader_2D00_when_2D00_external.patch&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Both of the patches are based on following version:&amp;nbsp;129b6312d61a9dc2c3b0c8810326678cdbd27b80 - v1.9.99-ncs1-rc2&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;What is the correct procedure for updating the bootloader ? We are currently using mcumgr upload -&amp;gt; test -&amp;gt; restart. This is works the main down fall of this method is that after second update(v1(s0) -&amp;gt; v2(s1) -&amp;gt; v3(s0)) the image swaped out from the s0 image will be marked as Test. This leads to bricking the device due to mcumgr not able to erase image marked as test and the update procedure will not unmark(test) the image in the secondary slot.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Do you experience this issue as well ? We solved this issue by modifying zephyr to allow&amp;nbsp;erase of a Test images. By my opinion this should be in upstream as well there are cases where user wants to cancel the update without restarting the device twice.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot Update hooks - Rejects any mcuboot updates when used with immutable bootlader</title><link>https://devzone.nordicsemi.com/thread/391998?ContentTypeID=1</link><pubDate>Sun, 23 Oct 2022 22:36:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76f4c2ed-bb2c-4975-a4d2-f6713ec842fa</guid><dc:creator>Simon</dc:creator><description>[quote user=""]&lt;p&gt;Dear nordic,&lt;/p&gt;
&lt;p&gt;state of your MCUBoot + Immutable bootloader is just awful.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Please fix this hook, when enabled it disables updates of the mcuboot bootloader when used with immutable bootloader.&lt;br /&gt;This issue is detected upon next mcuboot update, however then it is too late it will brick all devices due to next update rejection.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/zephyr/hooks_sample.c#L57"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/zephyr/hooks_sample.c#L57&lt;/a&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This hook is not specific to the Nordic downstream MCUboot version, it exist in the upstream MCUboot version as well (see &lt;a href="https://github.com/mcu-tools/mcuboot/blob/main/boot/zephyr/hooks_sample.c"&gt;https://github.com/mcu-tools/mcuboot/blob/main/boot/zephyr/hooks_sample.c&lt;/a&gt;). Can you create an issue in&amp;nbsp;&lt;a href="https://github.com/mcu-tools/mcuboot/issues"&gt;https://github.com/mcu-tools/mcuboot/issues&lt;/a&gt;&amp;nbsp;if there are any issues with this hook?&lt;/p&gt;
[quote user=""]MCUBoot + Immutable bootloader used with external flash does not work due reading the header directly from memory instead of the Flash_area. Honestly did you even tried it ?&amp;nbsp;&lt;br /&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/bootutil/src/loader.c#L920"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/bootutil/src/loader.c#L920&lt;/a&gt;&lt;br /&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/bootutil/src/loader.c#L934"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/bf00840a090f396ec1554968e19fa0e02c077d38/boot/bootutil/src/loader.c#L934&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I would submit a patch however you have disabled any&amp;nbsp;issue to the repository. Should i just create pull request ?[/quote]
&lt;p&gt;Are you using nRF9160 with MCUboot+immutable bootloader+external flash?&lt;/p&gt;
&lt;p&gt;Can you try this patch on MCUboot associated with NCS v2.1.0? Let me know if it works or not.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 2a5c89cd..7dd8fa43 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -50,6 +50,8 @@
  
 #if defined(CONFIG_SOC_NRF5340_CPUAPP) &amp;amp;&amp;amp; defined(PM_CPUNET_B0N_ADDRESS)
 #include &amp;lt;dfu/pcd.h&amp;gt;
+#include &amp;quot;flash_map_backend/flash_map_backend.h&amp;quot;
+#include &amp;lt;zephyr/drivers/flash/flash_simulator.h&amp;gt;
 #endif
  
 #ifdef MCUBOOT_ENC_IMAGES
@@ -917,9 +919,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
 #if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
     const struct flash_area *secondary_fa =
         BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
-    struct image_header *hdr = (struct image_header *)secondary_fa-&amp;gt;fa_off;
-    uint32_t vtable_addr = 0;
-    uint32_t *vtable = 0;
+    struct image_header *hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
     uint32_t reset_addr = 0;
     /* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
      * B1 slot S0 or S1) share the same secondary slot, we need to check
@@ -930,9 +930,12 @@ boot_validated_swap_type(struct boot_loader_state *state,
      */
  
     if (hdr-&amp;gt;ih_magic == IMAGE_MAGIC) {
-        vtable_addr = (uint32_t)hdr + hdr-&amp;gt;ih_hdr_size;
-        vtable = (uint32_t *)(vtable_addr);
-        reset_addr = vtable[1];
+        int rc = flash_area_read(secondary_fa, hdr-&amp;gt;ih_hdr_size +
+                                sizeof(uint32_t), &amp;amp;reset_addr,
+                                sizeof(reset_addr));
+        if (rc != 0) {
+            return BOOT_SWAP_TYPE_FAIL;
+        }
 #ifdef PM_S1_ADDRESS
 #ifdef PM_CPUNET_B0N_ADDRESS
         if(reset_addr &amp;lt; PM_CPUNET_B0N_ADDRESS)
@@ -981,11 +984,29 @@ boot_validated_swap_type(struct boot_loader_state *state,
          * available
          */
         if (upgrade_valid &amp;amp;&amp;amp; reset_addr &amp;gt; PM_CPUNET_B0N_ADDRESS) {
-            uint32_t fw_size = hdr-&amp;gt;ih_img_size;
-
             BOOT_LOG_INF(&amp;quot;Starting network core update&amp;quot;);
-            int rc = pcd_network_core_update(vtable, fw_size);
+            static const struct device *mock_flash_dev;
+            void *mock_flash;
+            size_t mock_size;
+
+            BOOT_LOG_INF(&amp;quot;Reading update image to flash simulator&amp;quot;);
+            //mock_flash_dev = device_get_binding(PM_MCUBOOT_PRIMARY_DEV_NAME);
+            //if (mock_flash_dev == NULL) {
+            mock_flash_dev = DEVICE_DT_GET(DT_NODELABEL(PM_MCUBOOT_PRIMARY_DEV));     
+            if (!device_is_ready(mock_flash_dev)) {
+                swap_type = BOOT_SWAP_TYPE_NONE;
+            }
+            mock_flash = flash_simulator_get_memory(mock_flash_dev, &amp;amp;mock_size);
+            int rc = flash_area_read(secondary_fa, 0U, mock_flash, hdr-&amp;gt;ih_hdr_size + hdr-&amp;gt;ih_img_size);
+            if (rc != 0) {
+                return BOOT_SWAP_TYPE_FAIL;
+            }
  
+            BOOT_LOG_INF(&amp;quot;Starting PCD update to network core&amp;quot;);
+            hdr = (struct image_header *) mock_flash;
+            uint32_t vtable_addr = (uint32_t)hdr + hdr-&amp;gt;ih_hdr_size;
+            uint32_t *vtable = (uint32_t *)(vtable_addr);
+            rc = pcd_network_core_update(vtable, hdr-&amp;gt;ih_img_size);
             if (rc != 0) {
                 swap_type = BOOT_SWAP_TYPE_FAIL;
             } else {
@@ -996,14 +1017,13 @@ boot_validated_swap_type(struct boot_loader_state *state,
                  * the image cannot be reverted.
                  */
                 rc = swap_erase_trailer_sectors(state,
-                        secondary_fa);
+                    secondary_fa);
 #endif
                 swap_type = BOOT_SWAP_TYPE_NONE;
             }
         }
 #endif /* CONFIG_SOC_NRF5340_CPUAPP */
     }
-
     return swap_type;
 }
 #endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;will get back to you on Monday/Tuesday with more information about this.&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>