Skip to content

Commit

Permalink
Fix build of the rpi baremetal target (#150)
Browse files Browse the repository at this point in the history
The problem was this bug in rust/llvm - rust-lang/rust#127269

- Fix the git version not updating when the common is not rebuilt by setting it to rebuild upon git head changing.
- Delete .cargo/config.toml and replace it with build script to make it simpler
- Move the config.txt output to the artifacts folder
  • Loading branch information
alloncm authored Dec 19, 2024
1 parent aad0702 commit 2bcf0d5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
1 change: 0 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 7 additions & 0 deletions common/build.rs
Original file line number Diff line number Diff line change
@@ -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(&current_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");
Expand Down
5 changes: 0 additions & 5 deletions rpi/.cargo/config.toml

This file was deleted.

28 changes: 23 additions & 5 deletions rpi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)");
}
}
4 changes: 4 additions & 0 deletions rpi/src/bin/baremetal/boot_armv7a.s
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2bcf0d5

Please sign in to comment.