<?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>Hook into MBR boot sequence to run custom code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34920/hook-into-mbr-boot-sequence-to-run-custom-code</link><description>I&amp;#39;m using S140 6.0.0 and associated MBR on an nRF52840 with a custom boot loader derived from the nRF5 SDK 15.0.0 examples. 
 I&amp;#39;d like to perform some custom actions as soon as possible after MCU reset such as setting some GPIO to a known value to control</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Aug 2018 01:22:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34920/hook-into-mbr-boot-sequence-to-run-custom-code" /><item><title>RE: Hook into MBR boot sequence to run custom code</title><link>https://devzone.nordicsemi.com/thread/144246?ContentTypeID=1</link><pubDate>Wed, 15 Aug 2018 01:22:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5c4cf70-2233-4719-ae4f-20ac6610f0af</guid><dc:creator>Austin</dc:creator><description>&lt;p&gt;Although binary patching the MBR is not necessarily a good option, I have tested this approach for a very simple case&amp;nbsp; which sets a GPIO pin before entry to the bootloader.&lt;/p&gt;
&lt;p&gt;The patch process uses the following steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Write a small bit of C code containing the required operations to perform as part of boot.&amp;nbsp; This should be very simply.&lt;/li&gt;
&lt;li&gt;Generate a set of assembler instructions by compiling the C code against the nRF5 SDK with GCC.&lt;/li&gt;
&lt;li&gt;Use the generated opcodes from the assembler as input to a patch process which will put the patch assembler instructions into upper MBR address memory.&lt;/li&gt;
&lt;li&gt;Patch the MBR reset vector to point to the patch instructions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When the MCU boots, the reset vector will now run the patch code.&amp;nbsp; In the attached example, the patch sets GPIO P0.15 to a high level on boot.&amp;nbsp; The last instruction in the patch jumps back to the original reset vector location to allow normal MBR functionality to run.&lt;/p&gt;
&lt;p&gt;Use this approach with caution as the MBR is the only component which is never updated as part of any firmware upgrade process when using the Nordic DFU modules.&lt;/p&gt;
&lt;p&gt;See the attached files for additional instructions and an example of how the patching process could work.&amp;nbsp; The patch code and tools will require manual modification to support each specific application.&amp;nbsp; e.g.&amp;nbsp; Changes will be needed for processors other than nRF52840, S140.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/patch_2D00_mbr_2D00_tools.tgz"&gt;devzone.nordicsemi.com/.../patch_2D00_mbr_2D00_tools.tgz&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hook into MBR boot sequence to run custom code</title><link>https://devzone.nordicsemi.com/thread/134149?ContentTypeID=1</link><pubDate>Thu, 31 May 2018 09:25:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08014ff1-4cd4-47b4-af2b-49606dc14f59</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Austin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, there will be a small window during the bootloader copy procedure where you will not have&amp;nbsp;be able to control the GPIO pin states, the size of the window will depend on the size of the bootloader as you&amp;#39;ve pointed out. My comments to you suggestions are:&lt;/p&gt;
&lt;p&gt;1. Yes, I agree that you should avoid binary patching.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. This would be the best option, but I am afraid that we do not distribute the MBR source code as this considered Nordic proprietary. However, I will forward your request for the MBR source to the Product Manager responsible for the SoftDevice.&amp;nbsp; It might be possible to share something under NDA, but I would not count on it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. As far as I know adding such a feature to the MBR is not a part of the SoftDevice roadmap and unless&amp;nbsp;more of our customers request such a feature this will most likely not be added in a future SoftDevice release.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>