<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>Modify the MCUboot&amp;#39;s booting process</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/88643/modify-the-mcuboot-s-booting-process</link><description>Hi, 
 I want to use the MCUboot for the DFU and I have been able to configure it and flash it on the device so far (tested that it is correctly flashed). 
 But I need to make some modifications to the MCUboot&amp;#39;s booting process to match with the device</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Wed, 15 Jun 2022 11:21:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/88643/modify-the-mcuboot-s-booting-process" /><item><title>RE: Modify the MCUboot's booting process</title><link>https://test-devzone.nordicsemi.com/thread/372540?ContentTypeID=1</link><pubDate>Wed, 15 Jun 2022 11:21:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0e89a96-776e-4b72-ae6b-861a38404a5e</guid><dc:creator>user15146</dc:creator><description>[quote user="Erasmo"] Is there a way to stop the device from continuing when there is an error (the button is released) in the board_init() function?[/quote]
&lt;p&gt;You could e.g. call&amp;nbsp;&lt;span&gt;k_panic() when you detect an error.&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/3.0.0/reference/kernel/other/fatal.html#kernel-panic"&gt;https://docs.zephyrproject.org/3.0.0/reference/kernel/other/fatal.html#kernel-panic&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="Erasmo"]Or is there a way in which I can create a new main.c file that can be used by the MCUboot without modifying the one in the NCS?[/quote]
&lt;p&gt;I don&amp;#39;t think so. If you are sure can&amp;#39;t do this in your application when it boots, and don&amp;#39;t want to change the MCUBoot main.c in NCS, you could always create a PR to the MCUBoot with your changes.&amp;nbsp;&lt;a href="https://github.com/zephyrproject-rtos/mcuboot"&gt;https://github.com/zephyrproject-rtos/mcuboot&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modify the MCUboot's booting process</title><link>https://test-devzone.nordicsemi.com/thread/371748?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2022 00:41:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e59e6adc-6fb2-428e-a9f0-0b8d7356ad23</guid><dc:creator>user114965</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I created the board.c file in the board folder and was able to set the PIN on High before the bootloader started, although I needed to define the PIN on the bootloader&amp;#39;s overlay file to use it in the board.c file. &lt;br /&gt;I have a condition that verifies the device and in case that the condition is met I would like the device to stop every thing and don&amp;#39;t turn on, right now I set the PIN back to Low and the device turn off over time, the problem is that in that interval the MCUboot starts its executions. Is there a way to stop the device from continuing when there is an error (the button is released) in the board_init() function? I already tried using a return codes 1 and -1. &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;Also, I would like to modify the MCUboot to implement points 2 (battery and charger verification) and 3 (change upgrade strategy) from the original ticket I submitted. &lt;/span&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;Will I have to modify the MCUboot&amp;#39;s main.c file directly on the NCS? Or is there a way in which I can create a new main.c file that can be used by the MCUboot without modifying the one in the NCS?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modify the MCUboot's booting process</title><link>https://test-devzone.nordicsemi.com/thread/371736?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2022 19:13:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bce1e214-bd42-4f6c-ac27-f24e7679c688</guid><dc:creator>user15146</dc:creator><description>[quote user="Erasmo"]I would like to keep the modifications in the git repository and avoid modifying the NCS directly (if possible).[/quote]
&lt;p&gt;I found a different way. Create a file named&amp;nbsp;CMakeLists.txt with this content:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if(CONFIG_GPIO AND DEFINED CONFIG_MCUBOOT)
	zephyr_library()
	zephyr_library_sources(board.c)
endif()&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;place it in in your board folder, e.g. for the nRF52840DK board it would be: zephyr\boards\arm\nrf52840dk_nrf52840\&lt;/p&gt;
&lt;p&gt;Then in the board folder create a file board.c , with something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;init.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;

/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(led1)

#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0	DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN	DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS	DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn&amp;#39;t set up to blink an LED. */
#error &amp;quot;Unsupported board: led0 devicetree alias is not defined&amp;quot;
#define LED0	&amp;quot;&amp;quot;
#define PIN	0
#define FLAGS	0
#endif

static int board_init(const struct device *dev)
{
	int err;
	printk(&amp;quot;board_init\n&amp;quot;);
	printk(&amp;quot;PIN %d\n&amp;quot;,PIN);

	static const struct device *led;

	led = device_get_binding(DT_GPIO_LABEL(LED0_NODE, gpios));

	bool led_is_on = false;

	err = gpio_pin_configure(led, PIN, GPIO_OUTPUT_ACTIVE);
	printk(&amp;quot;gpio_pin_configure() returned: %d \n&amp;quot;,err);
	if (err &amp;lt; 0) {
		return 1;
	}

	err = gpio_pin_set(led, PIN, (int)led_is_on);
	printk(&amp;quot;gpio_pin_set() returned: %d \n&amp;quot;,err);
	return 0;
}

SYS_INIT(board_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This board_init() function will then be called before the bootloader starts.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We do something similar here, but this is before the main application &lt;span&gt;starts&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/boards/arm/thingy91_nrf9160/adp5360_init.c"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/boards/arm/thingy91_nrf9160/adp5360_init.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/boards/arm/thingy91_nrf9160/CMakeLists.txt"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/boards/arm/thingy91_nrf9160/CMakeLists.txt&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modify the MCUboot's booting process</title><link>https://test-devzone.nordicsemi.com/thread/371504?ContentTypeID=1</link><pubDate>Wed, 08 Jun 2022 19:59:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a02c202c-50a1-44b4-a881-43cff23dffc4</guid><dc:creator>user114965</dc:creator><description>&lt;p&gt;Hi, &lt;/p&gt;
[quote userid="15146" url="~/f/nordic-q-a/88643/modify-the-mcuboot-s-booting-process/371307#371307"]&lt;span&gt;the&amp;nbsp;&lt;/span&gt;&lt;a title="SYS_INIT" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/drivers/index.html#c.SYS_INIT"&gt;&lt;code&gt;&lt;span&gt;SYS_INIT&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;&lt;span&gt;&amp;nbsp;can be used. (e.g. placed at the&amp;nbsp;&lt;/span&gt;&lt;span&gt;bottom of main.c of MCUBoot, assuming it&amp;#39;s too late for your device to do it in your own application).&lt;/span&gt;[/quote]
&lt;p&gt;Does the &lt;strong&gt;main.c&lt;/strong&gt; file that you mention is the one located on the NCS&amp;#39; path &lt;strong&gt;bootloader/mcuboot/boot/zephyr&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;If that is the file, is there a way to create a copy (with my modifications) inside my application&amp;#39;s project and just change the file that is going to be used?&lt;/p&gt;
&lt;p&gt;I would like to keep the modifications in the git repository and avoid modifying the NCS directly (if possible).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modify the MCUboot's booting process</title><link>https://test-devzone.nordicsemi.com/thread/371307?ContentTypeID=1</link><pubDate>Wed, 08 Jun 2022 08:13:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:320d8798-9476-4733-ada0-6bb3e85ac55c</guid><dc:creator>user15146</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]I would like to know the best way to make this modifications and in the case of the third point if there is a configuration option or example.[/quote]
&lt;p&gt;&lt;span&gt;If you need to run a function at boot, then the&amp;nbsp;&lt;/span&gt;&lt;a title="SYS_INIT" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/drivers/index.html#c.SYS_INIT"&gt;&lt;code&gt;&lt;span&gt;SYS_INIT&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;&lt;span&gt;&amp;nbsp;can be used. (e.g. placed at the&amp;nbsp;&lt;/span&gt;&lt;span&gt;bottom of main.c of MCUBoot, assuming it&amp;#39;s too late for your device to do it in your own application).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]Change the upgrade strategy from swapping the images in the memory slots to just changing the address of the image that it will boot.[/quote]
&lt;p&gt;I&amp;#39;m not seeing any such configs. You can read about the upgrade strategies e.g. &lt;a href="https://interrupt.memfault.com/blog/mcuboot-overview#mcuboot-configuration-options"&gt;here&amp;nbsp;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>