<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Wireless MCUのトピックImage Selection on JN5169</title>
    <link>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930752#M7136</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am coding a firmware update utility for the JN5169 and have a question about invalidating a resident code image in flash.&lt;/P&gt;&lt;P&gt;My initial code image is running fine, based at Segment 0 (Flash Address 0x00080000).&amp;nbsp; I am also able to make a copy of it and base the copy at the beginning of Segment 8 (Flash Address 0x000C0000) - I can see it there in memory via the IDE. So far so good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, I want to invalidate the first image at Flash Address 0x00080000 so that upon restart, the JN5169's bootloader will find the first valid BIR at 0x000C0000 and then remap and use the new image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Page 7 of JN-AN-1003 says: "One method to achieve this is to program the Status field byte (of the BIR) to 0x00, which will mark the image as invalid".&amp;nbsp; But since the BIR (the first entry in the Flash Header) is in FLASH, you can't just write to a single byte.&amp;nbsp; You have to first erase the entire sector, then write in blocks of 16-Byte "pagewords".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JN-UG-3087 Page-127 suggests reading the entire flash sector into RAM, then erasing the flash sector, then change the desired byte in RAM and then write the sector from RAM back into the flash sector.&amp;nbsp; But the JN5169 Flash Sector is 32k Bytes - there is not enough RAM available to actually do this!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried invalidating the initial image at Sector 0 by simply erasing all of&amp;nbsp; Sector 0, then looping in a while(1) waiting for the Watchdog to reset, with the hopes that after reset, the bootloader will then find the valid BIR based at flash sector 8 and remap and run ithe code image based there, but this does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone advise on how to invalidate the image based at Sector 0 and make the bootloader then find and run the new image which is based at Sector 8?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp; Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Oct 2019 00:21:22 GMT</pubDate>
    <dc:creator>mferrari1</dc:creator>
    <dc:date>2019-10-01T00:21:22Z</dc:date>
    <item>
      <title>Image Selection on JN5169</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930752#M7136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am coding a firmware update utility for the JN5169 and have a question about invalidating a resident code image in flash.&lt;/P&gt;&lt;P&gt;My initial code image is running fine, based at Segment 0 (Flash Address 0x00080000).&amp;nbsp; I am also able to make a copy of it and base the copy at the beginning of Segment 8 (Flash Address 0x000C0000) - I can see it there in memory via the IDE. So far so good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, I want to invalidate the first image at Flash Address 0x00080000 so that upon restart, the JN5169's bootloader will find the first valid BIR at 0x000C0000 and then remap and use the new image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Page 7 of JN-AN-1003 says: "One method to achieve this is to program the Status field byte (of the BIR) to 0x00, which will mark the image as invalid".&amp;nbsp; But since the BIR (the first entry in the Flash Header) is in FLASH, you can't just write to a single byte.&amp;nbsp; You have to first erase the entire sector, then write in blocks of 16-Byte "pagewords".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JN-UG-3087 Page-127 suggests reading the entire flash sector into RAM, then erasing the flash sector, then change the desired byte in RAM and then write the sector from RAM back into the flash sector.&amp;nbsp; But the JN5169 Flash Sector is 32k Bytes - there is not enough RAM available to actually do this!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried invalidating the initial image at Sector 0 by simply erasing all of&amp;nbsp; Sector 0, then looping in a while(1) waiting for the Watchdog to reset, with the hopes that after reset, the bootloader will then find the valid BIR based at flash sector 8 and remap and run ithe code image based there, but this does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone advise on how to invalidate the image based at Sector 0 and make the bootloader then find and run the new image which is based at Sector 8?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp; Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:21:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930752#M7136</guid>
      <dc:creator>mferrari1</dc:creator>
      <dc:date>2019-10-01T00:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Image Selection on JN5169</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930753#M7137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;The code normally runs based at Sector 0.&amp;nbsp; The goal is to load an alternate code image based at another Sector and be able to then invalidate the code based at Sector 0 and run the code based at the new Sector instead, and vice versa, thus creating a ping-pong method for loading and running an updated code image while maintaining the prior code image until the new code image is verified.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Assume the following definitions:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define FLASH_SECTOR_SIZE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x8000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define ALTERNATE_CODE_SECTOR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define SECTOR_ADDRESS_OF_ALTERNATE_CODE_SECTOR&amp;nbsp;&amp;nbsp; (ALTERNATE_CODE_SECTOR * FLASH_SECTOR_SIZE)&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define SECTOR_ADDRESS_OF_SECTOR_0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x00000000&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define FLASH_ADDRESS_OF_SECTOR_0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x00080000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define BOOT_IMAGE_RECORD_STATUS_BYTE_INDEX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;#define PAGEWORD_SIZE_IN_BYTES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;As an example, the following code will copy the code image currently based at Sector 0 and &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;duplicate it based at the Sector designated for the alternate (new) code image:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;uint8&amp;nbsp;&amp;nbsp; u8i, u8PagewordBytes[PAGEWORD_SIZE_IN_BYTES];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;for( u8i = 0; u8i &amp;lt; ALTERNATE_CODE_SECTOR; u8i++ ) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bAHI_FlashEraseSector( ALTERNATE_CODE_SECTOR + u8i );&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bAHI_FullFlashProgram( SECTOR_ADDRESS_OF_ALTERNATE_CODE_SECTOR + (u8i * FLASH_SECTOR_SIZE),&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FLASH_SECTOR_SIZE,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (uint8 *)(FLASH_ADDRESS_OF_SECTOR_0 + (u8i * FLASH_SECTOR_SIZE)) );&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // You may want to refresh your Watchdog timer in this loop...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Now that you have new code based at the new Sector, you can invalidate the existing code image based at Sector 0, and upon reset, the code image based at the new Sector will run instead of the code which was originally based at Sector 0.&amp;nbsp; Be aware that because of the remapping that will have occurred (as indicated by the REG_SYS_FLASH_REMAP &amp;amp; REG_SYS_FLASH_REMAP2 registers) the "new" code will still appear to be located at based at Sector 0, even though physically, it's actually based at the new Sector.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;The code below shows how to invalidate the current code image (regardless of whichever Sector it's physically based at):&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;bAHI_FullFlashRead( SECTOR_ADDRESS_OF_SECTOR_0, PAGEWORD_SIZE_IN_BYTES, u8PagewordBytes );&lt;/STRONG&gt;
&lt;STRONG style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;u8PagewordBytes[BOOT_IMAGE_RECORD_STATUS_BYTE_INDEX] = 0x00;&lt;/STRONG&gt;
&lt;SPAN style="font-size: 13px; font-family: courier new, courier, monospace; "&gt;&lt;STRONG&gt;bAHI_FullFlashProgram( SECTOR_ADDRESS_OF_SECTOR_0, PAGEWORD_SIZE_IN_BYTES, u8PagewordBytes );&lt;/STRONG&gt;

&lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Code &lt;/SPAN&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;always&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt; appears to be located and running as if it's located at Sector 0 (even if it's not), so&lt;/SPAN&gt;
&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;if Sectors have become remapped, then accessing "Sector 0" really accesses the remapped Sector.&lt;/SPAN&gt;
&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;So to invalidate the current image, always write to Sector 0, regardless...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;The documentation indicates that you need to erase the Flash prior to writing to it or an, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;exception may result, but Flash can only be erased one whole Sector at a time&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;(which doesn't work for us here).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Since our goal is only to zero out the Status byte in the BIR and since Flash writes &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;can only change bits from 1 to 0, this works without having to erase the Sector first.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Flash can only be written using 16-byte Pagewords however, thus the need to read, modify and&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;write a whole block of 16 bytes, instead of just the one Status byte we're actually interested in.&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;I hope this helps... What with the remapping and all, it can become a bit confusing...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace; font-size: 13px;"&gt;Matt&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2019 23:41:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930753#M7137</guid>
      <dc:creator>mferrari1</dc:creator>
      <dc:date>2019-10-01T23:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Image Selection on JN5169</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930754#M7138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am checking this and I will get back to you as soon as possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mario&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:02:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930754#M7138</guid>
      <dc:creator>mario_castaneda</dc:creator>
      <dc:date>2019-10-02T16:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Image Selection on JN5169</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930755#M7139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mario –&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see my updated posting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have already solved this problem and have posted an explanation for others in case anyone else needs to understand this also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:53:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/Image-Selection-on-JN5169/m-p/930755#M7139</guid>
      <dc:creator>mferrari1</dc:creator>
      <dc:date>2019-10-02T16:53:29Z</dc:date>
    </item>
  </channel>
</rss>

