<?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>Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110042/is-it-possible-to-update-the-bootloader-from-the-main-application-using-nrf5-sdk-program-crashes-from-flash-erase-calls</link><description>I need to update a custom bootloader from the main application running on an nRF52840. The bootloader is contained in 0xF0000 to 0xF90D7 in internal flash, and the S140 SoftDevice is present from 0x1000 to 0x253C7. I attempted to run the code below but</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 Apr 2024 20:56:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110042/is-it-possible-to-update-the-bootloader-from-the-main-application-using-nrf5-sdk-program-crashes-from-flash-erase-calls" /><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/480542?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 20:56:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a721dc1e-bd6a-4a2d-bd6d-58c01c7e4e2f</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;Thank you! I&amp;#39;m now using a different method for DFU, but if I revisit this method I will update the thread to confirm if the workaround to copy a params page is successful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/479618?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2024 08:06:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a65a7c11-9db9-4534-83a3-86a88c0facbd</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;I assume&amp;nbsp;0x10001018 is just empty as well? (0xFFFFFF)&lt;/p&gt;
&lt;p&gt;Try from the main app to write the&amp;nbsp;mbr_params_page address to&amp;nbsp;&lt;span&gt;0x10001018&amp;nbsp;(UICR).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Example code on how to write to UICR here:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/82409/example-code-to-write-to-uicr/342027"&gt;RE: Example code to write to UICR&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then try with&amp;nbsp;sd_mbr_command / SD_MBR_COMMAND_COPY_BL again.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/479516?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2024 15:35:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:703578d5-3222-4ee6-bab4-f189fb173372</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;I think that may have been the problem. I have the params page in my original bootloader&amp;#39;s linker script with a NOLOAD directive, and the memory region is empty when reading from the Connect programmer.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MEMORY
{
  FLASH (rx) : ORIGIN = 0xF0000, LENGTH = 0xE000
  RAM (rwx) :  ORIGIN = 0x20000008, LENGTH = 0x3fff8
  uicr_mbr_params_page (r) : ORIGIN = 0x10001018, LENGTH = 0x4
  mbr_params_page (r) : ORIGIN = 0x000FE000, LENGTH = 0x1000
  uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
  bootloader_settings_page (r) : ORIGIN = 0x000FF000, LENGTH = 0x1000
}

SECTIONS
{
  .uicr_mbr_params_page :
  {
    PROVIDE(__start_uicr_mbr_params_page = .);
    KEEP(*(SORT(.uicr_mbr_params_page*)))
    PROVIDE(__stop_uicr_mbr_params_page = .);
  } &amp;gt; uicr_mbr_params_page
  .mbr_params_page(NOLOAD) :
  {
    PROVIDE(__start_mbr_params_page = .);
    KEEP(*(SORT(.mbr_params_page*)))
    PROVIDE(__stop_mbr_params_page = .);
  } &amp;gt; mbr_params_page
  .uicr_bootloader_start_address :
  {
    PROVIDE(__start_uicr_bootloader_start_address = .);
    KEEP(*(SORT(.uicr_bootloader_start_address*)))
    PROVIDE(__stop_uicr_bootloader_start_address = .);
  } &amp;gt; uicr_bootloader_start_address
  .bootloader_settings_page(NOLOAD) :
  {
    PROVIDE(__start_bootloader_settings_page = .);
    KEEP(*(SORT(.bootloader_settings_page*)))
    PROVIDE(__stop_bootloader_settings_page = .);
  } &amp;gt; bootloader_settings_page
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is there a way to add this to units retroactively, or any alternative method to modify the bootloader in this circumstance? This bootloader&amp;#39;s linker script looks to be a very lightly modified version of example bootloader linker scripts in the nRF5 SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/479395?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2024 11:16:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a43d511-3376-42a2-a893-bfe05917ca21</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
[quote user="rbmarcus"]I tested the code below and got a return code of 4, which I believe corresponds to NRF_ERR_NO_MEM. I&amp;#39;m using a very small 6-byte array and testing this in a sandbox environment, so I suspect I&amp;#39;m either going about this method incorrectly or I may need to initialize something else before calling the sd_mbr_command?[/quote]
&lt;p&gt;Sounds like you might not have the&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;mbr params page in flash present.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/479325?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2024 03:19:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa72e7d1-33c7-418d-bad2-1dddc8dfd3ab</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p&gt;I just attempted this method, but unfortunately it did not successfully modify the bootloader region. I tested the code below and got a return code of 4, which I believe corresponds to NRF_ERR_NO_MEM. I&amp;#39;m using a very small 6-byte array and testing this in a sandbox environment, so I suspect I&amp;#39;m either going about this method incorrectly or I may need to initialize something else before calling the sd_mbr_command?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* Enable SoftDevice */

ret_code_t err_code;
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);

uint32_t ram_start = 0;
err_code = nrf_sdh_ble_app_ram_start_get(&amp;amp;ram_start);
APP_ERROR_CHECK(err_code);

err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
APP_ERROR_CHECK(err_code);

err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
APP_ERROR_CHECK(err_code);

/* MBR-&amp;gt;SD method */

uint8_t bootloader_bin[] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
uint32_t bootloader_bin_len = 6;
uint32_t len_words = bootloader_bin_len / sizeof(uint32_t);

sd_mbr_command_t command =
{
    .command = SD_MBR_COMMAND_COPY_BL,
    .params.copy_bl.bl_src = bootloader_bin,
    .params.copy_bl.bl_len = len_words
};
uint32_t ret_val = sd_mbr_command(&amp;amp;command);
NRF_LOG_INFO(&amp;quot;ret: %d&amp;quot;, ret_val);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I also tried the methods below, making one build for each and commenting out the other methods. They all return NRF_SUCCESS, but the bootloader is still present and functional after POR and the memory region is unchanged based on the device memory layouts from the nRF Connect Programmer.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* SoftDevice library method */
err_code = sd_flash_page_erase(240);
APP_ERROR_CHECK(err_code);

/* DFU library method */
err_code = nrf_dfu_flash_init(true);
APP_ERROR_CHECK(err_code);
err_code = nrf_dfu_flash_erase(0xF0000, 1, NULL);
APP_ERROR_CHECK(err_code);
	
	
/* Flash storage library method */
nrf_fstorage_api_t * p_fs_api = &amp;amp;nrf_fstorage_sd;
err_code = nrf_fstorage_init(&amp;amp;bl_flash, &amp;amp;nrf_fstorage_sd, NULL);
APP_ERROR_CHECK(err_code);
err_code = nrf_fstorage_erase(&amp;amp;bl_flash, 0xF0000, 1, NULL);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/479266?ContentTypeID=1</link><pubDate>Wed, 17 Apr 2024 14:11:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b322fbe-6a69-4241-b1b4-adf372459b99</guid><dc:creator>Sigurd</dc:creator><description>[quote user="rbmarcus"]Is a dual-bank update possible from the main application?[/quote]
&lt;p&gt;Yes, it should be possible, assuming you have a&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;mbr params page in flash.&lt;/span&gt;&lt;/span&gt; You need to&amp;nbsp;have the&amp;nbsp;&lt;span&gt;new bootloader image to be present in internal flash. Then use&amp;nbsp;sd_mbr_command() with the command&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.3.0/group___n_r_f___m_b_r___e_n_u_m_s.html?cp=5_7_4_1_2_6_1_0_0#ggad416fbc71855eb8e1533a812164b85a7a56ab45130d67e73165ac12b66e8db127"&gt;SD_MBR_COMMAND_COPY_BL&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/478551?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2024 12:41:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cba79ea3-6262-4928-8c07-a9ac0fbbc063</guid><dc:creator>rbmarcus</dc:creator><description>&lt;p class="p1"&gt;&lt;span class="s1"&gt;Hi Sigurd, &lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Thank you for your response. &lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Is a dual-bank update possible from the main application? &lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;I understand that updating the bootloader from main is risky, but currently I don&amp;rsquo;t see a better option available assuming this is possible. The units are enclosed in a waterproof chassis. The bootloader uses a custom protocol over the 2.4GHz radio and was purpose-built to update only the main application using this protocol. I want to overwrite it with an updated bootloader that can receive binaries over BLE following a more standard process. If the bootloader upgrade fails I can open the bricked units to access the debug pins and flash over-wire, but without the bootloader upgrade I would need to open all the units. &lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;This is an otherwise completed program, aside from the bootloader lacking BLE support or secure OTA DFU, so I don&amp;rsquo;t have the ability to shift to NCS + Zephyr. &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to update the bootloader from the main application using nRF5 SDK? Program crashes from flash erase calls.</title><link>https://devzone.nordicsemi.com/thread/478459?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2024 07:31:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12ab574e-2126-4f95-8b49-b794d88dda15</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;In the default bootloader, we have support for DFU of the Bootloader. See this page:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_bootloader_dfu_banks.html"&gt;https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_bootloader_dfu_banks.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But it need&amp;#39;s to be dual-bank. You should not try to overwrite/erase the current active bootloader from main, then if something goes wrong with the DFU, you could end up with a &amp;quot;bricked device&amp;quot;.&lt;/p&gt;
&lt;p&gt;See also&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader"&gt;Getting started with Nordic&amp;#39;s Secure DFU bootloader, a step by step guide&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS: If this is a new product you are creating, I would strongly recommend that you use nRF Connect SDK instead.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/nrf-connect-sdk-and-nrf5-sdk-statement"&gt;nRF Connect SDK and nRF5 SDK statement&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK"&gt;https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>