Add capabilities query
Add a simple function to query the bootloader for capabilities.
Ultimately, this API should be available to the running app, but the
simulator can use this to determine what to test.
diff --git a/sim/src/caps.rs b/sim/src/caps.rs
new file mode 100644
index 0000000..77be9de
--- /dev/null
+++ b/sim/src/caps.rs
@@ -0,0 +1,23 @@
+// Query the bootloader's capabilities.
+
+#[repr(u32)]
+#[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),
+}
+
+impl Caps {
+ pub fn present(self) -> bool {
+ let caps = unsafe { bootutil_get_caps() };
+ (caps as u32) & (self as u32) != 0
+ }
+}
+
+extern "C" {
+ fn bootutil_get_caps() -> Caps;
+}
diff --git a/sim/src/main.rs b/sim/src/main.rs
index de9e588..3998725 100644
--- a/sim/src/main.rs
+++ b/sim/src/main.rs
@@ -22,9 +22,11 @@
mod flash;
pub mod api;
mod pdump;
+mod caps;
use flash::Flash;
use area::{AreaDesc, FlashId};
+use caps::Caps;
const USAGE: &'static str = "
Mcuboot simulator
@@ -243,9 +245,11 @@
warn!("FAIL at step {} of {}", i, total_count);
bad += 1;
}
- if !verify_image(&fl3, slot1_base, &primary) {
- warn!("Slot 1 FAIL at step {} of {}", i, total_count);
- bad += 1;
+ if Caps::SwapUpgrade.present() {
+ if !verify_image(&fl3, slot1_base, &primary) {
+ warn!("Slot 1 FAIL at step {} of {}", i, total_count);
+ bad += 1;
+ }
}
}
error!("{} out of {} failed {:.2}%",
@@ -256,23 +260,29 @@
}
let (fl4, total_counts) = try_random_fails(&flash, &areadesc, total_count, 5);
- info!("Random fails at reset points={:?}", total_counts);
+ info!("Random interruptions at reset points={:?}", total_counts);
let slot0_ok = verify_image(&fl4, slot0_base, &upgrade);
- let slot1_ok = verify_image(&fl4, slot1_base, &primary);
- if !slot0_ok || !slot1_ok {
- error!("Image mismatch after random fails: slot0={} slot1={}",
+ let slot1_ok = if Caps::SwapUpgrade.present() {
+ verify_image(&fl4, slot1_base, &primary)
+ } 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" });
self.failures += 1;
return;
}
- for count in 2 .. 5 {
- info!("Try revert: {}", count);
- let fl2 = try_revert(&flash, &areadesc, count);
- if !verify_image(&fl2, slot0_base, &primary) {
- warn!("Revert failure on count {}", count);
- failed = true;
+ if Caps::SwapUpgrade.present() {
+ for count in 2 .. 5 {
+ info!("Try revert: {}", count);
+ let fl2 = try_revert(&flash, &areadesc, count);
+ if !verify_image(&fl2, slot0_base, &primary) {
+ warn!("Revert failure on count {}", count);
+ failed = true;
+ }
}
}