blob: 4944f463bb126c16397d2a7dd3c369069d01a2fe [file] [log] [blame]
David Brown902d6172017-05-05 09:37:41 -06001/*
David Brownaac71112020-02-03 16:13:42 -07002 * SPDX-License-Identifier: Apache-2.0
3 *
David Brown902d6172017-05-05 09:37:41 -06004 * Copyright (c) 2017 Linaro Limited
Roman Okhrimenko977b3752022-03-31 14:40:48 +03005 * Copyright (c) 2021 Arm Limited
David Brown902d6172017-05-05 09:37:41 -06006 *
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 Bolivarf91bca52018-04-12 12:40:46 -040021#include "mcuboot_config/mcuboot_config.h"
David Brown902d6172017-05-05 09:37:41 -060022
23uint32_t bootutil_get_caps(void)
24{
David Brown74b161e2019-04-16 15:41:07 -060025 uint32_t res = 0;
David Brown902d6172017-05-05 09:37:41 -060026
Fabio Utzig3488eef2017-06-12 10:25:43 -030027#if defined(MCUBOOT_SIGN_RSA)
Fabio Utzig39297432019-05-08 18:51:10 -030028#if MCUBOOT_SIGN_RSA_LEN == 2048
David Brown74b161e2019-04-16 15:41:07 -060029 res |= BOOTUTIL_CAP_RSA2048;
David Brown902d6172017-05-05 09:37:41 -060030#endif
Fabio Utzig39297432019-05-08 18:51:10 -030031#if MCUBOOT_SIGN_RSA_LEN == 3072
32 res |= BOOTUTIL_CAP_RSA3072;
33#endif
34#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030035#if defined(MCUBOOT_SIGN_EC)
David Brown74b161e2019-04-16 15:41:07 -060036 res |= BOOTUTIL_CAP_ECDSA_P224;
David Brown902d6172017-05-05 09:37:41 -060037#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030038#if defined(MCUBOOT_SIGN_EC256)
David Brown74b161e2019-04-16 15:41:07 -060039 res |= BOOTUTIL_CAP_ECDSA_P256;
David Brown902d6172017-05-05 09:37:41 -060040#endif
Fabio Utzig97710282019-05-24 17:44:49 -030041#if defined(MCUBOOT_SIGN_ED25519)
42 res |= BOOTUTIL_CAP_ED25519;
43#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030044#if defined(MCUBOOT_OVERWRITE_ONLY)
David Brown74b161e2019-04-16 15:41:07 -060045 res |= BOOTUTIL_CAP_OVERWRITE_UPGRADE;
Fabio Utzigf5480c72019-11-28 10:41:57 -030046#elif defined(MCUBOOT_SWAP_USING_MOVE)
47 res |= BOOTUTIL_CAP_SWAP_USING_MOVE;
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020048#elif defined(MCUBOOT_SWAP_USING_STATUS)
49 res |= BOOTUTIL_CAP_SWAP_USING_STATUS;
David Brown902d6172017-05-05 09:37:41 -060050#else
Fabio Utzigf5480c72019-11-28 10:41:57 -030051 res |= BOOTUTIL_CAP_SWAP_USING_SCRATCH;
David Brown902d6172017-05-05 09:37:41 -060052#endif
David Brownc4a60a32019-01-11 12:27:51 -070053#if defined(MCUBOOT_ENCRYPT_RSA)
David Brown74b161e2019-04-16 15:41:07 -060054 res |= BOOTUTIL_CAP_ENC_RSA;
David Brownc4a60a32019-01-11 12:27:51 -070055#endif
56#if defined(MCUBOOT_ENCRYPT_KW)
David Brown74b161e2019-04-16 15:41:07 -060057 res |= BOOTUTIL_CAP_ENC_KW;
David Brownc4a60a32019-01-11 12:27:51 -070058#endif
Fabio Utzig5ef883a2019-10-22 10:10:01 -030059#if defined(MCUBOOT_ENCRYPT_EC256)
60 res |= BOOTUTIL_CAP_ENC_EC256;
61#endif
Fabio Utzigfeb6c4c2020-04-02 10:28:39 -030062#if defined(MCUBOOT_ENCRYPT_X25519)
63 res |= BOOTUTIL_CAP_ENC_X25519;
64#endif
David Vincze2d736ad2019-02-18 11:50:22 +010065#if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT)
David Brown74b161e2019-04-16 15:41:07 -060066 res |= BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT;
David Brown8d0afa72019-01-11 12:31:55 -070067#endif
David Brown07e13812020-01-09 11:34:58 -070068#if defined(MCUBOOT_DOWNGRADE_PREVENTION)
69 res |= BOOTUTIL_CAP_DOWNGRADE_PREVENTION;
70#endif
Fabio Utzigd0157342020-10-02 15:22:11 -030071#if defined(MCUBOOT_BOOTSTRAP)
72 res |= BOOTUTIL_CAP_BOOTSTRAP;
73#endif
Roman Okhrimenko977b3752022-03-31 14:40:48 +030074#if defined(MCUBOOT_AES_256)
75 res |= BOOTUTIL_CAP_AES256;
76#endif
77#if defined(MCUBOOT_RAM_LOAD)
78 res |= BOOTUTIL_CAP_RAM_LOAD;
79#endif
80#if defined(MCUBOOT_DIRECT_XIP)
81 res |= BOOTUTIL_CAP_DIRECT_XIP;
82#endif
David Brown902d6172017-05-05 09:37:41 -060083
David Brown74b161e2019-04-16 15:41:07 -060084 return res;
David Brown902d6172017-05-05 09:37:41 -060085}
David Brown4c9883b2019-03-05 12:13:33 -070086
87uint32_t bootutil_get_num_images(void)
88{
89#if defined(MCUBOOT_IMAGE_NUMBER)
90 return MCUBOOT_IMAGE_NUMBER;
91#else
92 return 1;
93#endif
94}