@@ -256,6 +256,15 @@ int bootutil_img_hash_decompress(struct boot_loader_state *state, struct image_h
256
256
goto finish_without_clean ;
257
257
}
258
258
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
+
259
268
/* We need a modified header which has the updated sizes, start with the original header */
260
269
memcpy (& modified_hdr , hdr , sizeof (modified_hdr ));
261
270
@@ -267,28 +276,12 @@ int bootutil_img_hash_decompress(struct boot_loader_state *state, struct image_h
267
276
if (rc ) {
268
277
BOOT_LOG_ERR ("Unable to determine decompressed size of compressed image" );
269
278
rc = BOOT_EBADIMAGE ;
270
- goto finish_without_clean ;
279
+ goto finish ;
271
280
}
272
281
273
282
modified_hdr .ih_flags &= ~COMPRESSIONFLAGS ;
274
283
modified_hdr .ih_img_size = decompressed_image_size ;
275
284
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
-
292
285
/* Calculate the protected TLV size, these will not include the decompressed
293
286
* sha/size/signature entries
294
287
*/
@@ -1108,7 +1101,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
1108
1101
if (rc ) {
1109
1102
BOOT_LOG_ERR ("Invalid/missing image decrypted compressed size value" );
1110
1103
rc = BOOT_EBADIMAGE ;
1111
- goto finish_without_clean ;
1104
+ goto finish ;
1112
1105
}
1113
1106
1114
1107
if (IS_ENCRYPTED (hdr )) {
@@ -1131,7 +1124,7 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
1131
1124
*/
1132
1125
BOOT_LOG_ERR ("Invalid image compression flags: no supported compression found" );
1133
1126
rc = BOOT_EBADIMAGE ;
1134
- goto finish_without_clean ;
1127
+ goto finish ;
1135
1128
}
1136
1129
1137
1130
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
1142
1135
/* Compression library missing or missing required function pointer */
1143
1136
BOOT_LOG_ERR ("Decompression library fatal error" );
1144
1137
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 ;
1146
1148
}
1147
1149
1148
1150
write_alignment = flash_area_align (fap_dst );
@@ -1156,28 +1158,12 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
1156
1158
if (rc ) {
1157
1159
BOOT_LOG_ERR ("Unable to determine decompressed size of compressed image" );
1158
1160
rc = BOOT_EBADIMAGE ;
1159
- goto finish_without_clean ;
1161
+ goto finish ;
1160
1162
}
1161
1163
1162
1164
modified_hdr .ih_flags &= ~COMPRESSIONFLAGS ;
1163
1165
modified_hdr .ih_img_size = decompressed_image_size ;
1164
1166
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
-
1181
1167
/* Calculate protected TLV size for target image once items are removed */
1182
1168
rc = boot_size_protected_tlvs (hdr , fap_src , & protected_tlv_size );
1183
1169
@@ -1471,11 +1457,6 @@ int boot_copy_region_decompress(struct boot_loader_state *state, const struct fl
1471
1457
}
1472
1458
1473
1459
finish :
1474
- /* Clean up decompression system */
1475
- (void )compression_lzma -> deinit (NULL );
1476
- (void )compression_arm_thumb -> deinit (NULL );
1477
-
1478
- finish_without_clean :
1479
1460
memset (decomp_buf , 0 , sizeof (decomp_buf ));
1480
1461
1481
1462
return rc ;
0 commit comments