<?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>merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106103/merged-hex-file-built-from-the-same-code-base-is-different</link><description>Hello, 
 I noticed that if I rebuild the merged.hex file from exactly the same code base then all subsequent merged.hex files are different. This is causing us a problem at production. 
 I am guessing/suspecting this because the file signature/CRC has</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Dec 2023 14:23:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106103/merged-hex-file-built-from-the-same-code-base-is-different" /><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/459730?ContentTypeID=1</link><pubDate>Mon, 11 Dec 2023 14:23:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba445d94-9363-4dce-b909-b00246eb14e0</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Learner"]Do you mean I manually strip the part of the output build files that show differences built from the same code base&amp;nbsp;i.e merged.hex, app_update.bin and app_signed.hex?[/quote]
&lt;p&gt;That is my understanding of it, yes&lt;/p&gt;
[quote user="Learner"]&lt;p&gt;&lt;span&gt;I am not familiar with imgtool, so I had a look at the case you shared with me where Benjamin V used the command line below,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;imgtool verify --key &amp;lt;&lt;span style="background-color:rgba(255, 255, 0, 1);"&gt;key.pem&lt;/span&gt;&amp;gt; app_update.bin&lt;/strong&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I recommend that you have a look at &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/keys_and_signatures"&gt;https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/keys_and_signatures&lt;/a&gt;,&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/imgtool.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/imgtool.html&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#ug-fw-update-keys-imgtool"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#ug-fw-update-keys-imgtool&lt;/a&gt;&amp;nbsp;to familiarize yourself regarding imgtool&lt;/p&gt;
[quote user="Learner"]Where do I get the key.pem file from ?[/quote]
&lt;p&gt;Some default keys can be found in &amp;lt;sdk version&amp;gt;/bootloader/mcuboot but we recommend that you generate your own keys following the documentation to do so&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#generating-private-keys"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#generating-private-keys&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you have your own custom keys they are in CONFIG_BOOT_SIGNATURE_KEY_FILE&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/459370?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 13:34:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f1b8691-3b66-4339-a195-38bc3634a323</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;Thank you for all your efforts.&lt;/p&gt;
[quote userid="107683" url="~/f/nordic-q-a/106103/merged-hex-file-built-from-the-same-code-base-is-different/459357"]Strip the signature and hash before comparing the firmware itself.[/quote]
&lt;p&gt;Do you mean I manually strip the part of the output build files that show differences built from the same code base&amp;nbsp;i.e merged.hex, app_update.bin and app_signed.hex?&lt;/p&gt;
[quote userid="107683" url="~/f/nordic-q-a/106103/merged-hex-file-built-from-the-same-code-base-is-different/459357"]Use the imgtool verify command to check that the signature of both images can be verified with the same key.[/quote]
&lt;p&gt;&lt;span&gt;I am not familiar with imgtool, so I had a look at the case you shared with me where Benjamin V used the command line below,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;imgtool verify --key &amp;lt;&lt;span style="background-color:#ffff00;"&gt;key.pem&lt;/span&gt;&amp;gt; app_update.bin&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Where do I get the key.pem file from ?&lt;/p&gt;
[quote userid="107683" url="~/f/nordic-q-a/106103/merged-hex-file-built-from-the-same-code-base-is-different/459357"]The Merged.hex is also a composition of different files and we recommend that you compare it to zephyr.hex to look closer into where the difference occurs[/quote]
&lt;p&gt;I compared the files merged.hex and zypher.hex from the same build and I am no wiser.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/459357?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 12:32:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d03fafe-bf5f-491d-a725-2fad6d9eb226</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;First of apologies for the far too long response time. It took longer than expected to find an answer for the two questions&lt;/p&gt;
&lt;p&gt;In the general case, the signature schemes are non-deterministic so the difference in the binary is to be expected.&lt;br /&gt;&lt;br /&gt; In addition, if you&amp;#39;re using development keys (for NSIB, MCUBoot uses the same key every time), the keys are also re-generated when building from scratch&amp;nbsp;&lt;br /&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#using-development-keys"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/config_and_build/bootloaders_and_dfu/fw_update.html#using-development-keys&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Given the signature is non-deterministic, one way to ensure two builds have created the same firmware is to do these two steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Strip the signature and hash before comparing the firmware itself.&lt;/li&gt;
&lt;li&gt;Use the imgtool verify command to check that the signature of both images can be verified with the same key.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This option is also suggested in&amp;nbsp;&lt;a href="https://reproducible-builds.org/docs/embedded-signatures/"&gt;https://reproducible-builds.org/docs/embedded-signatures/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This case discusses the topic above and you can use that as a reference&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/105006/mcuboot---firmware-signature-looks-different-at-each-build"&gt;MCUBoot - Firmware signature looks different at each build&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The Merged.hex is also a composition of different files and we recommend that you compare it to zephyr.hex to look closer into where the difference occurs&lt;/p&gt;
&lt;p&gt;Once again, apologies for the long response time and I hope this answers your questions sufficiently&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/459233?ContentTypeID=1</link><pubDate>Wed, 06 Dec 2023 16:04:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e160eb7-8f74-49de-af08-cf518b261a85</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;I am sorry to keep chasing you about the answers I am looking for.&lt;/p&gt;
&lt;p&gt;I am stuck on this and I need help from someone from Nordic.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/458684?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2023 09:27:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:395847ad-cb31-426f-acb1-b976a887545c</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Good Morning Andreas,&lt;/p&gt;
&lt;p&gt;Any update on my two questions above?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/457927?ContentTypeID=1</link><pubDate>Tue, 28 Nov 2023 15:41:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3ce602d-f81f-416b-b635-7916d7ec76a1</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;Thank you for your reply.&lt;/p&gt;
&lt;p&gt;I am looking forward to&amp;nbsp;your answers to my other two questions.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: merged.hex file built from the same code base is different.</title><link>https://devzone.nordicsemi.com/thread/457921?ContentTypeID=1</link><pubDate>Tue, 28 Nov 2023 15:03:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b94117f-9795-4c94-96fb-a19269b9b1a4</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
[quote user=""]Q1/ Can you please explain why this is happening?[/quote]
&lt;p&gt;It is as you said due to your firmware beeing modified since you have a timestamp that changes from build to build&lt;/p&gt;
[quote user=""]&lt;p&gt;Q2/ Could you please point me to a document detailing the format of the merged.hex file.&lt;/p&gt;
&lt;p&gt;Q3/ Is there a utility that &lt;span style="text-decoration:underline;"&gt;checks only the code content&lt;/span&gt; of the merged.hex without including timestamp, CRC, Signature etc...?&lt;/p&gt;[/quote]
&lt;p&gt;I will have to ask around some more to see if we have something for this&lt;/p&gt;
&lt;p&gt;I will get back to you before the weekend.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>