mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
de6b29ab9d
This CL adds a "tpm" Cargo cfg to crosvm which enables a TPM device backed by libtpm2 simulator. Tested by running the following inside cros_sdk: LIBRARY_PATH=~/src/minijail LD_LIBRARY_PATH=~/src/minijail \ cargo run --release \ --features tpm \ -- \ run \ -r rootfs.ext4 \ --seccomp-policy-dir seccomp/x86_64/ \ -p init=/bin/bash \ -p panic=-1 \ --disable-sandbox \ vmlinux.bin with a Linux image built from CL:1387655. The TPM self test completes successfully with the following output: https://paste.googleplex.com/5996075978588160?raw Justin's TPM playground runs with the following trace output. https://paste.googleplex.com/4909751007707136?raw Design doc: go/vtpm-for-glinux TEST=ran TPM playground program inside crosvm TEST=local kokoro BUG=chromium:911799 Change-Id: I2feb24a3e38cba91f62c6d2cd1f378de4dd03ecf Reviewed-on: https://chromium-review.googlesource.com/1387624 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use std::env;
|
|
use std::io;
|
|
use std::path::Path;
|
|
use std::process::{self, Command};
|
|
|
|
fn main() -> io::Result<()> {
|
|
if pkg_config::Config::new()
|
|
.statik(true)
|
|
.probe("libtpm2")
|
|
.is_ok()
|
|
{
|
|
// Use tpm2 package from the standard system location if available.
|
|
return Ok(());
|
|
}
|
|
|
|
// Build with `RUSTFLAGS='--cfg hermetic'` to disallow building our own
|
|
// libtpm2 in a production build context. Building from the libtpm2
|
|
// submodule is a convenience only intended for developer environments.
|
|
if cfg!(hermetic) {
|
|
eprintln!("libtpm2 not found; unable to perform hermetic build");
|
|
process::exit(1);
|
|
}
|
|
|
|
if !Path::new("libtpm2/.git").exists() {
|
|
Command::new("git")
|
|
.args(&["submodule", "update", "--init"])
|
|
.status()?;
|
|
}
|
|
|
|
if !Path::new("libtpm2/build/libtpm2.a").exists() {
|
|
let ncpu = num_cpus::get();
|
|
let status = Command::new("make")
|
|
.arg(format!("-j{}", ncpu))
|
|
.current_dir("libtpm2")
|
|
.status()?;
|
|
if !status.success() {
|
|
process::exit(status.code().unwrap_or(1));
|
|
}
|
|
}
|
|
|
|
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
println!("cargo:rustc-link-search={}/libtpm2/build", dir);
|
|
println!("cargo:rustc-link-lib=static=tpm2");
|
|
println!("cargo:rustc-link-lib=ssl");
|
|
println!("cargo:rustc-link-lib=crypto");
|
|
Ok(())
|
|
}
|