Commit 873be31d authored by David Brown's avatar David Brown Committed by Fabio Utzig
Browse files

sim: Add OldCorrect and NoUpgrade dependency types

Add two additional dependency types.  The NoUpgrade type indicates that
this slot should not contain an upgrade at all.  The OldCorrect
indicates a dependency on the old version of the other slot.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 0e6bc7fe
Loading
Loading
Loading
Loading
+15 −0
Changes for sim/src/depends.rs: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -54,9 +54,14 @@ pub enum DepType {
    Nothing,
    /// Provide dependency information that matches the other image.
    Correct,
    /// Provide a dependency that matches the old version of the other
    /// image.
    OldCorrect,
    /// Provide dependency information describing something newer than the
    /// other image.
    Newer,
    /// Don't provide an upgrade image at all for this image
    NoUpgrade,
}

/// Describes what our expectation is for an upgrade.
@@ -101,16 +106,26 @@ impl Depender for PairDep {
    }

    fn my_deps(&self, _offset: usize, slot: usize) -> Vec<ImageVersion> {
        // For now, don't put any dependencies in slot zero.  They could be
        // added here if we someday implement checking these.
        if slot == 0 {
            vec![]
        } else {
            match self.test.depends[self.number] {
                DepType::Nothing => vec![],
                DepType::NoUpgrade => panic!("Shouldn't get to this point"),
                DepType::Correct => vec![
                    ImageVersion::new_synthetic(self.other_id(), slot as u8, 0)
                ],
                DepType::OldCorrect => vec![
                    ImageVersion::new_synthetic(self.other_id(), 0, 0)
                ],
                DepType::Newer => vec![
                    ImageVersion::new_synthetic(self.other_id(), slot as u8, 1)
                ],
            }
        }
    }

    fn other_id(&self) -> u8 {
        (1 - self.number) as u8
+13 −1
Changes for sim/src/image.rs: 13 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ use crate::depends::{
    BoringDep,
    Depender,
    DepTest,
    DepType,
    PairDep,
    UpgradeInfo,
};
@@ -167,7 +168,10 @@ impl ImagesBuilder {
                Box::new(BoringDep(image_num))
            };
            let primaries = install_image(&mut flash, &slots[0], 42784, &*dep, false);
            let upgrades = install_image(&mut flash, &slots[1], 46928, &*dep, false);
            let upgrades = match deps.depends[image_num] {
                DepType::NoUpgrade => install_no_image(),
                _ => install_image(&mut flash, &slots[1], 46928, &*dep, false)
            };
            OneImage {
                slots: slots,
                primaries: primaries,
@@ -1228,6 +1232,14 @@ fn install_image(flash: &mut SimMultiFlash, slot: &SlotInfo, len: usize,
    }
}

/// Install no image.  This is used when no upgrade happens.
fn install_no_image() -> ImageData {
    ImageData {
        plain: vec![],
        cipher: None,
    }
}

fn make_tlv() -> TlvGen {
    if Caps::EcdsaP224.present() {
        panic!("Ecdsa P224 not supported in Simulator");