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

sim: add new device with unequal slots

This device allows testing swap move with a primary slot that is one
sector larger than the secondary slot. No scratch was defined. Overwrite
upgrade could easily be made compatible as well, but for now leave it
as a disabled caps.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 826abf46
Loading
Loading
Loading
Loading
+13 −0
Changes for sim/src/image.rs: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -325,6 +325,19 @@ impl ImagesBuilder {
                flash.insert(dev_id, dev);
                (flash, areadesc, &[])
            }
            DeviceName::Nrf52840UnequalSlots => {
                let dev = SimFlash::new(vec![4096; 128], align as usize, erased_val);

                let dev_id = 0;
                let mut areadesc = AreaDesc::new();
                areadesc.add_flash_sectors(dev_id, &dev);
                areadesc.add_image(0x008000, 0x03c000, FlashId::Image0, dev_id);
                areadesc.add_image(0x044000, 0x03b000, FlashId::Image1, dev_id);

                let mut flash = SimMultiFlash::new();
                flash.insert(dev_id, dev);
                (flash, areadesc, &[Caps::SwapUsingScratch, Caps::OverwriteUpgrade])
            }
            DeviceName::Nrf52840SpiFlash => {
                // Simulate nrf52840 with external SPI flash. The external SPI flash
                // has a larger sector size so for now store scratch on that flash.
+6 −1
Changes for sim/src/lib.rs: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -62,7 +62,10 @@ struct Args {
}

#[derive(Copy, Clone, Debug, Deserialize)]
pub enum DeviceName { Stm32f4, K64f, K64fBig, K64fMulti, Nrf52840, Nrf52840SpiFlash, }
pub enum DeviceName {
    Stm32f4, K64f, K64fBig, K64fMulti, Nrf52840, Nrf52840SpiFlash,
    Nrf52840UnequalSlots,
}

pub static ALL_DEVICES: &'static [DeviceName] = &[
    DeviceName::Stm32f4,
@@ -71,6 +74,7 @@ pub static ALL_DEVICES: &'static [DeviceName] = &[
    DeviceName::K64fMulti,
    DeviceName::Nrf52840,
    DeviceName::Nrf52840SpiFlash,
    DeviceName::Nrf52840UnequalSlots,
];

impl fmt::Display for DeviceName {
@@ -82,6 +86,7 @@ impl fmt::Display for DeviceName {
            DeviceName::K64fMulti => "k64fmulti",
            DeviceName::Nrf52840 => "nrf52840",
            DeviceName::Nrf52840SpiFlash => "Nrf52840SpiFlash",
            DeviceName::Nrf52840UnequalSlots => "Nrf52840UnequalSlots",
        };
        f.write_str(name)
    }