blob: 32feba5baa8c1d6f232b5fe416118510b69f1b4d [file] [log] [blame]
David Brownc8d62012021-10-27 15:03:48 -06001// Copyright (c) 2017-2021 Linaro LTD
David Browne2acfae2020-01-21 16:45:01 -07002// Copyright (c) 2019 JUUL Labs
Salome Thirot6fdbf552021-05-14 16:46:14 +01003// Copyright (c) 2019-2021 Arm Limited
David Browne2acfae2020-01-21 16:45:01 -07004//
5// SPDX-License-Identifier: Apache-2.0
6
David Brown902d6172017-05-05 09:37:41 -06007// Query the bootloader's capabilities.
8
9#[repr(u32)]
Fabio Utzigf5480c72019-11-28 10:41:57 -030010#[derive(Copy, Clone, Debug, Eq, PartialEq)]
David Brown902d6172017-05-05 09:37:41 -060011#[allow(unused)]
12pub enum Caps {
David Vincze2d736ad2019-02-18 11:50:22 +010013 RSA2048 = (1 << 0),
14 EcdsaP224 = (1 << 1),
15 EcdsaP256 = (1 << 2),
Fabio Utzigf5480c72019-11-28 10:41:57 -030016 SwapUsingScratch = (1 << 3),
David Vincze2d736ad2019-02-18 11:50:22 +010017 OverwriteUpgrade = (1 << 4),
18 EncRsa = (1 << 5),
19 EncKw = (1 << 6),
20 ValidatePrimarySlot = (1 << 7),
Fabio Utzig39297432019-05-08 18:51:10 -030021 RSA3072 = (1 << 8),
Fabio Utzig97710282019-05-24 17:44:49 -030022 Ed25519 = (1 << 9),
Fabio Utzig5ef883a2019-10-22 10:10:01 -030023 EncEc256 = (1 << 10),
Fabio Utzigf5480c72019-11-28 10:41:57 -030024 SwapUsingMove = (1 << 11),
David Brown2ee5f7f2020-01-13 14:04:01 -070025 DowngradePrevention = (1 << 12),
Fabio Utzigfeb6c4c2020-04-02 10:28:39 -030026 EncX25519 = (1 << 13),
Fabio Utzigd0157342020-10-02 15:22:11 -030027 Bootstrap = (1 << 14),
Salome Thirot6fdbf552021-05-14 16:46:14 +010028 Aes256 = (1 << 15),
David Browndcea5642021-05-26 16:12:33 -060029 RamLoad = (1 << 16),
David Brown812a84b2021-05-26 17:10:01 -060030 DirectXip = (1 << 17),
David Brown902d6172017-05-05 09:37:41 -060031}
32
33impl Caps {
34 pub fn present(self) -> bool {
35 let caps = unsafe { bootutil_get_caps() };
36 (caps as u32) & (self as u32) != 0
37 }
David Brown4c9883b2019-03-05 12:13:33 -070038
David Brownb408b432021-10-27 15:55:39 -060039 /// Does this build have ECDSA of some type enabled for signatures.
40 pub fn has_ecdsa() -> bool {
41 Caps::EcdsaP256.present() || Caps::EcdsaP224.present()
42 }
43
David Brown4c9883b2019-03-05 12:13:33 -070044 /// Query for the number of images that have been configured into this
45 /// MCUboot build.
46 pub fn get_num_images() -> usize {
47 (unsafe { bootutil_get_num_images() }) as usize
48 }
David Browndcea5642021-05-26 16:12:33 -060049
50 /// Query if this configuration performs some kind of upgrade by writing to flash.
51 pub fn modifies_flash() -> bool {
52 // All other configurations perform upgrades by writing to flash.
David Brown812a84b2021-05-26 17:10:01 -060053 !(Self::RamLoad.present() || Self::DirectXip.present())
David Browndcea5642021-05-26 16:12:33 -060054 }
David Brown902d6172017-05-05 09:37:41 -060055}
56
57extern "C" {
58 fn bootutil_get_caps() -> Caps;
David Brown4c9883b2019-03-05 12:13:33 -070059 fn bootutil_get_num_images() -> u32;
David Brown902d6172017-05-05 09:37:41 -060060}