1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 16:36:18 +04:00
rCore/bootloader/build.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

2019-03-05 20:46:01 +04:00
extern crate cc;
use std::fs::File;
use std::io::{Result, Write};
use std::path::Path;
fn main() {
if let Ok(file_path) = gen_payload_asm() {
cc::Build::new().file(&file_path).compile("payload");
}
}
/// include payload and dtb in sections of asm
2019-03-05 20:46:01 +04:00
fn gen_payload_asm() -> Result<std::path::PathBuf> {
let out_dir = std::env::var("OUT_DIR").unwrap();
let payload = std::env::var("PAYLOAD").unwrap();
let dtb = std::env::var("DTB").unwrap();
2019-03-05 20:46:01 +04:00
if !Path::new(&payload).is_file() {
panic!("Kernel payload `{}` not found", payload)
}
let mut has_dtb = true;
if !Path::new(&dtb).is_file() {
has_dtb = false;
}
2019-03-05 20:46:01 +04:00
let file_path = Path::new(&out_dir).join("payload.S");
let mut f = File::create(&file_path).unwrap();
println!("{:x?} {:x?}", payload, file_path);
write!(f, "# generated by build.rs - do not edit")?;
write!(f, r#"
.section .payload,"a"
2019-03-05 20:46:01 +04:00
.align 12
.global _kernel_payload_start, _kernel_payload_end
_kernel_payload_start:
.incbin "{}"
_kernel_payload_end:
"#, payload)?;
2019-03-05 20:46:01 +04:00
println!("cargo:rerun-if-changed={}", payload);
println!("cargo:rerun-if-env-changed=PAYLOAD");
if has_dtb {
write!(f, r#"
.section .dtb,"a"
.align 12
.global _dtb_start, _dtb_end
_dtb_start:
.incbin "{}"
_dtb_end:
"#, dtb)?;
println!("{:x?} {:x?}", dtb, file_path);
println!("cargo:rerun-if-changed={}", dtb);
println!("cargo:rerun-if-env-changed=DTB");
}
2019-03-05 20:46:01 +04:00
Ok(file_path)
}