sim: Make BootGoResult into an enum

Now that this result is abstracted, take the special case for a sim stop
and make it its own field.  This hides the magic number we use to
indicate this to be entirely within mcuboot-sys.

Signed-off-by: David Brown <david.brown@linaro.org>
This commit is contained in:
David Brown 2021-06-04 14:41:33 -06:00 committed by David Brown
parent c423ac4517
commit 6d47d42eb6
1 changed files with 24 additions and 9 deletions

View File

@ -13,30 +13,41 @@ use crate::api;
/// The result of an invocation of `boot_go`. This is intentionally opaque so that we can provide /// The result of an invocation of `boot_go`. This is intentionally opaque so that we can provide
/// accessors for everything we need from this. /// accessors for everything we need from this.
#[derive(Debug)] #[derive(Debug)]
pub struct BootGoResult { pub enum BootGoResult {
/// This run was stopped by the flash simulation mechanism.
Stopped,
/// The bootloader ran to completion with the following data.
Normal {
result: i32, result: i32,
asserts: u8, asserts: u8,
},
} }
impl BootGoResult { impl BootGoResult {
/// Was this run interrupted. /// Was this run interrupted.
pub fn interrupted(&self) -> bool { pub fn interrupted(&self) -> bool {
self.result == -0x13579 matches!(self, BootGoResult::Stopped)
} }
/// Was this boot run successful (returned 0) /// Was this boot run successful (returned 0)
pub fn success(&self) -> bool { pub fn success(&self) -> bool {
self.result == 0 matches!(self, BootGoResult::Normal { result: 0, .. })
} }
/// Success, but also no asserts. /// Success, but also no asserts.
pub fn success_no_asserts(&self) -> bool { pub fn success_no_asserts(&self) -> bool {
self.result == 0 && self.asserts == 0 matches!(self, BootGoResult::Normal {
result: 0,
asserts: 0,
})
} }
/// Get the asserts count. /// Get the asserts count. An interrupted run will be considered to have no asserts.
pub fn asserts(&self) -> u8 { pub fn asserts(&self) -> u8 {
self.asserts match self {
BootGoResult::Normal { asserts, .. } => *asserts,
_ => 0,
}
} }
} }
@ -72,7 +83,11 @@ pub fn boot_go(multiflash: &mut SimMultiFlash, areadesc: &AreaDesc,
for &dev_id in multiflash.keys() { for &dev_id in multiflash.keys() {
api::clear_flash(dev_id); api::clear_flash(dev_id);
} }
BootGoResult { result, asserts } if result == -0x13579 {
BootGoResult::Stopped
} else {
BootGoResult::Normal { result, asserts }
}
} }
pub fn boot_trailer_sz(align: u32) -> u32 { pub fn boot_trailer_sz(align: u32) -> u32 {