Skip to content

Commit 4123b4d

Browse files
committed
scripts: imgtool: compression ARM thumb filter
Adds ARM thumb fileter to imgtool's LZMA2 compression. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 63fa7e4 commit 4123b4d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

scripts/imgtool/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def create(self, key, public_key_format, enckey, dependencies=None,
533533

534534
compression_flags = 0x0
535535
if compression_tlvs is not None:
536-
if compression_type == "lzma2":
536+
if compression_type in ["lzma2", "lzma2armthumb"]:
537537
compression_flags = IMAGE_F['COMPRESSED_LZMA2']
538538
# This adds the header to the payload as well
539539
if encrypt_keylen == 256:

scripts/imgtool/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def convert(self, value, param, ctx):
363363
help='When encrypting the image using AES, select a 128 bit or '
364364
'256 bit key len.')
365365
@click.option('--compression', default='disabled',
366-
type=click.Choice(['disabled', 'lzma2']),
366+
type=click.Choice(['disabled', 'lzma2', 'lzma2armthumb']),
367367
help='Enable image compression using specified type. '
368368
'Will fall back without image compression automatically '
369369
'if the compression increases the image size.')
@@ -513,7 +513,7 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
513513
custom_tlvs, compression_tlvs, int(encrypt_keylen), clear,
514514
baked_signature, pub_key, vector_to_sign, user_sha)
515515

516-
if compression == "lzma2":
516+
if compression in ["lzma2", "lzma2armthumb"]:
517517
compressed_img = image.Image(version=decode_version(version),
518518
header_size=header_size, pad_header=pad_header,
519519
pad=pad, confirm=confirm, align=int(align),
@@ -527,6 +527,8 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
527527
"dict_size": comp_default_dictsize, "lp": comp_default_lp,
528528
"lc": comp_default_lc}
529529
]
530+
if compression == "lzma2armthumb":
531+
compression_filters.insert(0, {"id":lzma.FILTER_ARMTHUMB})
530532
compressed_data = lzma.compress(img.get_infile_data(),filters=compression_filters,
531533
format=lzma.FORMAT_RAW)
532534
uncompressed_size = len(img.get_infile_data())

0 commit comments

Comments
 (0)