|
@@ -18,6 +18,9 @@ pub struct PrototyperArg {
|
|
|
|
|
|
#[clap(long, env = "PROTOTYPER_PAYLOAD_PATH")]
|
|
|
pub payload: Option<String>,
|
|
|
+
|
|
|
+ #[clap(long, default_value = "INFO")]
|
|
|
+ pub log_level: String,
|
|
|
}
|
|
|
|
|
|
#[must_use]
|
|
@@ -34,58 +37,64 @@ pub fn run(arg: &PrototyperArg) -> Option<ExitStatus> {
|
|
|
.join(arch)
|
|
|
.join("release");
|
|
|
|
|
|
- let status = cargo::Cargo::new("build")
|
|
|
+ info!("Building Protoyper");
|
|
|
+ cargo::Cargo::new("build")
|
|
|
.package("rustsbi-prototyper")
|
|
|
.target(arch)
|
|
|
.unstable("build-std", ["core"])
|
|
|
.env("RUSTFLAGS", "-C relocation-model=pie -C link-arg=-pie")
|
|
|
.features(&arg.features)
|
|
|
.optional(arg.fdt.is_some(), |cargo| {
|
|
|
- export_env!("PROTOTYPER_FDT_PATH" ?= fdt.unwrap());
|
|
|
+ cargo.env("PROTOTYPER_FDT_PATH", fdt.as_ref().unwrap());
|
|
|
cargo.features(["fdt".to_string()])
|
|
|
})
|
|
|
.optional(payload.is_some(), |cargo| {
|
|
|
- export_env!("PROTOTYPER_PAYLOAD_PATH" ?= payload.unwrap());
|
|
|
+ cargo.env("PROTOTYPER_PAYLOAD_PATH", payload.as_ref().unwrap());
|
|
|
cargo.features(["payload".to_string()])
|
|
|
})
|
|
|
+ .env("RUST_LOG", &arg.log_level)
|
|
|
.release()
|
|
|
.status()
|
|
|
.ok()?;
|
|
|
|
|
|
- if status.success() {
|
|
|
- let exit_status = Command::new("rust-objcopy")
|
|
|
- .args(["-O", "binary"])
|
|
|
- .arg("--binary-architecture=riscv64")
|
|
|
- .arg(target_dir.join("rustsbi-prototyper"))
|
|
|
- .arg(target_dir.join("rustsbi-prototyper.bin"))
|
|
|
- .status()
|
|
|
- .ok()?;
|
|
|
-
|
|
|
- if arg.payload.is_some() {
|
|
|
- fs::copy(
|
|
|
- target_dir.join("rustsbi-prototyper"),
|
|
|
- target_dir.join("rustsbi-prototyper-payload.elf"),
|
|
|
- )
|
|
|
- .ok()?;
|
|
|
- fs::copy(
|
|
|
- target_dir.join("rustsbi-prototyper.bin"),
|
|
|
- target_dir.join("rustsbi-prototyper-payload.bin"),
|
|
|
- )
|
|
|
- .ok()?;
|
|
|
- } else {
|
|
|
- fs::copy(
|
|
|
- target_dir.join("rustsbi-prototyper"),
|
|
|
- target_dir.join("rustsbi-prototyper-dynamic.elf"),
|
|
|
- )
|
|
|
- .ok()?;
|
|
|
- fs::copy(
|
|
|
- target_dir.join("rustsbi-prototyper.bin"),
|
|
|
- target_dir.join("rustsbi-prototyper-dynamic.bin"),
|
|
|
- ).ok()?;
|
|
|
- }
|
|
|
+ info!("Copy to binary");
|
|
|
+ let exit_status = Command::new("rust-objcopy")
|
|
|
+ .args(["-O", "binary"])
|
|
|
+ .arg("--binary-architecture=riscv64")
|
|
|
+ .arg(target_dir.join("rustsbi-prototyper"))
|
|
|
+ .arg(target_dir.join("rustsbi-prototyper.bin"))
|
|
|
+ .status()
|
|
|
+ .ok()?;
|
|
|
+ if !exit_status.success() {
|
|
|
+ error!("Failed to exec rust-objcopy, please check if cargo-binutils has been installed?");
|
|
|
return Some(exit_status);
|
|
|
+ }
|
|
|
+
|
|
|
+ if arg.payload.is_some() {
|
|
|
+ info!("Copy for payload mode");
|
|
|
+ fs::copy(
|
|
|
+ target_dir.join("rustsbi-prototyper"),
|
|
|
+ target_dir.join("rustsbi-prototyper-payload.elf"),
|
|
|
+ )
|
|
|
+ .ok()?;
|
|
|
+ fs::copy(
|
|
|
+ target_dir.join("rustsbi-prototyper.bin"),
|
|
|
+ target_dir.join("rustsbi-prototyper-payload.bin"),
|
|
|
+ )
|
|
|
+ .ok()?;
|
|
|
} else {
|
|
|
- eprintln!("Build failed with status: {:?}", status);
|
|
|
- return Some(status);
|
|
|
+ info!("Copy for dynamic mode");
|
|
|
+ fs::copy(
|
|
|
+ target_dir.join("rustsbi-prototyper"),
|
|
|
+ target_dir.join("rustsbi-prototyper-dynamic.elf"),
|
|
|
+ )
|
|
|
+ .ok()?;
|
|
|
+ fs::copy(
|
|
|
+ target_dir.join("rustsbi-prototyper.bin"),
|
|
|
+ target_dir.join("rustsbi-prototyper-dynamic.bin"),
|
|
|
+ )
|
|
|
+ .ok()?;
|
|
|
}
|
|
|
+
|
|
|
+ Some(exit_status)
|
|
|
}
|