David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 1 | // Build mcuboot as a library, based on the requested features. |
| 2 | |
Fabio Utzig | 455cad5 | 2018-10-15 14:36:33 -0700 | [diff] [blame] | 3 | extern crate cc; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 4 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 5 | use std::collections::BTreeSet; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 6 | use std::env; |
| 7 | use std::fs; |
| 8 | use std::io; |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 9 | use std::path::{Path, PathBuf}; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 10 | |
| 11 | fn main() { |
| 12 | // Feature flags. |
Matthew Dalzell | 34d5a69 | 2023-06-28 09:41:39 +0100 | [diff] [blame] | 13 | let psa_crypto_api = env::var("CARGO_FEATURE_PSA_CRYPTO_API").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 14 | let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok(); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 15 | let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 16 | let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok(); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 17 | let sig_ecdsa_mbedtls = env::var("CARGO_FEATURE_SIG_ECDSA_MBEDTLS").is_ok(); |
Roland Mikhel | 5899fac | 2023-03-14 13:59:55 +0100 | [diff] [blame] | 18 | let sig_ecdsa_psa = env::var("CARGO_FEATURE_SIG_ECDSA_PSA").is_ok(); |
| 19 | let sig_p384 = env::var("CARGO_FEATURE_SIG_P384").is_ok(); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 20 | let sig_ed25519 = env::var("CARGO_FEATURE_SIG_ED25519").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 21 | let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok(); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 22 | let swap_move = env::var("CARGO_FEATURE_SWAP_MOVE").is_ok(); |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 23 | let validate_primary_slot = |
| 24 | env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok(); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 25 | let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok(); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 26 | let enc_aes256_rsa = env::var("CARGO_FEATURE_ENC_AES256_RSA").is_ok(); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 27 | let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok(); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 28 | let enc_aes256_kw = env::var("CARGO_FEATURE_ENC_AES256_KW").is_ok(); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 29 | let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok(); |
Fabio Utzig | 6c553d6 | 2021-05-06 19:56:18 -0300 | [diff] [blame] | 30 | let enc_ec256_mbedtls = env::var("CARGO_FEATURE_ENC_EC256_MBEDTLS").is_ok(); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 31 | let enc_aes256_ec256 = env::var("CARGO_FEATURE_ENC_AES256_EC256").is_ok(); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 32 | let enc_x25519 = env::var("CARGO_FEATURE_ENC_X25519").is_ok(); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 33 | let enc_aes256_x25519 = env::var("CARGO_FEATURE_ENC_AES256_X25519").is_ok(); |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 34 | let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok(); |
David Brown | 5e6f5e0 | 2019-04-04 10:50:05 +0700 | [diff] [blame] | 35 | let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok(); |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 36 | let downgrade_prevention = env::var("CARGO_FEATURE_DOWNGRADE_PREVENTION").is_ok(); |
David Brown | 7e377ab | 2021-05-26 16:33:39 -0600 | [diff] [blame] | 37 | let ram_load = env::var("CARGO_FEATURE_RAM_LOAD").is_ok(); |
David Brown | 11ffa0a | 2021-05-26 17:10:47 -0600 | [diff] [blame] | 38 | let direct_xip = env::var("CARGO_FEATURE_DIRECT_XIP").is_ok(); |
David Brown | 1bc106e | 2021-12-16 13:23:52 -0700 | [diff] [blame] | 39 | let max_align_32 = env::var("CARGO_FEATURE_MAX_ALIGN_32").is_ok(); |
Roland Mikhel | d670352 | 2023-04-27 14:24:30 +0200 | [diff] [blame] | 40 | let hw_rollback_protection = env::var("CARGO_FEATURE_HW_ROLLBACK_PROTECTION").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 41 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 42 | let mut conf = CachedBuild::new(); |
| 43 | conf.conf.define("__BOOTSIM__", None); |
| 44 | conf.conf.define("MCUBOOT_HAVE_LOGGING", None); |
| 45 | conf.conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None); |
| 46 | conf.conf.define("MCUBOOT_HAVE_ASSERT_H", None); |
| 47 | conf.conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128")); |
Gustavo Henrique Nihei | 7bfd14b | 2021-11-24 23:27:22 -0300 | [diff] [blame] | 48 | |
David Brown | 1bc106e | 2021-12-16 13:23:52 -0700 | [diff] [blame] | 49 | if max_align_32 { |
| 50 | conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("32")); |
| 51 | } else { |
| 52 | conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("8")); |
| 53 | } |
Gustavo Henrique Nihei | 7bfd14b | 2021-11-24 23:27:22 -0300 | [diff] [blame] | 54 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 55 | conf.conf.define("MCUBOOT_IMAGE_NUMBER", Some(if multiimage { "2" } else { "1" })); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 56 | |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 57 | if downgrade_prevention && !overwrite_only { |
| 58 | panic!("Downgrade prevention requires overwrite only"); |
| 59 | } |
| 60 | |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 61 | if bootstrap { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 62 | conf.conf.define("MCUBOOT_BOOTSTRAP", None); |
| 63 | conf.conf.define("MCUBOOT_OVERWRITE_ONLY_FAST", None); |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 64 | } |
| 65 | |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 66 | if validate_primary_slot { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 67 | conf.conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 68 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 69 | |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 70 | if downgrade_prevention { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 71 | conf.conf.define("MCUBOOT_DOWNGRADE_PREVENTION", None); |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 72 | } |
| 73 | |
David Brown | 7e377ab | 2021-05-26 16:33:39 -0600 | [diff] [blame] | 74 | if ram_load { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 75 | conf.conf.define("MCUBOOT_RAM_LOAD", None); |
David Brown | 7e377ab | 2021-05-26 16:33:39 -0600 | [diff] [blame] | 76 | } |
| 77 | |
David Brown | 11ffa0a | 2021-05-26 17:10:47 -0600 | [diff] [blame] | 78 | if direct_xip { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 79 | conf.conf.define("MCUBOOT_DIRECT_XIP", None); |
David Brown | 11ffa0a | 2021-05-26 17:10:47 -0600 | [diff] [blame] | 80 | } |
| 81 | |
Roland Mikhel | d670352 | 2023-04-27 14:24:30 +0200 | [diff] [blame] | 82 | if hw_rollback_protection { |
| 83 | conf.conf.define("MCUBOOT_HW_ROLLBACK_PROT", None); |
| 84 | conf.file("csupport/security_cnt.c"); |
| 85 | } |
| 86 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 87 | // Currently no more than one sig type can be used simultaneously. |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 88 | if vec![sig_rsa, sig_rsa3072, sig_ecdsa, sig_ed25519].iter() |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 89 | .fold(0, |sum, &v| sum + v as i32) > 1 { |
| 90 | panic!("mcuboot does not support more than one sig type at the same time"); |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 91 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 92 | |
Matthew Dalzell | 34d5a69 | 2023-06-28 09:41:39 +0100 | [diff] [blame] | 93 | if psa_crypto_api { |
| 94 | if sig_ecdsa || enc_ec256 || enc_x25519 || |
| 95 | enc_aes256_ec256 || sig_ecdsa_mbedtls || enc_aes256_x25519 || |
| 96 | enc_kw || enc_aes256_kw { |
| 97 | conf.file("csupport/psa_crypto_init_stub.c"); |
| 98 | } else { |
| 99 | conf.conf.define("MCUBOOT_USE_PSA_CRYPTO", None); |
| 100 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 101 | conf.file("../../ext/mbedtls/library/aesni.c"); |
| 102 | conf.file("../../ext/mbedtls/library/aria.c"); |
| 103 | conf.file("../../ext/mbedtls/library/asn1write.c"); |
| 104 | conf.file("../../ext/mbedtls/library/base64.c"); |
| 105 | conf.file("../../ext/mbedtls/library/camellia.c"); |
| 106 | conf.file("../../ext/mbedtls/library/ccm.c"); |
| 107 | conf.file("../../ext/mbedtls/library/chacha20.c"); |
| 108 | conf.file("../../ext/mbedtls/library/chachapoly.c"); |
| 109 | conf.file("../../ext/mbedtls/library/cipher.c"); |
| 110 | conf.file("../../ext/mbedtls/library/cipher_wrap.c"); |
| 111 | conf.file("../../ext/mbedtls/library/ctr_drbg.c"); |
| 112 | conf.file("../../ext/mbedtls/library/des.c"); |
| 113 | conf.file("../../ext/mbedtls/library/ecdsa.c"); |
| 114 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 115 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 116 | conf.file("../../ext/mbedtls/library/entropy.c"); |
| 117 | conf.file("../../ext/mbedtls/library/entropy_poll.c"); |
| 118 | conf.file("../../ext/mbedtls/library/gcm.c"); |
| 119 | conf.file("../../ext/mbedtls/library/md5.c"); |
| 120 | conf.file("../../ext/mbedtls/library/nist_kw.c"); |
| 121 | conf.file("../../ext/mbedtls/library/oid.c"); |
| 122 | conf.file("../../ext/mbedtls/library/pem.c"); |
| 123 | conf.file("../../ext/mbedtls/library/pk.c"); |
| 124 | conf.file("../../ext/mbedtls/library/pkcs5.c"); |
| 125 | conf.file("../../ext/mbedtls/library/pkcs12.c"); |
| 126 | conf.file("../../ext/mbedtls/library/pkparse.c"); |
| 127 | conf.file("../../ext/mbedtls/library/pk_wrap.c"); |
| 128 | conf.file("../../ext/mbedtls/library/pkwrite.c"); |
| 129 | conf.file("../../ext/mbedtls/library/poly1305.c"); |
| 130 | conf.file("../../ext/mbedtls/library/psa_crypto.c"); |
| 131 | conf.file("../../ext/mbedtls/library/psa_crypto_cipher.c"); |
| 132 | conf.file("../../ext/mbedtls/library/psa_crypto_client.c"); |
| 133 | conf.file("../../ext/mbedtls/library/psa_crypto_driver_wrappers.c"); |
| 134 | conf.file("../../ext/mbedtls/library/psa_crypto_ecp.c"); |
| 135 | conf.file("../../ext/mbedtls/library/psa_crypto_hash.c"); |
| 136 | conf.file("../../ext/mbedtls/library/psa_crypto_mac.c"); |
| 137 | conf.file("../../ext/mbedtls/library/psa_crypto_rsa.c"); |
| 138 | conf.file("../../ext/mbedtls/library/psa_crypto_slot_management.c"); |
| 139 | conf.file("../../ext/mbedtls/library/psa_crypto_storage.c"); |
| 140 | conf.file("../../ext/mbedtls/library/psa_its_file.c"); |
| 141 | conf.file("../../ext/mbedtls/library/ripemd160.c"); |
| 142 | conf.file("../../ext/mbedtls/library/rsa_alt_helpers.c"); |
| 143 | conf.file("../../ext/mbedtls/library/sha1.c"); |
| 144 | conf.file("../../ext/mbedtls/library/sha512.c"); |
| 145 | conf.file("../../ext/mbedtls/tests/src/random.c"); |
| 146 | conf.conf.include("../../ext/mbedtls/library"); |
| 147 | } |
| 148 | |
| 149 | conf.conf.include("../../ext/mbedtls/tests/include/"); |
| 150 | conf.file("../../ext/mbedtls/tests/src/fake_external_rng_for_test.c"); |
| 151 | } |
| 152 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 153 | if sig_rsa || sig_rsa3072 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 154 | conf.conf.define("MCUBOOT_SIGN_RSA", None); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 155 | // The Kconfig style defines must be added here as well because |
| 156 | // they are used internally by "config-rsa.h" |
| 157 | if sig_rsa { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 158 | conf.conf.define("MCUBOOT_SIGN_RSA_LEN", "2048"); |
| 159 | conf.conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "2048"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 160 | } else { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 161 | conf.conf.define("MCUBOOT_SIGN_RSA_LEN", "3072"); |
| 162 | conf.conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "3072"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 163 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 164 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 165 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 166 | conf.conf.include("../../ext/mbedtls/include"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 167 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 168 | conf.file("csupport/keys.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 169 | |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 170 | conf.file("../../ext/mbedtls/library/rsa.c"); |
| 171 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 172 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 173 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 174 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Antonio de Angelis | 02bf072 | 2022-11-22 15:35:43 +0000 | [diff] [blame] | 175 | conf.file("../../ext/mbedtls/library/md.c"); |
| 176 | |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 177 | } else if sig_ecdsa { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 178 | conf.conf.define("MCUBOOT_SIGN_EC256", None); |
| 179 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 180 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 181 | if !enc_kw { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 182 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 183 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 184 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 185 | |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 186 | conf.file("csupport/keys.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 187 | |
| 188 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 189 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 190 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 191 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 192 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 193 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 194 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 195 | } else if sig_ecdsa_mbedtls { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 196 | conf.conf.define("MCUBOOT_SIGN_EC256", None); |
| 197 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 198 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 199 | conf.conf.include("../../ext/mbedtls/include"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 200 | conf.file("../../ext/mbedtls/library/sha256.c"); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 201 | conf.file("csupport/keys.c"); |
| 202 | |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 203 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 204 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 205 | conf.file("../../ext/mbedtls/library/ecdsa.c"); |
| 206 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 207 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 208 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 209 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
Roland Mikhel | 5899fac | 2023-03-14 13:59:55 +0100 | [diff] [blame] | 210 | } else if sig_ecdsa_psa { |
| 211 | conf.conf.include("../../ext/mbedtls/include"); |
| 212 | |
| 213 | if sig_p384 { |
| 214 | conf.conf.define("MCUBOOT_SIGN_EC384", None); |
| 215 | conf.file("../../ext/mbedtls/library/sha512.c"); |
| 216 | } else { |
| 217 | conf.conf.define("MCUBOOT_SIGN_EC256", None); |
| 218 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 219 | } |
| 220 | |
| 221 | conf.file("csupport/keys.c"); |
| 222 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 223 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 224 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 225 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 226 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 227 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 228 | } else if sig_ed25519 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 229 | conf.conf.define("MCUBOOT_SIGN_ED25519", None); |
| 230 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 231 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 232 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
| 233 | conf.conf.include("../../ext/tinycrypt-sha512/lib/include"); |
| 234 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | a1c142d | 2020-01-03 08:28:11 -0300 | [diff] [blame] | 235 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 236 | conf.file("../../ext/tinycrypt-sha512/lib/source/sha512.c"); |
| 237 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 238 | conf.file("csupport/keys.c"); |
| 239 | conf.file("../../ext/fiat/src/curve25519.c"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 240 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 241 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 242 | } else if !enc_ec256 && !enc_x25519 { |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 243 | // No signature type, only sha256 validation. The default |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 244 | // configuration file bundled with mbedTLS is sufficient. |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 245 | // When using ECIES-P256 rely on Tinycrypt. |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 246 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 247 | conf.conf.include("../../ext/mbedtls/include"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 248 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 249 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if overwrite_only { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 253 | conf.conf.define("MCUBOOT_OVERWRITE_ONLY", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 254 | } |
| 255 | |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 256 | if swap_move { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 257 | conf.conf.define("MCUBOOT_SWAP_USING_MOVE", None); |
Thomas Altenbach | 60806bc | 2024-05-02 14:56:21 +0200 | [diff] [blame] | 258 | } else if !overwrite_only && !direct_xip && !ram_load { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 259 | conf.conf.define("CONFIG_BOOT_SWAP_USING_SCRATCH", None); |
| 260 | conf.conf.define("MCUBOOT_SWAP_USING_SCRATCH", None); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 261 | } |
| 262 | |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 263 | if enc_rsa || enc_aes256_rsa { |
| 264 | if enc_aes256_rsa { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 265 | conf.conf.define("MCUBOOT_AES_256", None); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 266 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 267 | conf.conf.define("MCUBOOT_ENCRYPT_RSA", None); |
| 268 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 269 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 270 | |
| 271 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 272 | conf.file("csupport/keys.c"); |
| 273 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 274 | conf.conf.include("../../ext/mbedtls/include"); |
| 275 | conf.conf.include("../../ext/mbedtls/library"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 276 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 277 | |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 278 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 279 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 280 | conf.file("../../ext/mbedtls/library/rsa.c"); |
| 281 | conf.file("../../ext/mbedtls/library/rsa_alt_helpers.c"); |
| 282 | conf.file("../../ext/mbedtls/library/md.c"); |
| 283 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 284 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 285 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 286 | } |
| 287 | |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 288 | if enc_kw || enc_aes256_kw { |
| 289 | if enc_aes256_kw { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 290 | conf.conf.define("MCUBOOT_AES_256", None); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 291 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 292 | conf.conf.define("MCUBOOT_ENCRYPT_KW", None); |
| 293 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 294 | |
| 295 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 296 | conf.file("csupport/keys.c"); |
| 297 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 298 | if sig_rsa || sig_rsa3072 { |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 299 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 300 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 301 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 302 | /* Simulator uses Mbed-TLS to wrap keys */ |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 303 | conf.conf.include("../../ext/mbedtls/include"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 304 | conf.file("../../ext/mbedtls/library/platform.c"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 305 | conf.conf.include("../../ext/mbedtls/library"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 306 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 307 | conf.file("../../ext/mbedtls/library/nist_kw.c"); |
| 308 | conf.file("../../ext/mbedtls/library/cipher.c"); |
| 309 | conf.file("../../ext/mbedtls/library/cipher_wrap.c"); |
| 310 | conf.file("../../ext/mbedtls/library/aes.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 311 | |
| 312 | if sig_ecdsa { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 313 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 314 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 315 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 316 | |
| 317 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 318 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 319 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 320 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
Blaž Hrastnik | 4f4833d | 2020-09-14 13:53:31 +0900 | [diff] [blame] | 321 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 322 | } |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 323 | |
| 324 | if sig_ed25519 { |
| 325 | panic!("ed25519 does not support image encryption with KW yet"); |
| 326 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 327 | } |
| 328 | |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 329 | if enc_ec256 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 330 | conf.conf.define("MCUBOOT_ENCRYPT_EC256", None); |
| 331 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 332 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 333 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 334 | |
| 335 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 336 | conf.file("csupport/keys.c"); |
| 337 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 338 | conf.conf.include("../../ext/mbedtls/include"); |
| 339 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 340 | |
| 341 | /* FIXME: fail with other signature schemes ? */ |
| 342 | |
| 343 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 344 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 345 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 346 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 347 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
| 348 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 349 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 350 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 351 | |
| 352 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 353 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 354 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
| 355 | conf.file("../../ext/tinycrypt/lib/source/hmac.c"); |
| 356 | conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c"); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 357 | } else if enc_ec256_mbedtls || enc_aes256_ec256 { |
| 358 | if enc_aes256_ec256 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 359 | conf.conf.define("MCUBOOT_AES_256", None); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 360 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 361 | conf.conf.define("MCUBOOT_ENCRYPT_EC256", None); |
| 362 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 363 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 364 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Fabio Utzig | 6c553d6 | 2021-05-06 19:56:18 -0300 | [diff] [blame] | 365 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 366 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | 6c553d6 | 2021-05-06 19:56:18 -0300 | [diff] [blame] | 367 | |
| 368 | conf.file("../../boot/bootutil/src/encrypted.c"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 369 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 370 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 371 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 372 | conf.file("../../ext/mbedtls/library/ecdh.c"); |
| 373 | conf.file("../../ext/mbedtls/library/md.c"); |
| 374 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 375 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 376 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 377 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 378 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
Fabio Utzig | 6c553d6 | 2021-05-06 19:56:18 -0300 | [diff] [blame] | 379 | conf.file("csupport/keys.c"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 380 | } |
| 381 | |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 382 | if enc_x25519 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 383 | conf.conf.define("MCUBOOT_ENCRYPT_X25519", None); |
| 384 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 385 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 386 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 387 | |
| 388 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 389 | conf.file("csupport/keys.c"); |
| 390 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 391 | conf.conf.include("../../ext/mbedtls/include"); |
| 392 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
| 393 | conf.conf.include("../../ext/tinycrypt-sha512/lib/include"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 394 | |
| 395 | conf.file("../../ext/fiat/src/curve25519.c"); |
| 396 | |
| 397 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 398 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 399 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 400 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 401 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 402 | |
| 403 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 404 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 405 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
| 406 | conf.file("../../ext/tinycrypt/lib/source/hmac.c"); |
| 407 | } |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 408 | |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 409 | else if enc_aes256_x25519 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 410 | conf.conf.define("MCUBOOT_AES_256", None); |
| 411 | conf.conf.define("MCUBOOT_ENCRYPT_X25519", None); |
| 412 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 413 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 414 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 415 | |
| 416 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 417 | conf.file("csupport/keys.c"); |
| 418 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 419 | conf.conf.include("../../ext/mbedtls/include"); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 420 | conf.file("../../ext/fiat/src/curve25519.c"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 421 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 422 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 423 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 424 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 425 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 426 | conf.file("../../ext/mbedtls/library/md.c"); |
| 427 | conf.file("../../ext/mbedtls/library/sha512.c"); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Fabio Utzig | 251ef1d | 2018-12-18 17:20:19 -0200 | [diff] [blame] | 430 | if sig_rsa && enc_kw { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 431 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>")); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 432 | } else if sig_rsa || sig_rsa3072 || enc_rsa || enc_aes256_rsa { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 433 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>")); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 434 | } else if sig_ecdsa_mbedtls || enc_ec256_mbedtls || enc_aes256_ec256 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 435 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ec.h>")); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 436 | } else if (sig_ecdsa || enc_ec256) && !enc_kw { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 437 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>")); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 438 | } else if sig_ed25519 || enc_x25519 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 439 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>")); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 440 | } else if enc_kw || enc_aes256_kw { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 441 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>")); |
Salome Thirot | 6fdbf55 | 2021-05-14 16:46:14 +0100 | [diff] [blame] | 442 | } else if enc_aes256_x25519 { |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 443 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ed25519.h>")); |
Roland Mikhel | 5899fac | 2023-03-14 13:59:55 +0100 | [diff] [blame] | 444 | } else if sig_ecdsa_psa { |
| 445 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ec-psa.h>")); |
Fabio Utzig | 04fd63e | 2018-12-14 06:43:31 -0200 | [diff] [blame] | 446 | } |
| 447 | |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 448 | conf.file("../../boot/bootutil/src/image_validate.c"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 449 | if sig_rsa || sig_rsa3072 { |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 450 | conf.file("../../boot/bootutil/src/image_rsa.c"); |
Roland Mikhel | 5899fac | 2023-03-14 13:59:55 +0100 | [diff] [blame] | 451 | } else if sig_ecdsa || sig_ecdsa_mbedtls || sig_ecdsa_psa { |
Antonio de Angelis | 10529d3 | 2023-04-21 21:43:14 +0100 | [diff] [blame] | 452 | conf.file("../../boot/bootutil/src/image_ecdsa.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 453 | } else if sig_ed25519 { |
| 454 | conf.file("../../boot/bootutil/src/image_ed25519.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 455 | } |
Roland Mikhel | 5899fac | 2023-03-14 13:59:55 +0100 | [diff] [blame] | 456 | |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 457 | conf.file("../../boot/bootutil/src/loader.c"); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 458 | conf.file("../../boot/bootutil/src/swap_misc.c"); |
| 459 | conf.file("../../boot/bootutil/src/swap_scratch.c"); |
| 460 | conf.file("../../boot/bootutil/src/swap_move.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 461 | conf.file("../../boot/bootutil/src/caps.c"); |
| 462 | conf.file("../../boot/bootutil/src/bootutil_misc.c"); |
Andrzej Puzdrowski | f573b39 | 2020-11-10 14:35:15 +0100 | [diff] [blame] | 463 | conf.file("../../boot/bootutil/src/bootutil_public.c"); |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 464 | conf.file("../../boot/bootutil/src/tlv.c"); |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 465 | conf.file("../../boot/bootutil/src/fault_injection_hardening.c"); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 466 | conf.file("csupport/run.c"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 467 | conf.conf.include("../../boot/bootutil/include"); |
| 468 | conf.conf.include("csupport"); |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 469 | conf.conf.debug(true); |
| 470 | conf.conf.flag("-Wall"); |
| 471 | conf.conf.flag("-Werror"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 472 | |
Fabio Utzig | 0bccf9d | 2017-12-07 12:13:57 -0200 | [diff] [blame] | 473 | // FIXME: travis-ci still uses gcc 4.8.4 which defaults to std=gnu90. |
| 474 | // It has incomplete std=c11 and std=c99 support but std=c99 was checked |
| 475 | // to build correctly so leaving it here to updated in the future... |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 476 | conf.conf.flag("-std=c99"); |
Fabio Utzig | 0bccf9d | 2017-12-07 12:13:57 -0200 | [diff] [blame] | 477 | |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 478 | conf.conf.compile("libbootutil.a"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 479 | |
| 480 | walk_dir("../../boot").unwrap(); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 481 | walk_dir("../../ext/tinycrypt/lib/source").unwrap(); |
David Brown | b748f6f | 2019-10-11 10:07:31 -0600 | [diff] [blame] | 482 | walk_dir("../../ext/mbedtls-asn1").unwrap(); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 483 | walk_dir("csupport").unwrap(); |
Sherry Zhang | f4580cb | 2021-07-13 22:07:31 +0800 | [diff] [blame] | 484 | walk_dir("../../ext/mbedtls/include").unwrap(); |
| 485 | walk_dir("../../ext/mbedtls/library").unwrap(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | // Output the names of all files within a directory so that Cargo knows when to rebuild. |
| 489 | fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> { |
| 490 | for ent in fs::read_dir(path.as_ref())? { |
| 491 | let ent = ent?; |
| 492 | let p = ent.path(); |
| 493 | if p.is_dir() { |
| 494 | walk_dir(p)?; |
| 495 | } else { |
| 496 | // Note that non-utf8 names will fail. |
| 497 | let name = p.to_str().unwrap(); |
| 498 | if name.ends_with(".c") || name.ends_with(".h") { |
| 499 | println!("cargo:rerun-if-changed={}", name); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | Ok(()) |
| 505 | } |
David Brown | 5f4e148 | 2021-09-16 16:44:09 -0600 | [diff] [blame] | 506 | |
| 507 | /// Wrap the cc::Build type so that we can make sure that files are only added a single time. |
| 508 | /// Other methods can be passed through as needed. |
| 509 | struct CachedBuild { |
| 510 | conf: cc::Build, |
| 511 | seen: BTreeSet<PathBuf>, |
| 512 | } |
| 513 | |
| 514 | impl CachedBuild { |
| 515 | fn new() -> CachedBuild { |
| 516 | CachedBuild { |
| 517 | conf: cc::Build::new(), |
| 518 | seen: BTreeSet::new(), |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /// Works like `file` in the Build, but doesn't add a file if the same path has already been |
| 523 | /// given. |
| 524 | fn file<P: AsRef<Path>>(&mut self, p: P) -> &mut CachedBuild { |
| 525 | let p = p.as_ref(); |
| 526 | if !self.seen.contains(p) { |
| 527 | self.conf.file(p); |
| 528 | self.seen.insert(p.to_owned()); |
| 529 | } |
| 530 | self |
| 531 | } |
| 532 | } |