bootutil: sim: add cap for swap using move

Add cap for swap using move and rename old swap upgrade cap to swap
using scratch. Update sim to allow swapping tests to also run using
move.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/include/bootutil/caps.h b/boot/bootutil/include/bootutil/caps.h
index e721cf9..553fa5d 100644
--- a/boot/bootutil/include/bootutil/caps.h
+++ b/boot/bootutil/include/bootutil/caps.h
@@ -35,7 +35,7 @@
 #define BOOTUTIL_CAP_RSA2048                (1<<0)
 #define BOOTUTIL_CAP_ECDSA_P224             (1<<1)
 #define BOOTUTIL_CAP_ECDSA_P256             (1<<2)
-#define BOOTUTIL_CAP_SWAP_UPGRADE           (1<<3)
+#define BOOTUTIL_CAP_SWAP_USING_SCRATCH     (1<<3)
 #define BOOTUTIL_CAP_OVERWRITE_UPGRADE      (1<<4)
 #define BOOTUTIL_CAP_ENC_RSA                (1<<5)
 #define BOOTUTIL_CAP_ENC_KW                 (1<<6)
@@ -43,6 +43,7 @@
 #define BOOTUTIL_CAP_RSA3072                (1<<8)
 #define BOOTUTIL_CAP_ED25519                (1<<9)
 #define BOOTUTIL_CAP_ENC_EC256              (1<<10)
+#define BOOTUTIL_CAP_SWAP_USING_MOVE        (1<<11)
 
 /*
  * Query the number of images this bootloader is configured for.  This
diff --git a/boot/bootutil/src/caps.c b/boot/bootutil/src/caps.c
index e1b8c0d..0ca7b8c 100644
--- a/boot/bootutil/src/caps.c
+++ b/boot/bootutil/src/caps.c
@@ -40,8 +40,10 @@
 #endif
 #if defined(MCUBOOT_OVERWRITE_ONLY)
     res |= BOOTUTIL_CAP_OVERWRITE_UPGRADE;
+#elif defined(MCUBOOT_SWAP_USING_MOVE)
+    res |= BOOTUTIL_CAP_SWAP_USING_MOVE;
 #else
-    res |= BOOTUTIL_CAP_SWAP_UPGRADE;
+    res |= BOOTUTIL_CAP_SWAP_USING_SCRATCH;
 #endif
 #if defined(MCUBOOT_ENCRYPT_RSA)
     res |= BOOTUTIL_CAP_ENC_RSA;
diff --git a/sim/src/caps.rs b/sim/src/caps.rs
index 35ab14f..639894b 100644
--- a/sim/src/caps.rs
+++ b/sim/src/caps.rs
@@ -1,13 +1,13 @@
 // Query the bootloader's capabilities.
 
 #[repr(u32)]
-#[derive(Copy, Clone, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
 #[allow(unused)]
 pub enum Caps {
     RSA2048              = (1 << 0),
     EcdsaP224            = (1 << 1),
     EcdsaP256            = (1 << 2),
-    SwapUpgrade          = (1 << 3),
+    SwapUsingScratch     = (1 << 3),
     OverwriteUpgrade     = (1 << 4),
     EncRsa               = (1 << 5),
     EncKw                = (1 << 6),
@@ -15,6 +15,7 @@
     RSA3072              = (1 << 8),
     Ed25519              = (1 << 9),
     EncEc256             = (1 << 10),
+    SwapUsingMove        = (1 << 11),
 }
 
 impl Caps {
diff --git a/sim/src/image.rs b/sim/src/image.rs
index cfb5198..035370f 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -362,6 +362,10 @@
         self.verify_dep_images(&flash, deps)
     }
 
+    fn is_swap_upgrade(&self) -> bool {
+        Caps::SwapUsingScratch.present() || Caps::SwapUsingMove.present()
+    }
+
     pub fn run_basic_revert(&self) -> bool {
         if Caps::OverwriteUpgrade.present() {
             return false;
@@ -370,7 +374,7 @@
         let mut fails = 0;
 
         // FIXME: this test would also pass if no swap is ever performed???
-        if Caps::SwapUpgrade.present() {
+        if self.is_swap_upgrade() {
             for count in 2 .. 5 {
                 info!("Try revert: {}", count);
                 let flash = self.try_revert(count);
@@ -410,7 +414,7 @@
                 fails += 1;
             }
 
-            if Caps::SwapUpgrade.present() {
+            if self.is_swap_upgrade() {
                 if !self.verify_images(&flash, 1, 0) {
                     warn!("Secondary slot FAIL at step {} of {}",
                           i, total_flash_ops);
@@ -434,7 +438,7 @@
         info!("Random interruptions at reset points={:?}", total_counts);
 
         let primary_slot_ok = self.verify_images(&flash, 0, 1);
-        let secondary_slot_ok = if Caps::SwapUpgrade.present() {
+        let secondary_slot_ok = if self.is_swap_upgrade() {
             // TODO: This result is ignored.
             self.verify_images(&flash, 1, 0)
         } else {
@@ -472,7 +476,7 @@
 
         let mut fails = 0;
 
-        if Caps::SwapUpgrade.present() {
+        if self.is_swap_upgrade() {
             for i in 1 .. self.total_count.unwrap() {
                 info!("Try interruption at {}", i);
                 if self.try_revert_with_fail_at(i) {