Skip to content

Commit

Permalink
examples: Reuse TA linker script provided via TA devkit
Browse files Browse the repository at this point in the history
Having copies of TA linker scripts for every TA written in rust isn't
scalable and prone to version skews with the linker script provided by
TA devkit. And we would like to build and run TAs with different OP-TEE
versions. So lets reuse linker script provided by TA devkit and therby
drop copies from every TA direcetory.

Signed-off-by: Sumit Garg <[email protected]>
  • Loading branch information
b49020 committed Dec 21, 2023
1 parent 76b6fa5 commit dfe3b49
Show file tree
Hide file tree
Showing 52 changed files with 442 additions and 2,418 deletions.
31 changes: 28 additions & 3 deletions examples/acipher-rs/ta/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use proto;
use std::env;
use std::fs::File;
use std::io::Write;
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
use uuid::Uuid;

Expand All @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> {
}};",
time_low, time_mid, time_hi_and_version, clock_seq_and_node
)?;

let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string());
let optee_os_path = &PathBuf::from(optee_os_dir.clone());
let search_path = match env::var("ARCH") {
Ok(ref v) if v == "arm" => {
File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?;
let mut ta_lds = File::create(out.join("ta.lds"))?;
let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?;
let f = BufReader::new(f);

write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?;
write!(ta_lds, "OUTPUT_ARCH(arm)\n")?;
for line in f.lines() {
write!(ta_lds, "{}\n", line?)?;
}
Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib")
},
_ => {
File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?;
let mut ta_lds = File::create(out.join("ta.lds"))?;
let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?;
let f = BufReader::new(f);

write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?;
write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?;
for line in f.lines() {
let l = line?;

if l == "\t. = ALIGN(4096);" {
write!(ta_lds, "\t. = ALIGN(65536);\n")?;
} else {
write!(ta_lds, "{}\n", l)?;
}
}
Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib")
}
};
Expand All @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> {
println!("cargo:rustc-link-arg=-pie");
println!("cargo:rustc-link-arg=-Os");
println!("cargo:rustc-link-arg=--sort-section=alignment");
println!("cargo:rustc-link-arg=--dynamic-list=dyn_list");
Ok(())
}
6 changes: 6 additions & 0 deletions examples/acipher-rs/ta/dyn_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
__elf_phdr_info;
trace_ext_prefix;
trace_level;
ta_head;
};
92 changes: 0 additions & 92 deletions examples/acipher-rs/ta/ta_aarch64.lds

This file was deleted.

91 changes: 0 additions & 91 deletions examples/acipher-rs/ta/ta_arm.lds

This file was deleted.

31 changes: 28 additions & 3 deletions examples/aes-rs/ta/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use proto;
use std::env;
use std::fs::File;
use std::io::Write;
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
use uuid::Uuid;

Expand All @@ -42,14 +42,38 @@ fn main() -> std::io::Result<()> {
}};",
time_low, time_mid, time_hi_and_version, clock_seq_and_node
)?;

let optee_os_dir = env::var("OPTEE_OS_DIR").unwrap_or("../../../optee/optee_os".to_string());
let optee_os_path = &PathBuf::from(optee_os_dir.clone());
let search_path = match env::var("ARCH") {
Ok(ref v) if v == "arm" => {
File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_arm.lds"))?;
let mut ta_lds = File::create(out.join("ta.lds"))?;
let f = File::open(optee_os_path.join("out/arm/export-ta_arm32/src/ta.ld.S"))?;
let f = BufReader::new(f);

write!(ta_lds, "OUTPUT_FORMAT(\"elf32-littlearm\")\n")?;
write!(ta_lds, "OUTPUT_ARCH(arm)\n")?;
for line in f.lines() {
write!(ta_lds, "{}\n", line?)?;
}
Path::new(&optee_os_dir).join("out/arm/export-ta_arm32/lib")
},
_ => {
File::create(out.join("ta.lds"))?.write_all(include_bytes!("ta_aarch64.lds"))?;
let mut ta_lds = File::create(out.join("ta.lds"))?;
let f = File::open(optee_os_path.join("out/arm/export-ta_arm64/src/ta.ld.S"))?;
let f = BufReader::new(f);

write!(ta_lds, "OUTPUT_FORMAT(\"elf64-littleaarch64\")\n")?;
write!(ta_lds, "OUTPUT_ARCH(aarch64)\n")?;
for line in f.lines() {
let l = line?;

if l == "\t. = ALIGN(4096);" {
write!(ta_lds, "\t. = ALIGN(65536);\n")?;
} else {
write!(ta_lds, "{}\n", l)?;
}
}
Path::new(&optee_os_dir).join("out/arm/export-ta_arm64/lib")
}
};
Expand All @@ -64,5 +88,6 @@ fn main() -> std::io::Result<()> {
println!("cargo:rustc-link-arg=-pie");
println!("cargo:rustc-link-arg=-Os");
println!("cargo:rustc-link-arg=--sort-section=alignment");
println!("cargo:rustc-link-arg=--dynamic-list=dyn_list");
Ok(())
}
6 changes: 6 additions & 0 deletions examples/aes-rs/ta/dyn_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
__elf_phdr_info;
trace_ext_prefix;
trace_level;
ta_head;
};
Loading

0 comments on commit dfe3b49

Please sign in to comment.