Add test for erased secondary with leftover trailer
Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
This commit is contained in:
parent
260ec45734
commit
2c3be5cfb4
|
@ -239,6 +239,25 @@ impl ImagesBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn make_erased_secondary_image(self) -> Images {
|
||||
let mut flash = self.flash;
|
||||
let images = self.slots.into_iter().enumerate().map(|(image_num, slots)| {
|
||||
let dep = BoringDep::new(image_num, &NO_DEPS);
|
||||
let primaries = install_image(&mut flash, &slots[0], 32784, &dep, false);
|
||||
let upgrades = install_no_image();
|
||||
OneImage {
|
||||
slots: slots,
|
||||
primaries: primaries,
|
||||
upgrades: upgrades,
|
||||
}}).collect();
|
||||
Images {
|
||||
flash: flash,
|
||||
areadesc: self.areadesc,
|
||||
images: images,
|
||||
total_count: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the Flash and area descriptor for a given device.
|
||||
pub fn make_device(device: DeviceName, align: usize, erased_val: u8) -> (SimMultiFlash, AreaDesc, &'static [Caps]) {
|
||||
match device {
|
||||
|
@ -694,6 +713,43 @@ impl Images {
|
|||
fails > 0
|
||||
}
|
||||
|
||||
// Should detect there is a leftover trailer in an otherwise erased
|
||||
// secondary slot and erase its trailer.
|
||||
pub fn run_secondary_leftover_trailer(&self) -> bool {
|
||||
let mut flash = self.flash.clone();
|
||||
let mut fails = 0;
|
||||
|
||||
info!("Try with a leftover trailer in the secondary; must be erased");
|
||||
|
||||
// Add a trailer on the secondary slot
|
||||
self.mark_permanent_upgrades(&mut flash, 1);
|
||||
self.mark_upgrades(&mut flash, 1);
|
||||
|
||||
// Run the bootloader...
|
||||
let (result, _) = c::boot_go(&mut flash, &self.areadesc, None, false);
|
||||
if result != 0 {
|
||||
warn!("Failed first boot");
|
||||
fails += 1;
|
||||
}
|
||||
|
||||
// State should not have changed
|
||||
if !self.verify_images(&flash, 0, 0) {
|
||||
warn!("Failed image verification");
|
||||
fails += 1;
|
||||
}
|
||||
if !self.verify_trailers(&flash, 1, BOOT_MAGIC_UNSET,
|
||||
BOOT_FLAG_UNSET, BOOT_FLAG_UNSET) {
|
||||
warn!("Mismatched trailer for the secondary slot");
|
||||
fails += 1;
|
||||
}
|
||||
|
||||
if fails > 0 {
|
||||
error!("Expected trailer on secondary slot to be erased");
|
||||
}
|
||||
|
||||
fails > 0
|
||||
}
|
||||
|
||||
fn trailer_sz(&self, align: usize) -> usize {
|
||||
c::boot_trailer_sz(align as u32) as usize
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ macro_rules! sim_test {
|
|||
}
|
||||
|
||||
sim_test!(bad_secondary_slot, make_bad_secondary_slot_image(), run_signfail_upgrade());
|
||||
sim_test!(secondary_trailer_leftover, make_erased_secondary_image(), run_secondary_leftover_trailer());
|
||||
sim_test!(norevert_newimage, make_no_upgrade_image(&NO_DEPS), run_norevert_newimage());
|
||||
sim_test!(basic_revert, make_image(&NO_DEPS, true), run_basic_revert());
|
||||
sim_test!(revert_with_fails, make_image(&NO_DEPS, false), run_revert_with_fails());
|
||||
|
|
Loading…
Reference in New Issue