1 // Copyright (c) 2017-2019 Linaro LTD
2 // Copyright (c) 2019 JUUL Labs
3 // Copyright (c) 2019-2021 Arm Limited
4 //
5 // SPDX-License-Identifier: Apache-2.0
6 
7 // Query the bootloader's capabilities.
8 
9 #[repr(u32)]
10 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
11 #[allow(unused)]
12 pub enum Caps {
13     RSA2048              = (1 << 0),
14     EcdsaP224            = (1 << 1),
15     EcdsaP256            = (1 << 2),
16     SwapUsingScratch     = (1 << 3),
17     OverwriteUpgrade     = (1 << 4),
18     EncRsa               = (1 << 5),
19     EncKw                = (1 << 6),
20     ValidatePrimarySlot  = (1 << 7),
21     RSA3072              = (1 << 8),
22     Ed25519              = (1 << 9),
23     EncEc256             = (1 << 10),
24     SwapUsingMove        = (1 << 11),
25     DowngradePrevention  = (1 << 12),
26     EncX25519            = (1 << 13),
27     Bootstrap            = (1 << 14),
28     Aes256               = (1 << 15),
29 }
30 
31 impl Caps {
present(self) -> bool32     pub fn present(self) -> bool {
33         let caps = unsafe { bootutil_get_caps() };
34         (caps as u32) & (self as u32) != 0
35     }
36 
37     /// Query for the number of images that have been configured into this
38     /// MCUboot build.
get_num_images() -> usize39     pub fn get_num_images() -> usize {
40         (unsafe { bootutil_get_num_images() }) as usize
41     }
42 }
43 
44 extern "C" {
bootutil_get_caps() -> Caps45     fn bootutil_get_caps() -> Caps;
bootutil_get_num_images() -> u3246     fn bootutil_get_num_images() -> u32;
47 }
48