imgtool save to format of given output filename
Updates imgtool to infer, based on output image filename, which format
should be use for output file. Filenames that end with extension `.hex`
are saved in Intel HEX, otherwise saves a binary image.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/scripts/imgtool/main.py b/scripts/imgtool/main.py
index 1917a97..a03a164 100755
--- a/scripts/imgtool/main.py
+++ b/scripts/imgtool/main.py
@@ -142,15 +142,16 @@
@click.option('--align', type=click.Choice(['1', '2', '4', '8']),
required=True)
@click.option('-k', '--key', metavar='filename')
-@click.command(help='Create a signed or unsigned image')
+@click.command(help='''Create a signed or unsigned image\n
+ INFILE and OUTFILE are parsed as Intel HEX if the params have
+ .hex extension, othewise binary format is used''')
def sign(key, align, version, header_size, pad_header, slot_size, pad,
max_sectors, overwrite_only, endian, encrypt, infile, outfile):
- img = image.Image.load(infile, version=decode_version(version),
- header_size=header_size, pad_header=pad_header,
- pad=pad, align=int(align), slot_size=slot_size,
- max_sectors=max_sectors,
- overwrite_only=overwrite_only,
- endian=endian)
+ img = image.Image(version=decode_version(version), header_size=header_size,
+ pad_header=pad_header, pad=pad, align=int(align),
+ slot_size=slot_size, max_sectors=max_sectors,
+ overwrite_only=overwrite_only, endian=endian)
+ img.load(infile)
key = load_key(key) if key else None
enckey = load_key(encrypt) if encrypt else None
if enckey:
@@ -159,10 +160,6 @@
if key and not isinstance(key, (keys.RSA2048, keys.RSA2048Public)):
raise Exception("Encryption with sign only available with RSA")
img.create(key, enckey)
-
- if pad:
- img.pad_to(slot_size)
-
img.save(outfile)