blob: d8dd068ec37841e6e85587abd6a53aaf3810d424 [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
Roland Mikhel75c7c312023-02-23 15:39:14 +01003// Copyright (c) 2019-2023 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),
Roland Mikhel23fdb0d2023-06-30 15:26:02 +020014 /* 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),
Roland Mikhel5899fac2023-03-14 13:59:55 +010032 EcdsaP384 = (1 << 19),
David Brown902d6172017-05-05 09:37:41 -060033}
34
35impl Caps {
36 pub fn present(self) -> bool {
37 let caps = unsafe { bootutil_get_caps() };
38 (caps as u32) & (self as u32) != 0
39 }
David Brown4c9883b2019-03-05 12:13:33 -070040
David Brownb408b432021-10-27 15:55:39 -060041 /// Does this build have ECDSA of some type enabled for signatures.
42 pub fn has_ecdsa() -> bool {
Roland Mikhel5899fac2023-03-14 13:59:55 +010043 Caps::EcdsaP256.present() || Caps::EcdsaP384.present()
David Brownb408b432021-10-27 15:55:39 -060044 }
45
David Brown4c9883b2019-03-05 12:13:33 -070046 /// Query for the number of images that have been configured into this
47 /// MCUboot build.
48 pub fn get_num_images() -> usize {
49 (unsafe { bootutil_get_num_images() }) as usize
50 }
David Browndcea5642021-05-26 16:12:33 -060051
52 /// Query if this configuration performs some kind of upgrade by writing to flash.
53 pub fn modifies_flash() -> bool {
54 // All other configurations perform upgrades by writing to flash.
David Brown812a84b2021-05-26 17:10:01 -060055 !(Self::RamLoad.present() || Self::DirectXip.present())
David Browndcea5642021-05-26 16:12:33 -060056 }
David Brown902d6172017-05-05 09:37:41 -060057}
58
59extern "C" {
60 fn bootutil_get_caps() -> Caps;
David Brown4c9883b2019-03-05 12:13:33 -070061 fn bootutil_get_num_images() -> u32;
David Brown902d6172017-05-05 09:37:41 -060062}