Commit 71a697a4 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Add minimum size validation for header parameter

Throw exception on values that are less than the minimum acceptable size
of 32 bytes.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 9b7a2583
Loading
Loading
Loading
Loading
+10 −1
Changes for scripts/imgtool.py: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -98,6 +98,14 @@ def validate_version(ctx, param, value):
        raise click.BadParameter("{}".format(e))


def validate_header_size(ctx, param, value):
    min_hdr_size = image.IMAGE_HEADER_SIZE
    if value < min_hdr_size:
        raise click.BadParameter(
            "Minimum value for -H/--header-size is {}".format(min_hdr_size))
    return value


class BasedIntParamType(click.ParamType):
    name = 'integer'

@@ -128,7 +136,8 @@ class BasedIntParamType(click.ParamType):
              help='Size of the slot where the image will be written')
@click.option('--pad-header', default=False, is_flag=True,
              help='Add --header-size zeroed bytes at the beginning of the image')
@click.option('-H', '--header-size', type=BasedIntParamType(), required=True)
@click.option('-H', '--header-size', callback=validate_header_size,
              type=BasedIntParamType(), required=True)
@click.option('-v', '--version', callback=validate_version,  required=True)
@click.option('--align', type=click.Choice(['1', '2', '4', '8']),
              required=True)