<?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>Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87775/customize-bootloader-to-rollback-ota-dfu</link><description>Hi, 
 
 I&amp;#39;ve been requested a feature regarding buttonless OTA DFU that I&amp;#39;m not sure if it&amp;#39;s feasible or advisable to implement. 
 The feature is that once the OTA is successful and the new application has been successfully flashed, we should check if</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 May 2022 08:16:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87775/customize-bootloader-to-rollback-ota-dfu" /><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/368224?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 08:16:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ffe306b-ec04-43ae-a549-199b60c9e290</guid><dc:creator>Hung Bui</dc:creator><description>[quote user="alberto."]I think &lt;code&gt;app_activate()&lt;/code&gt; would be the best method where to copy the old app in Bank 0 to the new Bank 2 just before the new app in Bank 1 is copied to Bank 0.&amp;nbsp;Or maybe adding another case in &lt;code&gt;nrf_bootloader_fw_activate() could make more sense.&lt;/code&gt;[/quote]
&lt;p&gt;Yes you can modify app_activate. But please make sure you have configured the location of bank0, bank 1 and bank 2 correctly so that they won&amp;#39;t overlap.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/368139?ContentTypeID=1</link><pubDate>Tue, 17 May 2022 07:27:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:018fb9d7-4e15-4460-8973-a970d04333a6</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;I see, I understand now what you meant about the 5 seconds after booting to enter DFU mode. It could be certainly be an option. First, I will try to modify the bootloader to use this new Bank 2 for the old app. If I fail, I will look into these other methods.&lt;/p&gt;
&lt;p&gt;I think &lt;code&gt;app_activate()&lt;/code&gt; would be the best method where to copy the old app in Bank 0 to the new Bank 2 just before the new app in Bank 1 is copied to Bank 0.&amp;nbsp;Or maybe adding another case in &lt;code&gt;nrf_bootloader_fw_activate() could make more sense.&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367854?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 13:11:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55c01025-d9f9-4a02-b80d-08dd70cf6558</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Alberto,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As far as I know the bootloader wont automatically enter DFU mode if the reset was because of the watchdog. You may want to implement that. It should be added in function&amp;nbsp;dfu_enter_check() in nrf_bootloader.c&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The bootloader timeout after 2 minutes if the DFU mode is entered, but for normal booting it won&amp;#39;t enter DFU mode.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Calling&amp;nbsp;&lt;span&gt;ble_dfu_buttonless_bootloader_start_finalize() will write to GPREGRET and will put the bootloader to DFU mode as&amp;nbsp; you can find in the dfu_enter_check() function.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367684?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 14:33:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df2d5618-8866-4014-9e5a-148efc2740b7</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Thanks a lot for all your answers.&lt;/p&gt;
&lt;p&gt;Isn&amp;#39;t it so that after the watchdog reset, the DFU mode will be active for 2 minutes (set at&amp;nbsp;&lt;code&gt;#define NRF_BL_DFU_INACTIVITY_TIMEOUT_MS 120000&lt;/code&gt;). So there should be a 2 minute window for DFU advertising that the user can connect to the DFU target, no? I believe that has been what I have&amp;nbsp;experienced&amp;nbsp;during testing. After those 2 minutes, the application will start again if it is valid.&lt;/p&gt;
&lt;p&gt;Yes, I agree there should be enough time in DFU mode before starting the app again &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt; I&amp;#39;m guessing the reason why I have seen those 2 minutes before the timeout was because I called&amp;nbsp;&lt;span&gt;&lt;code&gt;ble_dfu_buttonless_bootloader_start_finalize();&lt;/code&gt; before &lt;code&gt;NVIC_SystemReset();&lt;/code&gt;. I assume that it would be possible to do the same from the watchdog reset.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367671?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 14:12:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5090632d-c1d3-4aeb-b3f5-6ff42d4db1df</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, the watchdog can bring the device to the bootloader. But the bootloader may just start the application again and you will end up in a infinite loop. If there isn&amp;#39;t a &amp;quot;5 seconds advertising&amp;quot; at bootloader booting, it would not be possible to connect and do DFU update. Usually the fall back is to have a button pressed and hold when booting to retain in DFU mode but I guess it&amp;#39;s not an option for you. In your case you can think of checking the reset reason, if it&amp;#39;s watchdog reset then you can start DFU.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="alberto."]The problem I see with staying in DFU mode when booting for 5 seconds is that it is not testing whether the application itself can connect to the central device. What I am worried about is that the new app would not be able to connect to the central device for some misconfiguration of BLE parameters or wrongly called methods. In that case, the device would not be able to be sent into DFU mode because it can not connect and the application itself is not crashing.[/quote]
&lt;p&gt;I see what you meant here, but 5 seconds could be too short to me. I would suggest to try 30seconds to give good user experience. But I guess you would know your application better than me :)&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367626?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 12:50:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08e7c50a-4a39-4b35-b30e-44303289f24f</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;Hi again.&lt;/p&gt;
&lt;p&gt;I tried answering earlier but for some reason the &amp;quot;reply&amp;quot; button seems to appear and disappear at will.&lt;/p&gt;
&lt;p&gt;In the case that the application would crash,&amp;nbsp;if a watchdog timer is in place, it should take the device into DFU mode, isn&amp;#39;t it? Then, that case would be covered.&lt;/p&gt;
&lt;p&gt;In the second case, if the user turned off the app or something similar after an OTA update, then it would go into DFU indeed. But the timeout would happen in 2 minutes and the app would be started so I don&amp;#39;t think it would be a big problem.&lt;/p&gt;
&lt;p&gt;The problem I see with staying in DFU mode when booting for 5 seconds is that it is not testing whether the application itself can connect to the central device. What I am worried about is that the new app would not be able to connect to the central device for some misconfiguration of BLE parameters or wrongly called methods. In that case, the device would not be able to be sent into DFU mode because it can not connect and the application itself is not crashing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367588?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 11:46:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5f22021-eb79-4d3f-bf29-8235dead1fa3</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Alberto,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes you can put the device in DFU with these call. However, you are making the assumption that the application can run normally and can trigger the reset after 5 seconds without central connection. But if there is a case that the application crashed before that (if it couldn&amp;#39;t boot, or when booting it assert for some reason) then it&amp;#39;s not possible to switch to DFU mode.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In addition, what if the central couldn&amp;#39;t reconnect within 5 seconds for some reason (use turn off the app , or Bluetooth signal was not strong enough) then the device will enter DFU.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If you choose to do 5 seconds staying DFU mode when booting, then it would not be dependent on the new application as it&amp;#39;s the bootloader handing this first phase of booting.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367543?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 08:46:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e564684-60a6-4514-a644-3dd31f1e0466</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The device does not have a button for power on/off. It will be turned off during charging. Based on this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57916/nrf52840-how-to-do-buttonless-dfu-with-nrf_power_gpregret_set"&gt;discussion&lt;/a&gt;, I have tested that I can send the device to DFU mode by calling &lt;code&gt;ble_dfu_buttonless_bootloader_start_finalize();NVIC_SystemReset();.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If when initializing the device after an OTA DFU update, the application can not connect to the central device in 5 seconds, I would call these 2 methods and the device goes into DFU mode.&lt;/p&gt;
&lt;p&gt;I have checked that the device goes into DFU when calling those 2 commands.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367536?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 08:30:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71638e3a-767f-4aa9-af42-fd16e44853a5</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Alberto,&amp;nbsp;&lt;br /&gt;The device is battery powered but does it has a power button on it ? So that you can turn off and on the device ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If the connection can not be successful with the central device with the new firmware, how would you put the device to DFU mode ? It&amp;#39;s the main challenge here.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367533?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 08:01:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:062346f6-e555-4dac-95ac-69d002e5aca9</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The device is battery powered so this approach could not quite work exactly like that.&lt;/p&gt;
&lt;p&gt;However, I think that if when the new app is initialized after&amp;nbsp;OTA DFU and the connection can not be successful with the central device, sending the device into DFU mode would work as a way to fix for this issue, no?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367442?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 13:36:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0c40532-2628-44b9-b475-77859407b10c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again,&lt;/p&gt;
&lt;p&gt;My idea was that if you dont have a button, you can configure the bootloader so that when you power up the device it will stay in the bootloader mode for 5 seconds, advertising and wait for a connection from the phone. If the phone connect before 5 seconds elapse it will&amp;nbsp;start to do DFU update (so that you can revert to previous application image). If there is no connection the bootloader will continue to start the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The main draw back of this approach is that you have longer booting up time, an addition of 5 seconds. And it wouldn&amp;#39;t work if your device is a battery powered device and never supposed to be reset in its lifetime.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367435?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 13:23:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c230bf27-a376-4635-8fa6-461ce6343523</guid><dc:creator>alberto.</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;Since my board has no buttons available, option 3 would require to enter the DFU mode from the application. My idea would be that if the new application can not secure a connection in (for example) 5 seconds after flashing, it should go into DFU mode and the old application should be uploaded over BLE. Is that the same procedure you are describing?&lt;/p&gt;
&lt;p&gt;I understand that option 3 would the easier to implement that 1 or 2. Do you see any added benefits of options 1 or 2 over option 3?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Customize bootloader to rollback OTA DFU</title><link>https://devzone.nordicsemi.com/thread/367412?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 12:43:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c782974-5b67-4968-8e3a-02197a348a5f</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Alberto,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think its feasible and there are multiple alternatives to achieve what you want. Here is the list I can think of:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. Do what you are planning, divide the flash into 3 banks and before you swap the application with the new image you copy the original application to &amp;quot;bank 2&amp;quot;.&lt;/p&gt;
&lt;p&gt;2. In stead of using 3 bank you can use 2 banks and copy the original image back to bank 1. You can use one swap page to temporarily store&amp;nbsp;the page you want to copy from bank 0 to bank 1 when overwriting the page on bank 0.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. Third option, is to simply use the phone to revert the image back to the original one via DFU update. This requires you to have a way to enter DFU mode even if the application failed. A physical button would works. You can hold the button when reset to enter DFU mode. Or you can configure a period of time (5 second for example) when you boot up to stay in DFU mode and wait for the phone to connect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Doing option 1 or 2 would require you to significantly change how the swap process works on the bootloader. But I don&amp;#39;t see any reason that it would work. Option 1 will limit the size of the application as you would need to divide the flash into 3 parts.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>