|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
extern crate cc;
|
|
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::io::{Result, Write};
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
println!("cargo:rerun-if-env-changed=LOG");
|
|
|
|
|
println!("cargo:rerun-if-env-changed=BOARD");
|
|
|
|
|
println!("cargo:rerun-if-env-changed=SFSIMG");
|
|
|
|
|
|
|
|
|
|
let arch: String = std::env::var("ARCH").unwrap();
|
|
|
|
|
let board: String = std::env::var("BOARD").unwrap();
|
|
|
|
@ -15,31 +15,14 @@ fn main() {
|
|
|
|
|
gen_vector_asm().unwrap();
|
|
|
|
|
}
|
|
|
|
|
"riscv32" => {
|
|
|
|
|
if let Ok(file_path) = gen_sfsimg_asm() {
|
|
|
|
|
cc::Build::new()
|
|
|
|
|
.file(&file_path)
|
|
|
|
|
.flag("-march=rv32imac")
|
|
|
|
|
.flag("-mabi=ilp32")
|
|
|
|
|
.compile("sfsimg");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"riscv64" => {
|
|
|
|
|
if let Ok(file_path) = gen_sfsimg_asm() {
|
|
|
|
|
cc::Build::new()
|
|
|
|
|
.file(&file_path)
|
|
|
|
|
.flag("-march=rv64imac")
|
|
|
|
|
.flag("-mabi=lp64")
|
|
|
|
|
.compile("sfsimg");
|
|
|
|
|
}
|
|
|
|
|
if board == "k210" {
|
|
|
|
|
println!("cargo:rustc-link-search=native={}", "../tools/k210");
|
|
|
|
|
println!("cargo:rustc-link-lib=static=kendryte");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"aarch64" => {
|
|
|
|
|
if let Ok(file_path) = gen_sfsimg_asm() {
|
|
|
|
|
cc::Build::new().file(&file_path).compile("sfsimg");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => panic!("Unknown arch {}", arch),
|
|
|
|
|
}
|
|
|
|
@ -68,27 +51,3 @@ fn gen_vector_asm() -> Result<()> {
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn gen_sfsimg_asm() -> Result<std::path::PathBuf> {
|
|
|
|
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
|
|
|
|
let sfsimg = std::env::var("SFSIMG").unwrap();
|
|
|
|
|
|
|
|
|
|
let file_path = Path::new(&out_dir).join("sfsimg.S");
|
|
|
|
|
let mut f = File::create(&file_path).unwrap();
|
|
|
|
|
|
|
|
|
|
write!(f, "# generated by build.rs - do not edit")?;
|
|
|
|
|
write!(f, r#"
|
|
|
|
|
.section .rodata
|
|
|
|
|
.align 12
|
|
|
|
|
.global _user_img_start
|
|
|
|
|
.global _user_img_end
|
|
|
|
|
_user_img_start:
|
|
|
|
|
.incbin "{}"
|
|
|
|
|
_user_img_end:
|
|
|
|
|
"#, sfsimg)?;
|
|
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", sfsimg);
|
|
|
|
|
println!("cargo:rerun-if-env-changed=SFSIMG");
|
|
|
|
|
|
|
|
|
|
Ok(file_path)
|
|
|
|
|
}
|
|
|
|
|