blob: 56b57915afe350a6a5f36ae2c88258987b3ebaea [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
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <bootutil/caps.h>
Marti Bolivarf91bca52018-04-12 12:40:46 -040020#include "mcuboot_config/mcuboot_config.h"
David Brown902d6172017-05-05 09:37:41 -060021
22uint32_t bootutil_get_caps(void)
23{
David Brown74b161e2019-04-16 15:41:07 -060024 uint32_t res = 0;
David Brown902d6172017-05-05 09:37:41 -060025
Fabio Utzig3488eef2017-06-12 10:25:43 -030026#if defined(MCUBOOT_SIGN_RSA)
Fabio Utzig39297432019-05-08 18:51:10 -030027#if MCUBOOT_SIGN_RSA_LEN == 2048
David Brown74b161e2019-04-16 15:41:07 -060028 res |= BOOTUTIL_CAP_RSA2048;
David Brown902d6172017-05-05 09:37:41 -060029#endif
Fabio Utzig39297432019-05-08 18:51:10 -030030#if MCUBOOT_SIGN_RSA_LEN == 3072
31 res |= BOOTUTIL_CAP_RSA3072;
32#endif
33#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030034#if defined(MCUBOOT_SIGN_EC)
David Brown74b161e2019-04-16 15:41:07 -060035 res |= BOOTUTIL_CAP_ECDSA_P224;
David Brown902d6172017-05-05 09:37:41 -060036#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030037#if defined(MCUBOOT_SIGN_EC256)
David Brown74b161e2019-04-16 15:41:07 -060038 res |= BOOTUTIL_CAP_ECDSA_P256;
David Brown902d6172017-05-05 09:37:41 -060039#endif
Fabio Utzig97710282019-05-24 17:44:49 -030040#if defined(MCUBOOT_SIGN_ED25519)
41 res |= BOOTUTIL_CAP_ED25519;
42#endif
Fabio Utzig3488eef2017-06-12 10:25:43 -030043#if defined(MCUBOOT_OVERWRITE_ONLY)
David Brown74b161e2019-04-16 15:41:07 -060044 res |= BOOTUTIL_CAP_OVERWRITE_UPGRADE;
Fabio Utzigf5480c72019-11-28 10:41:57 -030045#elif defined(MCUBOOT_SWAP_USING_MOVE)
46 res |= BOOTUTIL_CAP_SWAP_USING_MOVE;
David Brown902d6172017-05-05 09:37:41 -060047#else
Fabio Utzigf5480c72019-11-28 10:41:57 -030048 res |= BOOTUTIL_CAP_SWAP_USING_SCRATCH;
David Brown902d6172017-05-05 09:37:41 -060049#endif
David Brownc4a60a32019-01-11 12:27:51 -070050#if defined(MCUBOOT_ENCRYPT_RSA)
David Brown74b161e2019-04-16 15:41:07 -060051 res |= BOOTUTIL_CAP_ENC_RSA;
David Brownc4a60a32019-01-11 12:27:51 -070052#endif
53#if defined(MCUBOOT_ENCRYPT_KW)
David Brown74b161e2019-04-16 15:41:07 -060054 res |= BOOTUTIL_CAP_ENC_KW;
David Brownc4a60a32019-01-11 12:27:51 -070055#endif
Fabio Utzig5ef883a2019-10-22 10:10:01 -030056#if defined(MCUBOOT_ENCRYPT_EC256)
57 res |= BOOTUTIL_CAP_ENC_EC256;
58#endif
Fabio Utzigfeb6c4c2020-04-02 10:28:39 -030059#if defined(MCUBOOT_ENCRYPT_X25519)
60 res |= BOOTUTIL_CAP_ENC_X25519;
61#endif
David Vincze2d736ad2019-02-18 11:50:22 +010062#if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT)
David Brown74b161e2019-04-16 15:41:07 -060063 res |= BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT;
David Brown8d0afa72019-01-11 12:31:55 -070064#endif
David Brown07e13812020-01-09 11:34:58 -070065#if defined(MCUBOOT_DOWNGRADE_PREVENTION)
66 res |= BOOTUTIL_CAP_DOWNGRADE_PREVENTION;
67#endif
David Brown902d6172017-05-05 09:37:41 -060068
David Brown74b161e2019-04-16 15:41:07 -060069 return res;
David Brown902d6172017-05-05 09:37:41 -060070}
David Brown4c9883b2019-03-05 12:13:33 -070071
72uint32_t bootutil_get_num_images(void)
73{
74#if defined(MCUBOOT_IMAGE_NUMBER)
75 return MCUBOOT_IMAGE_NUMBER;
76#else
77 return 1;
78#endif
79}