<?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>Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89344/custom-bootloader-stuck-in-nrf_dfu_mbr_init_sd</link><description>Device: nRF52840 Softdevice: 140 SDK: 17.1.0 
 I&amp;#39;m trying to develop a custom bootloader that will determine which of two images (A or B) to jump to. The memory map that I&amp;#39;m aiming for is: 
 Flash Memory Map (256 pages of 4096 bytes = 1MByte): MBR 0x00000000</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Jun 2022 17:03:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89344/custom-bootloader-stuck-in-nrf_dfu_mbr_init_sd" /><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374967?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 17:03:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad951e54-14df-493c-8e63-e46259ce2114</guid><dc:creator>nordic_pdaj</dc:creator><description>&lt;p&gt;Thanks Vidar, I used the NVMC flash writing based on the &amp;#39;flashwrite&amp;#39; example and it is working fine now.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374831?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 07:14:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e738615-0370-423e-adf9-8f08c89a345b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You need to call &lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;/span&gt;nrf_dfu_mbr_init_sd(); followed by sd_softdevice_vector_table_base_set(&amp;lt;bootloader start address&amp;gt;); before you can make any Softdevice API calls. The SVC interrupt will not be forwarded to the Softdevice otherwise.&lt;/p&gt;
[quote user="nordic_pdaj"]Or would it be better to try and access the read/write/erase flash operations without using the softdevice (if that&amp;#39;s possible)?[/quote]
&lt;p&gt;Yes, there is slightly less overhead if you can access the NVMC directly. The &amp;quot;flashwrite&amp;quot; example in /examples/peripheral/flashwrite/ demonstrates how you can use the nrf_nvmc driver.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374796?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 16:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58aa50d1-06eb-4081-a66e-b532fa81ff3c</guid><dc:creator>nordic_pdaj</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I have come across another problem. I&amp;#39;m now trying to initialise the softdevice in the custom bootloader; this is because I need the bootloader to be able to read and write to the Image A/B config areas of flash, so I want to be able to use these functions in the bootloader:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sd_flash_write()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sd_flash_page_erase()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and process the&amp;nbsp;&lt;/span&gt;sys_evt_dispatch() callbacks. However when I try to initialise the softdevice in the bootloader, it hangs at the call to:&lt;/p&gt;
&lt;p&gt;nrf_sdh_enable_request()&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming that this is because the softdevice vector table base is pointing to the image not the bootloader. What is the correct way to deal with this? Should the bootloader adjust the softdevice vector table base back to itself at the start like this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;sd_softdevice_vector_table_base_set(bootloader_start_addr)

...

// Call flash read/write functions

sd_softdevice_vector_table_base_set(application_start_addr)

// Jump to application&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Or would it be better to try and access the read/write/erase flash operations without using the softdevice (if that&amp;#39;s possible)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374281?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2022 08:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6018c255-1a56-4b53-a60e-ced6e9129b56</guid><dc:creator>nordic_pdaj</dc:creator><description>&lt;p&gt;Thanks Vidar, that solved the problem.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374261?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2022 06:49:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a13488e2-6880-4ea9-8b6b-bd865bb39597</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You are right, the MBR addresses are not configurable but hardcoded within the MBR binary.&lt;/p&gt;
&lt;p&gt;I think the problem here is that Bootloader start address is not set correctly. It must be stored at either 0xFF8 or at 0x10001014 to indicate to the MBR that a bootloader is present (&lt;span&gt;&lt;a title="Master boot record and SoftDevice reset procedure" href="https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/mbr_bootloader/mbr_sd_reset_behavior.html?cp=4_7_4_0_11_2"&gt;Master boot record and SoftDevice reset procedure&lt;/a&gt;). &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To confirm this, please try to set the bootloader address with nrfjprog:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;$ nrfjprog --memwr 0x10001014 --val 0x27000 &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;$ nrfjprog --memwr 0x10001018 --val 0xFD000&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;$ nrfjprog --reset // Reset and start program execution&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom bootloader stuck in nrf_dfu_mbr_init_sd()</title><link>https://devzone.nordicsemi.com/thread/374231?ContentTypeID=1</link><pubDate>Sat, 25 Jun 2022 20:36:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:975bf5e5-26dc-4466-81b2-eaa47dc2097a</guid><dc:creator>nordic_pdaj</dc:creator><description>&lt;p&gt;I realised that I shouldn&amp;#39;t be modifying nrf_mbr.h. Now I am creating a settings hex file with:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;nrfutil&amp;nbsp;settings generate --family NRF52840 --application bootloader.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 settings.hex&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;and merging it into a hex file with bootloader, softdevice and settings with:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;mergehex&amp;nbsp;-m bootloader.hex settings.hex -o &lt;span&gt;bootloader_and&lt;/span&gt;_settings.hex&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;mergehex&amp;nbsp;-m &lt;span&gt;bootloader_and&lt;/span&gt;&lt;span&gt;_s&lt;/span&gt;&lt;span&gt;ettings&lt;/span&gt;&lt;span&gt;.hex&lt;/span&gt; s140_nrf52_7.2.0_softdevice.hex -o &lt;span&gt;bootloader_and&lt;/span&gt;_settings_and_softdevice.hex&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;That didn&amp;#39;t make a difference to the execution getting stuck in&amp;nbsp;&lt;span&gt;nrf_dfu_mbr_init_sd()&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>