From 27c83ca588ffd9ba8457b88bac2e5f8886db66e5 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 7 Oct 2024 08:40:16 +0100 Subject: [PATCH] [nrf noup] zephyr: Fix compressed image support fixup! [nrf noup] zephyr: Add support for compressed image updates Fixes some issues with compressed image update support Signed-off-by: Jamie McCrae --- boot/bootutil/src/image_validate.c | 6 ++++-- boot/zephyr/decompression.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c index 1ba0f7b23..600d25a1a 100644 --- a/boot/bootutil/src/image_validate.c +++ b/boot/bootutil/src/image_validate.c @@ -508,14 +508,16 @@ bootutil_img_validate(struct enc_key_data *enc_state, int image_index, found_flag = &found_decompressed_sha; break; case IMAGE_TLV_DECOMP_SIGNATURE: - expected_size = SIG_BUF_SIZE; found_flag = &found_decompressed_signature; break; default: continue; }; - if (len != expected_size) { + if (type == IMAGE_TLV_DECOMP_SIGNATURE && !EXPECTED_SIG_LEN(len)) { + rc = -1; + goto out; + } else if (type != IMAGE_TLV_DECOMP_SIGNATURE && len != expected_size) { rc = -1; goto out; } diff --git a/boot/zephyr/decompression.c b/boot/zephyr/decompression.c index 5d491adcf..b44caa8a2 100644 --- a/boot/zephyr/decompression.c +++ b/boot/zephyr/decompression.c @@ -1027,7 +1027,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl /* Check if we have unwritten data buffered up and, if so, write it out */ if (decomp_buf_size > 0) { - uint32_t write_padding_size = decomp_buf_size % write_alignment; + uint32_t write_padding_size = write_alignment - (decomp_buf_size % write_alignment); /* Check if additional write padding should be applied to meet the minimum write size */ if (write_padding_size) {