<?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>Modifying BL Settings Page from Main App</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60856/modifying-bl-settings-page-from-main-app</link><description>I&amp;#39;m using an SES with NRF52840, w/ SDK 15.3, and SoftDevice S140. Im working on DFU and have two components: 
 - a main app that already takes care of moving a FW image into BANK1 (which I&amp;#39;ve defined as 0x8a000) in internal flash 
 - a modified bootloader</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 01 May 2020 17:30:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60856/modifying-bl-settings-page-from-main-app" /><item><title>RE: Modifying BL Settings Page from Main App</title><link>https://devzone.nordicsemi.com/thread/247689?ContentTypeID=1</link><pubDate>Fri, 01 May 2020 17:30:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9b2eac2-104a-481c-94a8-0cfda4639d91</guid><dc:creator>lpvillaran</dc:creator><description>&lt;p&gt;&lt;strong&gt;UPDATE:&amp;nbsp;&lt;/strong&gt; I was able to get the settings written successfully.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am using the SD backend for fstorage because I am using S140. From the SDK:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[The SD] backend interfaces with the SoftDevice flash API to perform 
operations in flash. It can be used any time the SoftDevice is present, 
regardless of whether the SoftDevice is enabled or not. However, when 
running a protocol stack, the success of flash operations is tied to the 
timing constraints of the protocol and the characteristics of the hardware. 
Using too aggressive scan or advertising intervals, or running multiple 
connections, can influence the success of a flash operation.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;BUT I was only protecting the flash read/write/erases for my own internal flash transfers (by temporarily disabling the SD with nrf_sdh_disable_request()) and was re-enabling right after.&amp;nbsp; Because the sf_dfu_settings write was&amp;nbsp;placed after this re-enabling, the SD was now interfering with the settings writing.&amp;nbsp; I changed my code such that I&amp;nbsp;don&amp;#39;t re-enable the SD until after all the flash functions were complete and this fixed everything.&amp;nbsp; Hope this might help someone else!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying BL Settings Page from Main App</title><link>https://devzone.nordicsemi.com/thread/247641?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 18:23:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d868f9d-7fcb-4f84-a3f9-7d8d9ca8eaba</guid><dc:creator>lpvillaran</dc:creator><description>&lt;p&gt;&lt;strong&gt;UDPATE:&amp;nbsp;&lt;/strong&gt;I was able to get the update to work if I commented out the line right before the s_dfu_settings block.&amp;nbsp; This line was the piece of code that was actually doing the transferring of the code from external flash to Bank1, but since the&amp;nbsp;FW image&amp;nbsp;had already been transferred to Bank1 in previous calls, I could get away with commenting it out.&amp;nbsp; Obviously this won&amp;#39;t work in production, so I&amp;#39;m trying to understand how this line might affect the settings writing.&amp;nbsp; The function l commented out was the external_flash_transfer_to_bank1():&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;external_flash_transfer_to_bank1(test_fw_addr + CAM_UPDATE_HEADER_SIZE, scratchpad_data.app_len);

//Update BL settings to signal a new valid app is ready
s_dfu_settings.bank_1.bank_code                 = NRF_DFU_BANK_VALID_APP;
s_dfu_settings.bank_0.bank_code                 = ......&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;and the actual function looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;bool external_flash_transfer_to_bank1(uint32_t src_addr, uint32_t len)
{
    ret_code_t ret_val = NRF_ERROR_NOT_FOUND;
    uint32_t err_code;
    m_qspi_finished = false;

    uint8_t  num_full_pages = len/FLASH_PAGE_SIZE;
    uint16_t bytes_over_page = len%FLASH_PAGE_SIZE;

    NRF_LOG_INFO(&amp;quot;Transferring from external flash to BANK1&amp;quot;);

    // fstorage shares resources with SD, temporarily disable SD to avoid HardFaults
    nrf_sdh_disable_request();

    //Transfer all the full pages first
    for (uint16_t i = 0; i &amp;lt; num_full_pages; i++)
    {
      external_flash_read(m_buffer_rx, FLASH_PAGE_SIZE, src_addr + (i*FLASH_PAGE_SIZE));

      ret_val = write_data_to_flash(BANK1_FLASH_ADDR + (i * FLASH_PAGE_SIZE), m_buffer_rx, FLASH_PAGE_SIZE);
      if(ret_val != NRF_SUCCESS)
      {
          NRF_LOG_INFO(&amp;quot;Failed transferring full pages to bank1 on page %d.&amp;quot;, i);
          break;
      }
    }
    
    if(ret_val == NRF_SUCCESS)
    {
        //Transfer left over bytes
        memset(m_buffer_rx, 0xff, sizeof(m_buffer_rx));
        external_flash_read(m_buffer_rx, bytes_over_page, src_addr + (num_full_pages*FLASH_PAGE_SIZE));

        ret_val = write_data_to_flash(BANK1_FLASH_ADDR + (num_full_pages*FLASH_PAGE_SIZE), m_buffer_rx, FLASH_PAGE_SIZE);
        if(ret_val != NRF_SUCCESS) NRF_LOG_INFO(&amp;quot;Failed transferring bank1 overflow bytes.&amp;quot;);
    }
    
    NRF_LOG_INFO(&amp;quot;External flash transfer to BANK1 success.&amp;quot;);
    // re-enable the SD when done
    nrf_sdh_enable_request();
    return ret_val;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Any ideas on what in this function could be messing with the settings writing?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying BL Settings Page from Main App</title><link>https://devzone.nordicsemi.com/thread/247628?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 16:05:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:256a8ccf-d3b5-4e57-b650-e061080610bf</guid><dc:creator>lpvillaran</dc:creator><description>&lt;p&gt;Thanks for the response, Vidar.&amp;nbsp; Unfortunately I&amp;#39;m still not having luck.&amp;nbsp;&amp;nbsp;I&amp;nbsp;found &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/56993/not-able-to-update-firmware-using-bootloader-sdk15-3-0/231300#231300"&gt;this post&lt;/a&gt;&amp;nbsp;and so I did the following:&lt;/p&gt;
&lt;p&gt;IN THE MAIN APP&lt;/p&gt;
&lt;p&gt;-------------------------&lt;/p&gt;
&lt;p&gt;1. Updated my settings-writing code to look like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Update BL settings to signal a new valid app is ready
s_dfu_settings.bank_1.bank_code                 = NRF_DFU_BANK_VALID_APP;
s_dfu_settings.bank_0.bank_code                 = NRF_DFU_BANK_INVALID;
s_dfu_settings.app_version                      = 0;
s_dfu_settings.bank_1.image_crc                 = crc32_compute((uint8_t *)BANK1_FLASH_ADDR, scratchpad_data.app_len, NULL);
s_dfu_settings.bank_1.image_size                = scratchpad_data.app_len;
s_dfu_settings.bank_current                     = NRF_DFU_CURRENT_BANK_1;
s_dfu_settings.bank_layout                      = NRF_DFU_BANK_LAYOUT_DUAL;

/* Set the progress to zero and remove the last command */
memset(&amp;amp;s_dfu_settings.progress, 0, sizeof(dfu_progress_t));
memset(s_dfu_settings.init_command, 0xFF, DFU_SIGNED_COMMAND_SIZE);
s_dfu_settings.write_offset                     = 0;
s_dfu_settings.progress.update_start_address    = BANK1_FLASH_ADDR;

s_dfu_settings.boot_validation_softdevice.type  = NO_VALIDATION;
s_dfu_settings.boot_validation_app.type         = VALIDATE_CRC;
s_dfu_settings.boot_validation_bootloader.type  = NO_VALIDATION;
memcpy(s_dfu_settings.boot_validation_app.bytes, &amp;amp;s_dfu_settings.bank_1.image_crc, sizeof(uint32_t));

s_dfu_settings.settings_version                 = NRF_DFU_SETTINGS_VERSION;

APP_ERROR_CHECK(nrf_dfu_settings_write(NULL));

sd_nvic_SystemReset();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2. Disabled NRF_DFU_IN_APP in the main application to allow writing of forbidden sections&lt;/p&gt;
&lt;p&gt;3. Call nrf_dfu_settings_init(true) in the main app bc I have the SD initialized.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;IN THE BOOTLOADER&lt;/p&gt;
&lt;p&gt;--------------------------------&lt;/p&gt;
&lt;p&gt;1. call nrf_dfu_settings_init(false) and commented out the settings_forbidden_copy_from_backup() to avoid overwriting the settings I&amp;#39;ve written from the main app&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (settings_valid)
{
    NRF_LOG_DEBUG(&amp;quot;Using settings page.&amp;quot;);
    memcpy(&amp;amp;s_dfu_settings, m_dfu_settings_buffer, sizeof(nrf_dfu_settings_t));
    if (settings_backup_valid)
    {
        NRF_LOG_DEBUG(&amp;quot;Would have copied forbidden parts from backup page. Skipping.&amp;quot;);
        //NRF_LOG_DEBUG(&amp;quot;Copying forbidden parts from backup page.&amp;quot;);
        //settings_forbidden_parts_copy_from_backup((uint8_t *)&amp;amp;s_dfu_settings);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2. Commented out the post_validate() function&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if NRF_BL_DFU_ALLOW_UPDATE_FROM_APP
// Postvalidate if DFU has signaled that update is ready.
if (s_dfu_settings.bank_current == NRF_DFU_CURRENT_BANK_1)
{
    NRF_LOG_INFO(&amp;quot;Current bank is set to Bank1&amp;quot;);
    //postvalidate();
}
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;3. Enabled&amp;nbsp;NRF_BL_DFU_ALLOW_UPDATE_FROM_APP&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;RESULTS&lt;/p&gt;
&lt;p&gt;--------------&lt;/p&gt;
&lt;p&gt;1. If I put a breakpoint right before the reset in the main app I can see that the s_dfu_settings structure has changed and I get the following RTT logs, so to me that looks like the writing is happening successfully...&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; nrf_dfu_settings: Writing settings...
 nrf_dfu_settings: Erasing old settings at: 0x000FF000
 nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 0
 nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x20024A14, len=896 bytes), queue usage: 1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2. If I use RTT logging on the bootloader however, I see the reset happen, but I get the following print out:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Inside main
&amp;lt;debug&amp;gt; app: In nrf_bootloader_init
&amp;lt;debug&amp;gt; nrf_dfu_settings: Calling nrf_dfu_settings_init()...
&amp;lt;debug&amp;gt; nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
&amp;lt;debug&amp;gt; nrf_dfu_settings: Using settings page.
&amp;lt;debug&amp;gt; nrf_dfu_settings: Would have copied forbidden parts from backup page. Skipping.
&amp;lt;debug&amp;gt; nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
&amp;lt;info&amp;gt; nrf_dfu_settings: Backing up settings page to address 0xFE000.
&amp;lt;debug&amp;gt; nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
&amp;lt;debug&amp;gt; app: Enter nrf_bootloader_fw_activate
&amp;lt;info&amp;gt; app: No firmware to activate.
&amp;lt;info&amp;gt; nrf_dfu_settings: Backing up settings page to address 0xFE000.
&amp;lt;debug&amp;gt; nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
&amp;lt;debug&amp;gt; app: Running nrf_bootloader_app_start with address: 0x00001000
&amp;lt;debug&amp;gt; app: Disabling interrupts. NVIC-&amp;gt;ICER[0]: 0x0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So even though it seems like a successful write is happening on the main application side, the settings&amp;nbsp;don&amp;#39;t seem to take and the bootloader doesn&amp;#39;t recognize the new FW image.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying BL Settings Page from Main App</title><link>https://devzone.nordicsemi.com/thread/247574?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 13:12:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bac4fd2c-5183-43ec-9c9a-88a59a67866a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The default bootloader settings implementation does not allow the app to change the fields shown inside the red squares&amp;nbsp;below. This is to help ensure that only the bootloader can do the final validation and activation of new FW images.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-6605fc12e94e4bbea64c5ca64b1293bf/settings_5F00_struct.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;But it doesn&amp;#39;t mean that has to be done this way. I&amp;nbsp;see that you are not storing any&amp;nbsp;&amp;quot;init_command&amp;quot; for the bootloader, so I guess you have already done the validation and just want the bootloader to activate the FW by moving the image from Bank 1 to Bank 0? If that&amp;#39;s the case I&amp;nbsp;think it may make sense to just the change nrf_dfu_settings.c implementation to allow these fields to be controlled by the application as well. Relevant functions to modify would be settings_forbidden_parts_equal_to_backup() and&amp;nbsp;settings_forbidden_parts_copy_from_backup().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>