Skip to content

Commit 904f089

Browse files
committed
Revert "[nrf noup] decompression: Align to changes in nrfcompress API"
This reverts commit 002515b. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 15897b7 commit 904f089

File tree

1 file changed

+23
-42
lines changed

1 file changed

+23
-42
lines changed

boot/zephyr/decompression.c

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ int bootutil_img_hash_decompress(struct boot_loader_state *state, struct image_h
256256
goto finish_without_clean;
257257
}
258258

259+
rc = compression_lzma->init(NULL);
260+
rc = compression_arm_thumb->init(NULL);
261+
262+
if (rc) {
263+
BOOT_LOG_ERR("Decompression library fatal error");
264+
rc = BOOT_EBADSTATUS;
265+
goto finish_without_clean;
266+
}
267+
259268
/* We need a modified header which has the updated sizes, start with the original header */
260269
memcpy(&modified_hdr, hdr, sizeof(modified_hdr));
261270

@@ -267,28 +276,12 @@ int bootutil_img_hash_decompress(struct boot_loader_state *state, struct image_h
267276
if (rc) {
268277
BOOT_LOG_ERR("Unable to determine decompressed size of compressed image");
269278
rc = BOOT_EBADIMAGE;
270-
goto finish_without_clean;
279+
goto finish;
271280
}
272281

273282
modified_hdr.ih_flags &= ~COMPRESSIONFLAGS;
274283
modified_hdr.ih_img_size = decompressed_image_size;
275284

276-
rc = compression_lzma->init(NULL, decompressed_image_size);
277-
278-
if (rc) {
279-
BOOT_LOG_ERR("Decompression library fatal error");
280-
rc = BOOT_EBADSTATUS;
281-
goto finish_without_clean;
282-
}
283-
284-
rc = compression_arm_thumb->init(NULL, decompressed_image_size);
285-
286-
if (rc) {
287-
BOOT_LOG_ERR("Decompression library fatal error");
288-
rc = BOOT_EBADSTATUS;
289-
goto finish;
290-
}
291-
292285
/* Calculate the protected TLV size, these will not include the decompressed
293286
* sha/size/signature entries
294287
*/
@@ -1108,7 +1101,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
11081101
if (rc) {
11091102
BOOT_LOG_ERR("Invalid/missing image decrypted compressed size value");
11101103
rc = BOOT_EBADIMAGE;
1111-
goto finish_without_clean;
1104+
goto finish;
11121105
}
11131106

11141107
if (IS_ENCRYPTED(hdr)) {
@@ -1131,7 +1124,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
11311124
*/
11321125
BOOT_LOG_ERR("Invalid image compression flags: no supported compression found");
11331126
rc = BOOT_EBADIMAGE;
1134-
goto finish_without_clean;
1127+
goto finish;
11351128
}
11361129

11371130
compression_lzma = nrf_compress_implementation_find(NRF_COMPRESS_TYPE_LZMA);
@@ -1142,7 +1135,16 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
11421135
/* Compression library missing or missing required function pointer */
11431136
BOOT_LOG_ERR("Decompression library fatal error");
11441137
rc = BOOT_EBADSTATUS;
1145-
goto finish_without_clean;
1138+
goto finish;
1139+
}
1140+
1141+
rc = compression_lzma->init(NULL);
1142+
rc = compression_arm_thumb->init(NULL);
1143+
1144+
if (rc) {
1145+
BOOT_LOG_ERR("Decompression library fatal error");
1146+
rc = BOOT_EBADSTATUS;
1147+
goto finish;
11461148
}
11471149

11481150
write_alignment = flash_area_align(fap_dst);
@@ -1156,28 +1158,12 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
11561158
if (rc) {
11571159
BOOT_LOG_ERR("Unable to determine decompressed size of compressed image");
11581160
rc = BOOT_EBADIMAGE;
1159-
goto finish_without_clean;
1161+
goto finish;
11601162
}
11611163

11621164
modified_hdr.ih_flags &= ~COMPRESSIONFLAGS;
11631165
modified_hdr.ih_img_size = decompressed_image_size;
11641166

1165-
rc = compression_lzma->init(NULL, decompressed_image_size);
1166-
1167-
if (rc) {
1168-
BOOT_LOG_ERR("Decompression library fatal error");
1169-
rc = BOOT_EBADSTATUS;
1170-
goto finish_without_clean;
1171-
}
1172-
1173-
rc = compression_arm_thumb->init(NULL, decompressed_image_size);
1174-
1175-
if (rc) {
1176-
BOOT_LOG_ERR("Decompression library fatal error");
1177-
rc = BOOT_EBADSTATUS;
1178-
goto finish;
1179-
}
1180-
11811167
/* Calculate protected TLV size for target image once items are removed */
11821168
rc = boot_size_protected_tlvs(hdr, fap_src, &protected_tlv_size);
11831169

@@ -1471,11 +1457,6 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
14711457
}
14721458

14731459
finish:
1474-
/* Clean up decompression system */
1475-
(void)compression_lzma->deinit(NULL);
1476-
(void)compression_arm_thumb->deinit(NULL);
1477-
1478-
finish_without_clean:
14791460
memset(decomp_buf, 0, sizeof(decomp_buf));
14801461

14811462
return rc;

0 commit comments

Comments
 (0)