<?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>Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3756/protect-bootloader-from-overwrite-erase</link><description>I am using Nordics sample bootloader and I really want to make sure that given a freak accident in sending it the firmware or in the firmware code itself that the bootloader is never erased or overwritten. In its current state, is the bootloader protected</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 Sep 2014 09:18:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3756/protect-bootloader-from-overwrite-erase" /><item><title>RE: Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/thread/13626?ContentTypeID=1</link><pubDate>Wed, 24 Sep 2014 09:18:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cf25c8c-9f9c-48ed-bbab-e2236a24e4b2</guid><dc:creator>Asbj&amp;#248;rn</dc:creator><description>&lt;p&gt;I finally was able to see the behavior you are describing and I had to change the chip and use a nRF51822 revision 1. It&amp;#39;s marked with N51822, QFAACA, 1230AA. The second line is the important one here, on revision 1 of the nrf51822 it will say QFAACx, where x can be A or 0. I do suspect that the chip you are working on are marked with CA or C0 and hence a revision 1 chip.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been testing this on revision 2 of the chip QFAAGx and this is the first version where the flash protect was implemented and hence I have not be able to recreate the behavior you see as expected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/thread/13625?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2014 12:49:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f09e22d9-d98d-432b-838f-ba3f96accd37</guid><dc:creator>Eric Salem</dc:creator><description>&lt;p&gt;The flash write and erase routines are pstorage as it is the setup in the DFU/bootloader examples.&lt;/p&gt;
&lt;p&gt;The store is done in dfu_dual_bank:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) {
     switch(m_dfu_state) {
          case DFU_STATE_RX_DATA_PKT:
               err_code = pstorage_raw_store(&amp;amp;m_storage_handle_app, (uint8_t*) p_data, data_length, m_app_data_received);
     }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Erase is done in dfu_dual_bank:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t dfu_image_size_set(uint32_t image_size) {
     switch (m_dfu_state)   {
          case DFU_STATE_IDLE: 
                err_code = pstorage_raw_clear(&amp;amp;m_storage_handle_app, image_size);
      }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the setup is in main {&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Initialize.
    timers_init();
    gpiote_init();
    ble_stack_init();
    scheduler_init();
    sd_flash_protect((uint32_t)0,(uint32_t)0xFFFFFFFF);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void ble_stack_init(void)
{
    uint32_t err_code;
    
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_250_PPM, true);

    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note: It is very hard to write and edit this comment in the 3 line editor window this forum gives me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/thread/13624?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2014 11:19:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72a88aba-a4f3-4b08-9b68-47634f755cc1</guid><dc:creator>Asbj&amp;#248;rn</dc:creator><description>&lt;p&gt;I added an attachment to my initial reply here. Please have a look at that main.c file.&lt;/p&gt;
&lt;p&gt;If I understand you correctly you also set sd_flash_protect(0,0xFFFFFFFF) but are still allowed to write to that upper half of the memory? Any chance you could share the flash write routine that you use?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/thread/13623?ContentTypeID=1</link><pubDate>Tue, 16 Sep 2014 18:58:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4620395a-6d19-45b1-9bf8-874579016704</guid><dc:creator>Eric Salem</dc:creator><description>&lt;p&gt;I added in the call sd_flash_protect(0,0xFFFFFFFF); to the bootloader after the softdevice is enabled just to verify that it will hardfault(per spec) instead of completing its process. I know the bootloader is not only erasing that area, but my firmware is getting written to that area as it is almost 100K in size.  Using this to test, I not only have been able to successfully write firmware every time, but I have been able to erase the bootloader.&lt;/p&gt;
&lt;p&gt;I have tested this with and without a debugger connected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect bootloader from overwrite/erase</title><link>https://devzone.nordicsemi.com/thread/13622?ContentTypeID=1</link><pubDate>Tue, 16 Sep 2014 12:51:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c954a76e-1297-48cb-8493-c40548bb42dc</guid><dc:creator>Asbj&amp;#248;rn</dc:creator><description>&lt;p&gt;You can use the registers PROTENSETx to protect you bootloader. If you have enabled the softdevice these registers are accessed through the sd_flash_protect call. PROTENSETx enables you to protect 64 different blocks of the memory. For the nRF51x22 these blocks are 4 k big.&lt;/p&gt;
&lt;p&gt;Update:
&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6242.main.c"&gt;main.c&lt;/a&gt;
I edited the standard .../nRF6310/S110/bla_app_hrs example. The main file is above here. I added code to set the PROTENSET and protect the upper half of flash and then try to write to that area. It fails and gives me an error code.&lt;/p&gt;
&lt;p&gt;UPDATE 2:
Always make sure that you are using nRF51 of second revision if you are using sd_flash_protect() or PROTENSET. On nRF51 revision 1 this functionality is not available.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>