Commit 7724bcfd authored by Thomas Altenbach's avatar Thomas Altenbach Committed by Jamie
Browse files

sim: Add device with larger sectors in slot 0 than in slot 1



The simulator was not performing any test with a configuration where the
primary slot is composed of larger sectors than the secondary slot.
This can be typically case when using a STM32 with an external flash
memory since most STM32 have large internal sectors. This configuration
was causing issues when using the swap-scratch upgrade strategy.

Signed-off-by: default avatarThomas Altenbach <thomas.altenbach@legrand.com>
parent 7330df7c
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -453,6 +453,29 @@ impl ImagesBuilder {
                flash.insert(dev_id, dev);
                (flash, Rc::new(areadesc), &[Caps::SwapUsingMove, Caps::SwapUsingOffset])
            }
            DeviceName::Stm32f4SpiFlash => {
                // STM style internal flash and external SPI flash.
                let dev0 = SimFlash::new(vec![
                                        16 * 1024, 16 * 1024, 16 * 1024, 16 * 1024, 64 * 1024,
                                        32 * 1024, 32 * 1024, 64 * 1024,
                                        32 * 1024, 32 * 1024, 64 * 1024,
                                        128 * 1024],
                                        align as usize, erased_val);

                let dev1: SimFlash = SimFlash::new(vec![8192; 64], align as usize, erased_val);

                let mut areadesc = AreaDesc::new();
                areadesc.add_flash_sectors(0, &dev0);
                areadesc.add_flash_sectors(1, &dev1);
                areadesc.add_image(0x020000, 0x020000, FlashId::Image0, 0);
                areadesc.add_image(0x000000, 0x020000, FlashId::Image1, 1);
                areadesc.add_image(0x020000, 0x020000, FlashId::ImageScratch, 1);

                let mut flash = SimMultiFlash::new();
                flash.insert(0, dev0);
                flash.insert(1, dev1);
                (flash, Rc::new(areadesc), &[Caps::SwapUsingMove, Caps::SwapUsingOffset])
            }
            DeviceName::K64f => {
                // NXP style flash.  Small sectors, one small sector for scratch.
                let dev = SimFlash::new(vec![4096; 128], align as usize, erased_val);
+3 −1
Original line number Diff line number Diff line
@@ -63,12 +63,13 @@ struct Args {

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

pub static ALL_DEVICES: &[DeviceName] = &[
    DeviceName::Stm32f4,
    DeviceName::Stm32f4SpiFlash,
    DeviceName::K64f,
    DeviceName::K64fBig,
    DeviceName::K64fMulti,
@@ -82,6 +83,7 @@ impl fmt::Display for DeviceName {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let name = match *self {
            DeviceName::Stm32f4 => "stm32f4",
            DeviceName::Stm32f4SpiFlash => "stm32f4SpiFlash",
            DeviceName::K64f => "k64f",
            DeviceName::K64fBig => "k64fbig",
            DeviceName::K64fMulti => "k64fmulti",