Skip to content

Commit e2f01b8

Browse files
michalek-nonvlsianpu
authored andcommitted
[nrf noup] boot: zephyr: decompression: reflect pad value
move 0x00 or 0xFF from secondary slot during decompression Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
1 parent 36628f1 commit e2f01b8

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

boot/zephyr/decompression.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,25 +1210,26 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
12101210
}
12111211

12121212
#ifndef CONFIG_PARTITION_MANAGER_ENABLED
1213-
/* The image digest is calculated on a binary, that has the area between header and the image
1214-
* binary filled with zeros.
1215-
* The zeros are a result of building the image with the CONFIG_ROM_START_OFFSET option set to
1216-
* the ih_hdr_size.
1217-
* The configuration with partition manager leaves this area uninitialized and signs
1218-
* the image using the --pad-header option, which fills the gap with the erase value
1219-
* (usually 0xFF) instead of zeros.
1213+
/* Mirror the header padding present in the secondary slot so that the
1214+
* decompressed primary image matches the hash computed during signing.
1215+
* Images signed with --pad-header use the flash erase value (0xFF on
1216+
* Nordic RRAM), while ROM_START_OFFSET builds use zeros.
12201217
*/
1221-
1222-
/* Reuse decompression buffer to write zeros. */
1223-
memset(decomp_buf, 0x00, sizeof(decomp_buf));
12241218
hdr_write_pos = sizeof(modified_hdr);
12251219

12261220
while (hdr_write_pos < hdr->ih_hdr_size) {
12271221
uint32_t set_size = hdr->ih_hdr_size - hdr_write_pos;
12281222

1229-
/* Assuming that sizeof(modified_hdr) is always aligned to write block size. */
1230-
if (set_size > sizeof(modified_hdr)) {
1231-
set_size = sizeof(modified_hdr);
1223+
if (set_size > decomp_buf_max_size) {
1224+
set_size = decomp_buf_max_size;
1225+
}
1226+
1227+
rc = flash_area_read(fap_src, off_src + hdr_write_pos, decomp_buf, set_size);
1228+
if (rc != 0) {
1229+
BOOT_LOG_ERR("Flash read failed at offset: 0x%x, size: 0x%x, area: %d, rc: %d",
1230+
(off_src + hdr_write_pos), set_size, fap_src->fa_id, rc);
1231+
rc = BOOT_EFLASH;
1232+
goto finish;
12321233
}
12331234

12341235
rc = flash_area_write(fap_dst, off_dst + hdr_write_pos, decomp_buf, set_size);

0 commit comments

Comments
 (0)