blob: 620e84f5eb7e5ee05e5973e6427109e0b94bdf3d [file] [log] [blame]
David Brown63902772017-07-12 09:47:49 -06001// Build mcuboot as a library, based on the requested features.
2
Fabio Utzig455cad52018-10-15 14:36:33 -07003extern crate cc;
David Brown63902772017-07-12 09:47:49 -06004
5use std::env;
6use std::fs;
7use std::io;
8use std::path::Path;
9
10fn main() {
11 // Feature flags.
12 let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok();
Fabio Utzig39297432019-05-08 18:51:10 -030013 let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok();
David Brown63902772017-07-12 09:47:49 -060014 let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok();
David Brown641af452021-02-19 12:16:48 -070015 let sig_ecdsa_mbedtls = env::var("CARGO_FEATURE_SIG_ECDSA_MBEDTLS").is_ok();
Fabio Utzig97710282019-05-24 17:44:49 -030016 let sig_ed25519 = env::var("CARGO_FEATURE_SIG_ED25519").is_ok();
David Brown63902772017-07-12 09:47:49 -060017 let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok();
Fabio Utzig031eb7d2019-11-28 10:13:14 -030018 let swap_move = env::var("CARGO_FEATURE_SWAP_MOVE").is_ok();
David Vincze2d736ad2019-02-18 11:50:22 +010019 let validate_primary_slot =
20 env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok();
Fabio Utzig1e48b912018-09-18 09:04:18 -030021 let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok();
22 let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok();
Fabio Utzig90f449e2019-10-24 07:43:53 -030023 let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok();
Fabio Utzig6c553d62021-05-06 19:56:18 -030024 let enc_ec256_mbedtls = env::var("CARGO_FEATURE_ENC_EC256_MBEDTLS").is_ok();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -030025 let enc_x25519 = env::var("CARGO_FEATURE_ENC_X25519").is_ok();
Fabio Utzig9b97b132018-12-18 17:21:51 -020026 let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok();
David Brown5e6f5e02019-04-04 10:50:05 +070027 let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok();
David Brown2ee5f7f2020-01-13 14:04:01 -070028 let downgrade_prevention = env::var("CARGO_FEATURE_DOWNGRADE_PREVENTION").is_ok();
David Brown63902772017-07-12 09:47:49 -060029
Fabio Utzig455cad52018-10-15 14:36:33 -070030 let mut conf = cc::Build::new();
David Brown63902772017-07-12 09:47:49 -060031 conf.define("__BOOTSIM__", None);
Fabio Utzig08fcfe92018-11-26 10:18:18 -020032 conf.define("MCUBOOT_HAVE_LOGGING", None);
David Brown63902772017-07-12 09:47:49 -060033 conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None);
Marti Bolivar248da082018-04-24 15:11:39 -040034 conf.define("MCUBOOT_HAVE_ASSERT_H", None);
Marti Bolivarf9bfddd2018-04-24 14:28:33 -040035 conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128"));
David Brown5e6f5e02019-04-04 10:50:05 +070036 conf.define("MCUBOOT_IMAGE_NUMBER", Some(if multiimage { "2" } else { "1" }));
Fabio Utzigebdc9692017-11-23 16:28:25 -020037
David Brown2ee5f7f2020-01-13 14:04:01 -070038 if downgrade_prevention && !overwrite_only {
39 panic!("Downgrade prevention requires overwrite only");
40 }
41
Fabio Utzig9b97b132018-12-18 17:21:51 -020042 if bootstrap {
43 conf.define("MCUBOOT_BOOTSTRAP", None);
Fabio Utzig3c9d5c42020-10-04 10:12:53 -030044 conf.define("MCUBOOT_OVERWRITE_ONLY_FAST", None);
Fabio Utzig9b97b132018-12-18 17:21:51 -020045 }
46
David Vincze2d736ad2019-02-18 11:50:22 +010047 if validate_primary_slot {
48 conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None);
Fabio Utzigebdc9692017-11-23 16:28:25 -020049 }
David Brown63902772017-07-12 09:47:49 -060050
David Brown2ee5f7f2020-01-13 14:04:01 -070051 if downgrade_prevention {
52 conf.define("MCUBOOT_DOWNGRADE_PREVENTION", None);
53 }
54
Fabio Utzig39297432019-05-08 18:51:10 -030055 // Currently no more than one sig type can be used simultaneously.
Fabio Utzig97710282019-05-24 17:44:49 -030056 if vec![sig_rsa, sig_rsa3072, sig_ecdsa, sig_ed25519].iter()
Fabio Utzig39297432019-05-08 18:51:10 -030057 .fold(0, |sum, &v| sum + v as i32) > 1 {
58 panic!("mcuboot does not support more than one sig type at the same time");
David Brown704ac6f2017-07-12 10:14:47 -060059 }
David Brown63902772017-07-12 09:47:49 -060060
Fabio Utzig39297432019-05-08 18:51:10 -030061 if sig_rsa || sig_rsa3072 {
David Brown63902772017-07-12 09:47:49 -060062 conf.define("MCUBOOT_SIGN_RSA", None);
Fabio Utzig39297432019-05-08 18:51:10 -030063 // The Kconfig style defines must be added here as well because
64 // they are used internally by "config-rsa.h"
65 if sig_rsa {
66 conf.define("MCUBOOT_SIGN_RSA_LEN", "2048");
Fabio Utzig46268532020-01-04 21:12:55 -030067 conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "2048");
Fabio Utzig39297432019-05-08 18:51:10 -030068 } else {
69 conf.define("MCUBOOT_SIGN_RSA_LEN", "3072");
Fabio Utzig46268532020-01-04 21:12:55 -030070 conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "3072");
Fabio Utzig39297432019-05-08 18:51:10 -030071 }
David Brown63902772017-07-12 09:47:49 -060072 conf.define("MCUBOOT_USE_MBED_TLS", None);
73
Fabio Utzige60b12f2020-02-06 07:15:30 -030074 conf.include("../../ext/mbedtls/crypto/include");
75 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzig806af0e2018-04-26 10:53:54 -030076 conf.file("csupport/keys.c");
David Brown63902772017-07-12 09:47:49 -060077
Fabio Utzige60b12f2020-02-06 07:15:30 -030078 conf.file("../../ext/mbedtls/crypto/library/rsa.c");
79 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
80 conf.file("../../ext/mbedtls/crypto/library/platform.c");
81 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
82 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
David Brown704ac6f2017-07-12 10:14:47 -060083 } else if sig_ecdsa {
Fabio Utzigc7865402017-12-05 08:50:52 -020084 conf.define("MCUBOOT_SIGN_EC256", None);
David Brown63902772017-07-12 09:47:49 -060085 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzigc7865402017-12-05 08:50:52 -020086
Fabio Utzigb4d20c82018-12-27 16:08:39 -020087 if !enc_kw {
David Brownb748f6f2019-10-11 10:07:31 -060088 conf.include("../../ext/mbedtls-asn1/include");
Fabio Utzigb4d20c82018-12-27 16:08:39 -020089 }
Fabio Utzigc7865402017-12-05 08:50:52 -020090 conf.include("../../ext/tinycrypt/lib/include");
91
Fabio Utzig806af0e2018-04-26 10:53:54 -030092 conf.file("csupport/keys.c");
Fabio Utzigc7865402017-12-05 08:50:52 -020093
94 conf.file("../../ext/tinycrypt/lib/source/utils.c");
95 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
96 conf.file("../../ext/tinycrypt/lib/source/ecc.c");
97 conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c");
98 conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c");
99
David Brownb748f6f2019-10-11 10:07:31 -0600100 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
101 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
David Brown641af452021-02-19 12:16:48 -0700102 } else if sig_ecdsa_mbedtls {
103 conf.define("MCUBOOT_SIGN_EC256", None);
104 conf.define("MCUBOOT_USE_MBED_TLS", None);
105
106 conf.include("../../ext/mbedtls/crypto/include");
107 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
108 conf.file("csupport/keys.c");
109
110 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
111 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
112 conf.file("../../ext/mbedtls/crypto/library/ecdsa.c");
113 conf.file("../../ext/mbedtls/crypto/library/ecp.c");
114 conf.file("../../ext/mbedtls/crypto/library/ecp_curves.c");
115 conf.file("../../ext/mbedtls/crypto/library/platform.c");
116 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300117 } else if sig_ed25519 {
118 conf.define("MCUBOOT_SIGN_ED25519", None);
Fabio Utziga1c142d2020-01-03 08:28:11 -0300119 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzig97710282019-05-24 17:44:49 -0300120
Fabio Utziga1c142d2020-01-03 08:28:11 -0300121 conf.include("../../ext/tinycrypt/lib/include");
122 conf.include("../../ext/tinycrypt-sha512/lib/include");
123 conf.include("../../ext/mbedtls-asn1/include");
124 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
125 conf.file("../../ext/tinycrypt-sha512/lib/source/sha512.c");
126 conf.file("../../ext/tinycrypt/lib/source/utils.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300127 conf.file("csupport/keys.c");
128 conf.file("../../ext/fiat/src/curve25519.c");
Fabio Utziga1c142d2020-01-03 08:28:11 -0300129 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
130 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300131 } else if !enc_ec256 && !enc_x25519 {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300132 // No signature type, only sha256 validation. The default
Marti Bolivara4818a52018-04-12 13:02:38 -0400133 // configuration file bundled with mbedTLS is sufficient.
Fabio Utzig90f449e2019-10-24 07:43:53 -0300134 // When using ECIES-P256 rely on Tinycrypt.
David Brown704ac6f2017-07-12 10:14:47 -0600135 conf.define("MCUBOOT_USE_MBED_TLS", None);
Fabio Utzige60b12f2020-02-06 07:15:30 -0300136 conf.include("../../ext/mbedtls/crypto/include");
137 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
David Brown63902772017-07-12 09:47:49 -0600138 }
139
140 if overwrite_only {
141 conf.define("MCUBOOT_OVERWRITE_ONLY", None);
142 }
143
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300144 if swap_move {
145 conf.define("MCUBOOT_SWAP_USING_MOVE", None);
Andrzej Puzdrowski137d7972021-05-13 13:39:30 +0200146 } else if !overwrite_only {
147 conf.define("CONFIG_BOOT_SWAP_USING_SCRATCH", None);
148 conf.define("MCUBOOT_SWAP_USING_SCRATCH", None);
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300149 }
150
Fabio Utzig1e48b912018-09-18 09:04:18 -0300151 if enc_rsa {
152 conf.define("MCUBOOT_ENCRYPT_RSA", None);
153 conf.define("MCUBOOT_ENC_IMAGES", None);
154 conf.define("MCUBOOT_USE_MBED_TLS", None);
Fabio Utzig1e48b912018-09-18 09:04:18 -0300155
156 conf.file("../../boot/bootutil/src/encrypted.c");
157 conf.file("csupport/keys.c");
158
Fabio Utzige60b12f2020-02-06 07:15:30 -0300159 conf.include("../../ext/mbedtls/crypto/include");
160 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzig1e48b912018-09-18 09:04:18 -0300161
Fabio Utzige60b12f2020-02-06 07:15:30 -0300162 conf.file("../../ext/mbedtls/crypto/library/platform.c");
163 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
164 conf.file("../../ext/mbedtls/crypto/library/rsa.c");
165 conf.file("../../ext/mbedtls/crypto/library/rsa_internal.c");
166 conf.file("../../ext/mbedtls/crypto/library/md.c");
167 conf.file("../../ext/mbedtls/crypto/library/aes.c");
168 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
169 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
Fabio Utzig1e48b912018-09-18 09:04:18 -0300170 }
171
172 if enc_kw {
173 conf.define("MCUBOOT_ENCRYPT_KW", None);
174 conf.define("MCUBOOT_ENC_IMAGES", None);
Fabio Utzig1e48b912018-09-18 09:04:18 -0300175
176 conf.file("../../boot/bootutil/src/encrypted.c");
177 conf.file("csupport/keys.c");
178
Fabio Utzig39297432019-05-08 18:51:10 -0300179 if sig_rsa || sig_rsa3072 {
Fabio Utzige60b12f2020-02-06 07:15:30 -0300180 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200181 }
Fabio Utzig1e48b912018-09-18 09:04:18 -0300182
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200183 /* Simulator uses Mbed-TLS to wrap keys */
Fabio Utzige60b12f2020-02-06 07:15:30 -0300184 conf.include("../../ext/mbedtls/crypto/include");
185 conf.file("../../ext/mbedtls/crypto/library/platform.c");
186 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
187 conf.file("../../ext/mbedtls/crypto/library/nist_kw.c");
188 conf.file("../../ext/mbedtls/crypto/library/cipher.c");
189 conf.file("../../ext/mbedtls/crypto/library/cipher_wrap.c");
190 conf.file("../../ext/mbedtls/crypto/library/aes.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200191
192 if sig_ecdsa {
193 conf.define("MCUBOOT_USE_TINYCRYPT", None);
194
195 conf.include("../../ext/tinycrypt/lib/include");
196
197 conf.file("../../ext/tinycrypt/lib/source/utils.c");
198 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
199 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
200 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
Blaž Hrastnik4f4833d2020-09-14 13:53:31 +0900201 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200202 }
Fabio Utzig97710282019-05-24 17:44:49 -0300203
204 if sig_ed25519 {
205 panic!("ed25519 does not support image encryption with KW yet");
206 }
Fabio Utzig1e48b912018-09-18 09:04:18 -0300207 }
208
Fabio Utzig90f449e2019-10-24 07:43:53 -0300209 if enc_ec256 {
210 conf.define("MCUBOOT_ENCRYPT_EC256", None);
211 conf.define("MCUBOOT_ENC_IMAGES", None);
212 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzig4b4ed982020-01-06 09:09:51 -0300213 conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300214
215 conf.file("../../boot/bootutil/src/encrypted.c");
216 conf.file("csupport/keys.c");
217
218 conf.include("../../ext/mbedtls-asn1/include");
219 conf.include("../../ext/tinycrypt/lib/include");
220
221 /* FIXME: fail with other signature schemes ? */
222
223 conf.file("../../ext/tinycrypt/lib/source/utils.c");
224 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
225 conf.file("../../ext/tinycrypt/lib/source/ecc.c");
226 conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c");
227 conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c");
228
229 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
230 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
231
232 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
233 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
234 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
235 conf.file("../../ext/tinycrypt/lib/source/hmac.c");
236 conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c");
Fabio Utzig6c553d62021-05-06 19:56:18 -0300237 } else if enc_ec256_mbedtls {
238 conf.define("MCUBOOT_ENCRYPT_EC256", None);
239 conf.define("MCUBOOT_ENC_IMAGES", None);
240 conf.define("MCUBOOT_USE_MBED_TLS", None);
241 conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);
242
243 conf.include("../../ext/mbedtls/crypto/include");
244
245 conf.file("../../boot/bootutil/src/encrypted.c");
246 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
247 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
248 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
249 conf.file("../../ext/mbedtls/crypto/library/ecdh.c");
250 conf.file("../../ext/mbedtls/crypto/library/md.c");
251 conf.file("../../ext/mbedtls/crypto/library/aes.c");
252 conf.file("../../ext/mbedtls/crypto/library/ecp.c");
253 conf.file("../../ext/mbedtls/crypto/library/ecp_curves.c");
254 conf.file("../../ext/mbedtls/crypto/library/platform.c");
255 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
256 conf.file("csupport/keys.c");
Fabio Utzig90f449e2019-10-24 07:43:53 -0300257 }
258
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300259 if enc_x25519 {
260 conf.define("MCUBOOT_ENCRYPT_X25519", None);
261 conf.define("MCUBOOT_ENC_IMAGES", None);
262 conf.define("MCUBOOT_USE_TINYCRYPT", None);
263 conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);
264
265 conf.file("../../boot/bootutil/src/encrypted.c");
266 conf.file("csupport/keys.c");
267
268 conf.include("../../ext/mbedtls-asn1/include");
269 conf.include("../../ext/tinycrypt/lib/include");
270 conf.include("../../ext/tinycrypt-sha512/lib/include");
271
272 conf.file("../../ext/fiat/src/curve25519.c");
273
274 conf.file("../../ext/tinycrypt/lib/source/utils.c");
275 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
276
277 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
278 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
279
280 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
281 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
282 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
283 conf.file("../../ext/tinycrypt/lib/source/hmac.c");
284 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300285
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200286 if sig_rsa && enc_kw {
287 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>"));
Fabio Utzig39297432019-05-08 18:51:10 -0300288 } else if sig_rsa || sig_rsa3072 || enc_rsa {
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200289 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>"));
Fabio Utzig6c553d62021-05-06 19:56:18 -0300290 } else if sig_ecdsa_mbedtls || enc_ec256_mbedtls {
291 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ec.h>"));
Fabio Utzig90f449e2019-10-24 07:43:53 -0300292 } else if (sig_ecdsa || enc_ec256) && !enc_kw {
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200293 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300294 } else if sig_ed25519 || enc_x25519 {
Fabio Utziga1c142d2020-01-03 08:28:11 -0300295 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200296 } else if enc_kw {
297 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>"));
298 }
299
David Brown704ac6f2017-07-12 10:14:47 -0600300 conf.file("../../boot/bootutil/src/image_validate.c");
Fabio Utzig39297432019-05-08 18:51:10 -0300301 if sig_rsa || sig_rsa3072 {
Fabio Utzigc7865402017-12-05 08:50:52 -0200302 conf.file("../../boot/bootutil/src/image_rsa.c");
David Brown641af452021-02-19 12:16:48 -0700303 } else if sig_ecdsa || sig_ecdsa_mbedtls {
Fabio Utzigc7865402017-12-05 08:50:52 -0200304 conf.file("../../boot/bootutil/src/image_ec256.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300305 } else if sig_ed25519 {
306 conf.file("../../boot/bootutil/src/image_ed25519.c");
Fabio Utzigc7865402017-12-05 08:50:52 -0200307 }
David Brown63902772017-07-12 09:47:49 -0600308 conf.file("../../boot/bootutil/src/loader.c");
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300309 conf.file("../../boot/bootutil/src/swap_misc.c");
310 conf.file("../../boot/bootutil/src/swap_scratch.c");
311 conf.file("../../boot/bootutil/src/swap_move.c");
David Brown63902772017-07-12 09:47:49 -0600312 conf.file("../../boot/bootutil/src/caps.c");
313 conf.file("../../boot/bootutil/src/bootutil_misc.c");
Andrzej Puzdrowskif573b392020-11-10 14:35:15 +0100314 conf.file("../../boot/bootutil/src/bootutil_public.c");
Fabio Utzig61fd8882019-09-14 20:00:20 -0300315 conf.file("../../boot/bootutil/src/tlv.c");
Raef Colese8fe6cf2020-05-26 13:07:40 +0100316 conf.file("../../boot/bootutil/src/fault_injection_hardening.c");
David Brownd2b18532017-07-12 09:51:31 -0600317 conf.file("csupport/run.c");
David Brown63902772017-07-12 09:47:49 -0600318 conf.include("../../boot/bootutil/include");
Fabio Utzig57c40f72017-12-12 21:48:30 -0200319 conf.include("csupport");
Fabio Utzig9a4b9ba2018-05-07 08:31:27 -0300320 conf.include("../../boot/zephyr/include");
David Brown63902772017-07-12 09:47:49 -0600321 conf.debug(true);
322 conf.flag("-Wall");
David Brown0b693c02017-07-12 12:34:33 -0600323 conf.flag("-Werror");
David Brown63902772017-07-12 09:47:49 -0600324
Fabio Utzig0bccf9d2017-12-07 12:13:57 -0200325 // FIXME: travis-ci still uses gcc 4.8.4 which defaults to std=gnu90.
326 // It has incomplete std=c11 and std=c99 support but std=c99 was checked
327 // to build correctly so leaving it here to updated in the future...
328 conf.flag("-std=c99");
329
David Brown63902772017-07-12 09:47:49 -0600330 conf.compile("libbootutil.a");
331
332 walk_dir("../../boot").unwrap();
Fabio Utzigc7865402017-12-05 08:50:52 -0200333 walk_dir("../../ext/tinycrypt/lib/source").unwrap();
David Brownb748f6f2019-10-11 10:07:31 -0600334 walk_dir("../../ext/mbedtls-asn1").unwrap();
David Brownd2b18532017-07-12 09:51:31 -0600335 walk_dir("csupport").unwrap();
Fabio Utzige60b12f2020-02-06 07:15:30 -0300336 walk_dir("../../ext/mbedtls/crypto/include").unwrap();
337 walk_dir("../../ext/mbedtls/crypto/library").unwrap();
David Brown63902772017-07-12 09:47:49 -0600338}
339
340// Output the names of all files within a directory so that Cargo knows when to rebuild.
341fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
342 for ent in fs::read_dir(path.as_ref())? {
343 let ent = ent?;
344 let p = ent.path();
345 if p.is_dir() {
346 walk_dir(p)?;
347 } else {
348 // Note that non-utf8 names will fail.
349 let name = p.to_str().unwrap();
350 if name.ends_with(".c") || name.ends_with(".h") {
351 println!("cargo:rerun-if-changed={}", name);
352 }
353 }
354 }
355
356 Ok(())
357}