loader: add asm binary and ix build script to pick ARM asm and link.x

This commit is contained in:
eupn 2023-03-09 20:13:28 +04:00
parent 1867f6cf1a
commit 306fdee180
No known key found for this signature in database
GPG key ID: 0BBE77FB42014014
3 changed files with 36 additions and 3 deletions

Binary file not shown.

15
loader/bin/assemble.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2023 Foundation Devices, Inc <hello@foundationdevices.com>
# SPDX-License-Identifier: Apache-2.0
set -euxo pipefail
rm -f arm*.a
crate=loader
arm-none-eabi-gcc -ggdb3 -mfpu=vfpv4-d16 -mfloat-abi=hard -c -march=armv7-a ../src/platform/atsama5d27/asm.S -o $crate.o
ar crs armv7a-unknown-xous-elf.a $crate.o
rm $crate.o

View file

@ -8,15 +8,33 @@ fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let target = env::var("TARGET").unwrap();
if target.starts_with("riscv") {
let linker_file_path = if target.starts_with("riscv") {
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rustc-link-arg=-Tlink.x");
}
PathBuf::from("link.x")
} else if target.starts_with("armv7a") {
let name = env::var("CARGO_PKG_NAME").unwrap();
fs::copy(
format!("bin/{}.a", target),
out_dir.join(format!("lib{}.a", name)),
).expect("copy arm assembly binary");
println!("cargo:rustc-link-lib=static={}", name);
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rerun-if-changed=bin/{}.a", target);
println!("cargo:rustc-link-arg=-Tlink.x");
PathBuf::from("src/platform/atsama5d27/link.x")
} else {
unreachable!("unsupported target");
};
// Put the linker script somewhere the linker can find it
fs::File::create(out_dir.join("link.x"))
.unwrap()
.write_all(include_bytes!("link.x"))
.write_all(fs::read_to_string(linker_file_path).expect("linker file read").as_bytes())
.unwrap();
println!("cargo:rustc-link-search={}", out_dir.display());