Boot: Add version number from command line

- Add an optional command line argument that can be used to set an
image's version number at build-time (using
-DIMAGE_VERSION=maj.min.rev+build) so that the Cmake command within
bl2/ext/mcuboot/MCUBoot.cmake doesn't need to be edited each time the
specified version number needs to be changed
- If the version number is not defined in the command line, use a
default value and automatically increment it in the next build

Signed-off-by: Oliver Swede <oli.swede@arm.com>
Change-Id: I3ff44ffb8219d7ea1a441d918cceb525e7af60f2
diff --git a/bl2/ext/mcuboot/scripts/imgtool/version.py b/bl2/ext/mcuboot/scripts/imgtool/version.py
index 64962e9..d1d45f0 100644
--- a/bl2/ext/mcuboot/scripts/imgtool/version.py
+++ b/bl2/ext/mcuboot/scripts/imgtool/version.py
@@ -1,4 +1,5 @@
 # Copyright 2017 Linaro Limited
+# Copyright (c) 2018, Arm Limited.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -24,11 +25,29 @@
 
 SemiSemVersion = namedtuple('SemiSemVersion', ['major', 'minor', 'revision', 'build'])
 
+def increment_build_num(lastVer):
+    newVer = SemiSemVersion(lastVer.major, lastVer.minor, lastVer.revision, lastVer.build + 1)
+    return newVer
+
+# -1 if a is older than b; 0 if they're the same version; 1 if a is newer than b
+def compare(a, b):
+    if (a.major > b.major): return 1
+    elif (a.major < b.major): return -1
+    else:
+        if (a.minor > b.minor): return 1
+        elif (a.minor < b.minor): return -1
+        else:
+            if (a.revision > b.revision): return 1
+            elif (a.revision < b.revision): return -1
+            else:
+                if (a.build > b.build): return 1
+                elif (a.build < b.build): return -1
+                else: return 0
+
 version_re = re.compile(r"""^([1-9]\d*|0)(\.([1-9]\d*|0)(\.([1-9]\d*|0)(\+([1-9]\d*|0))?)?)?$""")
 def decode_version(text):
     """Decode the version string, which should be of the form maj.min.rev+build"""
     m = version_re.match(text)
-    # print("decode:", text, m.groups())
     if m:
         result = SemiSemVersion(
                 int(m.group(1)) if m.group(1) else 0,