<?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>nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113311/nrf5-sdk-custom-bootloader-attempting-flash-write-operation-returns-nrf_log_internal-and-nrf_error_invalid_addr</link><description>I&amp;#39;m writing a custom bootloader for an nRF52840 using the nRF5 SDK v15.0.0. This bootloader uses the SoftDevice to receive BLE packets containing binary data for the DFU. Write operations don&amp;#39;t work and I can&amp;#39;t trace back the source of the error, what</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Jul 2024 16:47:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113311/nrf5-sdk-custom-bootloader-attempting-flash-write-operation-returns-nrf_log_internal-and-nrf_error_invalid_addr" /><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/496459?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 16:47:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:123dd16d-e4a8-41af-b8fb-77249243b68f</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;Word alignment fixed the problem. Thank you Einar! I&amp;#39;m not sure why this hasn&amp;#39;t been a problem across other fstorage instances in my code, since there are several libraries also writing to internal flash without explicit word alignment that did not exhibit this problem. Maybe it&amp;#39;s because the source buffers in the other instances are declared globally rather than locally? In any case, this resolves the issue and I am now successfully able to write to flash: &lt;code&gt;static uint8_t binary_chunk[200] __attribute__((aligned(4)));&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/496427?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 13:28:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bce4313-530e-4ee7-b55a-7bf65cff03dc</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see that when you get the return valeue 0x0016 (NRF_ERROR_INVALID_ADDR) the source address is&amp;nbsp;0x2000850A, so it is not word aligned. So the error is expected in this case. Both the source and destination&amp;nbsp;address must be word aligned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/496282?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 16:54:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03913124-05d6-4e8b-8337-840b51d29bf4</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;I added the following print statements to my code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// in dfu flash callback
NRF_LOG_INFO(&amp;quot;callback evt: %u result: 0x%04X&amp;quot;, evt-&amp;gt;id, evt-&amp;gt;result);

// fstorage erase
err = nrf_fstorage_erase(&amp;amp;dfu_flash, dfu_flash.start_addr, num_pages, dfu_flash_callback);
NRF_LOG_INFO(&amp;quot;fstorage erase p_fs: %p, page_addr: 0x%08X, len: %u, err: 0x%04X)&amp;quot;, 
             (void*)&amp;amp;dfu_flash, dfu_flash.start_addr, num_pages, err);

// fstorage write
err = nrf_fstorage_write(&amp;amp;dfu_flash, payload_loc, binary_chunk, len, dfu_flash_callback);
NRF_LOG_INFO(&amp;quot;fstorage p_fs: %p, dest: 0x%08X, p_src: %p, len: %u, err: 0x%04X&amp;quot;, 
             (void*)&amp;amp;dfu_flash, payload_loc, (void*)binary_chunk, len, err);

// within write execute function, sd flash write
uint32_t err = sd_flash_write(p_dest, p_src, chunk_len);
NRF_LOG_INFO(&amp;quot;sd flash: p_dest: %p, p_src: %p, chunk len: %u, err: 0x%04X&amp;quot;, 
             (void*)p_dest, (void*)p_src, chunk_len, err);
return err;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and got these logs:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fstorage erase p_fs: 0x200059EC, page_addr: 0x00070000, len: 13, err: 0x0000
callback evt: 2 result: 0x0000

fstorage p_fs: 0x200059EC, dest: 0x00070000, p_src: 0x2000850A, len: 200, err: 0x0000
sd flash: p_dest: 0x00070000, p_src: 0x2000850A, chunk len: 5, err: 0x0016
callback evt: 1 result: 0x0003&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added the prints to the functional version of the code in the main app and got these results (the callback didn&amp;#39;t occur until after 15 successful flash write calls, I only included the first 2 to save space):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fstorage p_fs: 0x20002D54, dest: 0x00070000, p_src: 0x200044A8, len: 200, err: 0x0000
sd flash: p_dest: 0x00070000, p_src: 0x200044A8, chunk len: 5, err: 0x0000
sd flash: p_dest: 0x00070014, p_src: 0x200044BC, chunk len: 5, err: 0x0000
...
callback evt: 1 result: 0x0000&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/496128?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 07:10:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11e9506c-337d-44ed-afaa-7bce3c10daf2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I agree with your resoning, fstorage also checks for word alignment and boundaries. However, I do not see any other reason for getting&amp;nbsp;NRF_ERROR_INVALID_ADDR returned from a call to&amp;nbsp;sd_flash_write() when looking at the SoftDevice implementation. Can you log the parameters you pass to each call to&amp;nbsp;sd_flash_write() so that we can see which exact parameters you call it with when you get the unexpected&amp;nbsp;NRF_ERROR_INVALID_ADDR returned?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/496065?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 16:34:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f99b9958-8350-4552-86bf-ea6e1ce7a295</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;If there were a word alignment issue, wouldn&amp;#39;t this be rejected on the initial call to nrf_fstorage_write rather the error code being passed into the callback handler? I attempt to write a 200-byte chunk into address 0x70000, and the source address comes from &lt;code&gt;static uint8_t binary_chunk[200]&lt;/code&gt;. This process originally worked when it was used in the main app, but began reporting errors after I shifted the logic into the bootloader. The flash and RAM regions from the bootloader are taken from the secure bootloader sample in 15.0.0:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MEMORY
{
  FLASH (rx) : ORIGIN = 0xf1000, LENGTH = 0xd000
  RAM (rwx) :  ORIGIN = 0x200057b8, LENGTH = 0x3a848
  uicr_mbr_params_page (r) : ORIGIN = 0x10001018, LENGTH = 0x4
  mbr_params_page (r) : ORIGIN = 0x000FE000, LENGTH = 0x1000
  bootloader_settings_page (r) : ORIGIN = 0x000FF000, LENGTH = 0x1000
  uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/495974?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 10:33:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6250d806-ef21-44fb-97e4-e9f22ad02129</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Which address did you attempt to write to when you got&amp;nbsp;&lt;code&gt;NRF_ERROR_INVALID_ADDR&lt;/code&gt;? Are you able to log it or check with a debugger? You can get this error in a few different cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the source or destination adsdress is not word aligned&lt;/li&gt;
&lt;li&gt;If the destination address is outside of the physical address space of the device&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For reference, if you try to write over the SoftDevice itself, you will get a different error:&amp;nbsp;&lt;code&gt;NRF_ERROR_FORBIDDEN&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/495467?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2024 14:46:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5761d8ed-db5b-426f-b3ad-dca8019155fa</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p class="p1"&gt;&lt;span class="s1"&gt;The SoftDevice is being used in the bootloader for a custom DFU process. I&amp;rsquo;m working with a complex design involving several modules and pre-existing bootloader functionality so I don&amp;rsquo;t have the ability to use the Nordic samples at this point in the project, but the current bootloader code is based on a Nordic template. Are there SoftDevice functions not accessible to me in the bootloader? &lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;I do sidestep the Nordic DFU libraries for my BLE initialization (&lt;/span&gt;&lt;span class="s1"&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/111298/implementing-custom-ble-transfer-process-in-bootloader"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/111298/implementing-custom-ble-transfer-process-in-bootloader&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;span class="s1"&gt;and now I&amp;rsquo;m wondering if that could be related to the problem.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK custom bootloader, attempting flash write operation returns NRF_LOG_INTERNAL and NRF_ERROR_INVALID_ADDR</title><link>https://devzone.nordicsemi.com/thread/495402?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2024 12:02:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09f20dda-ea29-432a-be15-90e41e2c1bd2</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Initially, this seems to be caused by trying to access the SoftDevice addresses which you&amp;#39;re not allowed to read from or write to. What exactly is your use case for accessing the SoftDevice here? Is there a reason you can&amp;#39;t use the bootloader available in the SDK already?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>