sim: Make the test builder optional

Some of the simulated devices aren't large enough to support the 5 slots
needed to test a multi-image configuration.  To allow this to work, make
the return from the `ImagesBuilder` return an option, so that it will be
able to indicate (with `None`) that this configuration isn't possible to
test, and that the test should be skipped.

Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/image.rs b/sim/src/image.rs
index 92df421..899989c 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -62,7 +62,10 @@
 }
 
 impl ImagesBuilder {
-    pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Self {
+    /// Construct a new image builder for the given device.  Returns
+    /// Some(builder) if is possible to test this configuration, or None if
+    /// not possible (for example, if there aren't enough image slots).
+    pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Option<Self> {
         let (flash, areadesc) = Self::make_device(device, align, erased_val);
 
         let (slot0_base, slot0_len, slot0_dev_id) = areadesc.find(FlashId::Image0);
@@ -87,11 +90,11 @@
             dev_id: slot1_dev_id,
         };
 
-        ImagesBuilder {
+        Some(ImagesBuilder {
             flash: flash,
             areadesc: areadesc,
             slots: vec![[slot0, slot1]],
-        }
+        })
     }
 
     pub fn each_device<F>(f: F)
@@ -100,8 +103,10 @@
         for &dev in ALL_DEVICES {
             for &align in &[1, 2, 4, 8] {
                 for &erased_val in &[0, 0xff] {
-                    let run = Self::new(dev, align, erased_val);
-                    f(run);
+                    match Self::new(dev, align, erased_val) {
+                        Some(run) => f(run),
+                        None => warn!("Skipping {:?}, insufficient partitions", dev),
+                    }
                 }
             }
         }
diff --git a/sim/src/lib.rs b/sim/src/lib.rs
index 58f5c59..43a1e5a 100644
--- a/sim/src/lib.rs
+++ b/sim/src/lib.rs
@@ -161,7 +161,13 @@
     pub fn run_single(&mut self, device: DeviceName, align: u8, erased_val: u8) {
         warn!("Running on device {} with alignment {}", device, align);
 
-        let run = ImagesBuilder::new(device, align, erased_val);
+        let run = match ImagesBuilder::new(device, align, erased_val) {
+            Some(builder) => builder,
+            None => {
+                warn!("Skipping device with insuffienct partitions");
+                return;
+            }
+        };
 
         let mut failed = false;