Skip to content

Commit 735c887

Browse files
nordicjmrlubos
authored andcommitted
[nrf noup] zephyr: Fix issues with ARM thumb decompression
fixup! [nrf noup] zephyr: Add support for ARM thumb filter Fixes two issues with decompression, one with variables not being declared at the correct level and the other with the test decompression not checking the final decompressed image size Signed-off-by: Jamie McCrae <[email protected]> (cherry picked from commit 4fc8d2d)
1 parent 7e7c066 commit 735c887

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

boot/zephyr/decompression.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ int bootutil_img_hash_decompress(struct enc_key_data *enc_state, int image_index
121121
uint32_t write_pos = 0;
122122
uint32_t protected_tlv_size = 0;
123123
uint32_t decompressed_image_size;
124+
uint32_t output_size_total = 0;
124125
struct nrf_compress_implementation *compression_lzma = NULL;
125126
struct nrf_compress_implementation *compression_arm_thumb = NULL;
126127
TARGET_STATIC struct image_header modified_hdr;
@@ -300,7 +301,6 @@ int bootutil_img_hash_decompress(struct enc_key_data *enc_state, int image_index
300301
uint8_t *output_arm_thumb = NULL;
301302
uint32_t processed_size = 0;
302303
uint32_t output_size_arm_thumb = 0;
303-
uint32_t output_size_arm_thumb_total = 0;
304304

305305
while (processed_size < output_size) {
306306
uint32_t current_size = output_size - processed_size;
@@ -328,18 +328,12 @@ int bootutil_img_hash_decompress(struct enc_key_data *enc_state, int image_index
328328
}
329329

330330
bootutil_sha_update(&sha_ctx, output_arm_thumb, output_size_arm_thumb);
331-
output_size_arm_thumb_total += output_size_arm_thumb;
331+
output_size_total += output_size_arm_thumb;
332332
processed_size += current_size;
333333
}
334-
335-
if (output_size != output_size_arm_thumb_total) {
336-
BOOT_LOG_ERR("Decompression expected output_size mismatch: %d vs %d",
337-
output_size, output_size_arm_thumb);
338-
rc = BOOT_EBADSTATUS;
339-
goto finish;
340-
}
341334
} else {
342335
bootutil_sha_update(&sha_ctx, output, output_size);
336+
output_size_total += output_size;
343337
}
344338
}
345339

@@ -349,6 +343,13 @@ int bootutil_img_hash_decompress(struct enc_key_data *enc_state, int image_index
349343
read_pos += copy_size;
350344
}
351345

346+
if (modified_hdr.ih_img_size != output_size_total) {
347+
BOOT_LOG_ERR("Decompression expected output_size mismatch: %d vs %d",
348+
modified_hdr.ih_img_size, output_size_total);
349+
rc = BOOT_EBADSTATUS;
350+
goto finish;
351+
}
352+
352353
/* If there are any protected TLVs present, add them after the main decompressed image */
353354
if (modified_hdr.ih_protect_tlv_size > 0) {
354355
rc = boot_sha_protected_tlvs(hdr, fap, modified_hdr.ih_protect_tlv_size, tmp_buf,
@@ -869,6 +870,11 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
869870
TARGET_STATIC uint8_t decomp_buf[DECOMP_BUF_ALLOC_SIZE] __attribute__((aligned(4)));
870871
TARGET_STATIC struct image_header modified_hdr;
871872

873+
#if defined(CONFIG_NRF_COMPRESS_ARM_THUMB)
874+
uint8_t excess_data_buffer[DECOMP_BUF_EXTRA_SIZE];
875+
bool excess_data_buffer_full = false;
876+
#endif
877+
872878
hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
873879

874880
/* Setup decompression system */
@@ -953,10 +959,6 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
953959
while (pos < hdr->ih_img_size) {
954960
uint32_t copy_size = hdr->ih_img_size - pos;
955961
uint32_t tmp_off = 0;
956-
#if defined(CONFIG_NRF_COMPRESS_ARM_THUMB)
957-
uint8_t excess_data_buffer[DECOMP_BUF_EXTRA_SIZE];
958-
bool excess_data_buffer_full = false;
959-
#endif
960962

961963
if (copy_size > buf_size) {
962964
copy_size = buf_size;
@@ -1194,7 +1196,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
11941196
uint32_t write_padding_size = write_alignment - (decomp_buf_size % write_alignment);
11951197

11961198
/* Check if additional write padding should be applied to meet the minimum write size */
1197-
if (write_padding_size) {
1199+
if (write_alignment > 1 && write_padding_size) {
11981200
uint8_t flash_erased_value;
11991201

12001202
flash_erased_value = flash_area_erased_val(fap_dst);

0 commit comments

Comments
 (0)