sim: add bootstrap test

Add caps for bootstrap option and implement simple bootstrap test
for the simulator.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
This commit is contained in:
Fabio Utzig 2020-10-02 15:22:11 -03:00 committed by Fabio Utzig
parent aac99a14c9
commit d0157343dc
5 changed files with 58 additions and 0 deletions

View File

@ -46,6 +46,7 @@ uint32_t bootutil_get_caps(void);
#define BOOTUTIL_CAP_SWAP_USING_MOVE (1<<11)
#define BOOTUTIL_CAP_DOWNGRADE_PREVENTION (1<<12)
#define BOOTUTIL_CAP_ENC_X25519 (1<<13)
#define BOOTUTIL_CAP_BOOTSTRAP (1<<14)
/*
* Query the number of images this bootloader is configured for. This

View File

@ -65,6 +65,9 @@ uint32_t bootutil_get_caps(void)
#if defined(MCUBOOT_DOWNGRADE_PREVENTION)
res |= BOOTUTIL_CAP_DOWNGRADE_PREVENTION;
#endif
#if defined(MCUBOOT_BOOTSTRAP)
res |= BOOTUTIL_CAP_BOOTSTRAP;
#endif
return res;
}

View File

@ -24,6 +24,7 @@ pub enum Caps {
SwapUsingMove = (1 << 11),
DowngradePrevention = (1 << 12),
EncX25519 = (1 << 13),
Bootstrap = (1 << 14),
}
impl Caps {

View File

@ -258,6 +258,25 @@ impl ImagesBuilder {
}
}
pub fn make_bootstrap_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_no_image();
let upgrades = install_image(&mut flash, &slots[1], 32784, &dep, false);
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 {
@ -399,6 +418,39 @@ impl Images {
}
}
pub fn run_bootstrap(&self) -> bool {
let mut flash = self.flash.clone();
let mut fails = 0;
if Caps::Bootstrap.present() {
info!("Try bootstraping image in the primary");
let (result, _) = c::boot_go(&mut flash, &self.areadesc, None, false);
if result != 0 {
warn!("Failed first boot");
fails += 1;
}
if !self.verify_images(&flash, 0, 1) {
warn!("Image in the first slot was not bootstrapped");
fails += 1;
}
if !self.verify_trailers(&flash, 0, BOOT_MAGIC_GOOD,
BOOT_FLAG_SET, BOOT_FLAG_SET) {
warn!("Mismatched trailer for the primary slot");
fails += 1;
}
}
if fails > 0 {
error!("Expected trailer on secondary slot to be erased");
}
fails > 0
}
/// Test a simple upgrade, with dependencies given, and verify that the
/// image does as is described in the test.
pub fn run_check_deps(&self, deps: &DepTest) -> bool {

View File

@ -48,6 +48,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!(bootstrap, make_bootstrap_image(), run_bootstrap());
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());