<?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 program pages in flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64517/protect-program-pages-in-flash</link><description>Hi 
 I am using NRF52 with 512KB flash, and with SDK15.2 
 I am not using DFU 
 I tried to protect the program flash pages using &amp;quot;sd_flash_protect&amp;quot;. 
 I tried to protect pages: 
 1. START page/address- from FLASH_START=0x19000 (which I took from the linker_section_placement_macros</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 06 Aug 2020 09:26:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64517/protect-program-pages-in-flash" /><item><title>RE: Protect program pages in flash</title><link>https://devzone.nordicsemi.com/thread/263388?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 09:26:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d8f860e-efb0-419b-9888-e93289e74c62</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Actually, just save the test value in a separate array, so there will not be as much logging:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    uint32_t block_cfg[4] = {0x00000000};
    uint32_t block_protect_failed[4] = {0x00000000};
    NRF_LOG_INFO(&amp;quot;START;&amp;quot;);
    
    ret_code_t err_code = NRF_SUCCESS;
    
    for (uint8_t i=0; i&amp;lt;4; i++)
    {
        for (uint8_t j=0; j&amp;lt;32; j++)
        {
            uint32_t test_value = 0x000000000;
            test_value = 0x01 &amp;lt;&amp;lt; j;
            block_cfg[i] = test_value;
            
            err_code = sd_flash_protect(block_cfg[0], block_cfg[1], block_cfg[2], block_cfg[3]);
            
            if (err_code != NRF_SUCCESS)
            {
                //NRF_LOG_INFO(&amp;quot;failed i=%d, j=%d&amp;quot;, i, j);
                block_protect_failed[i] |= test_value;
            }
        }
        block_cfg[i] = 0x00000000;
    }
    NRF_LOG_INFO(&amp;quot;DONE 0x%08x:0x%08x:0x%08x:0x%08x&amp;quot;, block_protect_failed[0], block_protect_failed[1], block_protect_failed[2], block_protect_failed[3]);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect program pages in flash</title><link>https://devzone.nordicsemi.com/thread/263384?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 09:13:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b2d0d59-b4c7-4709-823a-52d21e256a58</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;But the FDS pages are the pages that are not flash protected, right?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;END page/address - fstorage.end_addr-3 pages, which I am using for event log. This is page 0x7A.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Perhaps you can try something like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint32_t block_cfg[4] = {0x00000000};
    NRF_LOG_INFO(&amp;quot;START;&amp;quot;);
    
    ret_code_t err_code = NRF_SUCCESS;
    
    for (uint8_t i=0; i&amp;lt;4; i++)
    {
        for (uint8_t j=0; j&amp;lt;32; j++)
        {
            uint32_t test_value = 0x000000000;
            test_value = 0x01 &amp;lt;&amp;lt; j;
            block_cfg[i] = test_value;
            
            err_code = sd_flash_protect(block_cfg[0], block_cfg[1], block_cfg[2], block_cfg[3]);
            
            if (err_code != NRF_SUCCESS)
            {
                NRF_LOG_INFO(&amp;quot;failed i=%d, j=%d&amp;quot;, i, j);
            }
        }
        block_cfg[i] = 0x00000000;
    }
    NRF_LOG_INFO(&amp;quot;DONE&amp;quot;);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NB: If many of the checks fail, you may lose some logs, but you can use it to get an idea of what areas you are not able to protect.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Another approach is to force this through, like it is done in the bootloader projects in the SDK. The flash is protected before the softdevice is enabled using the function&amp;nbsp;nrf_bootloader_flash_protect(). Check it out in the example:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;SDK\examples\dfu\secure_bootloader\pca10040_s132_ble.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect program pages in flash</title><link>https://devzone.nordicsemi.com/thread/263279?ContentTypeID=1</link><pubDate>Wed, 05 Aug 2020 14:46:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d1c4748-b8a1-4acd-b485-5602b54a18a6</guid><dc:creator>arikramon</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;We are using: NFC, BLE, FDS is enabled&lt;br /&gt;How can I tell which page I can protect and which I can&amp;#39;t?&lt;/p&gt;
&lt;p&gt;Trial and error is not a good practice&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Arik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect program pages in flash</title><link>https://devzone.nordicsemi.com/thread/263254?ContentTypeID=1</link><pubDate>Wed, 05 Aug 2020 13:51:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf5bb057-5f7a-4324-8755-d22d65848cef</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;so you are trying to protect:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;R3                          | R2                        | R1                        | R0
7FFF FFFF                   | FFFF FFFF                 | FFFF FFFF                 | FF00 0000

0x007E FFFF - 0x0060 0000   | 0x005F FFFF - 0x0040 0000 | 0x003F FFFF - 0x0020 0000 | 0x001F FFFF - 0x0001 8000


So basically, 0x0001 8000 -&amp;gt; 0x007E FFFF&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Does your application use the flash for anything else? Do you use the BLE? The peer manager? FDS? Fstorage? Or any other modules that would require to write to flash in any way?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[quote user=""][/quote]&lt;/p&gt;
&lt;p&gt;If I set l_iConfigReg[2] and l_iConfigReg[3] to 0, the function return with status code NRF_SUCCESS.&lt;/p&gt;
&lt;p&gt;If I set l_iConfigReg[2] to 0x1 l_iConfigReg[3] to 0, the function return with status code NRF_ERROR_NOT_SUPPORTED .&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So there is something in R2 that it doesn&amp;#39;t like. Have you tried any other values than 0xFFFFFFFF and 0x00000001? Perhaps it is one specific area in R1 that it doesn&amp;#39;t allow you to protect, possibly because the softdevice has set this area to e.g. fstorage or FDS?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>