Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: An effort to standardize OP-TEE rust based TAs development environment #114

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7fc7eae
optee-utee-sys: Add optional no_std feature support
b49020 Nov 23, 2023
639b420
optee-utee: Add optional no_std feature support
b49020 Dec 27, 2023
0acf835
optee-utee: Use libc_alloc as global heap allocator
b49020 Dec 27, 2023
be5fb57
optee-utee: Fix Box unused/drop warnings
b49020 Nov 23, 2023
e48f5b2
optee-utee: no_std: Add support for panic handler
b49020 Nov 24, 2023
b905f70
macros: Add no_std compatibility
b49020 Nov 24, 2023
06e6d1d
examples: std TAs: Explicitly use c_void binding
b49020 Dec 27, 2023
77368fd
examples: hello_world-rs: Switch to use #![no_std]
b49020 Nov 24, 2023
ae6f1f4
examples: acipher-rs: Switch to use #![no_std]
b49020 Nov 24, 2023
144f456
examples: aes-rs: Switch to use #![no_std]
b49020 Nov 24, 2023
cb29893
examples: authentication-rs: Switch to use #![no_std]
b49020 Nov 24, 2023
1cddd53
examples: big_int-rs: Switch to use #![no_std]
b49020 Nov 27, 2023
2af5d11
examples: diffie_hellman-rs: Switch to use #![no_std]
b49020 Nov 27, 2023
f4ee315
examples: digest-rs: Switch to use #![no_std]
b49020 Nov 27, 2023
a8b5b9d
examples: hotp-rs: Switch to use #![no_std]
b49020 Nov 27, 2023
afa14aa
examples: random-rs: Switch to use #![no_std]
b49020 Nov 27, 2023
6b30fb7
examples: secure_storage-rs: Switch to use #![no_std]
b49020 Nov 28, 2023
39ac92e
examples: signature_verification-rs: Rewrite to use GP TEE APIs
b49020 Dec 6, 2023
4f08edb
examples: time-rs: Switch to use #![no_std]
b49020 Dec 8, 2023
231c391
examples: supp_plugin-rs: Switch to use #![no_std]
b49020 Dec 8, 2023
9bcf14e
examples: tas: build.rs: Explicitly link libutils
b49020 Dec 13, 2023
3ea4831
examples: host: Fix unused crate warnings
b49020 Dec 13, 2023
99a5d19
examples: Reuse aarch64/arm host toolchain target for no_std TAs
b49020 Dec 27, 2023
d78cc1e
examples: no_std: Drop redundant Xargo.toml files
b49020 Dec 27, 2023
c2a8ba6
examples: no_std: Reuse TA linker script provided via TA devkit
b49020 Dec 21, 2023
411ba24
examples: std TAs: Add toochain override for nightly-2021-09-20
b49020 Dec 27, 2023
78cf50f
rust-toolchain.toml: Upgrade to latest nighlty release
b49020 Dec 27, 2023
36555de
CI: Build test optee-utee crate using latest nightly
b49020 Dec 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .cargo/config

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
source environment &&
make optee &&
. ~/.cargo/env &&
(cd optee-utee && xargo build --target aarch64-unknown-optee-trustzone -vv) &&
(cd optee-utee && cargo build --target aarch64-unknown-linux-gnu --no-default-features -vv) &&
(cd optee-teec && cargo build --target aarch64-unknown-linux-gnu -vv)
build-and-run-examples-in-OPTEE-repo:
runs-on: ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ ifneq ($(ARCH), arm)
VENDOR := qemu_v8.mk
AARCH_CROSS_COMPILE := $(OPTEE_PATH)/toolchains/aarch64/bin/aarch64-linux-gnu-
HOST_TARGET := aarch64-unknown-linux-gnu
TA_TARGET := aarch64-unknown-optee-trustzone
TA_TARGET := aarch64-unknown-linux-gnu
else
VENDOR := qemu.mk
ARCH_CROSS_COMPILE := $(OPTEE_PATH)/toolchains/aarch32/bin/arm-linux-gnueabihf-
HOST_TARGET := arm-unknown-linux-gnueabihf
TA_TARGET := arm-unknown-optee-trustzone
TA_TARGET := arm-unknown-linux-gnueabihf
endif

all: toolchains optee-os optee-client examples
Expand Down
2 changes: 1 addition & 1 deletion docs/debugging-optee-ta.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ D/LD: ldelf:168 ELF (133af0ca-bdab-11eb-9130-43bf7873bf67) at 0x40014000

Then, you can load symbols from TA file (in debug build) to the address.
```sh
(gdb) add-symbol-file /path/to/examples/hello_world-rs/ta/target/aarch64-unknown-optee-trustzone/debug/ta 0x40014000
(gdb) add-symbol-file /path/to/examples/hello_world-rs/ta/target/aarch64-unknown-linux-gnu/debug/ta 0x40014000
```
Now, you can add breakpoints according to your own needs in the corresponding
functions or addresses.
Expand Down
4 changes: 3 additions & 1 deletion examples/acipher-rs/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ ifeq ($(ARCH), arm)
OPTEE_BIN := $(OPTEE_DIR)/toolchains/aarch32/bin
OBJCOPY := $(OPTEE_BIN)/arm-linux-gnueabihf-objcopy
TARGET := arm-unknown-linux-gnueabihf
LINKER_CFG := target.arm-unknown-linux-gnueabihf..linker=\"arm-linux-gnueabihf-gcc\"
else
OPTEE_BIN := $(OPTEE_DIR)/toolchains/$(ARCH)/bin
OBJCOPY := $(OPTEE_BIN)/aarch64-linux-gnu-objcopy
TARGET := aarch64-unknown-linux-gnu
LINKER_CFG := target.aarch64-unknown-linux-gnu.linker=\"aarch64-linux-gnu-gcc\"
endif

OUT_DIR := $(CURDIR)/target/$(TARGET)/release
Expand All @@ -36,7 +38,7 @@ OUT_DIR := $(CURDIR)/target/$(TARGET)/release
all: host strip

host:
@cargo build --target $(TARGET) --release
@cargo build --target $(TARGET) --release --config $(LINKER_CFG)

strip:
@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/$(NAME) $(OUT_DIR)/$(NAME)
Expand Down
2 changes: 1 addition & 1 deletion examples/acipher-rs/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ edition = "2018"
[dependencies]

[build_dependencies]
uuid = { version = "0.8" }
uuid = { version = "1.6.1", default-features = false }
2 changes: 2 additions & 0 deletions examples/acipher-rs/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#![no_std]

pub enum Command {
GenKey,
GetSize,
Expand Down
105 changes: 0 additions & 105 deletions examples/acipher-rs/ta/Cargo.lock

This file was deleted.

8 changes: 4 additions & 4 deletions examples/acipher-rs/ta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ description = "An example of Rust OP-TEE TrustZone SDK."
edition = "2018"

[dependencies]
libc = { path = "../../../rust/libc" }
proto = { path = "../proto" }
optee-utee-sys = { path = "../../../optee-utee/optee-utee-sys" }
optee-utee = { path = "../../../optee-utee" }
optee-utee-sys = { path = "../../../optee-utee/optee-utee-sys", default-features = false }
optee-utee = { path = "../../../optee-utee", default-features = false }

[build_dependencies]
uuid = { version = "0.8" }
uuid = { version = "1.6.1", default-features = false }
proto = { path = "../proto" }

[profile.release]
panic = "abort"
lto = true
opt-level = 1
10 changes: 6 additions & 4 deletions examples/acipher-rs/ta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ ifeq ($(ARCH), arm)
SIGN := $(OPTEE_OS_DIR)/out/arm/export-ta_arm32/scripts/sign_encrypt.py
OPTEE_BIN := $(OPTEE_DIR)/toolchains/aarch32/bin
OBJCOPY := $(OPTEE_BIN)/arm-linux-gnueabihf-objcopy
TARGET := arm-unknown-optee-trustzone
TARGET := arm-unknown-linux-gnueabihf
LINKER_CFG := target.arm-unknown-linux-gnueabihf.linker=\"arm-linux-gnueabihf-ld.bfd\"
else
TA_SIGN_KEY ?= $(OPTEE_OS_DIR)/out/arm/export-ta_arm64/keys/default_ta.pem
SIGN := $(OPTEE_OS_DIR)/out/arm/export-ta_arm64/scripts/sign_encrypt.py
OPTEE_BIN := $(OPTEE_DIR)/toolchains/$(ARCH)/bin
OBJCOPY := $(OPTEE_BIN)/aarch64-linux-gnu-objcopy
TARGET := aarch64-unknown-optee-trustzone
TARGET := aarch64-unknown-linux-gnu
LINKER_CFG := target.aarch64-unknown-linux-gnu.linker=\"aarch64-linux-gnu-ld.bfd\"
endif

OUT_DIR := $(CURDIR)/target/$(TARGET)/release

all: ta strip sign

ta:
@xargo build --target $(TARGET) --release --verbose
@cargo build --target $(TARGET) --release --verbose --config $(LINKER_CFG)

strip:
@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/ta $(OUT_DIR)/stripped_ta
Expand All @@ -50,4 +52,4 @@ sign:
@echo "SIGN => ${UUID}"

clean:
@xargo clean
@cargo clean
25 changes: 0 additions & 25 deletions examples/acipher-rs/ta/Xargo.toml

This file was deleted.

37 changes: 34 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 @@ -58,5 +82,12 @@ fn main() -> std::io::Result<()> {

println!("cargo:rustc-link-search={}", search_path.display());
println!("cargo:rustc-link-lib=static=utee");
println!("cargo:rustc-link-lib=static=utils");
println!("cargo:rustc-link-arg=-Tta.lds");
println!("cargo:rustc-link-arg=-e__ta_entry");
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;
};
5 changes: 5 additions & 0 deletions examples/acipher-rs/ta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
// specific language governing permissions and limitations
// under the License.

#![no_std]
#![no_main]
#![feature(c_size_t)]

extern crate alloc;

use alloc::boxed::Box;
use optee_utee::{
ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_println,
};
Expand Down
Loading
Loading