@@ -1748,6 +1748,9 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
17481748 char * endptr ;
17491749 unsigned long tmp ;
17501750 uint32_t partition_sz , sector_sz = 0 ;
1751+ const char * env_nvm_wo = getenv ("NVM_FLASH_WRITEONCE" );
1752+ int nvm_writeonce = (env_nvm_wo && * env_nvm_wo &&
1753+ strcmp (env_nvm_wo , "1" ) == 0 );
17511754
17521755 errno = 0 ;
17531756 tmp = strtoul (env_psize , & endptr , 0 );
@@ -1775,15 +1778,23 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
17751778 uint32_t total_img_sz = CMD .header_sz + image_sz ;
17761779 /* Only subtract sector for trailer when sector < partition.
17771780 * When sector >= partition (e.g. update_ram targets), the
1778- * entire partition is available for the image. */
1779- uint32_t max_img_sz = (sector_sz < partition_sz ) ?
1780- (partition_sz - sector_sz ) : partition_sz ;
1781+ * entire partition is available for the image.
1782+ * NVM_FLASH_WRITEONCE reserves 2 sectors (active + redundant).
1783+ */
1784+ uint32_t trailer_sz = sector_sz ;
1785+ uint32_t max_img_sz ;
1786+ if (nvm_writeonce && sector_sz < partition_sz )
1787+ trailer_sz = 2 * sector_sz ;
1788+ max_img_sz = (sector_sz < partition_sz ) ?
1789+ (partition_sz - trailer_sz ) : partition_sz ;
17811790 if (total_img_sz > max_img_sz ) {
17821791 if (sector_sz < partition_sz ) {
17831792 printf ("Error: Image size %u (header %u + firmware %u) "
1784- "exceeds max %u (partition %u - sector %u)\n" ,
1793+ "exceeds max %u (partition %u - %d x sector %u)\n" ,
17851794 total_img_sz , CMD .header_sz , image_sz ,
1786- max_img_sz , partition_sz , sector_sz );
1795+ max_img_sz , partition_sz ,
1796+ nvm_writeonce ? 2 : 1 ,
1797+ sector_sz );
17871798 } else {
17881799 printf ("Error: Image size %u (header %u + firmware %u) "
17891800 "exceeds max %u (partition %u)\n" ,
0 commit comments