<?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>nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35312/nrf51-ota-ble-dfu-flash-space-erased-before-init-packet-validation</link><description>Hi! I&amp;#39;m developing on nRF51 with SDK 11 and trying to extend our application with buttonless BLE DFU support. Due to limited flash memory, we could only use single bank ble bootloader. Right now the bootloader works fine but we want to make it more secure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Jun 2018 21:33:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35312/nrf51-ota-ble-dfu-flash-space-erased-before-init-packet-validation" /><item><title>RE: nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/thread/136015?ContentTypeID=1</link><pubDate>Wed, 13 Jun 2018 21:33:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94e1d9d3-ce8d-429d-acff-2a189cb2e68f</guid><dc:creator>drmd</dc:creator><description>&lt;p&gt;So I managed to make the change that Hung suggested. And it works the way I want it to: if the init packet validation fails, the device can restart and run the original application without problem.&lt;/p&gt;
&lt;p&gt;All I needed to modify is dfu_single_bank.c and dfu_transport_ble.c (attached).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/single_5F00_bank_5F00_new_5F00_states.zip"&gt;devzone.nordicsemi.com/.../single_5F00_bank_5F00_new_5F00_states.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/thread/135947?ContentTypeID=1</link><pubDate>Wed, 13 Jun 2018 13:27:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cdd1872-c531-4f71-93b6-48d803cd8bcb</guid><dc:creator>drmd</dc:creator><description>&lt;p&gt;Thanks for the reply! I&amp;#39;ll give it a try.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/thread/135852?ContentTypeID=1</link><pubDate>Wed, 13 Jun 2018 08:35:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad556dd3-9cf9-4c63-aed4-911a7b846a90</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi drmd,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My mistake, I was thinking of the start packet not the init packet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are right that when erasing the old application, the bootloader need to wait for the erasing to be finished (max 90ms/page ). There is a call back called&amp;nbsp;dfu_cb_handler() in dfu_transport_ble.c that you can use. Currently it&amp;#39;s used to send the notification for the START packet after the erasing is done .&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What you can do is to modify it, so that the notification about the INIT packet complete ( ble_dfu_response_send(p_dfu, BLE_DFU_INIT_PROCEDURE, resp_val);)&amp;nbsp;&amp;nbsp;to be delayed instead of the START packet, until the flash erasing is finished.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What you planing to do is also fine,&amp;nbsp;I assume what you do is to verify the DFU master before allowing the bootloader to process the Start packet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note that, this trick can easily be recorded and replayed. So this approach is not really safe from attacker. It might be used to avoid accidental DFU update.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&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: nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/thread/135797?ContentTypeID=1</link><pubDate>Tue, 12 Jun 2018 16:35:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d073927-bf9b-4dd4-a3e8-7f0b4fbcdfd7</guid><dc:creator>drmd</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;I tried to put the dfu_prepare_func_app_erase() call after dfu_init_prevalidate() in dfu_init_pkt_complete(). I also changed the states correspondingly. My guess is that the clear can take arbitrary amount of time and the state could be messed up between DFU_STATE_RDY ( changed by pstorage_callback_handler() ) and DFU_STATE_RX_DATA_PKT.&lt;/p&gt;
&lt;p&gt;However, I found a way to only enable communication with DFU service when a certain value has been written to a characteristic and therefore effectively disable DFU functionality to public. So I&amp;#39;ll leave the dfu_single_bank.c as it is.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 OTA BLE DFU | flash space erased before init packet validation.</title><link>https://devzone.nordicsemi.com/thread/135793?ContentTypeID=1</link><pubDate>Tue, 12 Jun 2018 16:18:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38808e79-a785-4566-9981-95608b46e11b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi ,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you let me know what exactly you modified ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As far as I understand, the flash erasing of the original application only happens after the start packet is received and application version and image size verified. The function dfu_prepare_func_app_erase () is called inside &amp;quot;case DFU_STATE_IDLE: &amp;quot; in&amp;nbsp;dfu_start_pkt_handle() in dfu_single_bank.c&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>