<?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 Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115498/dfu-target-with-mcuboot-update-file</link><description>Hello, 
 I am attempting to use the DFU Target library to receive an update file over a custom protocol. I aim to do an MCUboot-style upgrade such that after the file upload, I can call dfu_target_schedule_update() and MCUboot will recognize the new image</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Oct 2024 20:48:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115498/dfu-target-with-mcuboot-update-file" /><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/507219?ContentTypeID=1</link><pubDate>Mon, 21 Oct 2024 20:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79a3c68e-6a3e-41ce-9a4c-26d8502214cf</guid><dc:creator>emilyd</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Abhijith,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes, I believe that 662-664 byte length difference is due to the image trailer. I have another project that uses MCUboot successfully, and I saw this byte difference there as well.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My invalid image error was due to there being occasional empty pages in my external flash when there should&amp;#39;ve been a portion of an image. These empty pages therefore caused the calculated hash to be incorrect, since the image actually was invalid.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I was able to solve this by setting the sck-delay parameter in my qspi devicetree entry. It was previously unset and defaulted to 0.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;After consulting with&amp;nbsp;my particular&amp;nbsp;QSPI flash chip&amp;#39;s datasheet, sck-delay = &amp;lt;&lt;/span&gt;&lt;span&gt;60&lt;/span&gt;&lt;span&gt;&amp;gt; resolved the errors that I was seeing, and the image in the QSPI was correct.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;My device will now successfully recognize the new image in the secondary partition (app_update.bin) and write that to the primary partition. Making sure that the image is versioned correctly as well as signed using a key generated by imgtool.py are also key components for this to be successful.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;To anyone using an external QSPI flash, I found Nordic command line tools to be very helpful. The&amp;nbsp;nrfjprog --readqspi command in particular was very helpful, as well as nrfjprog --qspieraseall&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Thank you for your help!&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/507097?ContentTypeID=1</link><pubDate>Mon, 21 Oct 2024 09:54:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc2fb9b9-7deb-4a4c-870a-d6220af3f248</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="emilyd"]I have now noticed that the in image header that MCUboot reads (hdr-&amp;gt;ih_img_size), the size is always between 662 and 664 bytes less than the actual size of app_update.bin. For example, I have written 380692 bytes, but hdr-&amp;gt;ih_img_size is 380028 bytes[/quote]
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;That&amp;#39;s actually a great finding. Do you have an update on this? Were you able to tackle the issue?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;The difference of around 662-664 bytes might be coming from the size of the image trailer itself.&amp;nbsp;The image trailer is usually appended to the end of the image and is not part of the &lt;/span&gt;&lt;code&gt;ih_img_size.&amp;nbsp;&lt;/code&gt;&lt;span style="font-family:inherit;"&gt;The MCUboot image header contains the ih_img_size field, which should match the size of the actual image (excluding the trailer). The size recorded in the header is critical because MCUboot uses this size to compute the hash for verification. &lt;/span&gt;&lt;span style="font-family:inherit;"&gt;If this size is wrong, MCUboot will compute the wrong hash, leading to validation failure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/506583?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2024 19:28:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ebcc3983-e93e-4c3b-8815-70f9568ef0fd</guid><dc:creator>emilyd</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Abhijith,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your clarification about the image trailer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I believe I am including the versioning correctly.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;0.0.2&amp;quot; is in my prj.conf and I load an app_update.bin that has a higher revision compiled in.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;I have now noticed that the in image header that MCUboot reads (hdr-&amp;gt;ih_img_size), the size is always between 662 and 664 bytes less than the actual size of app_update.bin. For example, I have written 380692 bytes, but hdr-&amp;gt;ih_img_size is 380028 bytes. I am assuming that this incorrect length contributes to the incorrect hash calculation. I am not sure where this length mismatch is coming from, as before I call&amp;nbsp;dfu_target_done(1), I can see that the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;dfu_target_offset_get() returns the correct total file length.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I am now debugging to see where this image header is written and where the total image size is calculated incorrectly. Let me know if you have any insight on this.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Thank you,&lt;/div&gt;
&lt;div&gt;Emily&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/506581?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2024 19:02:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef332167-8f89-452c-92f6-760bb73e8a00</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re already signing the image using &lt;code&gt;imgtool.py&lt;/code&gt;, and adding the signing key in your &lt;code&gt;CMakeLists.txt&lt;/code&gt;, the build system should generate an image that includes the trailer as part of the image. This means the&amp;nbsp;&lt;code&gt;app_update.bin&lt;/code&gt;&amp;nbsp;already has the required metadata and trailer that MCUboot needs for verification.&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;DFU Target library&amp;#39;s job is to write the image to the correct partition and manage the scheduling of the update.&lt;/p&gt;
[quote user="emilyd"]Please let me know if you have any other advice.[/quote]
&lt;p&gt;Is it because of the versioning?&amp;nbsp;MCUboot compares the version in the primary slot with the version of the new image in the secondary slot during the DFU process. If the version in the secondary slot is lower or the same as the version in the primary slot, MCUboot will refuse to perform the swap or validation, which can also be the reason for the error message you are getting.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/506359?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 16:26:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bf37319-82d4-4e20-ba84-25e20df2955b</guid><dc:creator>emilyd</dc:creator><description>&lt;p&gt;I will add that I notify the build system of the priv.pem key through CMakeLists.txt as shown below, and the build system seems to be successfully recognizing it :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;set(mcuboot_CONFIG_BOOT_SIGNATURE_KEY_FILE \&amp;quot;${CMAKE_CURRENT_SOURCE_DIR}/priv.pem\&amp;quot;)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/506358?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 16:24:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a8dcc17-e332-4f13-9ac1-0a9e3edad758</guid><dc:creator>emilyd</dc:creator><description>&lt;p&gt;Hello &lt;span&gt;Abhijith&lt;/span&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am using nRF Connect SDK v2.6.0. Thank you for confirming that app_update.bin is the correct image to upload.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Does&amp;nbsp;&lt;span&gt;the DFU Target library take care of writing the image trailer into the secondary partition?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I am signing the image. I have used imgtool.py to generate the MCUboot key:&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;python3 &amp;lt;NCS_PATH&amp;gt;/bootloader/mcuboot/scripts/imgtool.py keygen -t ecdsa-p256 -k priv.pem&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is my mcuboot.conf file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Increase main stack size
CONFIG_MAIN_STACK_SIZE=10240

# Configure logger
CONFIG_LOG=y
CONFIG_MCUBOOT_LOG_LEVEL_DBG=y
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_DBG=y
## Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
CONFIG_CBPRINTF_NANO=y

# Configure MCUboot features
CONFIG_NRF53_MULTI_IMAGE_UPDATE=y
CONFIG_BOOT_UPGRADE_ONLY=y
CONFIG_BOOT_MAX_IMG_SECTORS=256
CONFIG_MCUBOOT_DOWNGRADE_PREVENTION=y

# Allow for storing two images in MCUboot partitions
CONFIG_UPDATEABLE_IMAGE_NUMBER=2

# Store new images inside external flash
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

# Enable flash simulator
CONFIG_PCD_APP=y
CONFIG_FLASH_SIMULATOR=y
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
CONFIG_FLASH_SIMULATOR_STATS=n

# Configure QSPI for external flash
CONFIG_FLASH=y
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x15000
CONFIG_NORDIC_QSPI_NOR=y

# Increase number of sectors
CONFIG_BOOT_MAX_IMG_SECTORS=256

# Enable direct image upload
# CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y

# Set boot signature type
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And here is the relevant portion of my prj.conf file:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Bootloader configurations
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_B0N_MINIMAL=y
CONFIG_ZCBOR=y
CONFIG_CRC=y
CONFIG_BASE64=y

# Configure dependencies for CONFIG_IMG_MANAGER  
CONFIG_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
CONFIG_STREAM_FLASH_ERASE=y
CONFIG_FLASH_MAP=y
 
# DFU Target Library Configurations
CONFIG_DFU_MULTI_IMAGE=y
CONFIG_DFU_TARGET=y
CONFIG_DFU_TARGET_MCUBOOT=y
CONFIG_DFU_MULTI_IMAGE_PACKAGE_BUILD=y

CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION=&amp;quot;0.0.2&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please let me know if you have any other advice.&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;Emily&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU Target with MCUboot update file</title><link>https://devzone.nordicsemi.com/thread/506347?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 15:48:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a6566f7-dad1-438f-b590-b58118756623</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Could you tell me which version of the nRF Connect SDK you are using here?&lt;/p&gt;
[quote user=""]Is app_update.bin the appropriate image to write into the secondary partition with the DFU Target library? I[/quote]
&lt;p&gt;Yes, the &lt;code&gt;app_update.bin&lt;/code&gt; file is the correct image to upload.&lt;/p&gt;
&lt;p&gt;The error message &amp;quot;Image in the secondary slot is not valid!&amp;quot; typically occurs when the image is not signed, or the image trailer (which contains the hash and metadata) is missing or incorrect.&lt;/p&gt;
&lt;p&gt;Since you&amp;#39;re using a custom &lt;code&gt;pm_static.yml&lt;/code&gt;, ensure that the secondary partition is correctly defined for MCUboot. The image is typically written to a specific partition (the secondary slot) where MCUboot expects to find it. Make sure the secondary partition in your &lt;code&gt;pm_static.yml&lt;/code&gt; is properly configured and matches the expected partition layout that MCUboot uses.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>