<?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>How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77077/how-to-specify-signing-the-key-with-mcuboot</link><description>Hello, 
 
 I am using NCS v1.5.0 and an nRF9160 on a custom board, my application has a custom SPM and the secondary slot for the firmware image upgrade is stored on an external flash. 
 I generated a private key, and I am passing it to the MCUBoot as</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Jul 2021 09:41:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77077/how-to-specify-signing-the-key-with-mcuboot" /><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318587?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 09:41:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dae58b83-b62c-4430-9f0b-b279dad8d85d</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Great, thanks again !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318585?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 09:37:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ef01422-1bc0-4a39-8c0e-2ffe1a0c342d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;mcuboot is, from the user application, transport agnostic.&lt;/p&gt;
&lt;p&gt;You use the DFU library (dfu_target_init), as you linked to, and push data to it (dfu_target_write), and then you signal that its finished via &amp;quot;dfu_target_done&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ofcourse, the above is simplified in terms of the type of image, callbacks, error handling etc.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you search in the whole ncs tree for &amp;quot;dfu_target_init&amp;quot;, you will see tests/samples/libs that use this module. One example is the fota_download library (lib used in samples/nrf9160/http_update/application):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/subsys/net/lib/fota_download/src/fota_download.c#L122"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/subsys/net/lib/fota_download/src/fota_download.c#L122&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The job that you need to do is to implement a backend to route your proprietary transport into the dfu target lib, just as download_client + fota_download does for downloading a binary from a webserver.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318574?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 09:07:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66acff39-3c4f-40a4-b391-5c6b2e35719f</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Hakon,&lt;/p&gt;
&lt;p&gt;Thanks again for your help. I got everything up and running.&lt;/p&gt;
&lt;p&gt;I will take the opportunity to ask another question:&lt;/p&gt;
&lt;p&gt;In my application, the new firmware image is first transfered (through a proprietary protocol) to the device. And the upgrade only occurs if the user has requested it. With MCUBoot, will it try to update the firmware image as soon as it sees a valid new image in the secondary slot ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there a library for controlling the firmware update process ? I only could find the &lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.0/nrf/libraries/lib_dfu.html"&gt;DFU library&lt;/a&gt;, but it appears to be specific for the modem firmware, not the user application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318569?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 08:35:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24962edc-a6c3-4815-aa8f-328cdfa944c6</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Nelson,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="NelsonGoncalves"]&lt;p&gt;Thanks for the fast response and correcting my project configurations. I am now able to build, flash and boot my application. I still have two questions. The first is about the external flash organization.&lt;/p&gt;
&lt;p&gt;In my case, the external flash is divided in two parts. One for logs and application config items, and another for storing the new firmware image. When you edited the file pm_static.yml to become:&lt;/p&gt;[/quote][quote user="NelsonGoncalves"]&lt;p&gt;The firmware image slot is placed at the start of the external flash. Is this mandatory or can I place the image slot anywhere else in external flash ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;You can offset the flash as you&amp;#39;d like, as long as the size of the primary and secondary is equal. Note that you need to adjust this in the pm_static.yml and prj.conf.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Example where I add a 0x20000 offset. pm_static.yml:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;external_flash:
  address: 0x0000
  device: mx25r6435f
  end_address: 0x00200000
  region: external_flash
  size: 0x200000

mcuboot_secondary:
  address: 0x200000
  device: mx25r6435f
  end_address: 0x2f0000
  placement:
    align:
      start: 0x200000
  region: external_flash
  size: 0x0f0000
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;...
CONFIG_PM_EXTERNAL_FLASH_BASE=0x200000
CONFIG_PM_EXTERNAL_FLASH_SIZE=0x00f0000
...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="NelsonGoncalves"]&lt;p&gt;The second question is related to the MCUBoot keys. I uncommented&amp;nbsp;CONFIG_BOOT_SIGNATURE_KEY_FILE in mcuboot.conf, and the build process appears to have used my own private key. However on boot I got:&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v2.4.99-ncs1 ***&lt;br /&gt;[00:00:00.377,990] &amp;lt;inf&amp;gt; mcuboot: Starting bootloader&lt;br /&gt;[00:00:00.378,997] &amp;lt;inf&amp;gt; mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3&lt;br /&gt;[00:00:00.379,943] &amp;lt;inf&amp;gt; mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3&lt;br /&gt;[00:00:00.379,943] &amp;lt;inf&amp;gt; mcuboot: Boot source: none&lt;br /&gt;[00:00:00.381,378] &amp;lt;inf&amp;gt; mcuboot: Swap type: none&lt;br /&gt;[00:00:00.471,130] &amp;lt;err&amp;gt; mcuboot: Image in the primary slot is not valid!&lt;br /&gt;[00:00:00.471,130] &amp;lt;err&amp;gt; mcuboot: Unable to find bootable image&lt;/p&gt;
&lt;p&gt;So, what is the proper way to specifiy the private signing key ? Is it through the&amp;nbsp;&lt;span&gt;CONFIG_BOOT_SIGNATURE_KEY_FILE&amp;nbsp; option ? Or should I specify it in the command line ? Should I sign the image myself, or is it done by the build process ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;This must be set in mcuboot.conf, not in prj.conf.&lt;/p&gt;
&lt;p&gt;Note that if you have a space or a special character like &amp;quot;\&amp;quot; in your path, it must be escaped, as this needs to be in C-string format.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s say that you have the key.pem located in C:\key.pem, then the string must be:&lt;/p&gt;
&lt;p&gt;CONFIG_BOOT_SIGNATURE_KEY_FILE=&amp;quot;c:\\key.pem&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you have issues, you can go into menuconfig for mcuboot, setting the above mentioned config to point to your pem file, then &amp;quot;Save minimal config (advanced)&amp;quot; (shift + d in menuconfig) and look at the stored defconfig file.&lt;/p&gt;
&lt;p&gt;This will format the string for you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318564?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 08:17:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1867ce4-a731-4ec3-919b-7c629bbdb944</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Hello Hakon,&lt;/p&gt;
&lt;p&gt;Thanks for the fast response and correcting my project configurations. I am now able to build, flash and boot my application. I still have two questions. The first is about the external flash organization.&lt;/p&gt;
&lt;p&gt;In my case, the external flash is divided in two parts. One for logs and application config items, and another for storing the new firmware image. When you edited the file pm_static.yml to become:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;external_flash:
  address: 0xf0000
  device: mx25r6435f
  end_address: 0x00100000
  region: external_flash
  size: 0x10000

mcuboot_secondary:
  address: 0x0
  device: mx25r6435f
  end_address: 0xf0000
  placement:
    align:
      start: 0x000
  region: external_flash
  size: 0x0f0000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The firmware image slot is placed at the start of the external flash. Is this mandatory or can I place the image slot anywhere else in external flash ?&lt;/p&gt;
&lt;p&gt;The second question is related to the MCUBoot keys. I uncommented&amp;nbsp;CONFIG_BOOT_SIGNATURE_KEY_FILE in mcuboot.conf, and the build process appears to have used my own private key. However on boot I got:&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v2.4.99-ncs1 ***&lt;br /&gt;[00:00:00.377,990] &amp;lt;inf&amp;gt; mcuboot: Starting bootloader&lt;br /&gt;[00:00:00.378,997] &amp;lt;inf&amp;gt; mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3&lt;br /&gt;[00:00:00.379,943] &amp;lt;inf&amp;gt; mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3&lt;br /&gt;[00:00:00.379,943] &amp;lt;inf&amp;gt; mcuboot: Boot source: none&lt;br /&gt;[00:00:00.381,378] &amp;lt;inf&amp;gt; mcuboot: Swap type: none&lt;br /&gt;[00:00:00.471,130] &amp;lt;err&amp;gt; mcuboot: Image in the primary slot is not valid!&lt;br /&gt;[00:00:00.471,130] &amp;lt;err&amp;gt; mcuboot: Unable to find bootable image&lt;/p&gt;
&lt;p&gt;So, what is the proper way to specifiy the private signing key ? Is it through the&amp;nbsp;&lt;span&gt;CONFIG_BOOT_SIGNATURE_KEY_FILE&amp;nbsp; option ? Or should I specify it in the command line ? Should I sign the image myself, or is it done by the build process ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; Nelson&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to specify signing the key with MCUBoot</title><link>https://devzone.nordicsemi.com/thread/318558?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 07:35:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e43596ec-b283-49fd-ab60-44326460590d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for providing a sample. I needed to override your configuration slightly, as I&amp;#39;m testing on a DK.&lt;/p&gt;
&lt;p&gt;This means that you will get a JEDEC ID error check printed on runtime if you do not change back to your configuration in the boards/arm/dng_nrf9160/dng_nrf9160_common.dts&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]the secondary slot for the firmware image upgrade is stored on an external flash.[/quote]
&lt;p&gt;&amp;nbsp;The external flash setup is usually the reason for this error message in mcuboot, and it highly likely does not have anything to do with your signing process.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;You need to adjust mcuboot.conf::CONFIG_BOOT_MAX_IMG_SECTORS.&lt;/p&gt;
&lt;p&gt;The calculation is:&lt;/p&gt;
&lt;p&gt;flash_size / sector_size = CONFIG_BOOT_MAX_IMG_SECTORS.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;for a 1M flash, with 4k pages, this means it should be the default value of 256. In your case, you have set 8M, which needs a value of &amp;#39;2048&amp;#39;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;What will be printed when the primary and secondary has different sizes is this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.4.99-ncs1  ***
[00:00:00.400,848] &amp;lt;inf&amp;gt; mcuboot: Starting bootloader
[00:00:00.402,801] &amp;lt;wrn&amp;gt; mcuboot: Cannot upgrade: not a compatible amount of sectors
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After looking at the build-folder/partitions.yml, you can read out the&amp;nbsp;range (start+size)&amp;nbsp;of the mcuboot_primary_app, and adjust your secondary to the same.&lt;/p&gt;
&lt;p&gt;prj.conf: CONFIG_PM_EXTERNAL_FLASH_BASE and SIZE&lt;/p&gt;
&lt;p&gt;pm_static: &amp;quot;mcuboot_secondary:&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I may have butchered your project slightly (and added prints to the main app), my apologies for this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/272717.zip"&gt;devzone.nordicsemi.com/.../272717.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also included the build folder, with a merged.hex which runs on the nRF9160-DK (&lt;strong&gt;note:&lt;/strong&gt;&amp;nbsp;we have slightly different flash! remember to change back the configuration).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>