<?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>NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52504/nrf9160-fota-not-switching-to-secondary-after-boot_request_upgrade-and-sys_reboot</link><description>Hi, 
 In our firmware we&amp;#39;re writing the entire contents of our UPDATE.BIN file successfully with flash_img_buffered_write&amp;#39;s, but after boot_request_upgrade and a sys_reboot, it is still loading the original firmware from FLASH_AREA_IMAGE_PRIMARY rather</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Oct 2019 09:03:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52504/nrf9160-fota-not-switching-to-secondary-after-boot_request_upgrade-and-sys_reboot" /><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/213577?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2019 09:03:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69440720-b395-4306-8ad1-ffc63d14f386</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Great to know GJSea. Thanks for the update :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/213534?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2019 06:02:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93c88efe-1efc-43bd-a3ac-6a9553f7f03a</guid><dc:creator>GJSea</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;I figured the problem out,&amp;nbsp;I was using NVS in&amp;nbsp;our firmware app without changing nvs_fs.offset to&amp;nbsp;PM_MCUBOOT_STORAGE_ADDRESS which was somehow corrupting the written secondary firmware. Now it it working nicely.&lt;/p&gt;
&lt;p&gt;Thanks for your help in aiding me narrowing it down.&lt;/p&gt;
&lt;p&gt;Thx!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/213338?ContentTypeID=1</link><pubDate>Fri, 04 Oct 2019 08:55:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f742d715-8028-4475-aa84-32bb59952e3d</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m a bit out of idea on what could be wrong. We may need to have your code to reproduce the issue here. The problem is that&amp;nbsp;we may not have the SPI external flash as you have in your setup.&lt;/p&gt;
&lt;p&gt;If you can modify the code to copy from internal flash to&amp;nbsp;slot 2 so we can&amp;nbsp;test on a standalone board it would be great.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One thing you can do also is to read the hex dump and check if the update.bin image matched with what copied to slot 2. I understand that you have the CRC check but it could be offset. If possible can you send us the hex dump right after the FOTA ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding the check inside&amp;nbsp;&lt;span&gt;boot_validate_slot() here is the explanation&amp;nbsp;from the team:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (boot_check_header_erased(slot) == 0 || (hdr-&amp;gt;ih_flags &amp;amp; IMAGE_F_NON_BOOTABLE)) {&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Check if the magic field in image header is erased or non-bootable flag is set – this will be satisfied if for instance header structure is erased (this is my suspicion). Looks like what is written to the image slot is not the same as in update.bin, or with a offset.&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/213285?ContentTypeID=1</link><pubDate>Fri, 04 Oct 2019 03:04:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a520af7d-b32e-4113-bbf7-11e9a27dd979</guid><dc:creator>GJSea</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Yes&amp;nbsp;&lt;span&gt;CONFIG_IMG_ERASE_PROGRESSIVELY&amp;nbsp;was defined properly, I also added&amp;nbsp;boot_erase_img_bank for good measure. However&amp;nbsp;after that MCU_BOOT won&amp;#39;t even load&amp;nbsp;from the PRIMARY slot:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;bootutil_img_validate() fails in comparing the hash at&amp;nbsp;&lt;/p&gt;
&lt;p&gt;if (memcmp(hash, buf, sizeof(hash))) {&lt;br /&gt; return -1;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;Segger properly downloads the firmware image to the device as clearly I&amp;#39;m debugging MCUBOOT, can you provide guidance on how to restore booting the PRIMARY slot, so we can continue further in diagnosis?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/213182?ContentTypeID=1</link><pubDate>Thu, 03 Oct 2019 12:04:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c61479a-97fc-4c4b-b7cd-5cc091ce5dd6</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again GJSea,&lt;/p&gt;
&lt;p&gt;When doing our investigation we came across this case :&amp;nbsp;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/19438"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/19438&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It looks quite similar to your issue. But, I don&amp;#39;t think t&amp;#39;s the same. The case was about booting via the image on QSPI when in your case it&amp;#39;s the internal slot .&lt;/p&gt;
&lt;p&gt;But it could be related, we need to have a look at how you erase slot 2 prior to the swap.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Have you defined&amp;nbsp;CONFIG_IMG_ERASE_PROGRESSIVELY = y (or SELECT it )&lt;/p&gt;
&lt;p&gt;It&amp;#39;s selected inside fota_download\Kconfig file in our http applicatoin update example .&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If&amp;nbsp;&lt;span&gt;CONFIG_IMG_ERASE_PROGRESSIVELY&amp;nbsp; is not selected, you would need to do a&amp;nbsp;boot_erase_img_bank() before&amp;nbsp;flash_img_init()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/212973?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2019 11:09:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8689745-4f1d-42fa-85f0-bfbc292ea6ce</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi GJSea,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry for late response. I have forwarded the case to our MCUBoot team and will get back to you asap.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/212698?ContentTypeID=1</link><pubDate>Tue, 01 Oct 2019 03:50:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bdd60f2-ca85-4f84-abf4-f4fa298d8f63</guid><dc:creator>GJSea</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;So I did all three things above to no avail (&lt;span&gt;CONFIG_IMG_BLOCK_BUF_SIZE, checking&amp;nbsp;flash_img.bytes_written, and the small delay).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I ended up debugging mcuboot\boot\bootutil\src\LOADER.C to diagnose this further:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;In boot_validate_slot(...) boot_check_header_erased is the function that is failing.&lt;/p&gt;
&lt;p&gt;flash_area_erased_val() returns 0xFF, as is comparing it to hdr-&amp;gt;ih_magic (IMAGE_MAGIC) which contains values other than 0xFF, so returning -1&amp;nbsp;hence boot_validated_swap_type eventually loads the PRIMARY image again.&lt;/p&gt;
&lt;p&gt;So why is the ih_magic number from the SECONDARY&amp;#39;s boot_read_image_header() not returning 0xFF?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/211858?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2019 13:34:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:701c7d65-552f-40de-8906-6ed4cec8593c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Also, could you try adding a small delay before triggering the reset ? (1 -2 seconds for example)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/211843?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2019 13:14:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da7235e5-cfda-4cfb-9270-8d5ae20680e5</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi GJSea,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It looks fine to me. Could you post the UART logging when you update and the device get reset?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I talked to the team and got some suggestion:&lt;/p&gt;
&lt;p&gt;- To use&amp;nbsp;CONFIG_IMG_BLOCK_BUF_SIZE instead of&amp;nbsp;DOWNLOAD_MAX_FRAGMENT_SIZE when calculating readAmount&lt;/p&gt;
&lt;p&gt;- Before triggering the reset, could you&amp;nbsp;check flash_img.bytes_written if it matches with the image size ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/211667?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2019 05:09:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11a03575-941e-47bb-9df9-52d990383f6d</guid><dc:creator>GJSea</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes the code was from fota_download, except we read the firmware bits from a file on SPI flash storage that we previously loaded over http (so we can cater for&amp;nbsp;interrupted OTA byte range streaming). This has all been CRC32 checked so the integrity of the firmware binary stored in SPI flash that we&amp;#39;re doing f_reads from is correct. I stripped the error checking out from the paste of the code below to help in legibility.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes we have the boot_write_img_confirmed at the beginning of our main.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int err = flash_img_init(&amp;amp;flash_img);

bytesRemaining = filesize;
while(bytesRemaining &amp;gt; 0)
{
	int readAmount = MIN(bytesRemaining, DOWNLOAD_MAX_FRAGMENT_SIZE);

    fileResult = f_read(fwFile, recv_buf, readAmount, &amp;amp;dr);       
    err = flash_img_buffered_write(&amp;amp;flash_img, (uint8_t *) recv_buf, readAmount, false);
    bytesRemaining -= readAmount;
}

// Write with 0 length to flush the write operation to flash. 
flash_img_buffered_write(&amp;amp;flash_img,(uint8_t *)recv_buf, 0, true);

boot_request_upgrade(BOOT_UPGRADE_TEST);

// Reboot system to apply the firmware.
sys_reboot(SYS_REBOOT_COLD);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thx!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 FOTA not switching to secondary after boot_request_upgrade() and sys_reboot()</title><link>https://devzone.nordicsemi.com/thread/211578?ContentTypeID=1</link><pubDate>Tue, 24 Sep 2019 14:15:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc8e3e7f-cc5c-40dd-9a9c-4d9743911ad7</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi GJSea,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you provide us some more of your code where you handle FOTA ? I assume you are writing your own code based on our libraries, could you list the libraries you are using ?&lt;/p&gt;
&lt;p&gt;Please make sure that you have&amp;nbsp;boot_write_img_confirmed() in your new firmware as showed in our example. Otherwise the next reset it will return back to the Primary image.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you write using&amp;nbsp;&lt;span&gt;flash_img_buffered_write() do you flush the flash ? that what we do at:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/b456fb40c4912e3d435b9ee029d8ef24b113f7d0/subsys/net/lib/fota_download/src/fota_download.c#L59"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/b456fb40c4912e3d435b9ee029d8ef24b113f7d0/subsys/net/lib/fota_download/src/fota_download.c#L59&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You need to do that before resetting.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I assume you have tested with our http application update and it worked fine ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>