<?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>MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75471/mcuboot-image-in-the-primary-slot-is-not-valid</link><description>Hi Nordic Team, 
 
 I have a custom application running based on nRF NCS 1.5.0 with MCUboot enabled. 
 I&amp;#39;m having an issue where MCUboot simply doesn&amp;#39;t jump to the application. This comes and goes when I add/remove code from my main application... but</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Jan 2022 14:33:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75471/mcuboot-image-in-the-primary-slot-is-not-valid" /><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/348967?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 14:33:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2107eb21-8a94-41af-a26a-bcf18d359fa5</guid><dc:creator>Simon</dc:creator><description>[quote user="farhangj"]&lt;p&gt;Unrelated, but &lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt; any idea why this setting is not included in the master list of KConfigs?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html&lt;/a&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I think this is because CONFIG_BOOT_VALIDATE_SLOT0 is defined in the MCUboot sample&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/4e4e979c1998e6dad7e47011e6e076b861921645/boot/zephyr/Kconfig#L178"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/4e4e979c1998e6dad7e47011e6e076b861921645/boot/zephyr/Kconfig#L178&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html&lt;/a&gt;, you will only find the Kconfigs defined in Zephyr, nrf and nrfxlib.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1642775588270v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/347839?ContentTypeID=1</link><pubDate>Fri, 14 Jan 2022 18:18:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b0944a6-b13f-476d-80bb-c38379e17d66</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;I also came across this setting yesterday - and suspected could be the fix for this issue.&lt;/p&gt;
&lt;p&gt;It lines up with what &lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt; and I found regarding breakpoint instructions in Thumb:&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;span&gt;It seems like 0xBE00 is the thumb instruction for a break point:&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;a href="https://interrupt.memfault.com/blog/cortex-m-breakpoints"&gt;https://interrupt.memfault.com/blog/cortex-m-breakpoints&lt;/a&gt;.&amp;nbsp;&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Unrelated, but &lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt; any idea why this setting is not included in the master list of KConfigs?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index-all.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are many other settings with MCUboot that I can&amp;#39;t find in there either such as CONFIG_&lt;span&gt;BOOT_SWAP_USING_MOVE&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;From what I understand that list should include all the kconfigs in the entire NCS - no?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/347728?ContentTypeID=1</link><pubDate>Fri, 14 Jan 2022 10:41:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02d17e4a-24de-407e-ae7b-085fc2d82c10</guid><dc:creator>paat</dc:creator><description>&lt;p&gt;I experienced same or similar issue with MCUBoot checking the primary slot hash code and failing when debugging from SES. The workaround or solution that worked for me was to disable the check in MCUBoot conf:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_BOOT_VALIDATE_SLOT0=n&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/313344?ContentTypeID=1</link><pubDate>Thu, 03 Jun 2021 10:12:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ab77762-de4c-4831-93fb-2f801a6f5be6</guid><dc:creator>Simon</dc:creator><description>[quote user="farhangj"]1- Is Ozone the preferred/recommended debugger IDE for nRF NCS or is SES?[/quote]
&lt;p&gt;Ozone is free to use with our development kits, so both SES and Ozone are valid options to debug with.&amp;nbsp;&lt;/p&gt;
[quote user="farhangj"]2- Do you know which of the above fixed the issue?[/quote]
&lt;p&gt;I tried to comment out&amp;nbsp;the options below, and then set 7-8 breakpoints in &lt;em&gt;bootloader/mcuboot/boot/zephyr/main.c&lt;/em&gt;, but I did not encounter any issues with the validation.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I will do some more testing with SES later on&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312936?ContentTypeID=1</link><pubDate>Tue, 01 Jun 2021 14:50:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21e8ce60-fecb-4a3b-846c-68b2394ce243</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt; Thanks for the info above.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You did understand my issue, but I guess 3 things you added are different hence one of these may have fixed the issue.&lt;/p&gt;
&lt;p&gt;-&amp;nbsp;Debug optimizations on - which probably expands the size&lt;/p&gt;
&lt;p&gt;- larger FLASH partition for MCUBoot&lt;/p&gt;
&lt;p&gt;- Ozone rather than SES 5.34a&lt;/p&gt;
&lt;p&gt;I will try above but 2 follow up questions:&lt;/p&gt;
&lt;p&gt;1- Is Ozone the preferred/recommended debugger IDE for nRF NCS or is SES?&lt;/p&gt;
&lt;p&gt;2- Do you know which of the above fixed the issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312886?ContentTypeID=1</link><pubDate>Tue, 01 Jun 2021 12:42:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bccda0c-041a-46e8-a2ca-f66766af64a2</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I was not able to reproduce this with Ozone. I did the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Copied /application (the one you sent me over PM) into ncs/nrf/samples&lt;/li&gt;
&lt;li&gt;Added the following Kconfigs to nrf/samples/application/mcuboot.conf (checked nrf/samples/application/build/mcuboot/zephyr/.config to make sure they were set)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000&lt;/pre&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Built and flashed application + mcuboot: west build -b nrf52840dk_nrf52840 &amp;amp;&amp;amp; west flash&lt;/li&gt;
&lt;li&gt;Opened Ozone and chose the file ncs/nrf/samples/application/build/mcuboot/zephyr/zephyr.elf:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/400x400/__key/communityserver-discussions-components-files/4/6116.ozone_5F00_select_5F00_elf_5F00_file.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set several breakpoints in main.c:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/600x400/__key/communityserver-discussions-components-files/4/7776.main_5F00_mcuboot_5F00_brk_5F00_points.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;And some breakpoitns in loader.c, to see if the primary image was successfully validated&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/600x300/__key/communityserver-discussions-components-files/4/5633.mcuboot_5F00_loader_5F00_brk_5F00_point.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Then I stepped through all the breakpoints, and hit the first breakpoint in loader.c but not the other two after, so it was successfully validated. I also saw that the primary image was booted successfully, since I was able to see the log:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.4.99-ncs2  ***
[00:00:00.000,366] &amp;lt;inf&amp;gt; adc: nrfx_saadc_init
[00:00:00.000,396] &amp;lt;inf&amp;gt; adc: nrfx_saadc_channels_config = 0
[00:00:00.000,427] &amp;lt;inf&amp;gt; adc: nrfx_saadc_advanced_mode_set=0
[00:00:00.000,427] &amp;lt;inf&amp;gt; adc: nrfx_saadc_buffer_set=0
[00:00:00.000,427] &amp;lt;inf&amp;gt; adc: nrfx_saadc_buffer_set 2=0
[00:00:00.000,457] &amp;lt;inf&amp;gt; adc: BUF_REQ= 0
[00:00:00.000,457] &amp;lt;inf&amp;gt; adc: ppi ass 0
[00:00:00.000,457] &amp;lt;inf&amp;gt; adc: ppi en 0
[00:00:00.000,488] &amp;lt;inf&amp;gt; adc: nrfx_timer_init 0
[00:00:00.000,488] &amp;lt;inf&amp;gt; adc: CC Ticks = 31250

[00:00:00.008,422] &amp;lt;inf&amp;gt; fs_nvs: 2 Sectors of 4096 bytes
[00:00:00.008,422] &amp;lt;inf&amp;gt; fs_nvs: alloc wra: 0, ff0
[00:00:00.008,422] &amp;lt;inf&amp;gt; fs_nvs: data wra: 0, 0
Starting Radar
i=1
   [00:00:01.000,579] &amp;lt;inf&amp;gt; adc: ADC Task 0

[00:00:01.108,764] &amp;lt;inf&amp;gt; main: Read speed unit = 0,MPH, data rate=1
i=2
   [00:00:02.000,671] &amp;lt;inf&amp;gt; adc: ADC Task 1

[00:00:02.109,039] &amp;lt;inf&amp;gt; main: Read speed unit = 0,MPH, data rate=1
i=3
   [00:00:03.000,762] &amp;lt;inf&amp;gt; adc: ADC Task 2

[00:00:03.109,313] &amp;lt;inf&amp;gt; main: Read speed unit = 0,MPH, data rate=1
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Can you confirm that I have understood your issue correctly?&lt;/p&gt;
&lt;p&gt;I noticed now that you were using SES, and the issue might be SES related. Are you able to reproduce your issue with Ozone? Is it sufficient to use Ozone or do you want me to test it with SES as well?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312347?ContentTypeID=1</link><pubDate>Fri, 28 May 2021 11:41:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8089fa6-b5f0-4f64-8142-24820a453af9</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;It seems like 0xBE00 is the thumb instruction for a break point:&amp;nbsp;&lt;span style="background-color:rgba(255, 255, 255, 1);"&gt;&lt;a href="https://interrupt.memfault.com/blog/cortex-m-breakpoints"&gt;https://interrupt.memfault.com/blog/cortex-m-breakpoints&lt;/a&gt;. However, I still don&amp;#39;t understand how the validation for the primary image gets affected by setting breakpoints in MCUboot. Is the before and after comparison done for mcuboot or the primary image?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:rgba(255, 255, 255, 1);"&gt; It would be nice to get a hold of the application and do some testing myself.&lt;/span&gt;&lt;span style="background-color:rgba(255, 255, 255, 1);"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:rgba(255, 255, 255, 1);"&gt;I have sent you a private message for information on how to share the application&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312244?ContentTypeID=1</link><pubDate>Fri, 28 May 2021 01:52:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e68fac93-797e-4c4a-80a6-b469565d29d1</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I think I have narrowed the issue of hash mismatch down to breakpoints set by SES v5.34a.&lt;/p&gt;
&lt;p&gt;I downloaded the flash image using nrfjprog --memrd after download to the nRF52840dk and then read back immediately after, and also after debug via SES and adding breakpoints.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A 2byte word of 0xBE00 gets spread over the flash memory everywhere I add a breakpoint. This causes the hash calculation to not match.&lt;/p&gt;
&lt;p&gt;I can provide a zip package with the entire project privately to you, so you can replicate.&lt;/p&gt;
&lt;p&gt;What is this 0xBE00 word and why is it being added to FLASH?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I notice for 1-2 breakpoints the bootloader jumps to app fine but adding more breakpoints (e.g. 4-5), this word appears in flash. I can also tell when it happens as SES opens a &amp;quot;programming&amp;quot; progress window which disappears very quickly when I add these extra breakpoints.&lt;/p&gt;
&lt;p&gt;I cleared up my mcuboot.conf. There is a separate confusing issue of adding KEY_FILE..&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_BOOT_SIGNATURE_KEY_FILE=&amp;quot;mcuboot_private_ed256.pem&amp;quot;


# Flash
CONFIG_FLASH=y
CONFIG_BOOT_ERASE_PROGRESSIVELY=y
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y
CONFIG_MAIN_STACK_SIZE=10240

# Logger
#3 lines below switched to y will enable RTT logging in MCUboot
CONFIG_LOG_BACKEND_RTT=y
CONFIG_RTT_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG=y
CONFIG_MCUBOOT_LOG_LEVEL_DBG=y


CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_DETECT_PORT=&amp;quot;GPIO_0&amp;quot;
CONFIG_BOOT_SERIAL_DETECT_PIN=12
CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=0

CONFIG_EXTRA_EXCEPTION_INFO=y
CONFIG_LOG_OVERRIDE_LEVEL=2&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I made a mistake adding the mcuboot.conf as an OVERLAY file via CMAKE AND providing a relative path. Apparently these 2 don&amp;#39;t mix. So I converted to using set(mcuboot_CONF_FILE....)&lt;/p&gt;
&lt;p&gt;I commented out the former method and added the latter as you see below. And I no longer get the &amp;quot;WARNING - using Default KEY&amp;quot; when I open the project via SES.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (EXISTS &amp;quot;${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf&amp;quot;)
  set(mcuboot_CONF_FILE &amp;quot;${CMAKE_CURRENT_LIST_DIR}/mcuboot.conf&amp;quot;)
endif()

#if (EXISTS &amp;quot;${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf&amp;quot;)
#    list(APPEND mcuboot_OVERLAY_CONFIG
#      &amp;quot;${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf&amp;quot;
#      )
#endif()&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m up and running again developing with 1-2 breakpoints max, being aware that adding more is going to affect the flash with 0xBE00 and stuck in bootloader PANIC.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But very curious what you will find with the breakpoint issue. Let me know how I can transfer files to you. The entire zip of project is 1.4GB, we have box.com and I can upload there and send you a link in a private message.&lt;/p&gt;
&lt;p&gt;This is the comparison of flash before and after adding breakpoints, you can see 0xBE00 add over the place where I added breakpoints.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1622166723151v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312167?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 14:56:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:401bd329-e331-42cc-bba9-d0e0d538fd1f</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Ah, okay. You&amp;#39;re not using the default key. I overlooked that in the mcuboot conf file you provided. The mcuboot and the application need to use the same private key, such that mcuboot generates the public key (used to validate the image) from the same private key used to sign the image.&lt;/p&gt;
&lt;p&gt;I think there has been &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/67510/ncs-recommended-mcuboot-enabled-apps-build-and-flash-methods/277980#277980"&gt;some issues earlier&lt;/a&gt;, and that you had to set it in both the application and the mcuboot, but I believe it should be fixed in NCS v1.5.0, and you only need to set it one place using any of the options in the answer below&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/69344/how-to-create-a-mcuboot-image-and-an-application-image-without-modifying-the-sdk/307039#307039"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/69344/how-to-create-a-mcuboot-image-and-an-application-image-without-modifying-the-sdk/307039#307039&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will get back to you tomorrow and give more clarity.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312163?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 14:48:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:721cc267-d4d7-4a7b-8323-c2639e2f5f60</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you clarify please, whether or not I need to set the CONFIG_BOOT_SIGNAUTRE_KEY_FILE both in mcuboot.conf and also the application prj.conf?&lt;/p&gt;
&lt;p&gt;I think I&amp;#39;m close to a resolution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/312051?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 11:29:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5946f910-9dd0-46ca-8884-2d2163e1569c</guid><dc:creator>Simon</dc:creator><description>[quote user="farhangj"]Is there another blog post/question I need to be looking at for MCUboot resetting over and over?[/quote]
&lt;p&gt;Check out the tutorial&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/software/posts/device-firmware-update-dfu-with-mcuboot-bootloader"&gt;Device Firmware Update (DFU) with MCUBoot bootloader&lt;/a&gt;. I&amp;#39;m not sure if it will help you solve the problem though.&lt;/p&gt;
[quote user="farhangj"]Am I violating any rules by putting breakpoints in MCUboot? Adding a breakpoint doesn&amp;#39;t add contents to protected areas in FLASH does it?[/quote][quote user="farhangj"]It goes all the way to do_boot() but doesn&amp;#39;t hit the breakpoint in the main() in app.[/quote]
&lt;p&gt;&amp;nbsp;Putting breakpoints in MCUboot should not break any rules. Could you try to set CONFIG_DEBUG_OPTIMIZATIONS=y, then it should be able hit the breakpoints.&lt;/p&gt;
[quote user="farhangj"]What is the appropriate stack size for MCUboot Main?[/quote]
&lt;p&gt;&amp;nbsp;I think the default main stack size of 10240 should be good. However you can analyze the stack usage using the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/zephyr/guides/flash_debug/thread-analyzer.html"&gt;Thread Analyzer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, since I&amp;#39;m not entirely sure what&amp;#39;s causing the misbehaviour, I think the quickest way of resolving this is if you could provide me with some concrete and detailed steps how to reproduce this, and upload your application if possible (I can make the case private).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/311875?ContentTypeID=1</link><pubDate>Wed, 26 May 2021 15:06:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cba2aa3-6f84-4e6f-887b-1408e346f6d9</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;The current status of my MCUboot.conf file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_SIZE_OPTIMIZATIONS=y

# Disable memory guard to avoid false faults in application after boot
CONFIG_HW_STACK_PROTECTION=n

CONFIG_SYSTEM_CLOCK_DISABLE=y
CONFIG_SYSTEM_CLOCK_NO_WAIT=y
CONFIG_PM=n

CONFIG_MAIN_STACK_SIZE=4096
CONFIG_MBEDTLS_CFG_FILE=&amp;quot;mcuboot-mbedtls-cfg.h&amp;quot;
CONFIG_DEBUG=y

CONFIG_BOOT_MAX_IMG_SECTORS=256
CONFIG_BOOT_BOOTSTRAP=n

CONFIG_BOOT_ENCRYPT_RSA=n
CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=n
CONFIG_BOOT_SIGNATURE_KEY_FILE=&amp;quot;..\\..\\..\\application\\mcuboot_private.pem&amp;quot;
#CONFIG_DISABLE_FLASH_PATCH=y //should be used in production for max security. read more about flash patching

# Flash
CONFIG_FLASH=y
CONFIG_BOOT_ERASE_PROGRESSIVELY=y
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y

# Logger
#3 lines below switched to y will enable RTT logging in MCUboot
CONFIG_LOG_BACKEND_RTT=n
CONFIG_RTT_CONSOLE=n
CONFIG_LOG=n
CONFIG_LOG_MINIMAL=n
CONFIG_MCUBOOT_LOG_LEVEL_DBG=n
CONFIG_LOG_BACKEND_UART=n
CONFIG_UART_CONSOLE=n

#CONFIG_LOG_DEFAULT_LEVEL=4
#CONFIG_LOG_OVERRIDE_LEVEL=4
#CONFIG_LOG_MAX_LEVEL=4 
#CONFIG_LOG_IMMEDIATE=n
#CONFIG_LOG_PROCESS_THREAD=y

#CONFIG_LOG_DEFAULT_LEVEL=2
#CONFIG_LOG_MAX_LEVEL=3
#CONFIG_LOG_PRINTK=y
#CONFIG_LOG_BACKEND_SHOW_COLOR=n
#CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=n

CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_DETECT_PORT=&amp;quot;GPIO_0&amp;quot;
CONFIG_BOOT_SERIAL_DETECT_PIN=12
CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=0

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/311871?ContentTypeID=1</link><pubDate>Wed, 26 May 2021 14:55:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e21ce067-7f8a-4df9-a26d-bba46323dc98</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;&amp;nbsp;OK So I went and did debugging, originally the hashes were not matching as you guessed. But then adding more debug statements in MCUBoot and/or reducing the CONFIG_MAIN_STACK from 10KB to 4KB led to hashes matching but a new problem arose. It goes all the way to do_boot() but doesn&amp;#39;t hit the breakpoint in the main() in app.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It keep resetting over and over.&lt;/p&gt;
&lt;p&gt;What is the appropriate stack size for MCUboot Main?&lt;/p&gt;
&lt;p&gt;Is there another blog post/question I need to be looking at for MCUboot resetting over and over?&lt;/p&gt;
&lt;p&gt;Am I violating any rules by putting breakpoints in MCUboot? Adding a breakpoint doesn&amp;#39;t add contents to protected areas in FLASH does it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/311581?ContentTypeID=1</link><pubDate>Tue, 25 May 2021 16:41:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a455c69-19d8-406f-a92f-dc3acc901eec</guid><dc:creator>Simon</dc:creator><description>[quote userid="15670" url="~/f/nordic-q-a/75471/mcuboot-image-in-the-primary-slot-is-not-valid/311576#311576"]&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen" class="internal-link view-user-profile"&gt;Simon&lt;/a&gt; I forgot to mention, I do a clean/ full rebuild, so I assume all hashes are recalculated properly, no?&lt;/p&gt;
&lt;p&gt;I will do more debugging as you suggested and report back.&lt;/p&gt;[/quote]
&lt;p&gt;Okay, sounds good. I&amp;#39;ll be waiting for your report&lt;/p&gt;
[quote userid="15670" url="~/f/nordic-q-a/75471/mcuboot-image-in-the-primary-slot-is-not-valid/311576#311576"]&lt;p&gt;RE: overlap=replace, I didn&amp;#39;t change the build to this option, it was already set to that. Is that standard or not?&lt;/p&gt;
&lt;p&gt;I guess I can look at an sample/example and see how merge is done for a standard project.&lt;/p&gt;[/quote]
&lt;p&gt;Yes, it&amp;#39;s standard. It will make it such that the app_signed.hex file is used instead of the zephyr.hex file. Check my answer &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/69147/what-is-the-right-hex-file-to-use-to-program-the-device-via-mcuboot-dfu/283542#283542"&gt;here&lt;/a&gt;&amp;nbsp;for a more detailed explanation:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&amp;quot;merged.hex will contain the files &amp;lt;your sample&amp;gt;\&amp;lt;build folder&amp;gt;\&lt;strong&gt;mcuboot&lt;/strong&gt;\zephyr\zephyr.hex as well as &lt;strong&gt;&amp;lt;your sample&amp;gt;&lt;/strong&gt;\&amp;lt;build folder&amp;gt;\zephyr\app_signed.hex. If you&amp;#39;re building a nonsecure application (nrf9160dk_nrf9160ns) the merged hex file will include &amp;lt;your sample&amp;gt;\&amp;lt;build folder&amp;gt;\&lt;strong&gt;spm&lt;/strong&gt;\zephyr\zephyr.hex also. When you program the merged.hex file, it will program all the mentioned hex files at once.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/311576?ContentTypeID=1</link><pubDate>Tue, 25 May 2021 16:18:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb0e7819-df33-4b12-81f5-6c29bd711395</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt; I forgot to mention, I do a clean/ full rebuild, so I assume all hashes are recalculated properly, no?&lt;/p&gt;
&lt;p&gt;I will do more debugging as you suggested and report back.&lt;/p&gt;
&lt;p&gt;RE: overlap=replace, I didn&amp;#39;t change the build to this option, it was already set to that. Is that standard or not?&lt;/p&gt;
&lt;p&gt;I guess I can look at an sample/example and see how merge is done for a standard project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUBoot: Image in the primary slot is not valid!</title><link>https://devzone.nordicsemi.com/thread/311575?ContentTypeID=1</link><pubDate>Tue, 25 May 2021 16:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b10bc13-a8cd-4e7a-b34a-4206f17bdd98</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Would you be able to do some debugging/add some printk&amp;#39;s, and figure exactly where it&amp;#39;s failing? If it&amp;#39;s &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/loader.c#L679"&gt;boot_image_check()&lt;/a&gt;&lt;span&gt;&amp;nbsp;or &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/loader.c#L680"&gt;boot_is_header_valid()&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My guess is that it fails here: &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/loader.c#L432"&gt;boot_image_check()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/image_validate.c#L333"&gt;bootutil_image_validate()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/image_validate.c#L402"&gt;FIH_CALL(boot_fih_memequal, fih_rc, hash, buf, sizeof(hash))&lt;/a&gt;&amp;nbsp;(compare &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/image_validate.c#L361"&gt;calculated hash&lt;/a&gt; to &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/d816ab0e281a8a60ded2db1dcad9012758b6c724/boot/bootutil/src/image_validate.c#L397"&gt;hash stored in TLV&lt;/a&gt;). As mentioned in &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/design.html#integrity-check"&gt;MCUboot--&amp;gt;Integrity Check&lt;/a&gt;: &amp;quot;&lt;/span&gt;Calculated SHA256 must match SHA256 TLV contents&amp;quot;.&lt;/p&gt;
&lt;p&gt;Since the calculated hash of the application will not correspond to the stored hash, since you&amp;#39;re changing it: &lt;em&gt;&amp;quot;This comes and goes when I add/remove code from my main application&amp;quot;.&lt;/em&gt;&lt;/p&gt;
[quote user=""]&lt;p&gt;One clue is.... I started a bit of investigation into &amp;quot;merged.hex&amp;quot; and how it is created. I was surprised to see mergehex.py combines 4 different images with argument &amp;quot;--overlap=replace&amp;quot;&lt;/p&gt;
&lt;p&gt;C:\Python38\python.exe C:/depot/ncs/zephyr/scripts/mergehex.py -o C:/depot/application/build_nrf52840dk_nrf52840/zephyr/merged.hex &lt;strong&gt;--overlap=replace&lt;/strong&gt; C:/depot/application/build_nrf52840dk_nrf52840/mcuboot/zephyr/zephyr.hex C:/depot/application/build_nrf52840dk_nrf52840/zephyr/mcuboot_primary.hex C:/depot/application/build_nrf52840dk_nrf52840/zephyr/zephyr.hex C:/depot/application/build_nrf52840dk_nrf52840/zephyr/app_signed.hex&lt;/p&gt;
&lt;p&gt;When I looked at those 4 images there is a LOT of overlap. Shouldn&amp;#39;t the final image just consist of mcuboot image and app_signed?&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;The overlap parameter will decide what happens when an overlap between two images happens, and &lt;a href="https://python-intelhex.readthedocs.io/en/latest/part2-6.html"&gt;it can be set to three different options&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1280x200/__key/communityserver-discussions-components-files/4/2045.pastedimage1621958374755v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;If I understand it correctly, since overlap is set to &amp;quot;replace&amp;quot;, the&amp;nbsp;hex file&amp;nbsp;app_signed.hex will be used, since it&amp;#39;s mentioned last.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>