<?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>Does bootloader need put data on MBR section of coed?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59147/does-bootloader-need-put-data-on-mbr-section-of-coed</link><description>Hi, 
 
 I am developing a product based on nrf52840 soc, I need to write a softdevice, program hex file, bootloader on the chip. when I want to select them all in the nrf connect to program the chip, nrf connect says that bootloader and softdevice have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 Mar 2020 10:02:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59147/does-bootloader-need-put-data-on-mbr-section-of-coed" /><item><title>RE: Does bootloader need put data on MBR section of coed?</title><link>https://devzone.nordicsemi.com/thread/240387?ContentTypeID=1</link><pubDate>Wed, 18 Mar 2020 10:02:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4333d23c-8e4d-490e-9181-4c44c1b27a57</guid><dc:creator>bjorn-spockeli</dc:creator><description>[quote user="alireza sadeghpour"]1. what is the benefit of placing data in the MBR section instead of UICR?[/quote]
&lt;p&gt;&amp;nbsp;The UICR can potentially be erased from on-chip code through the&amp;nbsp;&lt;a title="  ERASEUICR  " href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/nvmc.html?cp=4_2_0_10_6_6#register.ERASEUICR"&gt;ERASEUICR&lt;/a&gt;&amp;nbsp;register.&amp;nbsp;So writing the addresses to the MBR adds a level of security, i.e. this will ensure that the NRF52 will jump to the bootloader in the unlikely case the the UICR registers are accidentally erased.&amp;nbsp;&lt;/p&gt;
[quote user="alireza sadeghpour"]2. I have got PCA10059 bootloader from&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/40924/how-can-i-restore-the-original-bootloader-of-a-pca10059"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/40924/how-can-i-restore-the-original-bootloader-of-a-pca10059&lt;/a&gt;, and this bootloader also has data&amp;nbsp;in the MBR section. and also I have written&amp;nbsp;SoftDevice in the PCA10059 many times and softdevice has data in the MBR section. so I think every time I write softdevice to PCA10059 stored data of bootloader in MBR section will be erased. how PCA10059 bootloader handle this?[/quote]
&lt;p&gt;&amp;nbsp;If you add the changes that I suggested, then the addresses will be written at run-time when the bootloader starts up, so then it does not matter if you re-flash the SoftDevice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Does bootloader need put data on MBR section of coed?</title><link>https://devzone.nordicsemi.com/thread/240324?ContentTypeID=1</link><pubDate>Tue, 17 Mar 2020 19:06:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85e5d1ad-93cb-42af-8e01-913dbac66ed7</guid><dc:creator>alireza sadeghpour</dc:creator><description>&lt;p&gt;Thank you so much for a detailed answer,&lt;/p&gt;
&lt;p&gt;Yes, I am using SDK v15.3. just some points that I did not get from your answer:&lt;/p&gt;
&lt;p&gt;1. what is the benefit of placing data in the MBR section instead of UICR?&lt;/p&gt;
&lt;p&gt;2. I have got PCA10059 bootloader from&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/40924/how-can-i-restore-the-original-bootloader-of-a-pca10059"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/40924/how-can-i-restore-the-original-bootloader-of-a-pca10059&lt;/a&gt;, and this bootloader also has data&amp;nbsp;in the MBR section. and also I have written&amp;nbsp;SoftDevice in the PCA10059 many times and softdevice has data in the MBR section. so I think every time I write softdevice to PCA10059 stored data of bootloader in MBR section will be erased. how PCA10059 bootloader handle this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Does bootloader need put data on MBR section of coed?</title><link>https://devzone.nordicsemi.com/thread/240159?ContentTypeID=1</link><pubDate>Tue, 17 Mar 2020 07:34:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aad613af-539a-4f95-a8ba-aa552cb02067</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Alireza,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which SDK version are you using? It could sound like you are using SDK v15.3.0, where we introduced support for the v6.1.1 SoftDevices. The v6.1.1 SoftDevices allows the bootloader to write the bootloader start address and the MBR parameter page address to flash locations inside the MBR. The MBR will then use these addresses instead of fecthing the&amp;nbsp;&lt;span&gt;bootloader start and the MBR parameter page addresses from the UICR registers. If the&amp;nbsp;bootloader start and the MBR parameter page address is not written to the MBR region, then the MBR will try to fetch the addresses from UICR like before.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In SDK v15.3.0 we modified the bootloader project so that it would place the&amp;nbsp;bootloader start and the MBR parameter page addresses in the MBR region, i.e. it would place the bootloader start and MBR parameter page addresses at 0xFF8 and 0xFFC respectivly. So the compiled bootloader binary will contain code in the MRB region, so this is why nRF Connect Programmer states that the bootloader and SoftDevice( specifically the MBR) overlaps.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This can be solved by modifying the bootloader to place&amp;nbsp;the bootlaoder start address and MBR parameter page to UICR and then write to 0xFF8 and 0xFFC at run-time, rather than placing the addresses in the MBR region in the compiled binary. The bootloader will only perform the write to the MBR region&amp;nbsp;on the first start up and on all subsequent startups the values inside the MBR will be used and not the ones stored in the UICR registers.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The modification needed is adding the snippet below to main() before&amp;nbsp;nrf_bootloader_flash_protect().&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Add this function to main() before the nrf_bootloader_flash_protect call

ret_code_t nrf_bootloader_write_bl_addr_to_mbr(void){

    if( (*(volatile uint32_t *)MBR_BOOTLOADER_ADDR != BOOTLOADER_START_ADDR) &amp;amp;&amp;amp; 
     (*(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS))
     {
          // Enable Write with the NVMC
          NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Wen &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos;
          while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}

          // Write Bootloader start address to MBR 
          *(volatile uint32_t *)MBR_BOOTLOADER_ADDR = BOOTLOADER_START_ADDR;
          // Write MBR parameter page address to MBR
          *(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS;
          // Revert NVMC to read-only
          NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos;
          while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}
      }

    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then you need to &amp;nbsp;modify the flash_placement.xml to place&amp;nbsp;the addresses in UICR instead of flash.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  &amp;lt;MemorySegment name=&amp;quot;uicr_bootloader_start_address&amp;quot; start=&amp;quot;0x10001014&amp;quot; size=&amp;quot;0x4&amp;quot;&amp;gt;
    &amp;lt;ProgramSection alignment=&amp;quot;4&amp;quot; keep=&amp;quot;Yes&amp;quot; load=&amp;quot;Yes&amp;quot; name=&amp;quot;.uicr_bootloader_start_address&amp;quot; address_symbol=&amp;quot;__start_uicr_bootloader_start_address&amp;quot; end_symbol=&amp;quot;__stop_uicr_bootloader_start_address&amp;quot; start = &amp;quot;0x10001014&amp;quot; size=&amp;quot;0x4&amp;quot; /&amp;gt;
  &amp;lt;/MemorySegment&amp;gt;
  &amp;lt;MemorySegment name=&amp;quot;uicr_mbr_params_page&amp;quot; start=&amp;quot;0x10001018&amp;quot; size=&amp;quot;0x4&amp;quot;&amp;gt;
    &amp;lt;ProgramSection alignment=&amp;quot;4&amp;quot; keep=&amp;quot;Yes&amp;quot; load=&amp;quot;Yes&amp;quot; name=&amp;quot;.uicr_mbr_params_page&amp;quot; address_symbol=&amp;quot;__start_uicr_mbr_params_page&amp;quot; end_symbol=&amp;quot;__stop_uicr_mbr_params_page&amp;quot; start = &amp;quot;0x10001018&amp;quot; size=&amp;quot;0x4&amp;quot; /&amp;gt;
  &amp;lt;/MemorySegment&amp;gt;
&amp;lt;/Root&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>