<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — NVM_FLASH_WRITEONCE doesn't seem to work]]></title>
		<link>https://www.wolfssl.com/forums/topic1974-nvmflashwriteonce-doesnt-seem-to-work.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1974.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in NVM_FLASH_WRITEONCE doesn't seem to work.]]></description>
		<lastBuildDate>Mon, 13 Mar 2023 19:05:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: NVM_FLASH_WRITEONCE doesn't seem to work]]></title>
			<link>https://www.wolfssl.com/forums/post7001.html#p7001</link>
			<description><![CDATA[<p>Hi Gareth,</p><p>Glad to hear this. We have merged the PR. Thanks again for reporting this issue. I&#039;m now adding more unit tests to intercept similar failures.</p><p>Best Regards,</p><p>-- <br />Daniele</p>]]></description>
			<author><![CDATA[null@example.com (danielinux)]]></author>
			<pubDate>Mon, 13 Mar 2023 19:05:55 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7001.html#p7001</guid>
		</item>
		<item>
			<title><![CDATA[Re: NVM_FLASH_WRITEONCE doesn't seem to work]]></title>
			<link>https://www.wolfssl.com/forums/post7000.html#p7000</link>
			<description><![CDATA[<p>Hi Daniele,</p><p>That change does now seem to work, from the quick test I&#039;ve done.</p><br /><p>Thank you,</p><p>Gareth.</p>]]></description>
			<author><![CDATA[null@example.com (ghorth)]]></author>
			<pubDate>Mon, 13 Mar 2023 18:44:06 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7000.html#p7000</guid>
		</item>
		<item>
			<title><![CDATA[Re: NVM_FLASH_WRITEONCE doesn't seem to work]]></title>
			<link>https://www.wolfssl.com/forums/post6998.html#p6998</link>
			<description><![CDATA[<p>Hello Gareth,</p><p>We have recently modified the NVM_FLASH_WRITEONCE code to add redundancy in the last two sectors of each partition, to mitigate the risk of corrupted/incomplete update flags for MCUs requiring this option.<br />This was introduced in <a href="https://github.com/wolfSSL/wolfBoot/pull/276">https://github.com/wolfSSL/wolfBoot/pull/276</a></p><p>The problem you are reporting seems indeed a bug introduced in the above PR. The non-selected block address should be rather </p><div class="codebox"><pre><code>(uint32_t)(base - ((1 + (!sel)) * WOLFBOOT_SECTOR_SIZE)) &amp; (~(NVM_CACHE_SIZE - 1); </code></pre></div><p>&gt;</p><p>I have submitted a fix here:<br /><a href="https://github.com/wolfSSL/wolfBoot/pull/287">https://github.com/wolfSSL/wolfBoot/pull/287</a> and I&#039;m planning to integrate more tests to avoid such errors in the future.</p><p>Please let me know if this fixes the issue for you.</p><p>Thanks,</p><p>-- <br />Daniele, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (danielinux)]]></author>
			<pubDate>Mon, 13 Mar 2023 09:46:15 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6998.html#p6998</guid>
		</item>
		<item>
			<title><![CDATA[NVM_FLASH_WRITEONCE doesn't seem to work]]></title>
			<link>https://www.wolfssl.com/forums/post6994.html#p6994</link>
			<description><![CDATA[<p>Hi,<br />I&#039;m implementing wolfboot on an STM32F1xx chip and I need to have NVM_FLASH_WRITEONCE set on. I&#039;ve arranged the partitions as follows:<br />WOLFBOOT_PARTITION_BOOT_ADDRESS = 0x8003800<br />WOLFBOOT_PARTITION_UPDATE_ADDRESS = 0x8011800<br />WOLFBOOT_PARTITION_SIZE = 0xE000 (=56k)<br />FLASH_PAGE_SIZE = 0x400 (=1k)<br />WOLFBOOT_SECTOR_SIZE = 0x400 (=1k)</p><p>I&#039;ve written the appropriate HAL functions for write and erase, etc.</p><p>The problem I&#039;m having is that when I call wolfBoot_success(), it does not set the sector flags at the end of the boot partition as expected.</p><p>I can step it through and see it call wolfBoot_set_partition_state() in libwolfboot.c, then call set_partition_magic(). This works and I can see the flash is now programmed with &quot;BOOT&quot; at address 0x80117FC to 0x80117FF (ie. the end of the boot partition, as expected).</p><p>Then &quot;state = get_partition_state(part);&quot; is called, which erases the page that it just programmed. If I step through get_partition_state() I can see it ultimately calls nvm_select_fresh_sector() and it&#039;s in here that it erases the same flash page that it just programmed.</p><p>In nvm_select_fresh_sector(), this code:<br /></p><div class="codebox"><pre><code>    /* Erase the non-selected partition */
    addr_align = (uint32_t)(base - ((!sel) * WOLFBOOT_SECTOR_SIZE))
        &amp; (~(NVM_CACHE_SIZE - 1));
    if (*((uint32_t*)(addr_align + WOLFBOOT_SECTOR_SIZE - sizeof(uint32_t)))
            != FLASH_WORD_ERASED) {
        hal_flash_erase(addr_align, WOLFBOOT_SECTOR_SIZE);
    }</code></pre></div><p>Seems to want to erase the wrong page: <br />If &quot;sel == 0&quot;, then:<br />addr_align = 0x8011800 - (1 * 0x400) = 0x8011400. So this will erase 0x8011400 to 0x80117FF.<br />If &quot;sel == 1&quot;, then:<br />addr_align = 0x8011800 - (0 * 0x400) = 0x8011800. So this will erase 0x8011800 to 0x8011BFF.<br />This is outside the boot partition (ie. it&#039;s the start of &#039;update&#039; partition).</p><br /><p>How is this supposed to work? Have I got some configuration wrong somewhere?</p><br /><p>Thanks,<br />Gareth.</p>]]></description>
			<author><![CDATA[null@example.com (ghorth)]]></author>
			<pubDate>Sun, 12 Mar 2023 10:27:51 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6994.html#p6994</guid>
		</item>
	</channel>
</rss>
