Skip to content

Commit d69933c

Browse files
michalek-node-nordic
authored andcommitted
scripts: imgtool: compression ARM thumb filter
Adds ARM thumb filter to imgtool's LZMA2 compression. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent a5f28c1 commit d69933c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

scripts/imgtool/image.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'ROM_FIXED': 0x0000100,
7171
'COMPRESSED_LZMA1': 0x0000200,
7272
'COMPRESSED_LZMA2': 0x0000400,
73+
'COMPRESSED_ARM_THUMB': 0x0000800,
7374
}
7475

7576
TLV_VALUES = {
@@ -533,8 +534,10 @@ def create(self, key, public_key_format, enckey, dependencies=None,
533534

534535
compression_flags = 0x0
535536
if compression_tlvs is not None:
536-
if compression_type == "lzma2":
537+
if compression_type in ["lzma2", "lzma2armthumb"]:
537538
compression_flags = IMAGE_F['COMPRESSED_LZMA2']
539+
if compression_type == "lzma2armthumb":
540+
compression_flags |= IMAGE_F['COMPRESSED_ARM_THUMB']
538541
# This adds the header to the payload as well
539542
if encrypt_keylen == 256:
540543
self.add_header(enckey, protected_tlv_size, compression_flags, 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)