<?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>RAM variables exchange between bootloader and application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33530/ram-variables-exchange-between-bootloader-and-application</link><description>Hello, 
 I wish to exchange variables (16 bytes) between bootloader and application in RAM. 
 What i have to modify please ? 
 Both LD file ? 
 Thank you</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 Apr 2018 14:18:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33530/ram-variables-exchange-between-bootloader-and-application" /><item><title>RE: RAM variables exchange between bootloader and application</title><link>https://devzone.nordicsemi.com/thread/129011?ContentTypeID=1</link><pubDate>Thu, 19 Apr 2018 14:18:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18be4182-2484-4805-a907-3470b53934b1</guid><dc:creator>Fabien Comte</dc:creator><description>&lt;p&gt;Thank you, i will try that asap.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM variables exchange between bootloader and application</title><link>https://devzone.nordicsemi.com/thread/128992?ContentTypeID=1</link><pubDate>Thu, 19 Apr 2018 13:20:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a058f928-33af-44cd-802b-fe87572f5da7</guid><dc:creator>ketil</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, these suggestions are for Flash memory. You can use option 3 with a named section of an absolute address that work for RAM with some additional modification.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Limit the size of the RAM available to the app/bootloader to one page less than the total available space. You can do this by editing the linker script&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Example code
RAM (rwx) :&amp;#160; ORIGIN = 0x200057b8, LENGTH = 0xa848 // before
RAM (rwx) :&amp;#160; ORIGIN = 0x200057b8, LENGTH = 0x9848 // after&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You also need to add memory retention on the reserved RAM page that you are going to use (in both Bootloader and APP) according to &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fmemory.html&amp;amp;anchor=memory"&gt;Fig 1. Memory Layout&lt;/a&gt; RAM 7 Section 1.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the section to use RAM retention according to the information about the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html&amp;amp;cp=2_1_0_17_8_33&amp;amp;anchor=register.RAM-7.POWERSET"&gt;RAM[7].POWERSET register&lt;/a&gt;. See POWER_RAM_POWERSET_S1RETENTION_Msk.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_POWER-&amp;gt;RAM[7].POWERSET = POWER_RAM_POWERSET_S1RETENTION_Msk;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The reason for reserving the top-page is that the stack is placed on the highest address in the memory layout in GCC. If this is reserved (not used) in both app and bootloader there will be no risk of invalid data being written to that location. This will however make 1 page of RAM unavailable in the system.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note that you will not have absolute assurances on the content in cases of power failures. This might be an issue if your bootloader needs to do multiple iterations of updates before the full firmware update process is finished (e.g. updating SoftDevice+Bootloader and then app). This is the reason why the buttonless DFU uses flash to store peer-data.. If we lost power during the firmware upgrade (which will reboot multiple times) we are never put in a bricked scenario (where the peer data is unavailable). You need to consider this with regards to your FW update process.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Ketil&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM variables exchange between bootloader and application</title><link>https://devzone.nordicsemi.com/thread/128870?ContentTypeID=1</link><pubDate>Wed, 18 Apr 2018 20:58:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dba677b-2707-4571-9af1-ad334b390464</guid><dc:creator>Fabien Comte</dc:creator><description>&lt;p&gt;Thank you for your response.&lt;/p&gt;
&lt;p&gt;Your proposal works in flash right ? Do you have any equivalent in RAM please ? (i will be limited by the number of flash cycle during product life)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM variables exchange between bootloader and application</title><link>https://devzone.nordicsemi.com/thread/128806?ContentTypeID=1</link><pubDate>Wed, 18 Apr 2018 12:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b9d01ec-7870-4988-94b7-b4cd8dff61d2</guid><dc:creator>ketil</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There are three options:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1) &amp;nbsp;using SVC interface&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Either use the Buttonless DFU as an example of using SuperVisor Calls to exchange data between app and bootloader. This would require storage in the Bootloader Settings page which has automatic deletion available when you go back to the application&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This implementation is however too complex to write anything about in this&amp;nbsp;answer and it may have some security considerations since you need to update the format of the bootloader settings page to do so.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2) using a named section&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The alternative method is just allocating a page to use for data exchange and use a &lt;strong&gt;named section&lt;/strong&gt; to refer to this from code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit linker script for main app and bootloader&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;MEMORY&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; FLASH (rx) : ORIGIN = 0x78000, LENGTH = 0x6000&lt;/p&gt;
&lt;p&gt;&amp;nbsp; RAM (rwx) :&amp;nbsp; ORIGIN = 0x200057b8, LENGTH = 0xa848&lt;/p&gt;
&lt;p&gt;&amp;nbsp; uicr_mbr_params_page (r) : ORIGIN = 0x10001018, LENGTH = 0x4&lt;/p&gt;
&lt;p&gt;&amp;nbsp; mbr_params_page (r) : ORIGIN = 0x0007E000, LENGTH = 0x1000&lt;/p&gt;
&lt;p&gt;&amp;nbsp; bootloader_settings_page (r) : ORIGIN = 0x0007F000, LENGTH = 0x1000&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp; dfu_exchange_page(r) : ORIGIN = 0x00067000, LENGTH = 0x1000 // Add this and set to what page to use&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Add this in linker script sections&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;SECTIONS&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; .dfu_exchange_page(NOLOAD) :&lt;/p&gt;
&lt;p&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROVIDE(__start_ dfu_exchange_page = .);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEEP(*(SORT(.dfu_exchange_page *)))&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROVIDE(__end_dfu_exchange_page = .);&lt;/p&gt;
&lt;p&gt;&amp;nbsp; } &amp;gt; dfu_exchange_page&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Create a structure type &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;typedef struct&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t version;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // &amp;nbsp;Ensure you aren’t handling illegal version&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t crc;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CRC of the rest of the structure to ensure to not act on invalid data&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t some_shared_data;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t some_other_shared_data;&lt;/p&gt;
&lt;p&gt;} dfu_exchange_data_t;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Create an instance of this type in the named section in both projects, set it to used to ensure that it is not optimized away&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;dfu_exchange_data_t &amp;nbsp;m_dfu_exchange &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;__attribute__((section(&amp;quot;.bootloader_settings_page&amp;quot;)))&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __attribute__((used));&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Flash API to write/erase from app/bootloader (don’t know if you need to go both ways)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is generally simplest to just use a structure type to read out in the bootloader, as this does not cost a lot of code space If you needed to add flash API and erase and so forth it just adds to the code-size (of which you may be limited)&lt;/li&gt;
&lt;li&gt;We allocate a full page in memory since this is the smallest to erase&lt;/li&gt;
&lt;li&gt;Section must be no-load on both app and bootloader to ensure it is not part of the hex-files to program the device&lt;/li&gt;
&lt;li&gt;You must use flash API to clear out and set this structure&lt;/li&gt;
&lt;li&gt;You can define your own structure type if you know what to exchange. Then you don&amp;#39;t need to copy it out&lt;/li&gt;
&lt;li&gt;Use a CRC-32 value to ensure that the exchanged data is correct&lt;/li&gt;
&lt;li&gt;Use a version (uint32_t) in the structure in the beginning to ensure that you can update the format later on&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3) Using an absolute address – The simplest, brute force method&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As long as you have a structure type known to both bootloader and application it is also a possibility to skip the linker scripts altogether and just make an absolute address into a structure type&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;typedef struct&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t version;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // &amp;nbsp;Ensure you aren’t handling illegal version&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t crc;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CRC of the rest of the structure to ensure to not act on invalid data&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t some_shared_data;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t some_other_shared_data;&lt;/p&gt;
&lt;p&gt;} dfu_exchange_data_t;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;dfu_exchange_data_t &amp;nbsp;&amp;nbsp;* p_dfu_exchange = (dfu_exchange_data_t*)0x67000;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: This is the simplest one but it will not be protected against the code growing into this area. You don’t have any assurances what will be in this page so you my end up erasing your code if you aren’t keeping track of what is at the address you are casting (and potentially are erasing). Method 2 is much safer in that regard.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ketil&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>