Skip to content

Commit 7724bcf

Browse files
taltenbachnordicjm
authored andcommitted
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: Thomas Altenbach <[email protected]>
1 parent 7330df7 commit 7724bcf

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

sim/src/image.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,29 @@ impl ImagesBuilder {
453453
flash.insert(dev_id, dev);
454454
(flash, Rc::new(areadesc), &[Caps::SwapUsingMove, Caps::SwapUsingOffset])
455455
}
456+
DeviceName::Stm32f4SpiFlash => {
457+
// STM style internal flash and external SPI flash.
458+
let dev0 = SimFlash::new(vec![
459+
16 * 1024, 16 * 1024, 16 * 1024, 16 * 1024, 64 * 1024,
460+
32 * 1024, 32 * 1024, 64 * 1024,
461+
32 * 1024, 32 * 1024, 64 * 1024,
462+
128 * 1024],
463+
align as usize, erased_val);
464+
465+
let dev1: SimFlash = SimFlash::new(vec![8192; 64], align as usize, erased_val);
466+
467+
let mut areadesc = AreaDesc::new();
468+
areadesc.add_flash_sectors(0, &dev0);
469+
areadesc.add_flash_sectors(1, &dev1);
470+
areadesc.add_image(0x020000, 0x020000, FlashId::Image0, 0);
471+
areadesc.add_image(0x000000, 0x020000, FlashId::Image1, 1);
472+
areadesc.add_image(0x020000, 0x020000, FlashId::ImageScratch, 1);
473+
474+
let mut flash = SimMultiFlash::new();
475+
flash.insert(0, dev0);
476+
flash.insert(1, dev1);
477+
(flash, Rc::new(areadesc), &[Caps::SwapUsingMove, Caps::SwapUsingOffset])
478+
}
456479
DeviceName::K64f => {
457480
// NXP style flash. Small sectors, one small sector for scratch.
458481
let dev = SimFlash::new(vec![4096; 128], align as usize, erased_val);

sim/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ struct Args {
6363

6464
#[derive(Copy, Clone, Debug, Deserialize)]
6565
pub enum DeviceName {
66-
Stm32f4, K64f, K64fBig, K64fMulti, Nrf52840, Nrf52840SpiFlash,
66+
Stm32f4, Stm32f4SpiFlash, K64f, K64fBig, K64fMulti, Nrf52840, Nrf52840SpiFlash,
6767
Nrf52840UnequalSlots, Nrf52840UnequalSlotsLargerSlot1,
6868
}
6969

7070
pub static ALL_DEVICES: &[DeviceName] = &[
7171
DeviceName::Stm32f4,
72+
DeviceName::Stm32f4SpiFlash,
7273
DeviceName::K64f,
7374
DeviceName::K64fBig,
7475
DeviceName::K64fMulti,
@@ -82,6 +83,7 @@ impl fmt::Display for DeviceName {
8283
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8384
let name = match *self {
8485
DeviceName::Stm32f4 => "stm32f4",
86+
DeviceName::Stm32f4SpiFlash => "stm32f4SpiFlash",
8587
DeviceName::K64f => "k64f",
8688
DeviceName::K64fBig => "k64fbig",
8789
DeviceName::K64fMulti => "k64fmulti",

0 commit comments

Comments
 (0)