blob: a63a3438bfc3c4f1f921966a1e7a3ce084e627a4 [file] [log] [blame]
David Browne2acfae2020-01-21 16:45:01 -07001// Copyright (c) 2017-2019 Linaro LTD
2// Copyright (c) 2019 JUUL Labs
3// Copyright (c) 2019 Arm Limited
4//
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 Brown902d6172017-05-05 09:37:41 -060025}
26
27impl Caps {
28 pub fn present(self) -> bool {
29 let caps = unsafe { bootutil_get_caps() };
30 (caps as u32) & (self as u32) != 0
31 }
David Brown4c9883b2019-03-05 12:13:33 -070032
33 /// Query for the number of images that have been configured into this
34 /// MCUboot build.
35 pub fn get_num_images() -> usize {
36 (unsafe { bootutil_get_num_images() }) as usize
37 }
David Brown902d6172017-05-05 09:37:41 -060038}
39
40extern "C" {
41 fn bootutil_get_caps() -> Caps;
David Brown4c9883b2019-03-05 12:13:33 -070042 fn bootutil_get_num_images() -> u32;
David Brown902d6172017-05-05 09:37:41 -060043}