1 // Copyright (c) 2017-2021 Linaro LTD 2 // Copyright (c) 2019 JUUL Labs 3 // Copyright (c) 2019-2023 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 /* reserved (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 RamLoad = (1 << 16), 30 DirectXip = (1 << 17), 31 HwRollbackProtection = (1 << 18), 32 EcdsaP384 = (1 << 19), 33 SwapUsingOffset = (1 << 20), 34 } 35 36 impl Caps { present(self) -> bool37 pub fn present(self) -> bool { 38 let caps = unsafe { bootutil_get_caps() }; 39 (caps as u32) & (self as u32) != 0 40 } 41 42 /// Does this build have ECDSA of some type enabled for signatures. has_ecdsa() -> bool43 pub fn has_ecdsa() -> bool { 44 Caps::EcdsaP256.present() || Caps::EcdsaP384.present() 45 } 46 47 /// Query for the number of images that have been configured into this 48 /// MCUboot build. get_num_images() -> usize49 pub fn get_num_images() -> usize { 50 (unsafe { bootutil_get_num_images() }) as usize 51 } 52 53 /// Query if this configuration performs some kind of upgrade by writing to flash. modifies_flash() -> bool54 pub fn modifies_flash() -> bool { 55 // All other configurations perform upgrades by writing to flash. 56 !(Self::RamLoad.present() || Self::DirectXip.present()) 57 } 58 } 59 60 extern "C" { bootutil_get_caps() -> Caps61 fn bootutil_get_caps() -> Caps; bootutil_get_num_images() -> u3262 fn bootutil_get_num_images() -> u32; 63 } 64