David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 1 | /* |
David Brown | aac7111 | 2020-02-03 16:13:42 -0700 | [diff] [blame] | 2 | * SPDX-License-Identifier: Apache-2.0 |
| 3 | * |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 4 | * Copyright (c) 2017 Linaro Limited |
Salome Thirot | 0f64197 | 2021-05-14 11:19:55 +0100 | [diff] [blame] | 5 | * Copyright (c) 2021 Arm Limited |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #include <bootutil/caps.h> |
Marti Bolivar | f91bca5 | 2018-04-12 12:40:46 -0400 | [diff] [blame] | 21 | #include "mcuboot_config/mcuboot_config.h" |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 22 | |
| 23 | uint32_t bootutil_get_caps(void) |
| 24 | { |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 25 | uint32_t res = 0; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 26 | |
Fabio Utzig | 3488eef | 2017-06-12 10:25:43 -0300 | [diff] [blame] | 27 | #if defined(MCUBOOT_SIGN_RSA) |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 28 | #if MCUBOOT_SIGN_RSA_LEN == 2048 |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 29 | res |= BOOTUTIL_CAP_RSA2048; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 30 | #endif |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 31 | #if MCUBOOT_SIGN_RSA_LEN == 3072 |
| 32 | res |= BOOTUTIL_CAP_RSA3072; |
| 33 | #endif |
| 34 | #endif |
Fabio Utzig | 3488eef | 2017-06-12 10:25:43 -0300 | [diff] [blame] | 35 | #if defined(MCUBOOT_SIGN_EC) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 36 | res |= BOOTUTIL_CAP_ECDSA_P224; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 37 | #endif |
Fabio Utzig | 3488eef | 2017-06-12 10:25:43 -0300 | [diff] [blame] | 38 | #if defined(MCUBOOT_SIGN_EC256) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 39 | res |= BOOTUTIL_CAP_ECDSA_P256; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 40 | #endif |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 41 | #if defined(MCUBOOT_SIGN_ED25519) |
| 42 | res |= BOOTUTIL_CAP_ED25519; |
| 43 | #endif |
Fabio Utzig | 3488eef | 2017-06-12 10:25:43 -0300 | [diff] [blame] | 44 | #if defined(MCUBOOT_OVERWRITE_ONLY) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 45 | res |= BOOTUTIL_CAP_OVERWRITE_UPGRADE; |
Fabio Utzig | f5480c7 | 2019-11-28 10:41:57 -0300 | [diff] [blame] | 46 | #elif defined(MCUBOOT_SWAP_USING_MOVE) |
| 47 | res |= BOOTUTIL_CAP_SWAP_USING_MOVE; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 48 | #else |
Fabio Utzig | f5480c7 | 2019-11-28 10:41:57 -0300 | [diff] [blame] | 49 | res |= BOOTUTIL_CAP_SWAP_USING_SCRATCH; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 50 | #endif |
David Brown | c4a60a3 | 2019-01-11 12:27:51 -0700 | [diff] [blame] | 51 | #if defined(MCUBOOT_ENCRYPT_RSA) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 52 | res |= BOOTUTIL_CAP_ENC_RSA; |
David Brown | c4a60a3 | 2019-01-11 12:27:51 -0700 | [diff] [blame] | 53 | #endif |
| 54 | #if defined(MCUBOOT_ENCRYPT_KW) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 55 | res |= BOOTUTIL_CAP_ENC_KW; |
David Brown | c4a60a3 | 2019-01-11 12:27:51 -0700 | [diff] [blame] | 56 | #endif |
Fabio Utzig | 5ef883a | 2019-10-22 10:10:01 -0300 | [diff] [blame] | 57 | #if defined(MCUBOOT_ENCRYPT_EC256) |
| 58 | res |= BOOTUTIL_CAP_ENC_EC256; |
| 59 | #endif |
Fabio Utzig | feb6c4c | 2020-04-02 10:28:39 -0300 | [diff] [blame] | 60 | #if defined(MCUBOOT_ENCRYPT_X25519) |
| 61 | res |= BOOTUTIL_CAP_ENC_X25519; |
| 62 | #endif |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 63 | #if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT) |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 64 | res |= BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT; |
David Brown | 8d0afa7 | 2019-01-11 12:31:55 -0700 | [diff] [blame] | 65 | #endif |
David Brown | 07e1381 | 2020-01-09 11:34:58 -0700 | [diff] [blame] | 66 | #if defined(MCUBOOT_DOWNGRADE_PREVENTION) |
| 67 | res |= BOOTUTIL_CAP_DOWNGRADE_PREVENTION; |
| 68 | #endif |
Fabio Utzig | d015734 | 2020-10-02 15:22:11 -0300 | [diff] [blame] | 69 | #if defined(MCUBOOT_BOOTSTRAP) |
| 70 | res |= BOOTUTIL_CAP_BOOTSTRAP; |
| 71 | #endif |
Salome Thirot | 0f64197 | 2021-05-14 11:19:55 +0100 | [diff] [blame] | 72 | #if defined(MCUBOOT_AES_256) |
| 73 | res |= BOOTUTIL_CAP_AES256; |
| 74 | #endif |
David Brown | dcea564 | 2021-05-26 16:12:33 -0600 | [diff] [blame^] | 75 | #if defined(MCUBOOT_RAM_LOAD) |
| 76 | res |= BOOTUTIL_CAP_RAM_LOAD; |
| 77 | #endif |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 78 | |
David Brown | 74b161e | 2019-04-16 15:41:07 -0600 | [diff] [blame] | 79 | return res; |
David Brown | 902d617 | 2017-05-05 09:37:41 -0600 | [diff] [blame] | 80 | } |
David Brown | 4c9883b | 2019-03-05 12:13:33 -0700 | [diff] [blame] | 81 | |
| 82 | uint32_t bootutil_get_num_images(void) |
| 83 | { |
| 84 | #if defined(MCUBOOT_IMAGE_NUMBER) |
| 85 | return MCUBOOT_IMAGE_NUMBER; |
| 86 | #else |
| 87 | return 1; |
| 88 | #endif |
| 89 | } |