Commit 6390277f authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Naive move of binding into mcuboot-sys

Create a crate `mcuboot-sys` to hold the building and binding of the
mcuboot code.  There aren't any substantive code changes here, just
moving the code into a separate crate.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 7e701d8c
Loading
Loading
Loading
Loading
+11
Changes for sim/Cargo.lock: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ dependencies = [
 "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "mcuboot-sys 0.1.0",
 "pem 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -171,6 +172,16 @@ name = "log"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "mcuboot-sys"
version = "0.1.0"
dependencies = [
 "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "simflash 0.1.0",
]

[[package]]
name = "memchr"
version = "0.1.11"
+1 −1
Changes for sim/Cargo.toml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
name = "bootsim"
version = "0.1.0"
authors = ["David Brown <davidb@davidb.org>"]
build = "build.rs"

[build-dependencies]
gcc = "0.3.38"
@@ -15,6 +14,7 @@ rustc-serialize = "0.3"
log = "0.3"
env_logger = "0.3"
simflash = { path = "simflash" }
mcuboot-sys = { path = "mcuboot-sys", features = ["sig-rsa"] }
bitflags = "0.9"
ring = { version = "0.11", features = ["rsa_signing"] }
untrusted = "0.5"
+1
Changes for sim/mcuboot-sys/.gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
Cargo.lock
+34
Changes for sim/mcuboot-sys/Cargo.toml: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
[package]
name = "mcuboot-sys"
version = "0.1.0"
authors = ["David Brown <david.brown@linaro.org>"]
description = "A simple wrapper around the mcuboot code."
build = "build.rs"
publish = false

[features]
# By default, build with simplistic signature verification.
default = []

# Verify RSA signatures.  Note that at this time, the C code will not
# compile with both sig-rsa and sig-ecdsa enabled.
sig-rsa = []

# Verify ECDSA signatures.
sig-ecdsa = []

# Overwrite only upgrade
overwrite-only = []

[build-dependencies]
gcc = "0.3.51"

[dependencies]
libc = "0.2.0"
log = "0.3"
simflash = { path = "../simflash" }

# Optimize some, even when building for debugging, otherwise the tests
# are too slow.
[profile.test]
opt-level = 1
+51 −28
Changes for sim/mcuboot-sys/build.rs: 51 added lines, 28 removed lines.
Original line number Diff line number Diff line
// Build the library.
// Build mcuboot as a library, based on the requested features.

extern crate gcc;

use std::env;
use std::fs;
use std::io;
use std::path::Path;

fn main() {
    let mut conf = gcc::Config::new();
    // Feature flags.
    let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok();
    let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok();
    let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok();

    conf.file("../boot/bootutil/src/loader.c");
    conf.file("../boot/bootutil/src/caps.c");
    conf.file("../boot/bootutil/src/bootutil_misc.c");
    conf.file("../boot/bootutil/src/image_validate.c");
    conf.file("../boot/bootutil/src/image_rsa.c");
    conf.file("../boot/zephyr/keys.c");
    conf.file("csupport/run.c");
    conf.include("../boot/bootutil/include");
    conf.include("../boot/zephyr/include");
    conf.debug(true);
    conf.flag("-Wall");
    // TODO: Force clang if we are requestion fuzzing.

    let mut conf = gcc::Config::new();
    conf.define("__BOOTSIM__", None);
    // conf.define("MCUBOOT_OVERWRITE_ONLY", None);
    conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None);
    conf.define("MCUBOOT_VALIDATE_SLOT0", None);

    if sig_rsa {
        if sig_ecdsa {
            panic!("mcuboot does not support RSA and ECDSA at the same time");
        }

        conf.define("MCUBOOT_SIGN_RSA", None);
        conf.define("MCUBOOT_USE_MBED_TLS", None);

        conf.file("../../boot/bootutil/src/image_validate.c");
        conf.file("../../boot/bootutil/src/image_rsa.c");
        conf.file("../../boot/zephyr/keys.c");

    // Bring in some pieces of mbedtls we need.
        conf.define("MCUBOOT_USE_MBED_TLS", None);
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-boot.h>"));
    conf.include("mbedtls/include");
    conf.file("mbedtls/library/sha256.c");
        conf.include("../mbedtls/include");
        conf.file("../mbedtls/library/sha256.c");

    // Code for RSA.
    conf.file("mbedtls/library/rsa.c");
    conf.file("mbedtls/library/bignum.c");
    conf.file("mbedtls/library/asn1parse.c");
        conf.file("../mbedtls/library/rsa.c");
        conf.file("../mbedtls/library/bignum.c");
        conf.file("../mbedtls/library/asn1parse.c");
    }
    if sig_ecdsa {
        conf.define("MCUBOOT_SIGN_ECDSA", None);
        conf.define("MCUBOOT_USE_TINYCRYPT", None);
        // TODO: Compile files + tinycrypt.
        panic!("ECDSA not yet implemented in sim");
    }

    // Test that signature/hashes are present.
    conf.define("MCUBOOT_VALIDATE_SLOT0", None);
    conf.define("MCUBOOT_SIGN_RSA", None);
    if overwrite_only {
        conf.define("MCUBOOT_OVERWRITE_ONLY", None);
    }

    conf.file("../../boot/bootutil/src/loader.c");
    conf.file("../../boot/bootutil/src/caps.c");
    conf.file("../../boot/bootutil/src/bootutil_misc.c");
    conf.file("../csupport/run.c");
    conf.include("../../boot/bootutil/include");
    conf.include("../../boot/zephyr/include");
    conf.debug(true);
    conf.flag("-Wall");

    conf.compile("libbootutil.a");
    walk_dir("../boot").unwrap();
    walk_dir("csupport").unwrap();
    walk_dir("mbedtls/include").unwrap();
    walk_dir("mbedtls/library").unwrap();

    walk_dir("../../boot").unwrap();
    walk_dir("../csupport").unwrap();
    walk_dir("../mbedtls/include").unwrap();
    walk_dir("../mbedtls/library").unwrap();
}

// Output the names of all files within a directory so that Cargo knows when to rebuild.
Loading