Commit f5480c74 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

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: default avatarFabio Utzig <utzig@apache.org>
parent 031eb7de
Loading
Loading
Loading
Loading
+2 −1
Changes for boot/bootutil/include/bootutil/caps.h: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ uint32_t bootutil_get_caps(void);
#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 @@ uint32_t bootutil_get_caps(void);
#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
+3 −1
Changes for boot/bootutil/src/caps.c: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -40,8 +40,10 @@ uint32_t bootutil_get_caps(void)
#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;
+3 −2
Changes for sim/src/caps.rs: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
// 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 @@ pub enum Caps {
    RSA3072              = (1 << 8),
    Ed25519              = (1 << 9),
    EncEc256             = (1 << 10),
    SwapUsingMove        = (1 << 11),
}

impl Caps {
+8 −4
Changes for sim/src/image.rs: 8 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -362,6 +362,10 @@ impl Images {
        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 @@ impl Images {
        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 @@ impl Images {
                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 @@ impl Images {
        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 @@ impl Images {

        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) {