blob: 639894b9f878d7f2221a6535a7137231c57b20a0 [file] [log] [blame]
David Brown902d6172017-05-05 09:37:41 -06001// Query the bootloader's capabilities.
2
3#[repr(u32)]
Fabio Utzigf5480c72019-11-28 10:41:57 -03004#[derive(Copy, Clone, Debug, Eq, PartialEq)]
David Brown902d6172017-05-05 09:37:41 -06005#[allow(unused)]
6pub enum Caps {
David Vincze2d736ad2019-02-18 11:50:22 +01007 RSA2048 = (1 << 0),
8 EcdsaP224 = (1 << 1),
9 EcdsaP256 = (1 << 2),
Fabio Utzigf5480c72019-11-28 10:41:57 -030010 SwapUsingScratch = (1 << 3),
David Vincze2d736ad2019-02-18 11:50:22 +010011 OverwriteUpgrade = (1 << 4),
12 EncRsa = (1 << 5),
13 EncKw = (1 << 6),
14 ValidatePrimarySlot = (1 << 7),
Fabio Utzig39297432019-05-08 18:51:10 -030015 RSA3072 = (1 << 8),
Fabio Utzig97710282019-05-24 17:44:49 -030016 Ed25519 = (1 << 9),
Fabio Utzig5ef883a2019-10-22 10:10:01 -030017 EncEc256 = (1 << 10),
Fabio Utzigf5480c72019-11-28 10:41:57 -030018 SwapUsingMove = (1 << 11),
David Brown902d6172017-05-05 09:37:41 -060019}
20
21impl Caps {
22 pub fn present(self) -> bool {
23 let caps = unsafe { bootutil_get_caps() };
24 (caps as u32) & (self as u32) != 0
25 }
David Brown4c9883b2019-03-05 12:13:33 -070026
27 /// Query for the number of images that have been configured into this
28 /// MCUboot build.
29 pub fn get_num_images() -> usize {
30 (unsafe { bootutil_get_num_images() }) as usize
31 }
David Brown902d6172017-05-05 09:37:41 -060032}
33
34extern "C" {
35 fn bootutil_get_caps() -> Caps;
David Brown4c9883b2019-03-05 12:13:33 -070036 fn bootutil_get_num_images() -> u32;
David Brown902d6172017-05-05 09:37:41 -060037}