Build: Sign the S and NS images separately

This patch modifies the build system to sign the secure and non-secure
images independently if the MCUBOOT_IMAGE_NUMBER build time switch is
greater than 1. This way the bootloader will be able to handle and
update the S and NS images separately.

Add separate security counter and image version variables for the S and
NS images in the build system. They can be specified at build time with
the SECURITY_COUNTER_S/_NS and IMAGE_VERSION_S/_NS defines.
In that case if any of the security counter values is missing, the
counter value will be generated just like in case of single image boot
(derived from image version).

Change-Id: Ia971fda818b92a7b27ee26f1b3893986322fd62e
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/bl2/ext/mcuboot/scripts/imgtool.py b/bl2/ext/mcuboot/scripts/imgtool.py
index b226faf..1976f72 100644
--- a/bl2/ext/mcuboot/scripts/imgtool.py
+++ b/bl2/ext/mcuboot/scripts/imgtool.py
@@ -42,6 +42,7 @@
 
 def next_version_number(args, defaultVersion, path):
     newVersion = None
+    versionProvided = False
     if (version.compare(args.version, defaultVersion) == 0): # Default version
         lastVersion = get_last_version(path)
         if (lastVersion is not None):
@@ -49,6 +50,7 @@
         else:
             newVersion = version.increment_build_num(defaultVersion)
     else: # Version number has been explicitly provided (not using the default)
+        versionProvided = True
         newVersion = args.version
     versionString = "{a}.{b}.{c}+{d}".format(
                     a=str(newVersion.major),
@@ -56,8 +58,9 @@
                     c=str(newVersion.revision),
                     d=str(newVersion.build)
     )
-    with open(path, "w") as newFile:
-        newFile.write(versionString)
+    if not versionProvided:
+        with open(path, "w") as newFile:
+            newFile.write(versionString)
     print("**[INFO]** Image version number set to " + versionString)
     return newVersion