Skip to content

Commit 2277dfa

Browse files
dgarskedanielinux
authored andcommitted
Peer review fix
1 parent d509e91 commit 2277dfa

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ endif
204204
SIGN_ENV=IMAGE_HEADER_SIZE=$(IMAGE_HEADER_SIZE) \
205205
WOLFBOOT_PARTITION_SIZE=$(WOLFBOOT_PARTITION_SIZE) \
206206
WOLFBOOT_SECTOR_SIZE=$(WOLFBOOT_SECTOR_SIZE) \
207+
NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
207208
ML_DSA_LEVEL=$(ML_DSA_LEVEL) \
208209
IMAGE_SIGNATURE_SIZE=$(IMAGE_SIGNATURE_SIZE) \
209210
LMS_LEVELS=$(LMS_LEVELS) \

tools/keytools/sign.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)