Replace flash partitioning terminology

This change replaces the slot 0/1 terminology with primary/secondary
slot and replaces FLASH_AREA_IMAGE_0/1 with
FLASH_AREA_IMAGE_PRIMARY/SECONDARY. This naming convention may be more
understandable, fits better to MCUs with multiple images and it is an
architecture agnostic alternative as well.

Change-Id: I655a585f6ae023852c671ee6635399efe25209c9
Signed-off-by: David Vincze <david.vincze@arm.com>
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/caps.rs b/sim/src/caps.rs
index 499add0..09f6dee 100644
--- a/sim/src/caps.rs
+++ b/sim/src/caps.rs
@@ -4,14 +4,14 @@
 #[derive(Copy, Clone, Eq, PartialEq)]
 #[allow(unused)]
 pub enum Caps {
-    RSA2048          = (1 << 0),
-    EcdsaP224        = (1 << 1),
-    EcdsaP256        = (1 << 2),
-    SwapUpgrade      = (1 << 3),
-    OverwriteUpgrade = (1 << 4),
-    EncRsa           = (1 << 5),
-    EncKw            = (1 << 6),
-    ValidateSlot0    = (1 << 7),
+    RSA2048              = (1 << 0),
+    EcdsaP224            = (1 << 1),
+    EcdsaP256            = (1 << 2),
+    SwapUpgrade          = (1 << 3),
+    OverwriteUpgrade     = (1 << 4),
+    EncRsa               = (1 << 5),
+    EncKw                = (1 << 6),
+    ValidatePrimarySlot  = (1 << 7),
 }
 
 impl Caps {
diff --git a/sim/src/image.rs b/sim/src/image.rs
index b940b6e..e41d1cd 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -76,19 +76,20 @@
 
             if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                                BOOT_FLAG_SET, BOOT_FLAG_SET) {
-                warn!("Mismatched trailer for Slot 0");
+                warn!("Mismatched trailer for the primary slot");
                 fails += 1;
             }
 
             if !verify_trailer(&flashmap, &self.slots, 1, BOOT_MAGIC_UNSET,
                                BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-                warn!("Mismatched trailer for Slot 1");
+                warn!("Mismatched trailer for the secondary slot");
                 fails += 1;
             }
 
             if Caps::SwapUpgrade.present() {
                 if !verify_image(&flashmap, &self.slots, 1, &self.primaries) {
-                    warn!("Slot 1 FAIL at step {} of {}", i, total_flash_ops);
+                    warn!("Secondary slot FAIL at step {} of {}",
+                          i, total_flash_ops);
                     fails += 1;
                 }
             }
@@ -113,26 +114,28 @@
                                                         total_flash_ops, total_fails);
         info!("Random interruptions at reset points={:?}", total_counts);
 
-        let slot0_ok = verify_image(&flashmap, &self.slots, 0, &self.upgrades);
-        let slot1_ok = if Caps::SwapUpgrade.present() {
+        let primary_slot_ok = verify_image(&flashmap, &self.slots,
+                                           0, &self.upgrades);
+        let secondary_slot_ok = if Caps::SwapUpgrade.present() {
             verify_image(&flashmap, &self.slots, 1, &self.primaries)
         } else {
             true
         };
-        if !slot0_ok || !slot1_ok {
-            error!("Image mismatch after random interrupts: slot0={} slot1={}",
-                   if slot0_ok { "ok" } else { "fail" },
-                   if slot1_ok { "ok" } else { "fail" });
+        if !primary_slot_ok || !secondary_slot_ok {
+            error!("Image mismatch after random interrupts: primary slot={} \
+                    secondary slot={}",
+                   if primary_slot_ok { "ok" } else { "fail" },
+                   if secondary_slot_ok { "ok" } else { "fail" });
             fails += 1;
         }
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_SET) {
-            error!("Mismatched trailer for Slot 0");
+            error!("Mismatched trailer for the primary slot");
             fails += 1;
         }
         if !verify_trailer(&flashmap, &self.slots, 1, BOOT_MAGIC_UNSET,
                            BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-            error!("Mismatched trailer for Slot 1");
+            error!("Mismatched trailer for the secondary slot");
             fails += 1;
         }
 
@@ -184,26 +187,27 @@
         //       was ever done?
 
         if !verify_image(&flashmap, &self.slots, 0, &self.upgrades) {
-            warn!("Slot 0 image verification FAIL");
+            warn!("Primary slot image verification FAIL");
             fails += 1;
         }
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_UNSET, BOOT_FLAG_SET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
         if !verify_trailer(&flashmap, &self.slots, 1, BOOT_MAGIC_UNSET,
                            BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 1");
+            warn!("Mismatched trailer for the secondary slot");
             fails += 1;
         }
 
-        // Marks image in slot0 as permanent, no revert should happen...
+        // Marks image in the primary slot as permanent,
+        // no revert should happen...
         mark_permanent_upgrade(&mut flashmap, &self.slots[0]);
 
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_SET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
 
@@ -215,7 +219,7 @@
 
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_SET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
         if !verify_image(&flashmap, &self.slots, 0, &self.upgrades) {
@@ -230,8 +234,9 @@
         fails > 0
     }
 
-    // Tests a new image written to slot0 that already has magic and image_ok set
-    // while there is no image on slot1, so no revert should ever happen...
+    // Tests a new image written to the primary slot that already has magic and
+    // image_ok set while there is no image on the secondary slot, so no revert
+    // should ever happen...
     pub fn run_norevert_newimage(&self) -> bool {
         let mut flashmap = self.flashmap.clone();
         let mut fails = 0;
@@ -240,10 +245,11 @@
 
         mark_upgrade(&mut flashmap, &self.slots[0]);
 
-        // This simulates writing an image created by imgtool to Slot 0
+        // This simulates writing an image created by imgtool to
+        // the primary slot
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
 
@@ -261,12 +267,12 @@
         }
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
         if !verify_trailer(&flashmap, &self.slots, 1, BOOT_MAGIC_UNSET,
                            BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 1");
+            warn!("Mismatched trailer for the secondary slot");
             fails += 1;
         }
 
@@ -277,8 +283,9 @@
         fails > 0
     }
 
-    // Tests a new image written to slot0 that already has magic and image_ok set
-    // while there is no image on slot1, so no revert should ever happen...
+    // Tests a new image written to the primary slot that already has magic and
+    // image_ok set while there is no image on the secondary slot, so no revert
+    // should ever happen...
     pub fn run_signfail_upgrade(&self) -> bool {
         let mut flashmap = self.flashmap.clone();
         let mut fails = 0;
@@ -291,7 +298,7 @@
 
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
 
@@ -309,7 +316,7 @@
         }
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_UNSET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
 
@@ -339,7 +346,7 @@
     /// allowing for fails in the status area. This should run to the end
     /// and warn that write fails were detected...
     pub fn run_with_status_fails_complete(&self) -> bool {
-        if !Caps::ValidateSlot0.present() {
+        if !Caps::ValidatePrimarySlot.present() {
             return false;
         }
 
@@ -366,7 +373,7 @@
 
         if !verify_trailer(&flashmap, &self.slots, 0, BOOT_MAGIC_GOOD,
                            BOOT_FLAG_SET, BOOT_FLAG_SET) {
-            warn!("Mismatched trailer for Slot 0");
+            warn!("Mismatched trailer for the primary slot");
             fails += 1;
         }
 
@@ -375,7 +382,8 @@
             fails += 1;
         }
 
-        info!("validate slot0 enabled; re-run of boot_go should just work");
+        info!("validate primary slot enabled; \
+               re-run of boot_go should just work");
         let (result, _) = c::boot_go(&mut flashmap, &self.areadesc, None, false);
         if result != 0 {
             warn!("Failed!");
@@ -395,7 +403,7 @@
     pub fn run_with_status_fails_with_reset(&self) -> bool {
         if Caps::OverwriteUpgrade.present() {
             false
-        } else if Caps::ValidateSlot0.present() {
+        } else if Caps::ValidatePrimarySlot.present() {
 
             let mut flashmap = self.flashmap.clone();
             let mut fails = 0;
@@ -425,7 +433,8 @@
             // or throw a single assert for small sector devices that fail
             // multiple times...
             if asserts > 1 {
-                warn!("Expected single assert validating slot0, more detected {}", asserts);
+                warn!("Expected single assert validating the primary slot, \
+                       more detected {}", asserts);
                 fails += 1;
             }
 
@@ -473,7 +482,7 @@
     }
 
     fn reset_bad_status(&self, flashmap: &mut SimFlashMap, slot: usize) {
-        if !Caps::ValidateSlot0.present() {
+        if !Caps::ValidatePrimarySlot.present() {
             return;
         }
 
@@ -553,21 +562,23 @@
     }
 
     if !verify_image(&flashmap, &images.slots, 0, &images.upgrades) {
-        warn!("Image in slot 0 before revert is invalid at stop={}", stop);
+        warn!("Image in the primary slot before revert is invalid at stop={}",
+              stop);
         fails += 1;
     }
     if !verify_image(&flashmap, &images.slots, 1, &images.primaries) {
-        warn!("Image in slot 1 before revert is invalid at stop={}", stop);
+        warn!("Image in the secondary slot before revert is invalid at stop={}",
+              stop);
         fails += 1;
     }
     if !verify_trailer(&flashmap, &images.slots, 0, BOOT_MAGIC_GOOD,
                        BOOT_FLAG_UNSET, BOOT_FLAG_SET) {
-        warn!("Mismatched trailer for Slot 0 before revert");
+        warn!("Mismatched trailer for the primary slot before revert");
         fails += 1;
     }
     if !verify_trailer(&flashmap, &images.slots, 1, BOOT_MAGIC_UNSET,
                        BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-        warn!("Mismatched trailer for Slot 1 before revert");
+        warn!("Mismatched trailer for the secondary slot before revert");
         fails += 1;
     }
 
@@ -579,21 +590,23 @@
     }
 
     if !verify_image(&flashmap, &images.slots, 0, &images.primaries) {
-        warn!("Image in slot 0 after revert is invalid at stop={}", stop);
+        warn!("Image in the primary slot after revert is invalid at stop={}",
+              stop);
         fails += 1;
     }
     if !verify_image(&flashmap, &images.slots, 1, &images.upgrades) {
-        warn!("Image in slot 1 after revert is invalid at stop={}", stop);
+        warn!("Image in the secondary slot after revert is invalid at stop={}",
+              stop);
         fails += 1;
     }
     if !verify_trailer(&flashmap, &images.slots, 0, BOOT_MAGIC_GOOD,
                        BOOT_FLAG_SET, BOOT_FLAG_SET) {
-        warn!("Mismatched trailer for Slot 1 after revert");
+        warn!("Mismatched trailer for the secondary slot after revert");
         fails += 1;
     }
     if !verify_trailer(&flashmap, &images.slots, 1, BOOT_MAGIC_UNSET,
                        BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
-        warn!("Mismatched trailer for Slot 1 after revert");
+        warn!("Mismatched trailer for the secondary slot after revert");
         fails += 1;
     }
 
@@ -723,10 +736,10 @@
 
     let result: [Option<Vec<u8>>; 2];
 
-    // Since images are always non-encrypted in slot0, we first write an
-    // encrypted image, re-read to use for verification, erase + flash
-    // un-encrypted. In slot1 the image is written un-encrypted, and if
-    // encryption is requested, it follows an erase + flash encrypted.
+    // Since images are always non-encrypted in the primary slot, we first write
+    // an encrypted image, re-read to use for verification, erase + flash
+    // un-encrypted. In the secondary slot the image is written un-encrypted,
+    // and if encryption is requested, it follows an erase + flash encrypted.
 
     let flash = flashmap.get_mut(&dev_id).unwrap();
 
diff --git a/sim/src/lib.rs b/sim/src/lib.rs
index 8131a70..ce3abfc 100644
--- a/sim/src/lib.rs
+++ b/sim/src/lib.rs
@@ -162,32 +162,34 @@
     pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Run {
         let (flashmap, areadesc) = make_device(device, align, erased_val);
 
-        let (slot0_base, slot0_len, slot0_dev_id) = areadesc.find(FlashId::Image0);
-        let (slot1_base, slot1_len, slot1_dev_id) = areadesc.find(FlashId::Image1);
+        let (primary_slot_base, primary_slot_len, primary_slot_dev_id) =
+             areadesc.find(FlashId::Image0);
+        let (secondary_slot_base, secondary_slot_len, secondary_slot_dev_id) =
+             areadesc.find(FlashId::Image1);
 
         // NOTE: not accounting "swap_size" because it is not used by sim...
         let offset_from_end = c::boot_magic_sz() + c::boot_max_align() * 2;
 
         // Construct a primary image.
-        let slot0 = SlotInfo {
-            base_off: slot0_base as usize,
-            trailer_off: slot0_base + slot0_len - offset_from_end,
-            len: slot0_len as usize,
-            dev_id: slot0_dev_id,
+        let primary_slot = SlotInfo {
+            base_off: primary_slot_base as usize,
+            trailer_off: primary_slot_base + primary_slot_len - offset_from_end,
+            len: primary_slot_len as usize,
+            dev_id: primary_slot_dev_id,
         };
 
         // And an upgrade image.
-        let slot1 = SlotInfo {
-            base_off: slot1_base as usize,
-            trailer_off: slot1_base + slot1_len - offset_from_end,
-            len: slot1_len as usize,
-            dev_id: slot1_dev_id,
+        let secondary_slot = SlotInfo {
+            base_off: secondary_slot_base as usize,
+            trailer_off: secondary_slot_base + secondary_slot_len - offset_from_end,
+            len: secondary_slot_len as usize,
+            dev_id: secondary_slot_dev_id,
         };
 
         Run {
             flashmap: flashmap,
             areadesc: areadesc,
-            slots: [slot0, slot1],
+            slots: [primary_slot, secondary_slot],
         }
     }
 
@@ -236,7 +238,7 @@
         images
     }
 
-    pub fn make_bad_slot1_image(&self) -> Images {
+    pub fn make_bad_secondary_slot_image(&self) -> Images {
         let mut bad_flashmap = self.flashmap.clone();
         let primaries = install_image(&mut bad_flashmap, &self.slots, 0, 32784, false);
         let upgrades = install_image(&mut bad_flashmap, &self.slots, 1, 41928, true);
@@ -272,11 +274,11 @@
 
         let mut failed = false;
 
-        // Creates a badly signed image in slot1 to check that it is not
-        // upgraded to
-        let bad_slot1_image = run.make_bad_slot1_image();
+        // Creates a badly signed image in the secondary slot to check that
+        // it is not upgraded to
+        let bad_secondary_slot_image = run.make_bad_secondary_slot_image();
 
-        failed |= bad_slot1_image.run_signfail_upgrade();
+        failed |= bad_secondary_slot_image.run_signfail_upgrade();
 
         let images = run.make_no_upgrade_image();
         failed |= images.run_norevert_newimage();