Allow passing max sectors as parameter to imgtool

This adds a new command line flag to allow passing in the max number of
sectors for a swap when the image is padded. It defaults to 128 and
should match the value configured in the bootloader.

Fixes #285

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/scripts/imgtool.py b/scripts/imgtool.py
index c7c17a4..f102111 100755
--- a/scripts/imgtool.py
+++ b/scripts/imgtool.py
@@ -114,7 +114,9 @@
 
 @click.argument('outfile')
 @click.argument('infile')
-@click.option('--pad', type=int,
+@click.option('-M', '--max-sectors', type=int,
+              help='When padding allow for this amount of sectors (defaults to 128)')
+@click.option('--pad', type=BasedIntParamType(),
               help='Pad image to this many bytes, adding trailer magic')
 @click.option('--included-header', default=False, is_flag=True,
               help='Image has gap for header')
@@ -124,8 +126,8 @@
               required=True)
 @click.option('-k', '--key', metavar='filename')
 @click.command(help='Create a signed or unsigned image')
-def sign(key, align, version, header_size, included_header, pad, infile,
-         outfile):
+def sign(key, align, version, header_size, included_header, pad, max_sectors,
+         infile, outfile):
     img = image.Image.load(infile, version=decode_version(version),
                            header_size=header_size,
                            included_header=included_header, pad=pad)
@@ -133,7 +135,7 @@
     img.sign(key)
 
     if pad is not None:
-        img.pad_to(pad, align)
+        img.pad_to(pad, int(align), max_sectors)
 
     img.save(outfile)