blob: 2751618319d79bae094d603a92bff05d4bd57aa8 [file] [log] [blame]
David Brown902d6172017-05-05 09:37:41 -06001// Query the bootloader's capabilities.
2
3#[repr(u32)]
4#[derive(Copy, Clone, Eq, PartialEq)]
5#[allow(unused)]
6pub enum Caps {
David Vincze2d736ad2019-02-18 11:50:22 +01007 RSA2048 = (1 << 0),
8 EcdsaP224 = (1 << 1),
9 EcdsaP256 = (1 << 2),
10 SwapUpgrade = (1 << 3),
11 OverwriteUpgrade = (1 << 4),
12 EncRsa = (1 << 5),
13 EncKw = (1 << 6),
14 ValidatePrimarySlot = (1 << 7),
David Brown902d6172017-05-05 09:37:41 -060015}
16
17impl Caps {
18 pub fn present(self) -> bool {
19 let caps = unsafe { bootutil_get_caps() };
20 (caps as u32) & (self as u32) != 0
21 }
David Brown4c9883b2019-03-05 12:13:33 -070022
23 /// Query for the number of images that have been configured into this
24 /// MCUboot build.
25 pub fn get_num_images() -> usize {
26 (unsafe { bootutil_get_num_images() }) as usize
27 }
David Brown902d6172017-05-05 09:37:41 -060028}
29
30extern "C" {
31 fn bootutil_get_caps() -> Caps;
David Brown4c9883b2019-03-05 12:13:33 -070032 fn bootutil_get_num_images() -> u32;
David Brown902d6172017-05-05 09:37:41 -060033}