diff --git a/Makefile.toml b/Makefile.toml index e192e64f..e32bcfa2 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -45,7 +45,6 @@ dependencies = ["build_rpi_baremetal","install_llvm_tools"] [tasks.build_rpi_baremetal] toolchain = "nightly" -cwd = "./rpi/" command = "cargo" args = ["build", "--release", "--target", "armv7a-none-eabihf","--package", "magenboy_rpi", "--bin", "baremetal", "-Z", "build-std=core"] dependencies = ["install_rust_src"] diff --git a/common/build.rs b/common/build.rs index 37336f5f..d2d8f4f3 100644 --- a/common/build.rs +++ b/common/build.rs @@ -1,6 +1,13 @@ use std::process::Command; fn main() { + let git_path = std::path::Path::new("../.git"); + let head_path = git_path.join("HEAD"); + let current_branch = std::fs::read_to_string(&head_path).unwrap().replace("refs: ", ""); + let current_commit_file = git_path.join(¤t_branch); + println!("cargo:rerun-if-changed={}", head_path.to_str().unwrap()); + println!("cargo:rerun-if-changed={}", current_commit_file.to_str().unwrap()); + let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output().unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); let version = env!("CARGO_PKG_VERSION"); diff --git a/rpi/.cargo/config.toml b/rpi/.cargo/config.toml deleted file mode 100644 index d93416cb..00000000 --- a/rpi/.cargo/config.toml +++ /dev/null @@ -1,5 +0,0 @@ -[target.armv7a-none-eabihf] -rustflags = [ - "-Clink-arg=--script=./rpi/src/bin/baremetal/link.ld", - "-Ctarget-feature=+virtualization" -] \ No newline at end of file diff --git a/rpi/build.rs b/rpi/build.rs index 77b0b719..ba702983 100644 --- a/rpi/build.rs +++ b/rpi/build.rs @@ -2,7 +2,6 @@ mod config{ pub const RPI_ENV_VAR_NAME:&'static str = "RPI"; pub const LD_SCRIPT_PATH:&str = "src/bin/baremetal/link.ld"; - pub const CONFIG_FILE_PATH: &str = "config.txt"; pub const CONFIG_TXT_CONTENT:&str = "# configuration for the RPI arm_64bit=0 # boot to 32 bit mode @@ -21,14 +20,33 @@ fn main(){ } #[cfg(not(feature = "os"))] { - println!("cargo:rerun-if-changed={}", config::LD_SCRIPT_PATH); + let crate_manifest_path = env!("CARGO_MANIFEST_DIR"); + let ld_script_path = std::path::Path::new(crate_manifest_path).join(config::LD_SCRIPT_PATH); + let ld_script_path = ld_script_path.to_str().unwrap(); + + println!("cargo:rerun-if-changed={}", ld_script_path); println!("cargo:rerun-if-env-changed={}", config::RPI_ENV_VAR_NAME); + // Linker script + println!("cargo:rustc-link-arg-bin=baremetal={}", ld_script_path); + // Creates config.txt - std::fs::write(config::CONFIG_FILE_PATH, config::CONFIG_TXT_CONTENT).unwrap(); + let out_dir = std::env::var("OUT_DIR").unwrap(); + // Turns the out dir to the artifacts dir + let mut config_file_path = std::path::Path::new(&out_dir).to_path_buf(); + config_file_path.pop(); + config_file_path.pop(); + config_file_path.pop(); + config_file_path = config_file_path.join("config.txt"); + std::fs::write(config_file_path, config::CONFIG_TXT_CONTENT).unwrap(); // Add the cfg option `rpi` with that value of the env var `RPI` - let rpi_revision = std::env::var(config::RPI_ENV_VAR_NAME).expect("RPI env must be set"); - println!("cargo:rustc-cfg=rpi=\"{}\"", rpi_revision); + let rpi_version = std::env::var(config::RPI_ENV_VAR_NAME) + .expect(std::format!("{} env must be set", config::RPI_ENV_VAR_NAME).as_str()); + println!("cargo:rustc-cfg=rpi=\"{}\"", rpi_version); + + // Silent warnings for this cfg + println!("cargo::rustc-check-cfg=cfg(rpi, values(\"4\", \"2\"))"); + println!("cargo::rustc-check-cfg=cfg(rpi)"); } } \ No newline at end of file diff --git a/rpi/src/bin/baremetal/boot_armv7a.s b/rpi/src/bin/baremetal/boot_armv7a.s index 13cce3d0..2877268d 100644 --- a/rpi/src/bin/baremetal/boot_armv7a.s +++ b/rpi/src/bin/baremetal/boot_armv7a.s @@ -1,3 +1,7 @@ +// Enabling all the features of the cortex-a72, currently rust has a bug preventing enabling with rustc +// For more see - https://github.com/rust-lang/rust/issues/127269 +.cpu cortex-a72 + // alias the PERIPHERALS_BASE_ADDRESS symbol at pointer // since it is a static global variable from the rust side .equ PERIPHERALS_BASE_ADDRESS_PTR, PERIPHERALS_BASE_ADDRESS