<?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 settings page &amp;quot;randomly&amp;quot; gets zeroed --&amp;gt; Application cannot start</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57487/dfu-settings-page-randomly-gets-zeroed----application-cannot-start</link><description>We do have a product in which we program a bootloader on the target. It is remotely based on the ble_app_buttonless_dfu example. The bootloader is not actually used in the end product, i.e. There is usually no occasion on which the bootloader is activated</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 Feb 2020 09:18:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57487/dfu-settings-page-randomly-gets-zeroed----application-cannot-start" /><item><title>RE: DFU settings page "randomly" gets zeroed --&gt; Application cannot start</title><link>https://devzone.nordicsemi.com/thread/233214?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2020 09:18:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:923631fd-987c-47c1-998a-37760bba4491</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Mike,&amp;nbsp;&lt;br /&gt;I agree that there isn&amp;#39;t much reason the&amp;nbsp;&lt;span&gt;NRF_DFU_SETTINGS_VERSION&lt;/span&gt;&lt;span&gt;&amp;nbsp;should be in the preprocessor symbols. I will report this internally.&amp;nbsp;&lt;br /&gt;Please let me know if you have any further question.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU settings page "randomly" gets zeroed --&gt; Application cannot start</title><link>https://devzone.nordicsemi.com/thread/233118?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 16:03:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79c46822-feea-4f83-9d54-374bcc7cd44c</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Hi Hung Bui&lt;/p&gt;
&lt;p&gt;Thanks for the response. As mentioned in the original post, we are using SDK 15.3. We upgraded at some point and in the course did not update the preprocessor defines for the compiler where &lt;span&gt;NRF_DFU_SETTINGS_VERSION&lt;/span&gt; is set.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I don&amp;#39;t see why NRF_DFU_SETTINGS_VERSION is not hardcoded in the dfu settings c-file? As the implementation does not support any other version than two, there is no reason to have it &amp;quot;hidden&amp;quot; in the project settings!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The wrong NRF_DFU_SETTINGS_VERSION does indeed lead leads to these lines changing the bootloader settings upon every reboot, requiring it to be erased and rewritten.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;memcpy(&amp;amp;s_dfu_settings.peer_data, (uint8_t *)&amp;amp;s_dfu_settings + DFU_SETTINGS_BOND_DATA_OFFSET_V1, NRF_DFU_PEER_DATA_LEN);
memcpy(&amp;amp;s_dfu_settings.adv_name,  (uint8_t *)&amp;amp;s_dfu_settings + DFU_SETTINGS_ADV_NAME_OFFSET_V1,  NRF_DFU_ADV_NAME_LEN);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Without the backup page this leads to irrecoverable failure when the device loses power or gets reset between the erase and the completion of the write.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;-mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU settings page "randomly" gets zeroed --&gt; Application cannot start</title><link>https://devzone.nordicsemi.com/thread/233114?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 15:51:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1848527b-acd4-40e0-a7fb-7a0e16a2f598</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Michael,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you let me know the SDK version you are using ? If you are using SDK v15.3 and above the&amp;nbsp;&lt;span&gt;NRF_DFU_SETTINGS_VERSION&lt;/span&gt;&lt;span&gt;&amp;nbsp; should be set to 2. It&amp;#39;s by default defined in the pre-processor symbols in the project setting of the bootloader project.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You should use newer nrfutil, the current version is v6.0&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The bootloader flash protect is performed via the call&amp;nbsp;&amp;nbsp; &amp;nbsp; ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false); in main.c&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU settings page "randomly" gets zeroed --&gt; Application cannot start</title><link>https://devzone.nordicsemi.com/thread/233095?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 14:43:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98695859-e491-4b47-ac3d-0d4ed26b2354</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Upon further examination, I noticed that the bootloader executes the following lines of Code in &lt;span style="font-family:courier new, courier;"&gt;nrf_dfu_settings.c&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (NRF_DFU_SETTINGS_COMPATIBILITY_MODE &amp;amp;&amp;amp; !NRF_DFU_IN_APP &amp;amp;&amp;amp; (s_dfu_settings.settings_version == 1))
{
    NRF_LOG_INFO(&amp;quot;Old settings page detected. Upgrading info.&amp;quot;);

    // Old version. Translate.
    memcpy(&amp;amp;s_dfu_settings.peer_data, (uint8_t *)&amp;amp;s_dfu_settings + DFU_SETTINGS_BOND_DATA_OFFSET_V1, NRF_DFU_PEER_DATA_LEN);
    memcpy(&amp;amp;s_dfu_settings.adv_name,  (uint8_t *)&amp;amp;s_dfu_settings + DFU_SETTINGS_ADV_NAME_OFFSET_V1,  NRF_DFU_ADV_NAME_LEN);

    // Initialize with defaults.
    s_dfu_settings.boot_validation_softdevice.type = NO_VALIDATION;
    s_dfu_settings.boot_validation_app.type        = VALIDATE_CRC;
    s_dfu_settings.boot_validation_bootloader.type = NO_VALIDATION;
    memcpy(s_dfu_settings.boot_validation_app.bytes, &amp;amp;s_dfu_settings.bank_0.image_crc, sizeof(uint32_t));

    s_dfu_settings.settings_version = NRF_DFU_SETTINGS_VERSION;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;but the value for &lt;span style="font-family:courier new, courier;"&gt;NRF_DFU_SETTINGS_VERSION&lt;/span&gt; is actually 1. So this check seems to always be true and it looks like the bootloader settings page gets rewritten every time the device boots! Since no bootloader settings backup page is available, if the power cuts during the erase/write procedure, the application won&amp;#39;t boot again.&lt;/p&gt;
&lt;p&gt;I use nrfutil 3.5.1 to generate the settings page.&lt;/p&gt;
&lt;p&gt;I assume, that I have to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use a newer nrfutil&lt;/li&gt;
&lt;li&gt;actually generate a backup page in the original image&lt;/li&gt;
&lt;li&gt;set &lt;span style="font-family:courier new, courier;"&gt;NRF_DFU_SETTINGS_VERSION&lt;/span&gt; to the value that the bootloader should actually use (for sure not to 1!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;Additionally, I found out that the check in settings_write() in nrf_dfu_settings.c which should prevent the bootloader settings page from being rewritten if not necessary, will get rewritten nonetheless because for whatever reason, some values change between reboots.&lt;/p&gt;
&lt;p&gt;The following screenshot shows on the left side the bootloader settings page as it is in flash and on the right side the s_dfu settings struct as it is in rame when settings_write is executed. There is only one reboot inbetween and there was no DFU activity whatsoever.&amp;nbsp; As you can see. peer_data.crc and peer_data.irk as well as the adv_name values changed. Why? To me, it looks like there is some strange memory corruption bug here, but I can&amp;#39;t pinpoint where and why it happens.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/dfu_5F00_settings_5F00_comparison.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>