You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by iv...@apache.org on 2026/09/21 06:10:04 UTC
(teaclave-trustzone-sdk) branch main updated (448a96d -> 5a85df8)
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
from 448a96d cargo-optee: set CROSS_COMPILE for TA build commands
new 0520801 cargo-optee: parse TA and plugin UUIDs from the unsigned ELF
new 1c1a257 examples: drop uuid.txt and wrap Make with cargo-optee
new f6d1a56 environment: re-derive TARGET_* from ARCH_*/STD
new b9e0d0c docs: describe Makefile builds through cargo-optee
new 5a85df8 ci: drop dedicated cargo-optee example jobs
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/workflows/ci.yml | 156 ++-----
.github/workflows/reuse_test.yml | 6 +
.licenserc.yaml | 3 -
Makefile | 31 +-
ci/build.sh | 461 ---------------------
docs/advanced-setup.md | 34 +-
docs/emulate-and-dev-in-docker-std.md | 21 +-
docs/emulate-and-dev-in-docker.md | 29 +-
docs/migrating-to-new-building-env.md | 98 ++---
docs/overview-of-optee-rust-examples.md | 6 +-
environment | 112 ++---
examples/Makefile | 40 +-
examples/ca/Makefile.include | 52 +--
examples/ca/acipher-rs/Makefile | 1 -
examples/ca/aes-rs/Makefile | 1 -
examples/ca/authentication-rs/Makefile | 1 -
examples/ca/big_int-rs/Makefile | 1 -
examples/ca/client_pool-rs/Makefile | 1 -
examples/ca/diffie_hellman-rs/Makefile | 1 -
examples/ca/digest-rs/Makefile | 1 -
examples/ca/error_handling-rs/Makefile | 1 -
examples/ca/hello_world-rs/Cargo.toml | 5 -
examples/ca/hello_world-rs/Makefile | 1 -
examples/ca/hotp-rs/Makefile | 1 -
examples/ca/inter_ta-rs/Makefile | 1 -
examples/ca/message_passing_interface-rs/Makefile | 1 -
examples/ca/mnist-rs/Makefile | 1 -
examples/ca/property-rs/Makefile | 1 -
examples/ca/random-rs/Makefile | 1 -
examples/ca/secure_db_abstraction-rs/Makefile | 1 -
examples/ca/secure_storage-rs/Makefile | 1 -
examples/ca/serde-rs/Makefile | 1 -
examples/ca/signature_verification-rs/Makefile | 1 -
examples/ca/supp_plugin-rs-plugin/Cargo.toml | 2 -
examples/ca/supp_plugin-rs-plugin/Makefile | 2 -
examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt | 1 -
examples/ca/supp_plugin-rs/Makefile | 1 -
examples/ca/tcp_client-rs/Makefile | 1 -
examples/ca/time-rs/Makefile | 1 -
examples/ca/tls_client-rs/Makefile | 1 -
examples/ca/tls_server-rs/Makefile | 1 -
examples/ca/udp_socket-rs/Makefile | 1 -
examples/ta/Makefile.include | 88 ++--
examples/ta/acipher-rs/Cargo.toml | 2 -
examples/ta/acipher-rs/Makefile | 2 -
examples/ta/acipher-rs/uuid.txt | 1 -
examples/ta/aes-rs/Cargo.toml | 2 -
examples/ta/aes-rs/Makefile | 2 -
examples/ta/aes-rs/uuid.txt | 1 -
examples/ta/authentication-rs/Cargo.toml | 2 -
examples/ta/authentication-rs/Makefile | 2 -
examples/ta/authentication-rs/uuid.txt | 1 -
examples/ta/big_int-rs/Cargo.toml | 2 -
examples/ta/big_int-rs/Makefile | 2 -
examples/ta/big_int-rs/uuid.txt | 1 -
examples/ta/client_pool-rs/Cargo.toml | 2 -
examples/ta/client_pool-rs/Makefile | 2 -
examples/ta/client_pool-rs/uuid.txt | 1 -
examples/ta/diffie_hellman-rs/Cargo.toml | 2 -
examples/ta/diffie_hellman-rs/Makefile | 2 -
examples/ta/diffie_hellman-rs/uuid.txt | 1 -
examples/ta/digest-rs/Cargo.toml | 2 -
examples/ta/digest-rs/Makefile | 2 -
examples/ta/digest-rs/uuid.txt | 1 -
examples/ta/error_handling-rs/Cargo.toml | 2 -
examples/ta/error_handling-rs/Makefile | 2 -
examples/ta/error_handling-rs/uuid.txt | 1 -
examples/ta/hello_world-rs/Cargo.toml | 2 -
examples/ta/hello_world-rs/Makefile | 2 -
examples/ta/hello_world-rs/uuid.txt | 1 -
examples/ta/hotp-rs/Cargo.toml | 2 -
examples/ta/hotp-rs/Makefile | 2 -
examples/ta/hotp-rs/uuid.txt | 1 -
examples/ta/inter_ta-rs/Cargo.toml | 2 -
examples/ta/inter_ta-rs/Makefile | 2 -
examples/ta/inter_ta-rs/uuid.txt | 1 -
.../ta/message_passing_interface-rs/Cargo.toml | 2 -
examples/ta/message_passing_interface-rs/Makefile | 2 -
examples/ta/message_passing_interface-rs/uuid.txt | 1 -
examples/ta/mnist-rs/inference/Cargo.toml | 2 -
examples/ta/mnist-rs/inference/Makefile | 3 -
examples/ta/mnist-rs/inference/build.rs | 2 +-
examples/ta/mnist-rs/inference/uuid.txt | 1 -
examples/ta/mnist-rs/train/Cargo.toml | 2 -
examples/ta/mnist-rs/train/Makefile | 3 -
examples/ta/mnist-rs/train/uuid.txt | 1 -
examples/ta/property-rs/Cargo.toml | 2 -
examples/ta/property-rs/Makefile | 2 -
examples/ta/property-rs/uuid.txt | 1 -
examples/ta/proto/src/acipher.rs | 5 +-
examples/ta/proto/src/aes.rs | 5 +-
examples/ta/proto/src/authentication.rs | 5 +-
examples/ta/proto/src/big_int.rs | 5 +-
examples/ta/proto/src/client_pool.rs | 5 +-
examples/ta/proto/src/diffie_hellman.rs | 5 +-
examples/ta/proto/src/digest.rs | 5 +-
examples/ta/proto/src/error_handling.rs | 5 +-
examples/ta/proto/src/hello_world.rs | 5 +-
examples/ta/proto/src/hotp.rs | 5 +-
examples/ta/proto/src/inter_ta.rs | 5 +-
examples/ta/proto/src/message_passing_interface.rs | 5 +-
examples/ta/proto/src/mnist/inference.rs | 2 +-
examples/ta/proto/src/mnist/train.rs | 2 +-
examples/ta/proto/src/property.rs | 5 +-
examples/ta/proto/src/random.rs | 5 +-
examples/ta/proto/src/secure_db_abstraction.rs | 5 +-
examples/ta/proto/src/secure_storage.rs | 5 +-
examples/ta/proto/src/serde.rs | 5 +-
examples/ta/proto/src/signature_verification.rs | 5 +-
examples/ta/proto/src/supp_plugin.rs | 10 +-
examples/ta/proto/src/tcp_client.rs | 5 +-
examples/ta/proto/src/time.rs | 5 +-
examples/ta/proto/src/tls_client.rs | 5 +-
examples/ta/proto/src/tls_server.rs | 5 +-
examples/ta/proto/src/udp_socket.rs | 5 +-
examples/ta/random-rs/Cargo.toml | 2 -
examples/ta/random-rs/Makefile | 2 -
examples/ta/random-rs/uuid.txt | 1 -
examples/ta/secure_db_abstraction-rs/Cargo.toml | 2 -
examples/ta/secure_db_abstraction-rs/Makefile | 2 -
examples/ta/secure_db_abstraction-rs/uuid.txt | 1 -
examples/ta/secure_storage-rs/Cargo.toml | 2 -
examples/ta/secure_storage-rs/Makefile | 2 -
examples/ta/secure_storage-rs/uuid.txt | 1 -
examples/ta/serde-rs/Cargo.toml | 2 -
examples/ta/serde-rs/Makefile | 2 -
examples/ta/serde-rs/uuid.txt | 1 -
examples/ta/signature_verification-rs/Cargo.toml | 2 -
examples/ta/signature_verification-rs/Makefile | 2 -
examples/ta/signature_verification-rs/uuid.txt | 1 -
examples/ta/supp_plugin-rs/Cargo.toml | 2 -
examples/ta/supp_plugin-rs/Makefile | 2 -
examples/ta/supp_plugin-rs/ta_uuid.txt | 1 -
examples/ta/tcp_client-rs/Cargo.toml | 2 -
examples/ta/tcp_client-rs/Makefile | 2 -
examples/ta/tcp_client-rs/uuid.txt | 1 -
examples/ta/time-rs/Cargo.toml | 2 -
examples/ta/time-rs/Makefile | 2 -
examples/ta/time-rs/uuid.txt | 1 -
examples/ta/tls_client-rs/Cargo.toml | 2 -
examples/ta/tls_client-rs/Makefile | 2 -
examples/ta/tls_client-rs/uuid.txt | 1 -
examples/ta/tls_server-rs/Cargo.toml | 2 -
examples/ta/tls_server-rs/Makefile | 2 -
examples/ta/tls_server-rs/uuid.txt | 1 -
examples/ta/udp_socket-rs/Cargo.toml | 2 -
examples/ta/udp_socket-rs/Makefile | 2 -
examples/ta/udp_socket-rs/uuid.txt | 1 -
projects/web3/eth_wallet/Makefile | 20 +-
projects/web3/eth_wallet/host/Makefile | 33 +-
projects/web3/eth_wallet/proto/src/lib.rs | 5 +-
projects/web3/eth_wallet/ta/Makefile | 48 +--
projects/web3/eth_wallet/uuid.txt | 1 -
scripts/runtime/config/host/aarch64 | 1 -
scripts/runtime/config/host/arm32 | 1 -
scripts/runtime/config/ta/no-std/aarch64 | 8 +-
scripts/runtime/config/ta/no-std/arm32 | 8 +-
scripts/runtime/config/ta/std/aarch64 | 11 +-
scripts/runtime/config/ta/std/arm32 | 11 +-
scripts/runtime/environment | 10 +-
tools/cargo-optee/Cargo.toml | 6 +
tools/cargo-optee/README.md | 220 ++++++----
tools/cargo-optee/src/ca_builder.rs | 235 +++++------
tools/cargo-optee/src/cli.rs | 60 ++-
tools/cargo-optee/src/common.rs | 362 ++++++++++++----
tools/cargo-optee/src/config.rs | 338 +++++++--------
tools/cargo-optee/src/elf_uuid.rs | 268 ++++++++++++
.../common => tools/cargo-optee}/src/lib.rs | 12 +-
tools/cargo-optee/src/main.rs | 167 +++++---
tools/cargo-optee/src/ta_builder.rs | 187 +++++----
170 files changed, 1642 insertions(+), 1805 deletions(-)
delete mode 100755 ci/build.sh
delete mode 100644 examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt
delete mode 100644 examples/ta/acipher-rs/uuid.txt
delete mode 100644 examples/ta/aes-rs/uuid.txt
delete mode 100644 examples/ta/authentication-rs/uuid.txt
delete mode 100644 examples/ta/big_int-rs/uuid.txt
delete mode 100644 examples/ta/client_pool-rs/uuid.txt
delete mode 100644 examples/ta/diffie_hellman-rs/uuid.txt
delete mode 100644 examples/ta/digest-rs/uuid.txt
delete mode 100644 examples/ta/error_handling-rs/uuid.txt
delete mode 100644 examples/ta/hello_world-rs/uuid.txt
delete mode 100644 examples/ta/hotp-rs/uuid.txt
delete mode 100644 examples/ta/inter_ta-rs/uuid.txt
delete mode 100644 examples/ta/message_passing_interface-rs/uuid.txt
delete mode 100644 examples/ta/mnist-rs/inference/uuid.txt
delete mode 100644 examples/ta/mnist-rs/train/uuid.txt
delete mode 100644 examples/ta/property-rs/uuid.txt
delete mode 100644 examples/ta/random-rs/uuid.txt
delete mode 100644 examples/ta/secure_db_abstraction-rs/uuid.txt
delete mode 100644 examples/ta/secure_storage-rs/uuid.txt
delete mode 100644 examples/ta/serde-rs/uuid.txt
delete mode 100644 examples/ta/signature_verification-rs/uuid.txt
delete mode 100644 examples/ta/supp_plugin-rs/ta_uuid.txt
delete mode 100644 examples/ta/tcp_client-rs/uuid.txt
delete mode 100644 examples/ta/time-rs/uuid.txt
delete mode 100644 examples/ta/tls_client-rs/uuid.txt
delete mode 100644 examples/ta/tls_server-rs/uuid.txt
delete mode 100644 examples/ta/udp_socket-rs/uuid.txt
delete mode 100644 projects/web3/eth_wallet/uuid.txt
create mode 100644 tools/cargo-optee/src/elf_uuid.rs
copy {examples/ta/mnist-rs/common => tools/cargo-optee}/src/lib.rs (88%)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org
(teaclave-trustzone-sdk) 05/05: ci: drop dedicated cargo-optee example jobs
Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit 5a85df88198dc1946ec9628116efaf8622028894
Author: ivila <39...@qq.com>
AuthorDate: Mon Sep 21 11:44:29 2026 +0800
ci: drop dedicated cargo-optee example jobs
Make now builds examples through cargo-optee, so the extra
cargo-optee-only jobs and ci/build.sh are redundant. Cover the
arch × std matrix with one test-build-on-dev-docker job. reuse_test
runs cargo-optee unit tests, clippy, and fmt from tools/.
---
.github/workflows/ci.yml | 156 ++++---------
.github/workflows/reuse_test.yml | 6 +
ci/build.sh | 461 ---------------------------------------
3 files changed, 48 insertions(+), 575 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a6fbd6c..75589eb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -64,128 +64,56 @@ jobs:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OPTEE_DIR/optee_client/export_arm64/usr/lib
(cd crates && cargo run -p optee-teec-systest && cargo build -p optee-utee-systest)
- # Test build no-std examples on dev docker container
- test-nostd-build-on-dev-docker:
- runs-on: ubuntu-latest
- container:
- image: teaclave/teaclave-trustzone-emulator-nostd-expand-memory:latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v7
- - name: Setup environment
- run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Build no-std and common examples
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- make
-
- # Test build std examples on dev docker container
- test-std-build-on-dev-docker:
- runs-on: ubuntu-latest
- container:
- image: teaclave/teaclave-trustzone-emulator-std-expand-memory:latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v7
- - name: Setup environment
- run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Build no-std and common examples
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- ln -s $RUST_STD_DIR rust
- make std-examples
-
- # Test cargo-optee build no-std examples - aarch64
- test-cargo-optee-nostd-aarch64:
- runs-on: ubuntu-latest
- container:
- image: teaclave/teaclave-trustzone-emulator-nostd-expand-memory:latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v7
- - name: Setup environment
- run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Test cargo-optee no-std build (aarch64)
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- # Build using cargo-optee tool with default aarch64 settings
- ./ci/build.sh
-
- # Test cargo-optee build no-std examples - arm32
- test-cargo-optee-nostd-arm32:
- runs-on: ubuntu-latest
- container:
- image: teaclave/teaclave-trustzone-emulator-nostd-expand-memory:latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v7
- - name: Setup environment
- run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Test cargo-optee no-std build (arm32)
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- # Switch to ARM32 configuration and build
- # Note: Explicit environment reload needed for GitHub Actions
- # (wrapper function in .bashrc not working for non-interactive shells: docker exec cmd=[...])
- # We can fix this by updating entrypoint.sh to make ~/.profile source ~/.bashrc
- switch_config --ta no-std/arm32 && \
- switch_config --host arm32 && \
- source ${TEACLAVE_TOOLCHAIN_BASE}/environment && \
- ./ci/build.sh --ta arm --host arm
-
- # Test cargo-optee build std examples - aarch64
- test-cargo-optee-std-aarch64:
+ # Build examples in the emulator image: arch × std.
+ test-build-on-dev-docker:
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - arch: aarch64
+ std: false
+ ta: no-std/aarch64
+ host: aarch64
+ image: teaclave/teaclave-trustzone-emulator-nostd-expand-memory:latest
+ - arch: arm32
+ std: false
+ ta: no-std/arm32
+ host: arm32
+ image: teaclave/teaclave-trustzone-emulator-nostd-expand-memory:latest
+ - arch: aarch64
+ std: true
+ ta: std/aarch64
+ host: aarch64
+ image: teaclave/teaclave-trustzone-emulator-std-expand-memory:latest
+ - arch: arm32
+ std: true
+ ta: std/arm32
+ host: arm32
+ image: teaclave/teaclave-trustzone-emulator-std-expand-memory:latest
+ name: test-build-on-dev-docker (${{ matrix.arch }}, ${{ matrix.std && 'std' || 'no-std' }})
runs-on: ubuntu-latest
container:
- image: teaclave/teaclave-trustzone-emulator-std-expand-memory:latest
+ image: ${{ matrix.image }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup environment
+ run: /entrypoint.sh true
+ - name: Build examples
+ shell: bash -l {0}
run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Test cargo-optee std build (aarch64)
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- # Link rust directory for std support
- ln -s $RUST_STD_DIR rust
- # Build using cargo-optee tool with default aarch64 std settings
- ./ci/build.sh --std
+ if [ "${{ matrix.std }}" = "true" ]; then
+ ln -s "$RUST_STD_DIR" rust
+ fi
+ switch_config --ta ${{ matrix.ta }} && \
+ switch_config --host ${{ matrix.host }} && \
+ source "${TEACLAVE_TOOLCHAIN_BASE}/environment" && \
+ if [ "${{ matrix.std }}" = "true" ]; then
+ make std-examples
+ else
+ make
+ fi
- # Test cargo-optee build std examples - arm32
- test-cargo-optee-std-arm32:
- runs-on: ubuntu-latest
- container:
- image: teaclave/teaclave-trustzone-emulator-std-expand-memory:latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v7
- - name: Setup environment
- run: |
- # Run entrypoint.sh to set up the bash profile
- /entrypoint.sh true
- - name: Test cargo-optee std build (arm32)
- shell: bash -l {0} # Use login shell to load the profile
- run: |
- # Link rust directory for std support
- ln -s $RUST_STD_DIR rust
- # Switch to ARM32 std configuration and build
- # Note: Explicit environment reload needed for GitHub Actions
- # (wrapper function in .bashrc not working for non-interactive shells: docker exec cmd=[...])
- # We can fix this by updating entrypoint.sh to make ~/.profile source ~/.bashrc
- switch_config --ta std/arm32 && \
- switch_config --host arm32 && \
- source ${TEACLAVE_TOOLCHAIN_BASE}/environment && \
- ./ci/build.sh --ta arm --host arm --std
license:
runs-on: ubuntu-latest
diff --git a/.github/workflows/reuse_test.yml b/.github/workflows/reuse_test.yml
index 2c3ea84..ccb9a81 100644
--- a/.github/workflows/reuse_test.yml
+++ b/.github/workflows/reuse_test.yml
@@ -79,6 +79,12 @@ jobs:
# fmt checks
(cd crates && cargo fmt --all --check)
+ # cargo-optee unit tests live in tools/, not crates/.
+ (cd tools && \
+ cargo test -p cargo-optee -vv && \
+ cargo clippy -p cargo-optee -- -D warnings && \
+ cargo fmt --all --check)
+
build-and-test-examples-for-32bit-no-std-TAs:
uses: ./.github/workflows/reuse_host_build_and_qemu_run.yml
with:
diff --git a/ci/build.sh b/ci/build.sh
deleted file mode 100755
index cbc05e5..0000000
--- a/ci/build.sh
+++ /dev/null
@@ -1,461 +0,0 @@
-#!/bin/bash
-
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-set -e
-
-# Show usage
-show_usage() {
- cat << EOF
-Usage: TA_DEV_KIT_DIR=<path> OPTEE_CLIENT_EXPORT=<path> $0 [OPTIONS]
-
-Required environment variables:
- TA_DEV_KIT_DIR Path to OP-TEE OS TA dev kit directory
- OPTEE_CLIENT_EXPORT Path to OP-TEE client export directory
-
-Options:
- --ta <arch> TA architecture: aarch64 or arm (default: aarch64)
- --host <arch> Host architecture for CA and plugins: aarch64 or arm (default: aarch64)
- --std Install with std support (default: no-std)
- --ta-install-dir <path> TA installation directory (default: ./tests/shared)
- --ca-install-dir <path> CA installation directory (default: ./tests/shared)
- --plugin-install-dir <path> Plugin installation directory (default: ./tests/shared)
- --help Show this help message
-
-Examples:
- # Install for aarch64 in no-std mode
- TA_DEV_KIT_DIR=/path/to/export-ta_arm64 OPTEE_CLIENT_EXPORT=/path/to/export ./build.sh
-
- # Install for ARM32 in std mode with custom directories
- TA_DEV_KIT_DIR=/path/to/export-ta_arm32 OPTEE_CLIENT_EXPORT=/path/to/export ./build.sh --ta arm --host arm --std --ta-install-dir /target/lib/optee_armtz --ca-install-dir /target/usr/bin
-
-Note: Binaries are installed to './tests/shared' directory by default.
-EOF
-}
-
-# Parse command line arguments
-ARCH_TA="aarch64" # Default: aarch64
-ARCH_HOST="aarch64" # Default: aarch64
-STD="" # Default: empty (no-std)
-TA_INSTALL_DIR="" # Default: will be set to ./tests/shared if not specified
-CA_INSTALL_DIR="" # Default: will be set to ./tests/shared if not specified
-PLUGIN_INSTALL_DIR="" # Default: will be set to ./tests/shared if not specified
-
-# Parse arguments (support both positional and flag-style)
-while [[ $# -gt 0 ]]; do
- case "$1" in
- --help|-h)
- show_usage
- exit 0
- ;;
- --ta)
- ARCH_TA="$2"
- shift 2
- ;;
- --host)
- ARCH_HOST="$2"
- shift 2
- ;;
- --std)
- STD="std"
- shift
- ;;
- --ta-install-dir)
- TA_INSTALL_DIR="$2"
- shift 2
- ;;
- --ca-install-dir)
- CA_INSTALL_DIR="$2"
- shift 2
- ;;
- --plugin-install-dir)
- PLUGIN_INSTALL_DIR="$2"
- shift 2
- ;;
- *)
- # Positional arguments (backward compatibility)
- if [[ -z "${ARCH_TA_SET:-}" ]]; then
- ARCH_TA="$1"
- ARCH_TA_SET=1
- elif [[ -z "${ARCH_HOST_SET:-}" ]]; then
- ARCH_HOST="$1"
- ARCH_HOST_SET=1
- elif [[ "$1" == "std" ]]; then
- STD="std"
- fi
- shift
- ;;
- esac
-done
-
-# Validate architecture
-if [[ "$ARCH_TA" != "aarch64" && "$ARCH_TA" != "arm" ]]; then
- echo "Error: ARCH_TA must be 'aarch64' or 'arm'"
- exit 1
-fi
-
-if [[ "$ARCH_HOST" != "aarch64" && "$ARCH_HOST" != "arm" ]]; then
- echo "Error: ARCH_HOST must be 'aarch64' or 'arm'"
- exit 1
-fi
-
-# Check required environment variables
-if [ -z "$TA_DEV_KIT_DIR" ]; then
- echo "Error: TA_DEV_KIT_DIR environment variable is not set"
- exit 1
-fi
-
-if [ -z "$OPTEE_CLIENT_EXPORT" ]; then
- echo "Error: OPTEE_CLIENT_EXPORT environment variable is not set"
- exit 1
-fi
-
-# For std builds, __CARGO_TESTS_ONLY_SRC_ROOT must be set (required by cargo -Z build-std)
-if [ -n "$STD" ]; then
- if [ -z "$__CARGO_TESTS_ONLY_SRC_ROOT" ]; then
- if [ -n "$RUST_STD_DIR" ]; then
- export __CARGO_TESTS_ONLY_SRC_ROOT="$RUST_STD_DIR/rust/library"
- else
- echo "Error: __CARGO_TESTS_ONLY_SRC_ROOT (or RUST_STD_DIR) must be set for std builds"
- echo " export __CARGO_TESTS_ONLY_SRC_ROOT=/path/to/rust/library"
- exit 1
- fi
- fi
- echo " __CARGO_TESTS_ONLY_SRC_ROOT: $__CARGO_TESTS_ONLY_SRC_ROOT"
-fi
-
-echo "==========================================="
-echo "Installing with configuration:"
-echo " ARCH_TA: $ARCH_TA"
-echo " ARCH_HOST: $ARCH_HOST"
-echo " STD: ${STD:-no-std}"
-echo " TA_DEV_KIT_DIR: $TA_DEV_KIT_DIR"
-echo " OPTEE_CLIENT_EXPORT: $OPTEE_CLIENT_EXPORT"
-echo "==========================================="
-
-# Step 1: Build cargo-optee tool
-echo ""
-echo "Step 1: Building cargo-optee tool..."
-cd tools
-cargo build -p cargo-optee --release
-CARGO_OPTEE="$(pwd)/target/release/cargo-optee"
-cd ..
-
-if [ ! -f "$CARGO_OPTEE" ]; then
- echo "Error: Failed to build cargo-optee"
- exit 1
-fi
-
-echo "cargo-optee built successfully: $CARGO_OPTEE"
-
-# Prepare std flag for cargo-optee
-STD_FLAG=""
-if [ -n "$STD" ]; then
- STD_FLAG="--std"
-fi
-
-# Step 2: Install all examples to shared directory
-echo ""
-echo "Step 2: Installing all examples..."
-
-# Set up installation directories
-# Each directory defaults to ./tests/shared if not specified
-if [ -z "$TA_INSTALL_DIR" ]; then
- TA_INSTALL_DIR="$(pwd)/tests/shared"
-fi
-
-if [ -z "$CA_INSTALL_DIR" ]; then
- CA_INSTALL_DIR="$(pwd)/tests/shared"
-fi
-
-if [ -z "$PLUGIN_INSTALL_DIR" ]; then
- PLUGIN_INSTALL_DIR="$(pwd)/tests/shared"
-fi
-
-# Create all directories
-mkdir -p "$TA_INSTALL_DIR"
-mkdir -p "$CA_INSTALL_DIR"
-mkdir -p "$PLUGIN_INSTALL_DIR"
-
-echo "Installing binaries to:"
-echo " TAs: $TA_INSTALL_DIR"
-echo " CAs: $CA_INSTALL_DIR"
-echo " Plugins: $PLUGIN_INSTALL_DIR"
-
-EXAMPLES_DIR="$(pwd)/examples"
-METADATA_JSON="$EXAMPLES_DIR/metadata.json"
-
-if [ ! -f "$METADATA_JSON" ]; then
- echo "Error: $METADATA_JSON not found"
- exit 1
-fi
-
-# Check if jq is available for JSON parsing
-if ! command -v jq &> /dev/null; then
- echo "Error: jq is required to parse metadata.json"
- echo "Please install jq: apt-get install jq"
- exit 1
-fi
-
-echo "Loading example metadata from $METADATA_JSON..."
-
-# Get all example names
-ALL_EXAMPLES=($(jq -r '.examples | keys[]' "$METADATA_JSON"))
-
-if [ -n "$STD" ]; then
- echo "Building in STD mode (std-only + common examples)"
-else
- echo "Building in NO-STD mode (no-std-only + common examples)"
-fi
-
-CURRENT=0
-FAILED_EXAMPLES=""
-
-# Build examples
-for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
- CATEGORY=$(jq -r ".examples[\"$EXAMPLE_NAME\"].category" "$METADATA_JSON")
-
- # Determine if we should build this example
- SHOULD_BUILD=false
- if [ -n "$STD" ]; then
- # STD mode: build std-only and common
- if [[ "$CATEGORY" == "std-only" || "$CATEGORY" == "common" ]]; then
- SHOULD_BUILD=true
- fi
- else
- # NO-STD mode: build no-std-only and common
- if [[ "$CATEGORY" == "no-std-only" || "$CATEGORY" == "common" ]]; then
- SHOULD_BUILD=true
- fi
- fi
-
- if [ "$SHOULD_BUILD" = false ]; then
- continue
- fi
-
- CURRENT=$((CURRENT + 1))
- echo ""
- echo "=========================================="
- echo "[$CURRENT] Building: $EXAMPLE_NAME ($CATEGORY)"
- echo "=========================================="
-
- # Get TA, CA, and Plugin directories from metadata
- TAS_JSON=$(jq -c ".examples[\"$EXAMPLE_NAME\"].tas" "$METADATA_JSON")
- CAS_JSON=$(jq -c ".examples[\"$EXAMPLE_NAME\"].cas" "$METADATA_JSON")
- PLUGINS_JSON=$(jq -c ".examples[\"$EXAMPLE_NAME\"].plugins // []" "$METADATA_JSON")
-
- # Build all TAs for this example
- TA_COUNT=$(echo "$TAS_JSON" | jq 'length')
- CA_COUNT=$(echo "$CAS_JSON" | jq 'length')
- PLUGIN_COUNT=$(echo "$PLUGINS_JSON" | jq 'length')
-
- echo "→ Found $TA_COUNT TA(s), $CA_COUNT CA(s), and $PLUGIN_COUNT Plugin(s)"
-
- if [ "$TA_COUNT" -gt 0 ]; then
- for ((i=0; i<$TA_COUNT; i++)); do
- TA_DIR=$(echo "$TAS_JSON" | jq -r ".[$i]")
- TA_DIR_FULL_PATH="$EXAMPLES_DIR/$TA_DIR"
-
- if [ ! -d "$TA_DIR_FULL_PATH" ]; then
- echo "ERROR: TA directory not found: $TA_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($TA_DIR)"
- continue
- fi
-
- if [ ! -f "$TA_DIR_FULL_PATH/Cargo.toml" ]; then
- echo "ERROR: Cargo.toml not found in TA directory: $TA_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($TA_DIR)"
- continue
- fi
-
- echo ""
- echo "→ Building TA [$((i+1))/$TA_COUNT]: $TA_DIR"
-
- # Determine STD_FLAG for TA
- TA_STD_FLAG=""
- if [ -n "$STD" ]; then
- # In std mode: always pass --std flag to cargo-optee
- TA_STD_FLAG="--std"
- fi
-
- # Change to TA directory and run cargo-optee without --manifest-path
- cd "$TA_DIR_FULL_PATH"
-
- # Run cargo-optee install and capture both stdout and stderr
- if $CARGO_OPTEE install ta \
- --target-dir "$TA_INSTALL_DIR" \
- --ta-dev-kit-dir "$TA_DEV_KIT_DIR" \
- --arch "$ARCH_TA" \
- $TA_STD_FLAG; then
- echo " ✓ TA installed successfully"
- else
- echo " ✗ ERROR: Failed to install TA: $TA_DIR"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($TA_DIR)"
- cd "$EXAMPLES_DIR" # Return to examples directory
- continue
- fi
-
- # Return to examples directory
- cd "$EXAMPLES_DIR"
- done
- else
- echo "WARNING: No TAs defined for $EXAMPLE_NAME"
- fi
-
- # Build each CA
- CA_INDEX=0
- while [[ "$CA_INDEX" -lt "$CA_COUNT" ]]; do
- CA_DIR=$(echo "$CAS_JSON" | jq -r ".[$CA_INDEX]")
- CA_DIR_FULL_PATH="$EXAMPLES_DIR/$CA_DIR"
-
- echo ""
- echo "→ Building CA [$((CA_INDEX+1))/$CA_COUNT]: $CA_DIR"
-
- if [ ! -d "$CA_DIR_FULL_PATH" ]; then
- echo "ERROR: CA directory not found: $CA_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($CA_DIR)"
- CA_INDEX=$((CA_INDEX + 1))
- continue
- fi
-
- if [ ! -f "$CA_DIR_FULL_PATH/Cargo.toml" ]; then
- echo "ERROR: Cargo.toml not found in CA directory: $CA_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($CA_DIR)"
- CA_INDEX=$((CA_INDEX + 1))
- continue
- fi
-
- # Change to CA directory and run cargo-optee without --manifest-path
- cd "$CA_DIR_FULL_PATH"
-
- if $CARGO_OPTEE install ca \
- --target-dir "$CA_INSTALL_DIR" \
- --optee-client-export "$OPTEE_CLIENT_EXPORT" \
- --arch "$ARCH_HOST"; then
- echo " ✓ CA installed successfully"
- else
- echo " ✗ ERROR: Failed to install CA: $CA_DIR"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($CA_DIR)"
- cd "$EXAMPLES_DIR" # Return to examples directory
- CA_INDEX=$((CA_INDEX + 1))
- continue
- fi
-
- # Return to examples directory
- cd "$EXAMPLES_DIR"
- CA_INDEX=$((CA_INDEX + 1))
- done
-
- # Build each Plugin
- PLUGIN_INDEX=0
- while [[ "$PLUGIN_INDEX" -lt "$PLUGIN_COUNT" ]]; do
- PLUGIN_DIR=$(echo "$PLUGINS_JSON" | jq -r ".[$PLUGIN_INDEX]")
- PLUGIN_DIR_FULL_PATH="$EXAMPLES_DIR/$PLUGIN_DIR"
-
- echo ""
- echo "→ Building Plugin [$((PLUGIN_INDEX+1))/$PLUGIN_COUNT]: $PLUGIN_DIR"
-
- if [ ! -d "$PLUGIN_DIR_FULL_PATH" ]; then
- echo "ERROR: Plugin directory not found: $PLUGIN_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($PLUGIN_DIR)"
- PLUGIN_INDEX=$((PLUGIN_INDEX + 1))
- continue
- fi
-
- if [ ! -f "$PLUGIN_DIR_FULL_PATH/Cargo.toml" ]; then
- echo "ERROR: Cargo.toml not found in Plugin directory: $PLUGIN_DIR_FULL_PATH"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($PLUGIN_DIR)"
- PLUGIN_INDEX=$((PLUGIN_INDEX + 1))
- continue
- fi
-
- # Change to Plugin directory and run cargo-optee without --manifest-path
- cd "$PLUGIN_DIR_FULL_PATH"
-
- if $CARGO_OPTEE install plugin \
- --target-dir "$PLUGIN_INSTALL_DIR" \
- --optee-client-export "$OPTEE_CLIENT_EXPORT" \
- --arch "$ARCH_HOST"; then
- echo " ✓ Plugin installed successfully"
- else
- echo " ✗ ERROR: Failed to install Plugin: $PLUGIN_DIR"
- FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($PLUGIN_DIR)"
- cd "$EXAMPLES_DIR" # Return to examples directory
- PLUGIN_INDEX=$((PLUGIN_INDEX + 1))
- continue
- fi
-
- # Return to examples directory
- cd "$EXAMPLES_DIR"
- PLUGIN_INDEX=$((PLUGIN_INDEX + 1))
- done
-
- echo ""
- echo "✓ Example $EXAMPLE_NAME completed successfully"
-done
-
-echo ""
-echo "==========================================="
-echo " WORKSPACE TARGET DISK USAGE"
-echo "==========================================="
-
-TARGET_DIRS=()
-if [ -d "$EXAMPLES_DIR/ta/target" ]; then
- TARGET_DIRS+=("$EXAMPLES_DIR/ta/target")
-fi
-if [ -d "$EXAMPLES_DIR/ca/target" ]; then
- TARGET_DIRS+=("$EXAMPLES_DIR/ca/target")
-fi
-
-if [ "${#TARGET_DIRS[@]}" -gt 0 ]; then
- du -sch "${TARGET_DIRS[@]}"
-else
- echo "No workspace target directories were created."
-fi
-
-echo ""
-echo "Cleaning workspace build artifacts..."
-cargo clean --manifest-path "$EXAMPLES_DIR/ta/Cargo.toml"
-cargo clean --manifest-path "$EXAMPLES_DIR/ca/Cargo.toml"
-echo "Workspace build artifacts cleaned successfully."
-
-# Summary
-echo ""
-echo "==========================================="
-echo " INSTALL SUMMARY"
-echo "==========================================="
-echo ""
-echo "Mode: ${STD:-no-std}"
-echo "Architecture: TA=$ARCH_TA, CA=$ARCH_HOST"
-echo "Examples: $CURRENT installed"
-echo "TA install dir: $TA_INSTALL_DIR"
-echo "CA install dir: $CA_INSTALL_DIR"
-echo "Plugin install dir: $PLUGIN_INSTALL_DIR"
-echo ""
-
-if [ -n "$FAILED_EXAMPLES" ]; then
- echo "❌ INSTALL FAILED"
- echo ""
- echo "Failed components:"
- echo -e "$FAILED_EXAMPLES"
- echo ""
- exit 1
-else
- echo "✅ ALL EXAMPLES INSTALLED SUCCESSFULLY!"
- echo ""
-fi
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org
(teaclave-trustzone-sdk) 03/05: environment: re-derive TARGET_* from ARCH_*/STD
Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit f6d1a56e6d39ca55f993d5ff56f1cb467224ea06
Author: ivila <39...@qq.com>
AuthorDate: Mon Sep 21 11:44:25 2026 +0800
environment: re-derive TARGET_* from ARCH_*/STD
ARCH_* stay shorthands. Re-sourcing refreshes TARGET_* unless the
triple was set explicitly. cargo-optee owns CROSS_COMPILE and crate
features, so drop those from environment and the docker switch_config
files.
---
environment | 112 +++++++++++++++++--------------
scripts/runtime/config/host/aarch64 | 1 -
scripts/runtime/config/host/arm32 | 1 -
scripts/runtime/config/ta/no-std/aarch64 | 8 +--
scripts/runtime/config/ta/no-std/arm32 | 8 +--
scripts/runtime/config/ta/std/aarch64 | 11 +--
scripts/runtime/config/ta/std/arm32 | 11 +--
scripts/runtime/environment | 10 ++-
8 files changed, 74 insertions(+), 88 deletions(-)
diff --git a/environment b/environment
index 957b11d..9d91e41 100644
--- a/environment
+++ b/environment
@@ -16,8 +16,10 @@
# under the License.
export PATH=$PATH:$HOME/.cargo/bin
-# for std: specify the target json file
-export RUST_TARGET_PATH="$(pwd)"
+
+# cargo-optee owns CROSS_COMPILE, crate features, and cargo flags.
+unset FEATURES CARGO_FLAGS CROSS_COMPILE_TA CROSS_COMPILE_HOST \
+ CROSS_COMPILE32 CROSS_COMPILE64 RUST_TARGET_PATH
# Disable incremental compilation to avoid ICE with recent nightly
# error: internal compiler error: encountered incremental compilation error
@@ -33,49 +35,50 @@ fi
export OPTEE_OS_DIR="$OPTEE_DIR/optee_os"
export OPTEE_CLIENT_DIR="$OPTEE_DIR/optee_client"
-export CROSS_COMPILE32="arm-linux-gnueabihf-"
-export CROSS_COMPILE64="aarch64-linux-gnu-"
-
-if [ "$ARCH_TA" = "arm" ]
+# TARGET_* is the Make/OP-TEE interface. ARCH_TA/ARCH_HOST are shorthands that
+# fill TARGET_* when it is unset, or when it still has the value this script
+# last derived. An explicit TARGET_TA/TARGET_HOST is left alone. To force a
+# fresh shorthand derivation: unset TARGET_TA TARGET_HOST
+if [ -z "$TARGET_TA" ] || [ "$TARGET_TA" = "${_TEACLAVE_DERIVED_TARGET_TA:-}" ]
then
- # build TA as 32-bit
- export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
- if [ "$STD" ]
+ if [ "$ARCH_TA" = "arm" ]
then
- export TARGET_TA="arm-unknown-optee"
- echo "set TARGET_TA=$TARGET_TA (std)"
- export FEATURES="--features std"
- export CARGO_FLAGS="-Z build-std=std,panic_abort -Z json-target-spec"
- export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-Z unstable-options"
- export __CARGO_TESTS_ONLY_SRC_ROOT="$(pwd)/rust/rust/library"
+ if [ "$STD" ]
+ then
+ export TARGET_TA="arm-unknown-optee"
+ else
+ export TARGET_TA="arm-unknown-linux-gnueabihf"
+ fi
else
- export TARGET_TA="arm-unknown-linux-gnueabihf"
- echo "set TARGET_TA=$TARGET_TA (no-std)"
- export FEATURES=""
- export CARGO_FLAGS=""
+ if [ "$STD" ]
+ then
+ export TARGET_TA="aarch64-unknown-optee"
+ else
+ export TARGET_TA="aarch64-unknown-linux-gnu"
+ fi
fi
- export CROSS_COMPILE_TA="$CROSS_COMPILE32"
- echo "set CROSS_COMPILE_TA=$CROSS_COMPILE_TA"
-else
- # build TA as 64-bit by default
- export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64"
- if [ "$STD" ]
- then
- export TARGET_TA="aarch64-unknown-optee"
+ export _TEACLAVE_DERIVED_TARGET_TA="$TARGET_TA"
+fi
+
+case "$TARGET_TA" in
+ arm-unknown-*)
+ export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
+ ;;
+ *)
+ export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64"
+ ;;
+esac
+
+case "$TARGET_TA" in
+ *-unknown-optee)
echo "set TARGET_TA=$TARGET_TA (std)"
- export FEATURES="--features std"
- export CARGO_FLAGS="-Z build-std=std,panic_abort -Z json-target-spec"
- export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-Z unstable-options"
export __CARGO_TESTS_ONLY_SRC_ROOT="$(pwd)/rust/rust/library"
- else
- export TARGET_TA="aarch64-unknown-linux-gnu"
+ ;;
+ *)
echo "set TARGET_TA=$TARGET_TA (no-std)"
- export FEATURES=""
- export CARGO_FLAGS=""
- fi
- export CROSS_COMPILE_TA="$CROSS_COMPILE64"
- echo "set CROSS_COMPILE_TA=$CROSS_COMPILE_TA"
-fi
+ unset __CARGO_TESTS_ONLY_SRC_ROOT
+ ;;
+esac
# check if libraries exist
if [ -d "$TA_DEV_KIT_DIR" ]
@@ -86,23 +89,28 @@ else
unset OPTEE_DIR
fi
-if [ "$ARCH_HOST" = "arm" ]
+if [ -z "$TARGET_HOST" ] || [ "$TARGET_HOST" = "${_TEACLAVE_DERIVED_TARGET_HOST:-}" ]
then
- # build host as 32-bit
- export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm32"
- export TARGET_HOST="arm-unknown-linux-gnueabihf"
- echo "set TARGET_HOST=$TARGET_HOST"
- export CROSS_COMPILE_HOST="$CROSS_COMPILE32"
- echo "set CROSS_COMPILE_HOST=$CROSS_COMPILE_HOST"
-else
- # build host as 64-bit by default
- export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm64"
- export TARGET_HOST="aarch64-unknown-linux-gnu"
- echo "set TARGET_HOST=$TARGET_HOST"
- export CROSS_COMPILE_HOST="$CROSS_COMPILE64"
- echo "set CROSS_COMPILE_HOST=$CROSS_COMPILE_HOST"
+ if [ "$ARCH_HOST" = "arm" ]
+ then
+ export TARGET_HOST="arm-unknown-linux-gnueabihf"
+ else
+ export TARGET_HOST="aarch64-unknown-linux-gnu"
+ fi
+ export _TEACLAVE_DERIVED_TARGET_HOST="$TARGET_HOST"
fi
+case "$TARGET_HOST" in
+ arm-unknown-*)
+ export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm32"
+ ;;
+ *)
+ export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm64"
+ ;;
+esac
+
+echo "set TARGET_HOST=$TARGET_HOST"
+
if [ -d "$OPTEE_CLIENT_EXPORT" ]
then
echo "set OPTEE_CLIENT_EXPORT=$OPTEE_CLIENT_EXPORT"
diff --git a/scripts/runtime/config/host/aarch64 b/scripts/runtime/config/host/aarch64
index e94789b..8b10531 100644
--- a/scripts/runtime/config/host/aarch64
+++ b/scripts/runtime/config/host/aarch64
@@ -17,4 +17,3 @@
export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm64"
export TARGET_HOST="aarch64-unknown-linux-gnu"
-export CROSS_COMPILE_HOST="aarch64-linux-gnu-"
diff --git a/scripts/runtime/config/host/arm32 b/scripts/runtime/config/host/arm32
index 9462f03..77d4a18 100644
--- a/scripts/runtime/config/host/arm32
+++ b/scripts/runtime/config/host/arm32
@@ -17,4 +17,3 @@
export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/export_arm32"
export TARGET_HOST="arm-unknown-linux-gnueabihf"
-export CROSS_COMPILE_HOST="arm-linux-gnueabihf-"
diff --git a/scripts/runtime/config/ta/no-std/aarch64 b/scripts/runtime/config/ta/no-std/aarch64
index c4598c8..c9607ab 100644
--- a/scripts/runtime/config/ta/no-std/aarch64
+++ b/scripts/runtime/config/ta/no-std/aarch64
@@ -15,11 +15,7 @@
# specific language governing permissions and limitations
# under the License.
+unset STD FEATURES CARGO_FLAGS CROSS_COMPILE_TA \
+ RUST_TARGET_PATH __CARGO_TESTS_ONLY_SRC_ROOT
export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64"
export TARGET_TA="aarch64-unknown-linux-gnu"
-export CROSS_COMPILE_TA="aarch64-linux-gnu-"
-
-# CARGO_FLAGS is empty for no-std TAs
-export CARGO_FLAGS=""
-# Initialize FEATURES as empty for no-std TAs
-export FEATURES=""
\ No newline at end of file
diff --git a/scripts/runtime/config/ta/no-std/arm32 b/scripts/runtime/config/ta/no-std/arm32
index 974e347..0affa89 100644
--- a/scripts/runtime/config/ta/no-std/arm32
+++ b/scripts/runtime/config/ta/no-std/arm32
@@ -15,11 +15,7 @@
# specific language governing permissions and limitations
# under the License.
+unset STD FEATURES CARGO_FLAGS CROSS_COMPILE_TA \
+ RUST_TARGET_PATH __CARGO_TESTS_ONLY_SRC_ROOT
export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
export TARGET_TA="arm-unknown-linux-gnueabihf"
-export CROSS_COMPILE_TA="arm-linux-gnueabihf-"
-
-# CARGO_FLAGS is empty for no-std TAs
-export CARGO_FLAGS=""
-# Initialize FEATURES as empty for no-std TAs
-export FEATURES=""
\ No newline at end of file
diff --git a/scripts/runtime/config/ta/std/aarch64 b/scripts/runtime/config/ta/std/aarch64
index 33e3181..8350ece 100644
--- a/scripts/runtime/config/ta/std/aarch64
+++ b/scripts/runtime/config/ta/std/aarch64
@@ -15,17 +15,8 @@
# specific language governing permissions and limitations
# under the License.
+export STD=y
export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64"
export TARGET_TA="aarch64-unknown-optee"
-export CROSS_COMPILE_TA="aarch64-linux-gnu-"
-
-# CARGO_FLAGS for building std TAs with cargo -Z build-std
-export CARGO_FLAGS="-Z build-std=std,panic_abort -Z json-target-spec"
-export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-Z unstable-options"
# rust library source for cargo -Z build-std
export __CARGO_TESTS_ONLY_SRC_ROOT=$RUST_STD_DIR/rust/library
-# enable std feature for building std TAs (defined in TA's Cargo.toml and used in TA's Makefile)
-export FEATURES="--features std"
-
-# assume $customized-target.json is located here
-export RUST_TARGET_PATH=$RUST_STD_DIR
diff --git a/scripts/runtime/config/ta/std/arm32 b/scripts/runtime/config/ta/std/arm32
index 086b2e4..8e5d1f9 100644
--- a/scripts/runtime/config/ta/std/arm32
+++ b/scripts/runtime/config/ta/std/arm32
@@ -15,17 +15,8 @@
# specific language governing permissions and limitations
# under the License.
+export STD=y
export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
export TARGET_TA="arm-unknown-optee"
-export CROSS_COMPILE_TA="arm-linux-gnueabihf-"
-
-# CARGO_FLAGS for building std TAs with cargo -Z build-std
-export CARGO_FLAGS="-Z build-std=std,panic_abort -Z json-target-spec"
-export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-Z unstable-options"
# rust library source for cargo -Z build-std
export __CARGO_TESTS_ONLY_SRC_ROOT=$RUST_STD_DIR/rust/library
-# enable std feature for building std TAs (defined in TA's Cargo.toml and used in TA's Makefile)
-export FEATURES="--features std"
-
-# assume $customized-target.json is located here
-export RUST_TARGET_PATH=$RUST_STD_DIR
diff --git a/scripts/runtime/environment b/scripts/runtime/environment
index 5cc6b24..0c68a96 100755
--- a/scripts/runtime/environment
+++ b/scripts/runtime/environment
@@ -62,6 +62,13 @@ source "$SCRIPT_DIR/ta/active"
# Load active Host configuration
source "$SCRIPT_DIR/host/active"
+# cargo-optee owns CROSS_COMPILE, crate features, and cargo flags.
+unset FEATURES CARGO_FLAGS CROSS_COMPILE_TA CROSS_COMPILE_HOST \
+ CROSS_COMPILE32 CROSS_COMPILE64 RUST_TARGET_PATH
+if [ -z "${STD:-}" ]; then
+ unset __CARGO_TESTS_ONLY_SRC_ROOT
+fi
+
# Validate OP-TEE directories exist
if [ ! -d "$TA_DEV_KIT_DIR" ]; then
echo "Error: TA_DEV_KIT_DIR=$TA_DEV_KIT_DIR does not exist" >&2
@@ -91,13 +98,12 @@ echo "TA: $(readlink "$SCRIPT_DIR/ta/active")"
echo "Host: $(readlink "$SCRIPT_DIR/host/active")"
echo ""
echo "TA Configuration:"
+echo " STD: ${STD:-}"
echo " TARGET_TA: $TARGET_TA"
-echo " CROSS_COMPILE_TA: $CROSS_COMPILE_TA"
echo " TA_DEV_KIT_DIR: $TA_DEV_KIT_DIR"
echo ""
echo "Host Configuration:"
echo " TARGET_HOST: $TARGET_HOST"
-echo " CROSS_COMPILE_HOST: $CROSS_COMPILE_HOST"
echo " OPTEE_CLIENT_EXPORT: $OPTEE_CLIENT_EXPORT"
echo ""
echo "QEMU Shared Directory: $QEMU_HOST_SHARE_DIR"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org
(teaclave-trustzone-sdk) 04/05: docs: describe Makefile builds through cargo-optee
Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit b9e0d0c01a2be9e7e783c33d5d9ce632700fdb3a
Author: ivila <39...@qq.com>
AuthorDate: Mon Sep 21 11:44:27 2026 +0800
docs: describe Makefile builds through cargo-optee
UUID now lives in the proto crate and the TA header; Make no longer
depends on uuid.txt. emulate installs through cargo-optee into
QEMU_HOST_SHARE_DIR. ARCH_TA is only an environment shorthand.
---
docs/advanced-setup.md | 34 +++++++++---
docs/emulate-and-dev-in-docker-std.md | 21 +++----
docs/emulate-and-dev-in-docker.md | 29 ++++------
docs/migrating-to-new-building-env.md | 98 ++++++++++++++++-----------------
docs/overview-of-optee-rust-examples.md | 6 +-
5 files changed, 101 insertions(+), 87 deletions(-)
diff --git a/docs/advanced-setup.md b/docs/advanced-setup.md
index 67f2463..5c16564 100644
--- a/docs/advanced-setup.md
+++ b/docs/advanced-setup.md
@@ -26,7 +26,7 @@ you can try the develop version using `git pull`:
```sh
cd [YOUR_OPTEE_DIR]/optee_rust/
-git pull github master
+git pull github main
```
### Develop on Other Platforms
@@ -88,14 +88,26 @@ Currently, we support building on both `aarch64` and `x86_64` host machines, and
3. Before building applications, set up the configuration:
- a. By default, the target platform is `aarch64` for both CA and TA. If
- you want to build for the `arm` target, you can set up `ARCH`:
+ a. By default, the target platform is `aarch64` for both CA and TA. To
+ build for `arm`, set the shorthands that `source environment` turns into
+ `TARGET_HOST` / `TARGET_TA` (Make derives cargo-optee `--arch` from those
+ triples; you can also export the triples directly):
```sh
export ARCH_HOST=arm
export ARCH_TA=arm
```
+ Re-sourcing `environment` refreshes `TARGET_*` when they still hold the
+ triple this script last derived from `ARCH_*` / `STD`. An explicit
+ `TARGET_TA` / `TARGET_HOST` is kept. To throw away a pinned triple and
+ derive again:
+
+ ```sh
+ unset TARGET_TA TARGET_HOST
+ source environment
+ ```
+
b. By default, the build is for `no-std` TA. If you want to enable
`std` TA, set the `STD` variable:
@@ -117,17 +129,25 @@ Run this command to build all Rust examples:
make examples
```
-Or build your own CA and TA:
+Or build a single example (CA and TA):
+
+```sh
+make -C examples hello_world-rs
+```
+
+The CA crate is `examples/ca/<name>/` and the TA crate is
+`examples/ta/<name>/`. You can also invoke those directories directly:
```sh
-make -C examples/[YOUR_APPLICATION]
+make -C examples/ca/hello_world-rs
+make -C examples/ta/hello_world-rs
```
Besides, you can collect all example CAs and TAs to
`/teaclave-trustzone-sdk/out`:
```sh
-make examples-install
+make install
```
## Run Rust Applications
@@ -150,7 +170,7 @@ Recompile QEMU in OP-TEE to enable QEMU VirtFS:
```sh
mkdir shared_folder
-cd [YOUR_OPTEE_DIR]/optee_rust/ && make examples-install)
+cd [YOUR_OPTEE_DIR]/optee_rust/ && make install
cp -r [YOUR_OPTEE_DIR]/optee_rust/out/* shared_folder/
```
diff --git a/docs/emulate-and-dev-in-docker-std.md b/docs/emulate-and-dev-in-docker-std.md
index f270818..b298869 100644
--- a/docs/emulate-and-dev-in-docker-std.md
+++ b/docs/emulate-and-dev-in-docker-std.md
@@ -56,8 +56,11 @@ $ ln -s $RUST_STD_DIR rust
The key difference is the **unified configuration system** that allows switching
between std/no-std modes and different architectures on demand.
-And [cargo-optee](../tools/cargo-optee/README.md#configuration-system) is available as
-an alternative to the original configuration management tool: switch_config.
+Example Makefiles invoke [cargo-optee](../tools/cargo-optee/README.md) after
+`switch_config` (or `source environment`) has set `STD` and the target
+architecture. You can also pass `--std` / `--arch` to cargo-optee directly;
+see the [cargo-optee configuration
+system](../tools/cargo-optee/README.md#configuration-system).
### If you use switch_config:
@@ -92,11 +95,6 @@ $ switch_config --host arm32 # Use 32-bit host
$ switch_config --host arm32 && switch_config --ta std/aarch64
```
-### If you use cargo-optee:
-
-You can see the [cargo-optee configuration
-system](../tools/cargo-optee/README.md#configuration-system) for details.
-
## 3. Building and Target Differences
Follow the [original building
@@ -105,8 +103,8 @@ note these important target differences:
| Configuration | TA Target | Build Tool | Host Target |
|---------------|-----------|------------|-------------|
-| `std/*` | `*-unknown-optee` | `cargo -Z build-std` | `*-unknown-linux-gnu` |
-| `no-std/*` | `*-unknown-linux-gnu` | `cargo` | `*-unknown-linux-gnu` |
+| `std/*` | `*-unknown-optee` | `cargo-optee --std` | `*-unknown-linux-gnu` |
+| `no-std/*` | `*-unknown-linux-gnu` | `cargo-optee --no-std` | `*-unknown-linux-gnu` |
**Example std build output:**
```bash
@@ -138,9 +136,8 @@ $ make clean && make
TA=examples/ta/target/aarch64-unknown-linux-gnu/release/133af0ca-bdab-11eb-9130-43bf7873bf67.ta
```
-If you are using cargo-optee, the relevant workflow is already clearly
-documented in the [cargo-optee appendix](../tools/cargo-optee/README.md#appendix), so
-it will not be repeated here.
+To invoke cargo-optee without Make, see the [cargo-optee
+appendix](../tools/cargo-optee/README.md#appendix).
## 5. Emulation and Execution
diff --git a/docs/emulate-and-dev-in-docker.md b/docs/emulate-and-dev-in-docker.md
index d2110ee..80a26dc 100644
--- a/docs/emulate-and-dev-in-docker.md
+++ b/docs/emulate-and-dev-in-docker.md
@@ -33,23 +33,17 @@ $ docker run -it --rm \
## 2. Build the Hello World Example
-Update: cargo-optee is available as an alternative to the original Makefile
-system. See the [cargo-optee documentation](../tools/cargo-optee/README.md) for
-details.
-
-### If you use Makefile:
-
**Still in Terminal A** (inside the Docker container, at the repository root):
```bash
# Build the Hello World example (both CA and TA)
make -C examples hello_world-rs
```
-Under the hood, the top-level `examples/Makefile` builds both the Trusted
-Application (TA) and the Client Application (CA) separately. The example is
-split across two crates: the CA crate lives in `examples/ca/hello_world-rs/`
-and the TA crate lives in `examples/ta/hello_world-rs/`. After a successful
-build, you'll find the resulting binaries in the shared workspace target
-directories:
+The example Makefiles invoke [cargo-optee](../tools/cargo-optee/README.md) to
+build, strip, and sign. The top-level `examples/Makefile` builds the Trusted
+Application (TA) and the Client Application (CA) separately. The CA crate lives
+in `examples/ca/hello_world-rs/` and the TA crate lives in
+`examples/ta/hello_world-rs/`. After a successful build, you'll find the
+resulting binaries in the shared workspace target directories:
```bash
TA=examples/ta/target/aarch64-unknown-linux-gnu/release/133af0ca-bdab-11eb-9130-43bf7873bf67.ta
HOST_APP=examples/ca/target/aarch64-unknown-linux-gnu/release/hello_world-rs
@@ -63,10 +57,9 @@ You can verify both artifacts exist before moving on:
ls $TA $HOST_APP
```
-### If you use cargo-optee:
-
-You can see the [cargo-optee Quick Build for Hello
-World](../tools/cargo-optee/README.md#quick-build-for-hello-world) for details.
+To call cargo-optee yourself instead of through Make, see the [cargo-optee
+Quick Build for Hello
+World](../tools/cargo-optee/README.md#quick-build-for-hello-world).
## 3. Make the Artifacts Accessible to the Emulator
After building the Hello World example, the next step is to make the compiled
@@ -76,7 +69,6 @@ There are **two approaches** to do this. You can choose either based on your
preference:
- 📦 **Manual sync**: Explicitly sync host and TA binaries to the emulator
- ⚙️ **Makefile integration**: Use `make emulate` to build and sync in one step
- (only when you use Makefile for building)
#### Option 1: Manual Sync via `sync_to_emulator`
We provide a helper command called `sync_to_emulator`, which simplifies the
@@ -89,6 +81,9 @@ sync_to_emulator --host $HOST_APP
Run `sync_to_emulator -h` for more usage options.
#### Option 2: Integrate sync with the example Makefiles
+
+The `emulate` target uses `cargo-optee install` to build and copy the current
+artifact into `$QEMU_HOST_SHARE_DIR/ta` or `$QEMU_HOST_SHARE_DIR/host`.
For convenience during daily development, the sync invocation can be integrated
into the Makefiles. Both the CA crate (`examples/ca/hello_world-rs`) and the TA
crate (`examples/ta/hello_world-rs`) provide an `emulate` target, which builds
diff --git a/docs/migrating-to-new-building-env.md b/docs/migrating-to-new-building-env.md
index 8ad6475..67c86b2 100644
--- a/docs/migrating-to-new-building-env.md
+++ b/docs/migrating-to-new-building-env.md
@@ -27,29 +27,12 @@ We have retained almost the same structure as the original but removed
we have some modification on `ta/ta_static.rs`, `ta/build.rs` and all
`Makefile`s. (See the explanation in next part).
-For example the current `examples/acipher-rs/`:
+For example the current `examples/{ca,ta}/acipher-rs/` (the 2024 layout kept
+host / ta / proto under one example directory; examples later split by side):
```
-examples/acipher-rs/
-├── host
-│ ├── Cargo.toml
-│ ├── Makefile
-│ └── src
-│ └── main.rs
-├── Makefile
-├── proto
-│ ├── build.rs
-│ ├── Cargo.toml
-│ └── src
-│ └── lib.rs
-├── ta
-│ ├── build.rs
-│ ├── Cargo.toml
-│ ├── Makefile
-│ ├── src
-│ │ └── main.rs
-│ ├── ta_static.rs
-│ └── Xargo.toml
-└── uuid.txt
+examples/ca/acipher-rs/ # Client Application (was host/)
+examples/ta/acipher-rs/ # Trusted Application
+examples/ta/proto/ # Shared command IDs and TA UUID
```
@@ -99,18 +82,18 @@ examples/acipher-rs/
5. **ENV variables**:
The original script for setting the toolchain path has some modifications.
- Due to the more complex building options mentioned above, `CROSS_COMPILE_{HOST, TA}`
- and `TARGET_{HOST, TA}` should be set by `source environment`.
- You should also set whether you want to build in `STD` mode (`export STD=y`)
- and specify the target architecture (`ARM32` or `AArch64`) for both CA and TA.
- Running `source environment` will set up all toolchains and libraries.
+ Set whether you want to build in `STD` mode (`export STD=y`) and the target
+ architecture. `ARCH_HOST` / `ARCH_TA` (`arm` or `aarch64`) are shorthands
+ for `source environment`; it derives `TARGET_{HOST,TA}`, `TA_DEV_KIT_DIR`,
+ and `OPTEE_CLIENT_EXPORT`. Make talks to cargo-optee from those triples;
+ cargo-optee owns the cross compiler, crate features, and cargo flags.
6. **Makefile Polishing**:
- a. Top-level Makefile (`examples/*/Makefile`): Reads the `CROSS_COMPILE_{HOST, TA}`
- and `TARGET_{HOST, TA}`.
- b. `host/Makefile`: Simplified and polished for the changes in ENV variables.
- c. `ta/Makefile`: For `std` TAs, checks if the `STD` environment variable is set,
- and further simplifications and polish are done.
+ a. Top-level Makefile (`examples/Makefile`): Passes `STD` and
+ `TARGET_{HOST,TA}`. `--arch` is derived from the triple.
+ b. `examples/ca/Makefile.include`: CA / plugin wrapper around cargo-optee.
+ c. `examples/ta/Makefile.include`: TA wrapper; `--std` from `STD` or from a
+ `*-unknown-optee` triple.
### Step 1: Migrating Projects
@@ -118,9 +101,10 @@ examples/acipher-rs/
If you have developed based on one of our example structures and haven't
modified the build scripts mentioned above, you can simply copy a current
example and move your code into it.
-Note that the `Makefile` for `std` TAs has tiny differences from the `no_std`
-one. If you are using a `no_std` TA, refer to `hello_world-rs`. For `std` TAs,
-refer to `serde-rs`.
+`no_std` and `std` TAs now share `examples/ta/Makefile.include`; `--std` is
+derived from `STD` or from a `*-unknown-optee` triple. Use `hello_world-rs`
+as the `no_std` template and `serde-rs` as the `std` template for application
+code.
We provide a shell script to assist with this migration (you may need to make
small adjustments based on whether you are building in `no_std` or `std` mode).
@@ -132,29 +116,45 @@ OLD_ROOT_PATH="/path/to/old/sdk"
NEW_PATH="/path/to/current/sdk"
# Duplicate the hello-world example in the new path as a template
-cp -r ${NEW_PATH}/examples/hello_world-rs ${NEW_PATH}/examples/${TARGET_EXAMPLE}
+cp -r ${NEW_PATH}/examples/ca/hello_world-rs ${NEW_PATH}/examples/ca/${TARGET_EXAMPLE}
+cp -r ${NEW_PATH}/examples/ta/hello_world-rs ${NEW_PATH}/examples/ta/${TARGET_EXAMPLE}
# Remove the source code directory and copy from the old path to the new path
-# including: src/ and Cargo.toml in host, ta, proto
-(cd ${NEW_PATH}/examples/${TARGET_EXAMPLE}/host && rm -rf src/ Cargo.* && \
+# including: src/ and Cargo.toml in host (now ca/), ta, proto
+(cd ${NEW_PATH}/examples/ca/${TARGET_EXAMPLE} && rm -rf src/ Cargo.* && \
cp -r ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/host/src . && \
cp ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/host/Cargo.toml .)
-(cd ${NEW_PATH}/examples/${TARGET_EXAMPLE}/ta && rm -rf src/ Cargo.* && \
+(cd ${NEW_PATH}/examples/ta/${TARGET_EXAMPLE} && rm -rf src/ Cargo.* && \
cp -r ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/ta/src . && \
cp ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/ta/Cargo.toml .)
-(cd ${NEW_PATH}/examples/${TARGET_EXAMPLE}/proto && rm -rf src/ Cargo.* && \
-cp -r ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/proto/src . && \
-cp ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/proto/Cargo.toml .)
-
-# Copy the UUID file from the old path to the new path
-cp ${OLD_ROOT_PATH}/examples/${TARGET_EXAMPLE}/uuid.txt \
-${NEW_PATH}/examples/${TARGET_EXAMPLE}/uuid.txt
-# Update binary names in host/Cargo.toml and host/Makefile
+# Proto is a workspace crate at examples/ta/proto/. Add a module named after
+# the example (hyphens → underscores, drop a trailing -rs) and put the TA UUID
+# there as a string constant (same value as the old uuid.txt):
+# pub const UUID: &str = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
+# Register it in examples/ta/proto/src/lib.rs (`pub mod your_project;`).
+#
+# The copied hello_world template still has
+# proto::hello_world::UUID
+# in ta/build.rs, so the signed .ta would keep the Hello World UUID until you
+# point build.rs (and CA `use proto::hello_world`) at the new module:
+PROTO_MOD="$(echo "${TARGET_EXAMPLE%-rs}" | tr '-' '_')"
+sed -i "s/proto::hello_world::/proto::${PROTO_MOD}::/g" \
+ ${NEW_PATH}/examples/ta/${TARGET_EXAMPLE}/build.rs
+
+# Overlaying the old Cargo.toml drops `{ workspace = true }`. Restore proto,
+# optee-utee / optee-teec, and optee-utee-build to workspace deps like the
+# hello_world template, then port any extra crates from the old manifest.
+
+# Update remaining hello_world-rs names in the CA/TA Cargo.toml and Makefile
+sed -i "s/hello_world-rs/${TARGET_EXAMPLE}/g" \
+${NEW_PATH}/examples/ca/${TARGET_EXAMPLE}/Cargo.toml
+sed -i "s/hello_world-rs/${TARGET_EXAMPLE}/g" \
+${NEW_PATH}/examples/ca/${TARGET_EXAMPLE}/Makefile
sed -i "s/hello_world-rs/${TARGET_EXAMPLE}/g" \
-${NEW_PATH}/examples/${TARGET_EXAMPLE}/host/Cargo.toml
+${NEW_PATH}/examples/ta/${TARGET_EXAMPLE}/Cargo.toml
sed -i "s/hello_world-rs/${TARGET_EXAMPLE}/g" \
-${NEW_PATH}/examples/${TARGET_EXAMPLE}/host/Makefile
+${NEW_PATH}/examples/ta/${TARGET_EXAMPLE}/Makefile
```
#### Case 2: Custom Migration (With Modified Build Scripts)
diff --git a/docs/overview-of-optee-rust-examples.md b/docs/overview-of-optee-rust-examples.md
index 4ac979d..0fef781 100644
--- a/docs/overview-of-optee-rust-examples.md
+++ b/docs/overview-of-optee-rust-examples.md
@@ -8,10 +8,12 @@ All OP-TEE Rust examples are suffixed with `-rs`, which work as standalone host
application and corresponding TA (Trusted Application) and can be found in
separate directories.
-To install all examples in `SDK_ROOT_DIR/out/`, run `make examples-install`
+To install all examples in `SDK_ROOT_DIR/out/`, run `make install`
after `make examples`.
-To compile one of the examples, run `make -C examples/EXAMPLE_DIR`.
+To compile one of the examples, run `make -C examples EXAMPLE_DIR`
+(for example `make -C examples hello_world-rs`). The CA lives in
+`examples/ca/EXAMPLE_DIR/` and the TA in `examples/ta/EXAMPLE_DIR/`.
| Host application name | TA UUID | Description | Std/No-std Support |
| ---------------------------- | -------------------------------------- | ------------------------------------------------------------ | ------------------ |
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org
(teaclave-trustzone-sdk) 01/05: cargo-optee: parse TA and plugin UUIDs from the unsigned ELF
Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit 0520801e558aa05e262f6045af7cc983d239ed77
Author: ivila <39...@qq.com>
AuthorDate: Mon Sep 21 11:44:20 2026 +0800
cargo-optee: parse TA and plugin UUIDs from the unsigned ELF
Drop uuid-path CLI/metadata inputs. Naming, signing, and install read
the OP-TEE 4.10 ABI from the built artifact. clippy is a separate
command; builders honour CROSS_COMPILE/TA_SIGN_KEY and use
Command::current_dir instead of changing the process cwd. Signed .ta
files are chmod 0644 so tee-supplicant can read them after install.
---
tools/cargo-optee/Cargo.toml | 6 +
tools/cargo-optee/README.md | 220 +++++++++++++---------
tools/cargo-optee/src/ca_builder.rs | 235 ++++++++++++-----------
tools/cargo-optee/src/cli.rs | 60 ++++--
tools/cargo-optee/src/common.rs | 362 +++++++++++++++++++++++++++---------
tools/cargo-optee/src/config.rs | 338 ++++++++++++++++-----------------
tools/cargo-optee/src/elf_uuid.rs | 268 ++++++++++++++++++++++++++
tools/cargo-optee/src/lib.rs | 23 +++
tools/cargo-optee/src/main.rs | 167 ++++++++++-------
tools/cargo-optee/src/ta_builder.rs | 187 ++++++++++---------
10 files changed, 1245 insertions(+), 621 deletions(-)
diff --git a/tools/cargo-optee/Cargo.toml b/tools/cargo-optee/Cargo.toml
index be5d0a2..3b1de6e 100644
--- a/tools/cargo-optee/Cargo.toml
+++ b/tools/cargo-optee/Cargo.toml
@@ -24,6 +24,10 @@ license.workspace = true
repository.workspace = true
edition.workspace = true
+[lib]
+name = "cargo_optee"
+path = "src/lib.rs"
+
[[bin]]
name = "cargo-optee"
path = "src/main.rs"
@@ -40,3 +44,5 @@ env_logger = "0.11"
log = "0.4"
tempfile = "3.8"
dirs = "5.0"
+goblin = "0.8"
+uuid = { version = "1", features = ["std"] }
diff --git a/tools/cargo-optee/README.md b/tools/cargo-optee/README.md
index 46e659e..c7331e3 100644
--- a/tools/cargo-optee/README.md
+++ b/tools/cargo-optee/README.md
@@ -5,10 +5,9 @@ Applications (CAs) in Rust.
## Overview
-`cargo-optee` simplifies the development workflow for OP-TEE applications by
-replacing complex Makefiles with a unified, type-safe command-line interface. It
-handles cross-compilation, custom target specifications, environment setup, and
-signing automatically.
+`cargo-optee` simplifies the development workflow for OP-TEE applications. SDK
+example Makefiles invoke it for clippy, cross-compilation, stripping, and
+signing; you can also call the same CLI directly.
## High-Level Design
@@ -38,11 +37,9 @@ signing automatically.
│ └──────────────────┬─────────────────────┘ │
│ │ │
│ ┌──────────────────▼─────────────────────┐ │
- │ │ 3. Execute Build Pipeline │ │
- │ │ - Run clippy (linting) │ │
- │ │ - Build binary: cargo + gcc │ │
- │ │ - Strip symbols: objcopy │ │
- │ │ - Sign TA: Python script (TA only) │ │
+ │ │ 3. Execute command │ │
+ │ │ clippy: cargo fmt + clippy │ │
+ │ │ build: cargo + strip + sign TA │ │
│ └──────────────────┬─────────────────────┘ │
│ │ │
└─────────────────────┼────────────────────────┘
@@ -178,10 +175,17 @@ After building, you can:
2. **Cargo.toml Metadata** - Project-specific configuration in
`[package.metadata.optee.*]` sections (see [Build through
metadata](#build-through-metadata))
-3. **Defaults** - Built-in sensible defaults
+3. **Environment variables** - Used when CLI and metadata omit a value:
+ - `TA_DEV_KIT_DIR`, `OPTEE_CLIENT_EXPORT` for kit / client export paths
+ - `TA_SIGN_KEY` for the TA signing key
+ - `CROSS_COMPILE` for the toolchain prefix (no CLI or metadata equivalent;
+ otherwise derived from `--arch`)
+4. **Defaults** - Built-in sensible defaults (for example
+ `<ta-dev-kit-dir>/keys/default_ta.pem`)
This allows projects to define their standard configuration in `Cargo.toml`
-while still permitting CLI overrides for specific builds.
+while still permitting CLI overrides for specific builds. Make wrappers pass
+`CROSS_COMPILE` and `TA_SIGN_KEY` through the environment.
### Project Structure
@@ -189,12 +193,11 @@ Cargo-optee expects the following project structure by default.
```
project/
-├── uuid.txt # TA UUID
├── ta/ # Trusted Application
│ ├── Cargo.toml
│ ├── src/
│ │ └── main.rs
-│ └── build.rs # Build script
+│ └── build.rs # Build script (optional; UUID lives in the TA header)
├── host/ # Client Application (host)
│ ├── Cargo.toml
│ ├── src/
@@ -205,16 +208,27 @@ project/
└── lib.rs
```
+The TA UUID is defined in the TA's own header (`ta_head.uuid`) and, if you use a
+shared proto crate, as a Rust constant consumed by the CA and the TA build
+script. `cargo-optee` parses the UUID from the unsigned ELF after the crate is
+built. The same rule applies to plugins (`plugin_method.uuid`). Shared proto
+crates and `optee-utee-build` / `optee-teec-build` are optional development
+helpers — UUID extraction depends only on the OP-TEE 4.10.0 ABI.
+
See examples in the SDK for reference, such as `hello_world-rs`. Note that in
this SDK's `examples/` directory the layout is split by side instead of by
-project: the TA crate lives in `examples/ta/hello_world-rs/` (with `uuid.txt`
-next to it), the CA crate lives in `examples/ca/hello_world-rs/` (named `ca/`
-rather than `host/`), and the shared definitions live in the workspace crate
-`examples/ta/proto`. The `cargo new`
-command (planned, not yet available) will generate a project template with this
-structure. For now, copy an existing example as a starting point.
+project: the TA crate lives in `examples/ta/hello_world-rs/`, the CA crate lives
+in `examples/ca/hello_world-rs/` (named `ca/` rather than `host/`), and the
+shared definitions live in the workspace crate `examples/ta/proto`. The `cargo
+new` command (planned, not yet available) will generate a project template with
+this structure. For now, copy an existing example as a starting point.
+
+### Usage Workflows
-### Usage Workflows (including future design)
+Implemented commands are `build`, `clippy`, `install`, `clean`, and
+`inspect-uuid`. `cargo-optee new` and a single `install --target` / `clean --all`
+that cover a whole project are not implemented; use the per-component commands
+below.
#### Development/Emulation Environment
@@ -240,8 +254,16 @@ cargo-optee build ca \
--manifest-path ./host/Cargo.toml \
--arch aarch64
-# 3. Install to specific folder (future), e.g. QEMU shared folder for emulation
-cargo-optee install --target /tmp/qemu-shared-folder
+# 3. Install (copies the built TA/CA into --target-dir, resolved from the
+# process cwd — not the crate directory)
+cargo-optee install ta \
+ --target-dir /tmp/qemu-shared-folder \
+ --ta-dev-kit-dir $TA_DEV_KIT_DIR \
+ --manifest-path ./ta/Cargo.toml
+cargo-optee install ca \
+ --target-dir /tmp/qemu-shared-folder \
+ --optee-client-export $OPTEE_CLIENT_EXPORT \
+ --manifest-path ./host/Cargo.toml
```
**Using metadata configuration:**
@@ -281,11 +303,12 @@ cargo-optee build ca \
--manifest-path ./host/Cargo.toml \
--arch aarch64
-# Install to staging area (future)
-cargo-optee install --target ./dist
+# Install (implemented: install ta|ca|plugin --target-dir <DIR>)
+cargo-optee install ta --target-dir ./dist --manifest-path ./ta/Cargo.toml
+cargo-optee install ca --target-dir ./dist --manifest-path ./host/Cargo.toml
-# Clean build artifacts to save space (future)
-cargo-optee clean --all
+# Clean the crate (implemented: cargo-optee clean [--manifest-path ...])
+cargo-optee clean --manifest-path ./ta/Cargo.toml
```
### Build through CLI
@@ -300,7 +323,6 @@ cargo-optee build ta \
[--std] \
[--no-std] \
[--signing-key <PATH>] \
- [--uuid-path <PATH>] \
[--debug]
```
@@ -312,12 +334,17 @@ cargo-optee build ta \
- `--arch <ARCH>`: Target architecture (default: `aarch64`)
- `aarch64`: ARM 64-bit architecture
- `arm`: ARM 32-bit architecture
+ The cross-compiler prefix is derived from this; set `CROSS_COMPILE` in the
+ environment to override (there is no CLI flag).
- `--std`: Build with std support (uses `cargo -Z build-std` and custom target)
- `--no-std`: Build without std support (mutually exclusive with --std)
-- `--signing-key <PATH>`: Path to signing key (default:
- `<ta-dev-kit-dir>/keys/default_ta.pem`)
-- `--uuid-path <PATH>`: Path to UUID file (default: `../uuid.txt`)
-- `--debug`: Build in debug mode (default: release mode)
+- `--signing-key <PATH>`: Path to signing key (fallback: Cargo.toml metadata,
+ then `TA_SIGN_KEY`, then `<ta-dev-kit-dir>/keys/default_ta.pem`)
+- `--debug`: Force a debug build. If omitted, Cargo.toml metadata is used
+ (default: release)
+
+The UUID used for signing and the `<uuid>.ta` name is parsed from the unsigned
+TA ELF (`ta_head.uuid`).
**Example:**
```bash
@@ -364,7 +391,8 @@ cargo-optee build ca \
`OPTEE_CLIENT_EXPORT`.
- `--manifest-path <PATH>`: Path to Cargo.toml manifest file
- `--arch <ARCH>`: Target architecture (default: `aarch64`)
-- `--debug`: Build in debug mode (default: release mode)
+- `--debug`: Force a debug build. If omitted, Cargo.toml metadata is used
+ (default: release)
**Example:**
```bash
@@ -388,7 +416,6 @@ We have one example for plugin: `examples/ca/supp_plugin-rs-plugin`.
```bash
cargo-optee build plugin \
[--optee-client-export <PATH>] \
- --uuid-path <PATH> \
[--manifest-path <PATH>] \
[--arch aarch64|arm] \
[--debug]
@@ -399,10 +426,13 @@ cargo-optee build plugin \
- `--optee-client-export <PATH>`: Path to the OP-TEE client export directory.
If omitted, cargo-optee reads it from Cargo.toml metadata, then
`OPTEE_CLIENT_EXPORT`.
-- `--uuid-path <PATH>`: Path to UUID file for naming the plugin
- `--manifest-path <PATH>`: Path to Cargo.toml manifest file
- `--arch <ARCH>`: Target architecture (default: `aarch64`)
-- `--debug`: Build in debug mode (default: release mode)
+- `--debug`: Force a debug build. If omitted, Cargo.toml metadata is used
+ (default: release)
+
+The plugin is copied to `<uuid>.plugin.so` using the UUID parsed from the
+dynamic `plugin_method` export.
**Example:**
```bash
@@ -410,13 +440,48 @@ cargo-optee build plugin \
cargo-optee build plugin \
--optee-client-export /opt/optee/export-client \
--manifest-path ./examples/ca/supp_plugin-rs-plugin/Cargo.toml \
- --uuid-path ./examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt \
--arch aarch64
```
**Output:**
- Plugin binary: `target/<target-triple>/release/<uuid>.plugin.so`
+#### Inspect UUID
+
+```bash
+cargo-optee inspect-uuid --kind ta --elf path/to/ta.elf
+cargo-optee inspect-uuid --kind plugin --elf path/to/plugin.so
+```
+
+Prints the UUID to stdout. Same parser as `build ta` / `build plugin`.
+
+#### Clippy
+
+Lint only. Same target and environment as the corresponding `build` command;
+does not compile the final binary, strip, or sign, and does not require a
+signing key.
+
+```bash
+cargo-optee clippy ta \
+ --manifest-path examples/ta/hello_world-rs/Cargo.toml \
+ --arch aarch64 \
+ --no-std
+
+cargo-optee clippy ca --manifest-path examples/ca/hello_world-rs/Cargo.toml
+cargo-optee clippy plugin --manifest-path examples/ca/supp_plugin-rs-plugin/Cargo.toml
+```
+
+Example Makefiles keep the original target split: `make clippy` calls this
+command; `make ta` / `make host` depend on it and then call `build`.
+
+`make install` delegates to `cargo-optee install` for each selected example;
+`STD` / `TARGET_TA` select the std or no-std set. `O`, `bindir`, and `libdir`
+control the installation layout. A component can also be installed with
+`make -C examples/ta/hello_world-rs install INSTALL_DIR=/path/to/destination`.
+`make emulate` uses the same install command with the `ta` or `host` directory
+under `QEMU_HOST_SHARE_DIR`. Makefiles do not infer Cargo artifact paths or
+scan target directories for previously built binaries.
+
### Build through metadata
#### Trusted Application (TA) Metadata
@@ -428,10 +493,9 @@ Configure TA builds in your `Cargo.toml`:
arch = "aarch64" # Target architecture: "aarch64" | "arm" (optional, default: "aarch64")
debug = false # Debug build: true | false (optional, default: false)
std = false # Use std library: true | false (optional, default: false)
-uuid-path = "../uuid.txt" # Path to UUID file (optional, default: "../uuid.txt")
# Architecture-specific configuration (omitted architectures default to null/unsupported)
ta-dev-kit-dir = { aarch64 = "/opt/optee/export-ta_arm64", arm = "/opt/optee/export-ta_arm32" }
-signing-key = "/path/to/key.pem" # Path to signing key (optional, defaults to ta-dev-kit/keys/default_ta.pem)
+signing-key = "/path/to/key.pem" # optional; else TA_SIGN_KEY, else ta-dev-kit/keys/default_ta.pem
```
**Allowed entries:**
@@ -439,10 +503,12 @@ signing-key = "/path/to/key.pem" # Path to signing key (optional, defaults to
- `arch`: Target architecture (`"aarch64"` or `"arm"`)
- `debug`: Build in debug mode (`true` or `false`)
- `std`: Enable std library support (`true` or `false`)
-- `uuid-path`: Relative or absolute path to UUID file
- `ta-dev-kit-dir`: Architecture-specific paths to the TA development kit. If
omitted, `TA_DEV_KIT_DIR` is used.
-- `signing-key`: Path to signing key file
+- `signing-key`: Path to signing key file. If omitted, `TA_SIGN_KEY` then
+ `<ta-dev-kit-dir>/keys/default_ta.pem`.
+
+The TA UUID is taken from the TA header after the crate is built.
#### Client Application (CA) Metadata
@@ -472,7 +538,6 @@ Configure plugin builds in your `Cargo.toml`:
[package.metadata.optee.plugin]
arch = "aarch64" # Target architecture: "aarch64" | "arm" (optional, default: "aarch64")
debug = false # Debug build: true | false (optional, default: false)
-uuid-path = "../plugin_uuid.txt" # Path to UUID file (required for plugins)
# Architecture-specific configuration
optee-client-export = { aarch64 = "/opt/optee/export-client_arm64", arm = "/opt/optee/export-client_arm32" }
```
@@ -481,20 +546,23 @@ optee-client-export = { aarch64 = "/opt/optee/export-client_arm64", arm = "/opt/
- `arch`: Target architecture (`"aarch64"` or `"arm"`)
- `debug`: Build in debug mode (`true` or `false`)
-- `uuid-path`: Relative or absolute path to UUID file (required for plugins)
- `optee-client-export`: Architecture-specific paths to OP-TEE client export
(falls back to `OPTEE_CLIENT_EXPORT`)
+The plugin UUID is parsed from the dynamically exported `struct plugin_method`.
+
## Implementation Status
| Feature | Status | Notes |
|---------|--------|-------|
-| `build ta` | ✅ Implemented | Supports aarch64/arm, std/no-std |
+| `build ta` | ✅ Implemented | cargo + strip + sign; aarch64/arm, std/no-std |
| `build ca` | ✅ Implemented | Supports aarch64/arm |
| `build plugin` | ✅ Implemented | Supports aarch64/arm, builds shared library plugins |
-| `clean` | ✅ Implemented | Remove build artifacts |
+| `clippy ta/ca/plugin` | ✅ Implemented | cargo fmt + clippy only |
+| `inspect-uuid` | ✅ Implemented | Parse UUID from an unsigned TA ELF or plugin `.so` |
+| `install ta/ca/plugin` | ✅ Implemented | Copy the built artifact to `--target-dir` (cwd-relative) |
+| `clean` | ✅ Implemented | `cargo clean` for one crate (`--manifest-path`) |
| `new` | ⏳ Planned | Project scaffolding |
-| `install` | ⏳ Planned | Deploy to target filesystem |
-----
## Appendix
@@ -515,30 +583,24 @@ cargo-optee build ta \
**cargo-optee translates to:**
```bash
-# 1. Clippy
-cd ./ta
+# cargo-optee does not chdir the process; each command uses current_dir +
+# --manifest-path pointing at the crate.
TA_DEV_KIT_DIR=/opt/optee/export-ta_arm64 \
RUSTFLAGS="-C panic=abort" \
-cargo clippy --target aarch64-unknown-linux-gnu --release
-
-# 2. Build
-TA_DEV_KIT_DIR=/opt/optee/export-ta_arm64 \
-RUSTFLAGS="-C panic=abort" \
-cargo build --target aarch64-unknown-linux-gnu --release \
- --manifest-path ./ta/Cargo.toml \
+cargo build --manifest-path ./ta/Cargo.toml --target aarch64-unknown-linux-gnu --release \
--config target.aarch64-unknown-linux-gnu.linker="aarch64-linux-gnu-gcc"
-# 3. Strip
+# 2. Strip (unique tempfile, then discarded after signing)
aarch64-linux-gnu-objcopy --strip-unneeded \
target/aarch64-unknown-linux-gnu/release/ta \
- target/aarch64-unknown-linux-gnu/release/stripped_ta
+ target/aarch64-unknown-linux-gnu/release/stripped_ta.<unique>
-# 4. Sign
+# 3. Sign (unique .ta.partial, then rename onto <uuid>.ta)
python3 /opt/optee/export-ta_arm64/scripts/sign_encrypt.py \
- --uuid <uuid-from-file> \
+ --uuid <uuid-parsed-from-stripped-elf> \
--key /opt/optee/export-ta_arm64/keys/default_ta.pem \
- --in target/aarch64-unknown-linux-gnu/release/stripped_ta \
- --out target/aarch64-unknown-linux-gnu/release/<uuid>.ta
+ --in target/aarch64-unknown-linux-gnu/release/stripped_ta.<unique> \
+ --out target/aarch64-unknown-linux-gnu/release/<uuid>.ta.<unique>.partial
```
#### Example 2: Build arm std TA
@@ -554,35 +616,25 @@ cargo-optee build ta \
**cargo-optee translates to:**
```bash
-# 1. Clippy
-cd ./ta
TA_DEV_KIT_DIR=/opt/optee/export-ta_arm32 \
RUSTFLAGS="-C panic=abort" \
RUST_TARGET_PATH=/tmp/cargo-optee-XXXXX \
__CARGO_TESTS_ONLY_SRC_ROOT=/path/to/rust/library \
-cargo -Z build-std=std,panic_abort -Z json-target-spec clippy --target arm-unknown-optee --features std --release \
- --manifest-path ./ta/Cargo.toml
-
-# 2. Build
-TA_DEV_KIT_DIR=/opt/optee/export-ta_arm32 \
-RUSTFLAGS="-C panic=abort" \
-RUST_TARGET_PATH=/tmp/cargo-optee-XXXXX \
-__CARGO_TESTS_ONLY_SRC_ROOT=/path/to/rust/library \
-cargo -Z build-std=std,panic_abort -Z json-target-spec build --target arm-unknown-optee --features std --release \
- --manifest-path ./ta/Cargo.toml \
+cargo -Z build-std=std,panic_abort -Z json-target-spec build \
+ --manifest-path ./ta/Cargo.toml --target arm-unknown-optee --features std --release \
--config target.arm-unknown-optee.linker="arm-linux-gnueabihf-gcc"
-# 3. Strip
+# 2. Strip (unique tempfile)
arm-linux-gnueabihf-objcopy --strip-unneeded \
target/arm-unknown-optee/release/ta \
- target/arm-unknown-optee/release/stripped_ta
+ target/arm-unknown-optee/release/stripped_ta.<unique>
-# 4. Sign
+# 3. Sign (unique .ta.partial, then rename onto <uuid>.ta)
python3 /opt/optee/export-ta_arm32/scripts/sign_encrypt.py \
- --uuid <uuid-from-file> \
+ --uuid <uuid-parsed-from-stripped-elf> \
--key /opt/optee/export-ta_arm32/keys/default_ta.pem \
- --in target/arm-unknown-optee/release/stripped_ta \
- --out target/arm-unknown-optee/release/<uuid>.ta
+ --in target/arm-unknown-optee/release/stripped_ta.<unique> \
+ --out target/arm-unknown-optee/release/<uuid>.ta.<unique>.partial
```
**Note:** `/tmp/cargo-optee-XXXXX` is a temporary directory containing the
@@ -599,19 +651,11 @@ cargo-optee build ca \
**cargo-optee translates to:**
```bash
-# 1. Clippy
-cd ./host
OPTEE_CLIENT_EXPORT=/opt/optee/export-client \
-cargo clippy --target aarch64-unknown-linux-gnu \
- --manifest-path ./host/Cargo.toml
-
-# 2. Build
-OPTEE_CLIENT_EXPORT=/opt/optee/export-client \
-cargo build --target aarch64-unknown-linux-gnu --release \
- --manifest-path ./host/Cargo.toml \
+cargo build --manifest-path ./host/Cargo.toml --target aarch64-unknown-linux-gnu --release \
--config target.aarch64-unknown-linux-gnu.linker="aarch64-linux-gnu-gcc"
-# 3. Strip
+# 2. Strip
aarch64-linux-gnu-objcopy --strip-unneeded \
target/aarch64-unknown-linux-gnu/release/<binary> \
target/aarch64-unknown-linux-gnu/release/<binary>
diff --git a/tools/cargo-optee/src/ca_builder.rs b/tools/cargo-optee/src/ca_builder.rs
index d4095b7..f1ef6f3 100644
--- a/tools/cargo-optee/src/ca_builder.rs
+++ b/tools/cargo-optee/src/ca_builder.rs
@@ -15,40 +15,32 @@
// specific language governing permissions and limitations
// under the License.
-use crate::cargo_command;
-use crate::common;
use crate::common::{
- BuildMode, ChangeDirectoryGuard, get_package_name, get_target_and_cross_compile,
- get_target_directory_from_metadata, print_cargo_command, print_output_and_bail,
- read_uuid_from_file,
+ BuildMode, CargoArtifactKind, absolute_dir, apply_clippy_deny_lints, cargo_command_in,
+ manifest_path, print_cargo_command, print_output_and_bail, publish_tempfile,
+ resolve_target_and_cross_compile, unique_cargo_artifact, unique_tempfile_in,
};
use crate::config::CaBuildConfig;
+use crate::elf_uuid;
use anyhow::{Result, bail};
use std::path::{Path, PathBuf};
// Main function to build the CA, optionally installing to a target directory
-pub fn build_ca(config: CaBuildConfig, install_dir: Option<&Path>) -> Result<()> {
- // Change to the CA directory
- let _guard = ChangeDirectoryGuard::new(&config.path)?;
+pub fn build_ca(mut config: CaBuildConfig, install_dir: Option<&Path>) -> Result<()> {
+ config.path = absolute_dir(&config.path)?;
let component_type = if config.plugin { "Plugin" } else { "CA" };
- // Get the absolute path for better clarity
- let absolute_path = std::fs::canonicalize(&config.path).unwrap_or_else(|_| config.path.clone());
println!(
"Building {} in directory: {}",
component_type,
- absolute_path.display()
+ config.path.display()
);
- // Step 1: Run clippy for code quality checks
- run_clippy(&config)?;
-
- // Step 2: Build the CA
- build_binary(&config)?;
+ let built_path = build_binary(&config)?;
// Step 3: Post-build processing (strip for binaries, copy for plugins)
- let final_binary = post_build(&config)?;
+ let final_binary = post_build(&config, &built_path)?;
// Print the final binary path with descriptive prompt
let absolute_final_binary = final_binary
@@ -72,14 +64,10 @@ pub fn build_ca(config: CaBuildConfig, install_dir: Option<&Path>) -> Result<()>
bail!("Install directory does not exist: {:?}", install_dir);
}
- // Get package name from the final binary path
- let package_name = final_binary
+ let dest_name = final_binary
.file_name()
- .and_then(|name| name.to_str())
.ok_or_else(|| anyhow::anyhow!("Could not get binary name"))?;
-
- // Copy binary to install directory
- let dest_path = install_dir.join(package_name);
+ let dest_path = install_dir.join(dest_name);
fs::copy(&final_binary, &dest_path)?;
println!(
@@ -94,31 +82,27 @@ pub fn build_ca(config: CaBuildConfig, install_dir: Option<&Path>) -> Result<()>
Ok(())
}
+/// Run cargo fmt and clippy with the same target/env as a CA/plugin build.
+pub fn clippy_ca(mut config: CaBuildConfig) -> Result<()> {
+ config.path = absolute_dir(&config.path)?;
+ run_clippy(&config)
+}
+
fn run_clippy(config: &CaBuildConfig) -> Result<()> {
println!("Running cargo fmt and clippy...");
- // Run cargo fmt
- let fmt_output = cargo_command().arg("fmt").output()?;
+ let fmt_output = cargo_command_in(&config.path)
+ .arg("fmt")
+ .arg("--manifest-path")
+ .arg(manifest_path(&config.path))
+ .output()?;
if !fmt_output.status.success() {
print_output_and_bail("cargo fmt", &fmt_output)?;
}
- // Determine target based on arch (CA runs in Normal World Linux)
- let (target, _cross_compile) = get_target_and_cross_compile(config.arch, BuildMode::Ca)?;
-
- let mut clippy_cmd = cargo_command();
- clippy_cmd.arg("clippy");
- clippy_cmd.arg("--target").arg(&target);
-
- // Set OPTEE_CLIENT_EXPORT environment variable for build scripts
- clippy_cmd.env("OPTEE_CLIENT_EXPORT", &config.optee_client_export);
-
- clippy_cmd.arg("--");
- clippy_cmd.arg("-D").arg("warnings");
- clippy_cmd.arg("-D").arg("clippy::unwrap_used");
- clippy_cmd.arg("-D").arg("clippy::expect_used");
- clippy_cmd.arg("-D").arg("clippy::panic");
+ let mut clippy_cmd = setup_ca_cargo_command(config, "clippy")?;
+ apply_clippy_deny_lints(&mut clippy_cmd);
let clippy_output = clippy_cmd.output()?;
@@ -129,130 +113,141 @@ fn run_clippy(config: &CaBuildConfig) -> Result<()> {
Ok(())
}
-fn build_binary(config: &CaBuildConfig) -> Result<()> {
- let component_type = if config.plugin { "Plugin" } else { "CA" };
- println!("Building {} binary...", component_type);
-
- // Determine target and cross-compile based on arch (CA runs in Normal World Linux)
- let (target, cross_compile) = get_target_and_cross_compile(config.arch, BuildMode::Ca)?;
-
- let mut build_cmd = cargo_command();
- build_cmd.arg("build");
- build_cmd.arg("--target").arg(&target);
-
- // Add --no-default-features if specified
+fn setup_ca_cargo_command(config: &CaBuildConfig, command: &str) -> Result<std::process::Command> {
+ let (target, _cross_compile) = resolve_target_and_cross_compile(config.arch, BuildMode::Ca)?;
+ let mut cmd = cargo_command_in(&config.path);
+ cmd.arg(command);
+ cmd.arg("--manifest-path").arg(manifest_path(&config.path));
+ cmd.arg("--target").arg(&target);
if config.no_default_features {
- build_cmd.arg("--no-default-features");
+ cmd.arg("--no-default-features");
}
-
- // Add additional features if specified
if let Some(ref features) = config.features {
- build_cmd.arg("--features").arg(features);
+ cmd.arg("--features").arg(features);
+ }
+ cmd.env("OPTEE_CLIENT_EXPORT", &config.optee_client_export);
+ for (key, value) in &config.env {
+ cmd.env(key, value);
}
+ Ok(cmd)
+}
+fn build_binary(config: &CaBuildConfig) -> Result<PathBuf> {
+ let component_type = if config.plugin { "Plugin" } else { "CA" };
+ println!("Building {} binary...", component_type);
+
+ let (target, cross_compile) = resolve_target_and_cross_compile(config.arch, BuildMode::Ca)?;
+
+ let mut build_cmd = setup_ca_cargo_command(config, "build")?;
if !config.debug {
build_cmd.arg("--release");
}
- // Configure linker
let linker = format!("{}gcc", cross_compile);
let linker_cfg = format!("target.{}.linker=\"{}\"", target, linker);
build_cmd.arg("--config").arg(&linker_cfg);
+ build_cmd.arg("--message-format=json");
- // Set OPTEE_CLIENT_EXPORT environment variable
- build_cmd.env("OPTEE_CLIENT_EXPORT", &config.optee_client_export);
-
- // Apply custom environment variables
- for (key, value) in &config.env {
- build_cmd.env(key, value);
- }
-
- // Print the full cargo build command for debugging
print_cargo_command(&build_cmd, "Building CA binary");
let build_output = build_cmd.output()?;
+ let kind = if config.plugin {
+ CargoArtifactKind::Cdylib
+ } else {
+ CargoArtifactKind::Bin
+ };
+ let manifest = manifest_path(&config.path);
if !build_output.status.success() {
+ let _ = unique_cargo_artifact(&build_output.stdout, &manifest, kind);
print_output_and_bail("build", &build_output)?;
}
- Ok(())
+ unique_cargo_artifact(&build_output.stdout, &manifest, kind)
}
-fn post_build(config: &CaBuildConfig) -> Result<PathBuf> {
+fn post_build(config: &CaBuildConfig, built_path: &Path) -> Result<PathBuf> {
if config.plugin {
- copy_plugin(config)
+ copy_plugin(built_path)
} else {
- strip_binary(config)
+ strip_binary(config, built_path)
}
}
-fn copy_plugin(config: &CaBuildConfig) -> Result<PathBuf> {
+fn copy_plugin(plugin_src: &Path) -> Result<PathBuf> {
println!("Processing plugin...");
- // Determine target based on arch (CA runs in Normal World Linux)
- let (target, _cross_compile) = get_target_and_cross_compile(config.arch, BuildMode::Ca)?;
-
- let profile = if config.debug { "debug" } else { "release" };
-
- // Use cargo metadata to get the target directory (supports workspace and CARGO_TARGET_DIR)
- let target_directory = get_target_directory_from_metadata()?;
- let target_dir = target_directory.join(target).join(profile);
-
- // Get the library name from Cargo.toml (we're already in the project directory)
- let lib_name = get_package_name()?;
-
- // Plugin is built as a shared library (lib<name>.so)
- let plugin_src = common::join_format_and_check::<&str>(
- &target_dir,
- &[],
- &format!("lib{}.so", lib_name),
- "Plugin library",
- )?;
-
- // Read UUID from specified file
- let uuid = read_uuid_from_file(
- config
- .uuid_path
- .as_ref()
- .ok_or_else(|| anyhow::anyhow!("UUID path is required for plugin builds"))?,
- )?;
-
- // Copy to <uuid>.plugin.so
- let plugin_dest = target_dir.join(format!("{}.plugin.so", uuid));
- std::fs::copy(plugin_src, &plugin_dest)?;
+ let uuid = elf_uuid::read_plugin_uuid(plugin_src)?;
+ let plugin_dest = plugin_src.with_file_name(format!("{}.plugin.so", uuid));
+ let parent = plugin_src
+ .parent()
+ .ok_or_else(|| anyhow::anyhow!("Plugin path has no parent: {:?}", plugin_src))?;
+ let tmp = unique_tempfile_in(parent, &format!("{}.plugin.so.", uuid), "")?;
+ std::fs::copy(plugin_src, tmp.path())?;
+ publish_tempfile(tmp, &plugin_dest)?;
Ok(plugin_dest)
}
-fn strip_binary(config: &CaBuildConfig) -> Result<PathBuf> {
+fn strip_binary(config: &CaBuildConfig, binary_path: &Path) -> Result<PathBuf> {
println!("Stripping binary...");
- // Determine target and cross-compile based on arch (CA runs in Normal World Linux)
- let (target, cross_compile) = get_target_and_cross_compile(config.arch, BuildMode::Ca)?;
-
- let profile = if config.debug { "debug" } else { "release" };
-
- // Use cargo metadata to get the target directory (supports workspace and CARGO_TARGET_DIR)
- let target_directory = get_target_directory_from_metadata()?;
- let target_dir = target_directory.join(target).join(profile);
-
- // Get the binary name from Cargo.toml (we're already in the project directory)
- let binary_name = get_package_name()?;
-
- let binary_path = common::join_and_check(&target_dir, &[binary_name], "Binary")?;
-
+ let (_, cross_compile) = resolve_target_and_cross_compile(config.arch, BuildMode::Ca)?;
let objcopy = format!("{}objcopy", cross_compile);
let strip_output = std::process::Command::new(&objcopy)
.arg("--strip-unneeded")
- .arg(&binary_path)
- .arg(&binary_path) // Strip in place
+ .arg(binary_path)
+ .arg(binary_path) // Strip in place
.output()?;
if !strip_output.status.success() {
print_output_and_bail(&objcopy, &strip_output)?;
}
- Ok(binary_path)
+ Ok(binary_path.to_path_buf())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::common::Arch;
+
+ fn ca_config() -> CaBuildConfig {
+ CaBuildConfig {
+ arch: Arch::Aarch64,
+ debug: false,
+ path: PathBuf::from("/tmp/project"),
+ env: vec![("CUSTOM".into(), "1".into())],
+ no_default_features: true,
+ features: Some("needed".into()),
+ optee_client_export: PathBuf::from("/tmp/client-export"),
+ plugin: false,
+ }
+ }
+
+ /// Guarantee: `clippy` and `build` receive the same `--features`,
+ /// `--no-default-features`, and custom env, so clippy lints the crate
+ /// graph that will be signed and installed.
+ #[test]
+ fn clippy_and_build_share_package_flags() {
+ let config = ca_config();
+ let clippy = setup_ca_cargo_command(&config, "clippy").unwrap();
+ let build = setup_ca_cargo_command(&config, "build").unwrap();
+ for cmd in [&clippy, &build] {
+ let args: Vec<_> = cmd
+ .get_args()
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+ assert!(args.contains(&"--features".to_string()));
+ assert!(args.contains(&"needed".to_string()));
+ assert!(args.contains(&"--no-default-features".to_string()));
+ let env = cmd
+ .get_envs()
+ .find(|(k, _)| k.to_str() == Some("CUSTOM"))
+ .and_then(|(_, v)| v)
+ .map(|v| v.to_string_lossy().into_owned());
+ assert_eq!(env.as_deref(), Some("1"));
+ }
+ }
}
diff --git a/tools/cargo-optee/src/cli.rs b/tools/cargo-optee/src/cli.rs
index a493c57..5c9a5fb 100644
--- a/tools/cargo-optee/src/cli.rs
+++ b/tools/cargo-optee/src/cli.rs
@@ -15,11 +15,19 @@
// specific language governing permissions and limitations
// under the License.
-use clap::{Args, Parser, Subcommand};
+use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
use crate::common::Arch;
+/// Kind of ELF whose UUID should be parsed.
+#[derive(Debug, Clone, Copy, ValueEnum)]
+#[value(rename_all = "lower")]
+pub enum UuidKind {
+ Ta,
+ Plugin,
+}
+
#[derive(Debug, Parser)]
#[command(version, about)]
pub struct Cli {
@@ -43,6 +51,20 @@ pub enum Command {
#[command(flatten)]
clean_cmd: CleanCommand,
},
+ /// Parse a UUID from an unsigned TA ELF or plugin shared library
+ #[clap(name = "inspect-uuid")]
+ InspectUuid {
+ /// Artifact kind: `ta` or `plugin`
+ #[arg(long = "kind")]
+ kind: UuidKind,
+ /// Path to the unsigned TA ELF or plugin `.so`
+ #[arg(long = "elf")]
+ elf: PathBuf,
+ },
+ /// Lint OP-TEE components (cargo fmt + clippy). Does not build, strip, or sign.
+ #[clap(name = "clippy")]
+ #[command(subcommand)]
+ Clippy(ClippyCommand),
}
#[derive(Debug, Subcommand)]
@@ -67,6 +89,28 @@ pub enum BuildCommand {
},
}
+#[derive(Debug, Subcommand)]
+pub enum ClippyCommand {
+ /// Lint a Trusted Application (TA)
+ #[command(about = "Lint a Trusted Application (TA)")]
+ TA {
+ #[command(flatten)]
+ build_cmd: TABuildArgs,
+ },
+ /// Lint a Client Application (Host)
+ #[command(about = "Lint a Client Application (Host)")]
+ CA {
+ #[command(flatten)]
+ build_cmd: CABuildArgs,
+ },
+ /// Lint a Plugin (Shared Library)
+ #[command(about = "Lint a Plugin (Shared Library)")]
+ Plugin {
+ #[command(flatten)]
+ build_cmd: PluginBuildArgs,
+ },
+}
+
#[derive(Debug, Subcommand)]
pub enum InstallCommand {
/// Install a Trusted Application (TA)
@@ -116,11 +160,11 @@ pub struct CommonBuildArgs {
#[arg(long = "manifest-path")]
pub manifest_path: Option<PathBuf>,
- /// Target architecture (default: aarch64)
+ /// Target architecture (default: aarch64). CROSS_COMPILE overrides the derived prefix.
#[arg(long = "arch")]
pub arch: Option<Arch>,
- /// Enable debug build (default: false)
+ /// Force a debug build. If omitted, Cargo.toml metadata is used (default: release).
#[arg(long = "debug")]
pub debug: bool,
@@ -161,13 +205,9 @@ pub struct TABuildArgs {
#[arg(long = "ta-dev-kit-dir")]
pub ta_dev_kit_dir: Option<PathBuf>,
- /// TA signing key path (default: TA_DEV_KIT_DIR/keys/default_ta.pem)
+ /// TA signing key path (fallback: metadata, then TA_SIGN_KEY, then TA_DEV_KIT_DIR/keys/default_ta.pem)
#[arg(long = "signing-key")]
pub signing_key: Option<PathBuf>,
-
- /// UUID file path (default: "../uuid.txt")
- #[arg(long = "uuid-path")]
- pub uuid_path: Option<PathBuf>,
}
/// CA-specific build arguments
@@ -190,10 +230,6 @@ pub struct PluginBuildArgs {
/// OP-TEE client export directory (fallback: OPTEE_CLIENT_EXPORT)
#[arg(long = "optee-client-export")]
pub optee_client_export: Option<PathBuf>,
-
- /// UUID file path (default: "../uuid.txt")
- #[arg(long = "uuid-path")]
- pub uuid_path: Option<PathBuf>,
}
/// Parse environment variable in KEY=VALUE format
diff --git a/tools/cargo-optee/src/common.rs b/tools/cargo-optee/src/common.rs
index 75ea756..9c389aa 100644
--- a/tools/cargo-optee/src/common.rs
+++ b/tools/cargo-optee/src/common.rs
@@ -15,35 +15,44 @@
// specific language governing permissions and limitations
// under the License.
-use anyhow::{Result, bail};
+use anyhow::{Context, Result, bail};
+use cargo_metadata::Message;
use clap::ValueEnum;
use std::env;
use std::fs;
-use std::path::PathBuf;
+use std::io::Cursor;
+use std::os::unix::fs::PermissionsExt;
+use std::path::{Path, PathBuf};
use std::process::{Command, Output};
-use toml::Value;
-use crate::cargo_command;
+use uuid::Uuid;
-/// RAII guard to ensure we return to the original directory
-pub struct ChangeDirectoryGuard {
- original: PathBuf,
+/// Canonical project directory. Does not change the process cwd.
+pub fn absolute_dir(path: &Path) -> Result<PathBuf> {
+ fs::canonicalize(path).with_context(|| format!("project directory {}", path.display()))
}
-impl ChangeDirectoryGuard {
- pub fn new(new_dir: &PathBuf) -> Result<Self> {
- let original = env::current_dir()?;
- env::set_current_dir(new_dir)?;
- Ok(Self { original })
- }
+pub fn manifest_path(project_dir: &Path) -> PathBuf {
+ project_dir.join("Cargo.toml")
}
-impl Drop for ChangeDirectoryGuard {
- fn drop(&mut self) {
- let _ = env::set_current_dir(&self.original);
+/// Resolve `dir` against the process cwd. Relative install paths must not be
+/// interpreted against the crate directory.
+pub fn absolute_from_cwd(dir: &Path) -> Result<PathBuf> {
+ if dir.is_absolute() {
+ Ok(dir.to_path_buf())
+ } else {
+ Ok(env::current_dir()?.join(dir))
}
}
+/// Cargo invocation rooted at `project_dir` without changing the process cwd.
+pub fn cargo_command_in(project_dir: &Path) -> Command {
+ let mut cmd = cargo_command();
+ cmd.current_dir(project_dir);
+ cmd
+}
+
/// Target architecture for building
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
pub enum Arch {
@@ -137,6 +146,25 @@ pub fn get_target_and_cross_compile(arch: Arch, mode: BuildMode) -> Result<(Stri
)
}
+/// Like [`get_target_and_cross_compile`], but honour `CROSS_COMPILE` from the
+/// process environment when OP-TEE rust.mk / Make supplied a toolchain prefix.
+pub fn resolve_target_and_cross_compile(arch: Arch, mode: BuildMode) -> Result<(String, String)> {
+ resolve_target_and_cross_compile_with(
+ arch,
+ mode,
+ env::var("CROSS_COMPILE").ok().filter(|s| !s.is_empty()),
+ )
+}
+
+fn resolve_target_and_cross_compile_with(
+ arch: Arch,
+ mode: BuildMode,
+ cross_compile_override: Option<String>,
+) -> Result<(String, String)> {
+ let (target, default_cc) = get_target_and_cross_compile(arch, mode)?;
+ Ok((target, cross_compile_override.unwrap_or(default_cc)))
+}
+
/// Helper function to print command output and return error
pub fn print_output_and_bail(cmd_name: &str, output: &Output) -> Result<()> {
eprintln!(
@@ -178,6 +206,10 @@ pub fn print_cargo_command(cmd: &Command, description: &str) {
println!(" Environment: {}", envs.join(" "));
}
+ if let Some(dir) = cmd.get_current_dir() {
+ println!(" Working directory: {}", dir.display());
+ }
+
// Print command
println!(
" Command: {} {}",
@@ -189,68 +221,154 @@ pub fn print_cargo_command(cmd: &Command, description: &str) {
);
}
-/// Get the target directory using cargo metadata
-pub fn get_target_directory_from_metadata() -> Result<PathBuf> {
- // We're already in the project directory, so no need for --manifest-path
- let output = cargo_command()
- .arg("metadata")
- .arg("--format-version")
- .arg("1")
- .arg("--no-deps")
- .output()?;
-
- if !output.status.success() {
- bail!("Failed to get cargo metadata");
- }
+/// Invoke Cargo, honoring the `CARGO` environment variable.
+pub fn cargo_command() -> Command {
+ const ENV_CARGO: &str = "CARGO";
+ Command::new(std::env::var_os(ENV_CARGO).unwrap_or_else(|| "cargo".into()))
+}
- let metadata: serde_json::Value = serde_json::from_slice(&output.stdout)?;
- let target_directory = metadata
- .get("target_directory")
- .and_then(|v| v.as_str())
- .ok_or_else(|| anyhow::anyhow!("Could not get target directory from cargo metadata"))?;
+/// Artifact produced by a TA or plugin build, named from the UUID parsed out of
+/// the unsigned ELF rather than from any external configuration.
+#[derive(Debug, Clone)]
+pub struct BuildArtifact {
+ pub uuid: Uuid,
+ pub path: PathBuf,
+}
- Ok(PathBuf::from(target_directory))
+/// Kind of Cargo compiler artifact to collect from `--message-format=json`.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum CargoArtifactKind {
+ Bin,
+ Cdylib,
}
-/// Read UUID from a file (e.g., uuid.txt)
-pub fn read_uuid_from_file(uuid_path: &std::path::Path) -> Result<String> {
- if !uuid_path.exists() {
- bail!("UUID file not found: {}", uuid_path.display());
+/// Collect the current package's compiler artifacts from `cargo --message-format=json`.
+pub fn collect_cargo_artifacts(
+ stdout: &[u8],
+ manifest_path: &std::path::Path,
+ kind: CargoArtifactKind,
+) -> Result<Vec<PathBuf>> {
+ let expected =
+ std::fs::canonicalize(manifest_path).unwrap_or_else(|_| manifest_path.to_path_buf());
+ let mut artifacts = Vec::new();
+
+ for message in Message::parse_stream(Cursor::new(stdout)) {
+ let message = match message {
+ Ok(message) => message,
+ Err(_) => continue,
+ };
+ match message {
+ Message::CompilerMessage(msg) => {
+ if let Some(rendered) = &msg.message.rendered {
+ eprint!("{rendered}");
+ }
+ }
+ Message::CompilerArtifact(artifact) => {
+ let artifact_manifest = artifact.manifest_path.into_std_path_buf();
+ let artifact_manifest =
+ std::fs::canonicalize(&artifact_manifest).unwrap_or(artifact_manifest);
+ if artifact_manifest != expected {
+ continue;
+ }
+ if artifact.profile.test {
+ continue;
+ }
+ if artifact.target.kind.iter().any(|k| k == "custom-build") {
+ continue;
+ }
+ match kind {
+ CargoArtifactKind::Bin => {
+ if let Some(path) = artifact.executable {
+ artifacts.push(path.into_std_path_buf());
+ }
+ }
+ CargoArtifactKind::Cdylib => {
+ if !artifact.target.crate_types.iter().any(|t| t == "cdylib") {
+ continue;
+ }
+ for path in artifact.filenames {
+ if path.as_str().ends_with(".so") {
+ artifacts.push(path.into_std_path_buf());
+ }
+ }
+ }
+ }
+ }
+ _ => {}
+ }
}
- let uuid_content = fs::read_to_string(uuid_path)?;
- let uuid = uuid_content.trim().to_string();
+ Ok(artifacts)
+}
- if uuid.is_empty() {
- bail!("UUID file is empty: {}", uuid_path.display());
+pub fn unique_cargo_artifact(
+ stdout: &[u8],
+ manifest_path: &std::path::Path,
+ kind: CargoArtifactKind,
+) -> Result<PathBuf> {
+ let mut artifacts = collect_cargo_artifacts(stdout, manifest_path, kind)?;
+ artifacts.sort();
+ artifacts.dedup();
+ match artifacts.len() {
+ 1 => Ok(artifacts.remove(0)),
+ 0 => bail!(
+ "Cargo produced no {:?} artifact for {}",
+ kind,
+ manifest_path.display()
+ ),
+ _ => bail!(
+ "Cargo produced multiple {:?} artifacts for {}: {:?}. Use a single bin/cdylib target.",
+ kind,
+ manifest_path.display(),
+ artifacts
+ ),
}
+}
- Ok(uuid)
+/// Create a unique tempfile in `parent` so a later rename onto a sibling path
+/// stays on the same filesystem.
+pub fn unique_tempfile_in(
+ parent: &Path,
+ prefix: &str,
+ suffix: &str,
+) -> Result<tempfile::NamedTempFile> {
+ tempfile::Builder::new()
+ .prefix(prefix)
+ .suffix(suffix)
+ .tempfile_in(parent)
+ .with_context(|| format!("create unique temp in {}", parent.display()))
}
-/// Join path segments and check if the resulting path exists
-pub fn join_and_check<P: AsRef<std::path::Path>>(
- base: &std::path::Path,
- segments: &[P],
- error_context: &str,
-) -> Result<PathBuf> {
- let mut path = base.to_path_buf();
- for segment in segments {
- path = path.join(segment);
- }
+/// Move a unique tempfile onto `dest`, replacing it on Unix.
+pub fn publish_tempfile(tmp: tempfile::NamedTempFile, dest: &Path) -> Result<()> {
+ let (_file, path) = tmp.keep().map_err(|e| e.error)?;
+ fs::rename(&path, dest)
+ .with_context(|| format!("failed to publish {} to {}", path.display(), dest.display()))
+}
- if !path.exists() {
- bail!("{} does not exist: {:?}", error_context, path);
- }
+/// Mode for signed `.ta` files. `NamedTempFile` is 0600; `sign_encrypt.py`
+/// truncates `--out` without resetting it. tee-supplicant may not be the
+/// build user, so keep the artifact world-readable.
+pub const TA_FILE_MODE: u32 = 0o644;
- Ok(path)
+pub fn set_ta_file_permissions(path: &Path) -> Result<()> {
+ fs::set_permissions(path, fs::Permissions::from_mode(TA_FILE_MODE))
+ .with_context(|| format!("set permissions on {}", path.display()))
+}
+
+/// Deny lints used by `cargo-optee clippy` and the former in-build clippy step.
+pub fn apply_clippy_deny_lints(cmd: &mut Command) {
+ cmd.arg("--");
+ cmd.arg("-D").arg("warnings");
+ cmd.arg("-D").arg("clippy::unwrap_used");
+ cmd.arg("-D").arg("clippy::expect_used");
+ cmd.arg("-D").arg("clippy::panic");
}
-/// Join path segments with a formatted final segment and check if the resulting path exists
-pub fn join_format_and_check<P: AsRef<std::path::Path>>(
- base: &std::path::Path,
+/// Join path segments and check if the resulting path exists
+pub fn join_and_check<P: AsRef<Path>>(
+ base: &Path,
segments: &[P],
- formatted_segment: &str,
error_context: &str,
) -> Result<PathBuf> {
let mut path = base.to_path_buf();
@@ -258,22 +376,22 @@ pub fn join_format_and_check<P: AsRef<std::path::Path>>(
path = path.join(segment);
}
- let final_path = path.join(formatted_segment);
-
- if !final_path.exists() {
- bail!("{} does not exist: {:?}", error_context, final_path);
+ if !path.exists() {
+ bail!("{} does not exist: {:?}", error_context, path);
}
- Ok(final_path)
+ Ok(path)
}
/// Clean build artifacts for any OP-TEE component (TA, CA, Plugin)
pub fn clean_project(project_path: &std::path::Path) -> Result<()> {
+ let project_path = absolute_dir(project_path)?;
println!("Cleaning build artifacts in: {:?}", project_path);
- let output = cargo_command()
+ let output = cargo_command_in(&project_path)
.arg("clean")
- .current_dir(project_path)
+ .arg("--manifest-path")
+ .arg(manifest_path(&project_path))
.output()?;
if !output.status.success() {
@@ -291,22 +409,100 @@ pub fn clean_project(project_path: &std::path::Path) -> Result<()> {
Ok(())
}
-/// Get the package name from Cargo.toml in the current directory
-pub fn get_package_name() -> Result<String> {
- // We assume we're already in the project directory (via ChangeDirectoryGuard)
- let manifest_path = PathBuf::from("Cargo.toml");
- if !manifest_path.exists() {
- bail!("Cargo.toml not found in current directory");
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Guarantee: cargo is rooted at the crate via child cwd; the process
+ /// cwd is unchanged so relative `--target-dir` follows make/emulate.
+ #[test]
+ fn cargo_command_in_sets_child_cwd_only() {
+ let dir = PathBuf::from("/tmp/project");
+ let cmd = cargo_command_in(&dir);
+ assert_eq!(cmd.get_current_dir(), Some(dir.as_path()));
}
- let cargo_toml_content = fs::read_to_string(&manifest_path)?;
- let cargo_toml: Value = toml::from_str(&cargo_toml_content)?;
+ /// Guarantee: a non-empty `CROSS_COMPILE` replaces the arch default
+ /// prefix, so `cc` build scripts use the OP-TEE toolchain.
+ #[test]
+ fn cross_compile_override_replaces_default() {
+ let (_, cc) = resolve_target_and_cross_compile_with(
+ Arch::Aarch64,
+ BuildMode::TaNoStd,
+ Some("custom-none-".into()),
+ )
+ .unwrap();
+ assert_eq!(cc, "custom-none-");
+ }
- let package_name = cargo_toml
- .get("package")
- .and_then(|p| p.get("name"))
- .and_then(|n| n.as_str())
- .ok_or_else(|| anyhow::anyhow!("Could not find package name in Cargo.toml"))?;
+ /// Guarantee: two temps with the same prefix/suffix in one directory
+ /// get distinct paths, so parallel strip/sign cannot clobber each other.
+ #[test]
+ fn unique_tempfiles_do_not_share_a_path() {
+ let dir = tempfile::tempdir().unwrap();
+ let a = unique_tempfile_in(dir.path(), "ta.", ".partial").unwrap();
+ let b = unique_tempfile_in(dir.path(), "ta.", ".partial").unwrap();
+ assert_ne!(a.path(), b.path());
+ }
- Ok(package_name.to_string())
+ /// Guarantee: publishing onto an existing path replaces its contents,
+ /// so a rebuild cannot leave make/emulate installing a stale `.ta`.
+ #[test]
+ fn publish_tempfile_replaces_destination() {
+ let dir = tempfile::tempdir().unwrap();
+ let dest = dir.path().join("out.ta");
+ std::fs::write(&dest, b"old").unwrap();
+ let tmp = unique_tempfile_in(dir.path(), "ta.", ".partial").unwrap();
+ std::fs::write(tmp.path(), b"new").unwrap();
+ publish_tempfile(tmp, &dest).unwrap();
+ assert_eq!(std::fs::read(&dest).unwrap(), b"new");
+ }
+
+ /// Guarantee: `unique_tempfile_in` creates a 0600 file. `sign_encrypt.py`
+ /// truncates `--out` without resetting mode, so this is the `.ta` mode
+ /// unless `set_ta_file_permissions` runs after publish.
+ #[test]
+ fn unique_tempfile_is_owner_only() {
+ let dir = tempfile::tempdir().unwrap();
+ let tmp = unique_tempfile_in(dir.path(), "ta.", ".partial").unwrap();
+ let mode = fs::metadata(tmp.path()).unwrap().permissions().mode() & 0o777;
+ assert_eq!(mode, 0o600);
+ }
+
+ /// Guarantee: after `set_ta_file_permissions`, the published `.ta` and
+ /// the install copy are 0644, so tee-supplicant can read them.
+ #[test]
+ fn published_ta_is_world_readable() {
+ let dir = tempfile::tempdir().unwrap();
+ let dest = dir.path().join("out.ta");
+ let tmp = unique_tempfile_in(dir.path(), "ta.", ".partial").unwrap();
+ std::fs::write(tmp.path(), b"ta").unwrap();
+ publish_tempfile(tmp, &dest).unwrap();
+ set_ta_file_permissions(&dest).unwrap();
+ let mode = fs::metadata(&dest).unwrap().permissions().mode() & 0o777;
+ assert_eq!(mode, TA_FILE_MODE);
+
+ let installed = dir.path().join("installed.ta");
+ fs::copy(&dest, &installed).unwrap();
+ set_ta_file_permissions(&installed).unwrap();
+ let installed_mode = fs::metadata(&installed).unwrap().permissions().mode() & 0o777;
+ assert_eq!(installed_mode, TA_FILE_MODE);
+ }
+
+ /// Guarantee: an absolute `--target-dir` is returned unchanged, not
+ /// joined onto the process cwd.
+ #[test]
+ fn absolute_from_cwd_keeps_absolute_paths() {
+ let abs = PathBuf::from("/tmp/dist");
+ assert_eq!(absolute_from_cwd(&abs).unwrap(), abs);
+ }
+
+ /// Guarantee: unset `CROSS_COMPILE` still yields the arch default
+ /// prefix, so `cc` build scripts do not compile C for the host.
+ #[test]
+ fn cross_compile_default_when_unset() {
+ let (_, cc) =
+ resolve_target_and_cross_compile_with(Arch::Aarch64, BuildMode::TaNoStd, None).unwrap();
+ assert_eq!(cc, "aarch64-linux-gnu-");
+ }
}
diff --git a/tools/cargo-optee/src/config.rs b/tools/cargo-optee/src/config.rs
index 67f936b..c0ba923 100644
--- a/tools/cargo-optee/src/config.rs
+++ b/tools/cargo-optee/src/config.rs
@@ -18,6 +18,7 @@
use anyhow::{Result, bail};
use cargo_metadata::MetadataCommand;
use serde_json::Value;
+use std::env;
use std::path::{Path, PathBuf};
use crate::common::Arch;
@@ -54,10 +55,9 @@ enum PathType {
#[derive(Clone)]
pub struct TaBuildConfig {
- pub arch: Arch, // Architecture
- pub debug: bool, // Debug mode (default false = release)
- pub path: PathBuf, // Path to TA directory
- pub uuid_path: Option<PathBuf>, // Path to UUID file
+ pub arch: Arch, // Architecture
+ pub debug: bool, // Debug mode (default false = release)
+ pub path: PathBuf, // Path to TA directory
// Customized variables
pub env: Vec<(String, String)>, // Custom environment variables for cargo build
pub no_default_features: bool, // Disable default features
@@ -68,29 +68,37 @@ pub struct TaBuildConfig {
pub signing_key: PathBuf, // Path to signing key
}
+/// CLI overrides shared by TA and CA/plugin resolution.
+pub struct BuildOverrides {
+ pub arch: Option<Arch>,
+ pub debug: Option<bool>,
+ pub env: Vec<(String, String)>,
+ pub no_default_features: bool,
+ pub features: Option<String>,
+}
+
impl TaBuildConfig {
pub fn resolve(
project_path: &Path,
- cmd_arch: Option<Arch>,
- cmd_debug: Option<bool>,
- cmd_uuid_path: Option<PathBuf>,
- common_env: Vec<(String, String)>,
- common_no_default_features: bool,
- common_features: Option<String>,
+ overrides: BuildOverrides,
cmd_std: Option<bool>,
cmd_ta_dev_kit_dir: Option<PathBuf>,
cmd_signing_key: Option<PathBuf>,
+ need_signing_key: bool,
) -> Result<Self> {
// Get base configuration from metadata
- let metadata_config = MetadataConfig::resolve(project_path, ComponentType::Ta, cmd_arch)?;
+ let metadata_config =
+ MetadataConfig::resolve(project_path, ComponentType::Ta, overrides.arch)?;
// Determine final arch: CLI > metadata > default
- let arch = cmd_arch
+ let arch = overrides
+ .arch
.or_else(|| metadata_config.as_ref().map(|c| c.arch))
.unwrap_or(Arch::Aarch64);
// Handle priority: CLI > metadata > default
- let debug = cmd_debug
+ let debug = overrides
+ .debug
.or_else(|| metadata_config.as_ref().map(|c| c.debug))
.unwrap_or(false);
@@ -116,33 +124,29 @@ impl TaBuildConfig {
"TA development kit directory",
)?;
- // Handle signing_key: CLI > metadata > default (ta_dev_kit_dir/keys/default_ta.pem)
- let signing_key_config = cmd_signing_key
- .or_else(|| metadata_config.as_ref().and_then(|c| c.signing_key.clone()))
- .unwrap_or_else(|| ta_dev_kit_dir_config.join("keys").join("default_ta.pem"));
-
- // Resolve signing_key path (relative to absolute)
- let signing_key = resolve_path_relative_to_project(
- &signing_key_config,
- project_path,
- PathType::File,
- "Signing key file",
- )?;
-
- // Handle uuid_path: CLI > metadata > default (../uuid.txt)
- let uuid_path = resolve_uuid_path(
- cmd_uuid_path,
- metadata_config.as_ref().and_then(|c| c.uuid_path.clone()),
- project_path,
- PathBuf::from("../uuid.txt"),
- )?;
+ // Handle signing_key: CLI > metadata > TA_SIGN_KEY > default_ta.pem.
+ // Clippy does not sign, so skip the key file when linting.
+ let signing_key = if need_signing_key {
+ let signing_key_config = cmd_signing_key
+ .or_else(|| metadata_config.as_ref().and_then(|c| c.signing_key.clone()))
+ .or_else(|| env::var_os("TA_SIGN_KEY").map(PathBuf::from))
+ .unwrap_or_else(|| ta_dev_kit_dir_config.join("keys").join("default_ta.pem"));
+ resolve_path_relative_to_project(
+ &signing_key_config,
+ project_path,
+ PathType::File,
+ "Signing key file",
+ )?
+ } else {
+ PathBuf::new()
+ };
// Merge environment variables: metadata env + CLI env (CLI overrides metadata)
let mut env = metadata_config
.as_ref()
.map(|c| c.env.clone())
.unwrap_or_default();
- env.extend(common_env);
+ env.extend(overrides.env);
Ok(TaBuildConfig {
arch,
@@ -151,26 +155,29 @@ impl TaBuildConfig {
ta_dev_kit_dir,
signing_key,
path: project_path.to_path_buf(),
- uuid_path: Some(uuid_path),
env,
- no_default_features: common_no_default_features,
- features: common_features,
+ no_default_features: overrides.no_default_features,
+ features: overrides.features,
})
}
/// Print the final TA configuration parameters being used
pub fn print_config(&self) {
- println!("Building TA with:");
+ self.print_config_with("Building");
+ }
+
+ pub fn print_lint_config(&self) {
+ self.print_config_with("Linting");
+ }
+
+ fn print_config_with(&self, action: &str) {
+ println!("{} TA with:", action);
println!(" Arch: {:?}", self.arch);
println!(" Debug: {}", self.debug);
println!(" Std: {}", self.std);
println!(" TA dev kit dir: {:?}", self.ta_dev_kit_dir);
- println!(" Signing key: {:?}", self.signing_key);
- if let Some(ref uuid_path) = self.uuid_path {
- let absolute_uuid_path = uuid_path
- .canonicalize()
- .unwrap_or_else(|_| uuid_path.clone());
- println!(" UUID path: {:?}", absolute_uuid_path);
+ if !self.signing_key.as_os_str().is_empty() {
+ println!(" Signing key: {:?}", self.signing_key);
}
if !self.env.is_empty() {
println!(" Environment variables: {} set", self.env.len());
@@ -180,10 +187,9 @@ impl TaBuildConfig {
#[derive(Clone)]
pub struct CaBuildConfig {
- pub arch: Arch, // Architecture
- pub debug: bool, // Debug mode (default false = release)
- pub path: PathBuf, // Path to CA directory
- pub uuid_path: Option<PathBuf>, // Path to UUID file (for plugins)
+ pub arch: Arch, // Architecture
+ pub debug: bool, // Debug mode (default false = release)
+ pub path: PathBuf, // Path to CA directory
// Customized variables
pub env: Vec<(String, String)>, // Custom environment variables for cargo build
pub no_default_features: bool, // Disable default features
@@ -196,12 +202,7 @@ pub struct CaBuildConfig {
impl CaBuildConfig {
pub fn resolve(
project_path: &Path,
- cmd_arch: Option<Arch>,
- cmd_debug: Option<bool>,
- cmd_uuid_path: Option<PathBuf>,
- common_env: Vec<(String, String)>,
- common_no_default_features: bool,
- common_features: Option<String>,
+ overrides: BuildOverrides,
cmd_optee_client_export: Option<PathBuf>,
plugin: bool,
) -> Result<Self> {
@@ -212,15 +213,18 @@ impl CaBuildConfig {
};
// Get base configuration from metadata
- let metadata_config = MetadataConfig::resolve(project_path, component_type, cmd_arch)?;
+ let metadata_config =
+ MetadataConfig::resolve(project_path, component_type, overrides.arch)?;
// Determine final arch: CLI > metadata > default
- let arch = cmd_arch
+ let arch = overrides
+ .arch
.or_else(|| metadata_config.as_ref().map(|c| c.arch))
.unwrap_or(Arch::Aarch64);
// Handle priority: CLI > metadata > default
- let debug = cmd_debug
+ let debug = overrides
+ .debug
.or_else(|| metadata_config.as_ref().map(|c| c.debug))
.unwrap_or(false);
@@ -242,33 +246,20 @@ impl CaBuildConfig {
"OP-TEE client export directory",
)?;
- // Handle uuid_path: only for plugins, CLI > metadata > default
- let uuid_path = if plugin {
- Some(resolve_uuid_path(
- cmd_uuid_path,
- metadata_config.as_ref().and_then(|c| c.uuid_path.clone()),
- project_path,
- PathBuf::from("../uuid.txt"),
- )?)
- } else {
- None
- };
-
// Merge environment variables: metadata env + CLI env (CLI overrides metadata)
let mut env = metadata_config
.as_ref()
.map(|c| c.env.clone())
.unwrap_or_default();
- env.extend(common_env);
+ env.extend(overrides.env);
Ok(CaBuildConfig {
arch,
debug,
path: project_path.to_path_buf(),
- uuid_path,
env,
- no_default_features: common_no_default_features,
- features: common_features,
+ no_default_features: overrides.no_default_features,
+ features: overrides.features,
optee_client_export,
plugin,
})
@@ -276,19 +267,19 @@ impl CaBuildConfig {
/// Print the final CA/Plugin configuration parameters being used
pub fn print_config(&self) {
+ self.print_config_with("Building");
+ }
+
+ pub fn print_lint_config(&self) {
+ self.print_config_with("Linting");
+ }
+
+ fn print_config_with(&self, action: &str) {
let component_name = if self.plugin { "Plugin" } else { "CA" };
- println!("Building {} with:", component_name);
+ println!("{} {} with:", action, component_name);
println!(" Arch: {:?}", self.arch);
println!(" Debug: {}", self.debug);
println!(" OP-TEE client export: {:?}", self.optee_client_export);
- if self.plugin
- && let Some(ref uuid_path) = self.uuid_path
- {
- let absolute_uuid_path = uuid_path
- .canonicalize()
- .unwrap_or_else(|_| uuid_path.clone());
- println!(" UUID path: {:?}", absolute_uuid_path);
- }
if !self.env.is_empty() {
println!(" Environment variables: {} set", self.env.len());
}
@@ -305,45 +296,22 @@ struct MetadataConfig {
pub ta_dev_kit_dir: Option<PathBuf>,
pub optee_client_export: Option<PathBuf>,
pub signing_key: Option<PathBuf>,
- pub uuid_path: Option<PathBuf>,
/// additional environment key-value pairs, that should be passed to underlying
/// build commands
pub env: Vec<(String, String)>,
}
impl MetadataConfig {
- /// Extract build configuration from metadata only
- /// This function only parses metadata and does not handle priority resolution
- /// Determines arch with priority: cmd_arch > metadata > default
- /// Returns None if metadata is not found or parsing fails
+ /// Extract build configuration from metadata only.
+ /// Returns `Ok(None)` when the package has no `[package.metadata.optee.<kind>]`
+ /// table. Parse errors, including removed keys, are returned to the CLI.
pub fn resolve(
project_path: &Path,
component_type: ComponentType,
cmd_arch: Option<Arch>,
) -> Result<Option<Self>> {
- // Try to find application metadata (optional)
- let app_metadata = match discover_app_metadata(project_path) {
- Ok(meta) => meta,
- Err(_) => return Ok(None),
- };
-
- // Determine architecture with priority: cmd_arch > metadata > default
- let arch = cmd_arch
- .or_else(|| {
- app_metadata
- .get("optee")?
- .get(component_type.as_str())?
- .get("arch")
- .and_then(|v| v.as_str())
- .and_then(|s| s.parse().ok())
- })
- .unwrap_or(Arch::Aarch64);
-
- // Extract metadata config with the determined architecture
- // Return None if metadata parsing fails (metadata not found or invalid)
- extract_build_config_with_arch(&app_metadata, arch, component_type)
- .map(Some)
- .or_else(|_| Ok(None))
+ let app_metadata = discover_app_metadata(project_path)?;
+ extract_build_config(&app_metadata, component_type, cmd_arch)
}
}
@@ -389,34 +357,42 @@ fn discover_app_metadata(project_path: &Path) -> Result<Value> {
Ok(current_package.metadata.clone())
}
-/// Extract build configuration from application package metadata with specific architecture
-fn extract_build_config_with_arch(
+/// Extract build configuration from application package metadata.
+fn extract_build_config(
metadata: &Value,
- arch: Arch,
component_type: ComponentType,
-) -> Result<MetadataConfig> {
- let optee_metadata = metadata
- .get("optee")
- .ok_or_else(|| anyhow::anyhow!("No optee metadata found in application package"))?;
-
- let component_metadata = optee_metadata.get(component_type.as_str()).ok_or_else(|| {
- anyhow::anyhow!(
- "No {} metadata found in optee section",
+ cmd_arch: Option<Arch>,
+) -> Result<Option<MetadataConfig>> {
+ let Some(optee_metadata) = metadata.get("optee") else {
+ return Ok(None);
+ };
+ let Some(component_metadata) = optee_metadata.get(component_type.as_str()) else {
+ return Ok(None);
+ };
+
+ if component_metadata.get("uuid-path").is_some() {
+ bail!(
+ "package.metadata.optee.{}.uuid-path is not supported; UUID is parsed from the unsigned ELF",
component_type.as_str()
- )
- })?;
+ );
+ }
- // Parse debug with fallback to false
- let debug = component_metadata
- .get("debug")
- .and_then(|v| v.as_bool())
- .unwrap_or(false);
+ let arch = match cmd_arch {
+ Some(arch) => arch,
+ None => match component_metadata.get("arch") {
+ None => Arch::Aarch64,
+ Some(v) => {
+ let s = v
+ .as_str()
+ .ok_or_else(|| anyhow::anyhow!("metadata key arch must be a string"))?;
+ s.parse()
+ .map_err(|e: String| anyhow::anyhow!("invalid metadata arch {s:?}: {e}"))?
+ }
+ },
+ };
- // Parse std with fallback to false
- let std = component_metadata
- .get("std")
- .and_then(|v| v.as_bool())
- .unwrap_or(false);
+ let debug = metadata_bool(component_metadata, "debug")?;
+ let std = metadata_bool(component_metadata, "std")?;
// Architecture-specific path resolution
let arch_key = match arch {
@@ -497,48 +473,23 @@ fn extract_build_config_with_arch(
})
.unwrap_or_default();
- // Parse uuid_path from metadata (for TA and Plugin)
- // component_metadata already points to the correct section (optee.ta or optee.plugin)
- let uuid_path =
- if component_type == ComponentType::Ta || component_type == ComponentType::Plugin {
- component_metadata
- .get("uuid-path")
- .and_then(|v| v.as_str())
- .filter(|s| !s.is_empty())
- .map(PathBuf::from)
- } else {
- None // CA doesn't need uuid_path
- };
-
- Ok(MetadataConfig {
+ Ok(Some(MetadataConfig {
arch,
debug,
std,
ta_dev_kit_dir,
optee_client_export,
signing_key,
- uuid_path,
env,
- })
+ }))
}
-/// Resolve uuid_path with priority: CLI > metadata > default
-/// Returns the resolved absolute path
-fn resolve_uuid_path(
- cmd_uuid_path: Option<PathBuf>,
- metadata_uuid_path: Option<PathBuf>,
- project_path: &Path,
- default: PathBuf,
-) -> Result<PathBuf> {
- let uuid_path_was_from_cli = cmd_uuid_path.is_some();
- let uuid_path_str = cmd_uuid_path.or(metadata_uuid_path).unwrap_or(default);
-
- if uuid_path_was_from_cli {
- // CLI provided - resolve relative to current directory
- Ok(std::env::current_dir()?.join(&uuid_path_str))
- } else {
- // From metadata or default - resolve relative to project directory
- Ok(project_path.join(&uuid_path_str))
+fn metadata_bool(table: &Value, key: &str) -> Result<bool> {
+ match table.get(key) {
+ None => Ok(false),
+ Some(v) => v
+ .as_bool()
+ .ok_or_else(|| anyhow::anyhow!("metadata key {key} must be a boolean")),
}
}
@@ -622,3 +573,58 @@ fn resolve_path_relative_to_project(
Ok(resolved_path)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ fn ta_meta(ta: Value) -> Value {
+ json!({ "optee": { "ta": ta } })
+ }
+
+ /// Guarantee: missing `debug` / `std` in metadata are false (release
+ /// and no-std).
+ #[test]
+ fn debug_and_std_default_false() {
+ let cfg = extract_build_config(&ta_meta(json!({})), ComponentType::Ta, None)
+ .unwrap()
+ .unwrap();
+ assert!(!cfg.debug);
+ assert!(!cfg.std);
+ }
+
+ /// Guarantee: metadata `debug = true` is extracted as true.
+ #[test]
+ fn debug_true_is_honored() {
+ let cfg = extract_build_config(&ta_meta(json!({ "debug": true })), ComponentType::Ta, None)
+ .unwrap()
+ .unwrap();
+ assert!(cfg.debug);
+ assert!(!cfg.std);
+ }
+
+ /// Guarantee: a non-boolean `debug` value is an error, not a silent
+ /// `false` that always builds `--release`.
+ #[test]
+ fn debug_rejects_non_bool() {
+ let err = extract_build_config(
+ &ta_meta(json!({ "debug": "true" })),
+ ComponentType::Ta,
+ None,
+ )
+ .unwrap_err();
+ assert!(err.to_string().contains("debug"));
+ assert!(err.to_string().contains("boolean"));
+ }
+
+ /// Guarantee: a non-boolean `std` value is an error, not a silent
+ /// `false` that keeps `--no-std`.
+ #[test]
+ fn std_rejects_non_bool() {
+ let err = extract_build_config(&ta_meta(json!({ "std": 1 })), ComponentType::Ta, None)
+ .unwrap_err();
+ assert!(err.to_string().contains("std"));
+ assert!(err.to_string().contains("boolean"));
+ }
+}
diff --git a/tools/cargo-optee/src/elf_uuid.rs b/tools/cargo-optee/src/elf_uuid.rs
new file mode 100644
index 0000000..ea78dec
--- /dev/null
+++ b/tools/cargo-optee/src/elf_uuid.rs
@@ -0,0 +1,268 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! UUID extraction from unsigned OP-TEE 4.10.0 TA ELF images and plugins.
+//!
+//! TA: `ldelf` resolves `ta_head` from dynsym; UUID is the first 16 bytes of
+//! `struct ta_head` (`user_ta_header.h`).
+//! Plugin: `tee-supplicant` uses `dlsym("plugin_method")`; UUID follows the
+//! leading `name` pointer in `struct plugin_method` (`tee_plugin_method.h`;
+//! pointer width from the ELF class). Both symbols must be objects large
+//! enough to cover the UUID field.
+
+use anyhow::{Context, Result, bail, ensure};
+use goblin::elf::header::{ELFCLASS32, ELFCLASS64, EM_AARCH64, EM_ARM, ET_DYN};
+use goblin::elf::program_header::PT_LOAD;
+use goblin::elf::{Elf, header, sym};
+use std::path::Path;
+use uuid::Uuid;
+
+const TEE_UUID_SIZE: usize = 16;
+
+/// Read the TA UUID from an unsigned TA ELF.
+pub fn read_ta_uuid(path: &Path) -> Result<Uuid> {
+ let data =
+ std::fs::read(path).with_context(|| format!("{}: failed to read ELF", path.display()))?;
+ read_ta_uuid_from_bytes(path, &data)
+}
+
+/// Read the plugin UUID from an unsigned plugin shared library.
+pub fn read_plugin_uuid(path: &Path) -> Result<Uuid> {
+ let data =
+ std::fs::read(path).with_context(|| format!("{}: failed to read ELF", path.display()))?;
+ read_plugin_uuid_from_bytes(path, &data)
+}
+
+fn read_ta_uuid_from_bytes(path: &Path, data: &[u8]) -> Result<Uuid> {
+ let elf = parse_optee_elf(path, data)?;
+ let sym = exported_symbol(&elf, "ta_head").ok_or_else(|| {
+ if has_named_sym(&elf, "ta_head") {
+ anyhow::anyhow!(
+ "{}: ta_head exists in the regular symbol table but is not dynamically exported; ldelf resolves it from dynsym",
+ path.display()
+ )
+ } else {
+ anyhow::anyhow!(
+ "{}: dynamically exported symbol ta_head not found",
+ path.display()
+ )
+ }
+ })?;
+ ensure_object(path, "ta_head", &sym, TEE_UUID_SIZE as u64)?;
+ tee_uuid(bytes_at_va(path, &elf, data, sym.st_value, TEE_UUID_SIZE)?)
+}
+
+fn read_plugin_uuid_from_bytes(path: &Path, data: &[u8]) -> Result<Uuid> {
+ let elf = parse_optee_elf(path, data)?;
+ let sym = exported_symbol(&elf, "plugin_method").ok_or_else(|| {
+ if has_named_sym(&elf, "plugin_method") {
+ anyhow::anyhow!(
+ "{}: plugin_method exists in the regular symbol table but is not dynamically exported; tee-supplicant resolves it with dlsym and a non-exported object cannot be used",
+ path.display()
+ )
+ } else {
+ anyhow::anyhow!(
+ "{}: dynamically exported symbol plugin_method not found",
+ path.display()
+ )
+ }
+ })?;
+ let uuid_off = pointer_width(&elf);
+ ensure_object(path, "plugin_method", &sym, uuid_off + TEE_UUID_SIZE as u64)?;
+ let va = sym.st_value.checked_add(uuid_off).with_context(|| {
+ format!(
+ "{}: plugin_method address {:#x} overflowed when skipping the name pointer",
+ path.display(),
+ sym.st_value
+ )
+ })?;
+ tee_uuid(bytes_at_va(path, &elf, data, va, TEE_UUID_SIZE)?)
+}
+
+fn parse_optee_elf<'a>(path: &Path, data: &'a [u8]) -> Result<Elf<'a>> {
+ ensure!(
+ data.starts_with(b"\x7fELF"),
+ "{}: not an ELF file: missing ELF magic",
+ path.display()
+ );
+ let elf = Elf::parse(data).with_context(|| {
+ format!(
+ "{}: failed to parse ELF (truncated or malformed)",
+ path.display()
+ )
+ })?;
+ ensure!(
+ elf.little_endian,
+ "{}: unsupported ELF endianness (OP-TEE ARM/AArch64 TAs and plugins are little-endian)",
+ path.display()
+ );
+ ensure!(
+ elf.header.e_type == ET_DYN,
+ "{}: unsupported ELF type {} (OP-TEE 4.10 requires ET_DYN for TAs and plugins)",
+ path.display(),
+ elf.header.e_type
+ );
+ match (
+ elf.header.e_machine,
+ elf.header.e_ident[header::EI_CLASS],
+ elf.is_64,
+ ) {
+ (EM_AARCH64, ELFCLASS64, true) | (EM_ARM, ELFCLASS32, false) => Ok(elf),
+ (machine, class, is_64) => bail!(
+ "{}: unsupported ELF target machine={} class={} is_64={} (supported: AArch64 little-endian 64-bit, ARM little-endian 32-bit)",
+ path.display(),
+ machine,
+ class,
+ is_64
+ ),
+ }
+}
+
+fn pointer_width(elf: &Elf<'_>) -> u64 {
+ if elf.is_64 { 8 } else { 4 }
+}
+
+fn exported_symbol(elf: &Elf<'_>, name: &str) -> Option<goblin::elf::Sym> {
+ elf.dynsyms.iter().find(|sym| {
+ elf.dynstrtab.get_at(sym.st_name) == Some(name)
+ && sym.st_shndx != 0
+ && matches!(sym.st_bind(), sym::STB_GLOBAL | sym::STB_WEAK)
+ })
+}
+
+/// `ta_head` and `plugin_method` are C structs (`struct ta_head`,
+/// `struct plugin_method`). Reject functions and undersized objects so a
+/// shifted layout fails instead of returning a neighboring field as a UUID.
+/// `st_size == 0` means the size is unknown.
+fn ensure_object(path: &Path, name: &str, sym: &goblin::elf::Sym, min_size: u64) -> Result<()> {
+ match sym.st_type() {
+ sym::STT_OBJECT | sym::STT_NOTYPE => {}
+ t => bail!(
+ "{}: {name} has ELF symbol type {t} (expected STT_OBJECT)",
+ path.display()
+ ),
+ }
+ if sym.st_size != 0 {
+ ensure!(
+ sym.st_size >= min_size,
+ "{}: {name} is {} bytes, need at least {min_size} to read the UUID",
+ path.display(),
+ sym.st_size
+ );
+ }
+ Ok(())
+}
+
+fn has_named_sym(elf: &Elf<'_>, name: &str) -> bool {
+ elf.syms
+ .iter()
+ .any(|sym| elf.strtab.get_at(sym.st_name) == Some(name) && sym.st_shndx != 0)
+}
+
+fn bytes_at_va<'a>(
+ path: &Path,
+ elf: &Elf<'_>,
+ data: &'a [u8],
+ va: u64,
+ size: usize,
+) -> Result<&'a [u8]> {
+ let size_u64 = u64::try_from(size).map_err(|_| {
+ anyhow::anyhow!(
+ "{}: malformed ELF: requested {} bytes at {:#x}",
+ path.display(),
+ size,
+ va
+ )
+ })?;
+ let end = va.checked_add(size_u64).with_context(|| {
+ format!(
+ "{}: malformed ELF: virtual address overflow at {:#x}",
+ path.display(),
+ va
+ )
+ })?;
+ for ph in elf.program_headers.iter().filter(|ph| ph.p_type == PT_LOAD) {
+ let load_end = ph.p_vaddr.checked_add(ph.p_memsz).with_context(|| {
+ format!(
+ "{}: malformed ELF: PT_LOAD p_vaddr {:#x} + p_memsz {:#x} overflow",
+ path.display(),
+ ph.p_vaddr,
+ ph.p_memsz
+ )
+ })?;
+ if va < ph.p_vaddr || end > load_end {
+ continue;
+ }
+ let file_end = ph.p_vaddr.checked_add(ph.p_filesz).with_context(|| {
+ format!(
+ "{}: malformed ELF: PT_LOAD p_vaddr {:#x} + p_filesz {:#x} overflow",
+ path.display(),
+ ph.p_vaddr,
+ ph.p_filesz
+ )
+ })?;
+ ensure!(
+ end <= file_end,
+ "{}: virtual address {:#x} is in BSS of a PT_LOAD segment (not file-backed); UUID cannot be read from the file",
+ path.display(),
+ va
+ );
+ let delta = va - ph.p_vaddr;
+ let off = ph.p_offset.checked_add(delta).with_context(|| {
+ format!(
+ "{}: malformed ELF: PT_LOAD file offset overflow at {:#x}",
+ path.display(),
+ va
+ )
+ })?;
+ let off = usize::try_from(off).map_err(|_| {
+ anyhow::anyhow!(
+ "{}: malformed ELF: file offset {:#x} does not fit in usize",
+ path.display(),
+ off
+ )
+ })?;
+ let end_off = off.checked_add(size).with_context(|| {
+ format!(
+ "{}: malformed ELF: file range overflow at offset {}",
+ path.display(),
+ off
+ )
+ })?;
+ return data.get(off..end_off).with_context(|| {
+ format!(
+ "{}: offset {} size {} exceeds file length {}",
+ path.display(),
+ off,
+ size,
+ data.len()
+ )
+ });
+ }
+ bail!(
+ "{}: virtual address {:#x} is not in any PT_LOAD segment",
+ path.display(),
+ va
+ )
+}
+
+fn tee_uuid(bytes: &[u8]) -> Result<Uuid> {
+ let b: [u8; 16] = bytes
+ .try_into()
+ .map_err(|_| anyhow::anyhow!("TEE_UUID must be 16 bytes, got {}", bytes.len()))?;
+ Ok(Uuid::from_bytes_le(b))
+}
diff --git a/tools/cargo-optee/src/lib.rs b/tools/cargo-optee/src/lib.rs
new file mode 100644
index 0000000..99cc402
--- /dev/null
+++ b/tools/cargo-optee/src/lib.rs
@@ -0,0 +1,23 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+pub mod ca_builder;
+pub mod cli;
+pub mod common;
+pub mod config;
+pub mod elf_uuid;
+pub mod ta_builder;
diff --git a/tools/cargo-optee/src/main.rs b/tools/cargo-optee/src/main.rs
index 7ef79ca..7832192 100644
--- a/tools/cargo-optee/src/main.rs
+++ b/tools/cargo-optee/src/main.rs
@@ -15,19 +15,20 @@
// specific language governing permissions and limitations
// under the License.
+use cargo_optee::ca_builder;
+use cargo_optee::cli::{
+ BuildCommand, Cli, ClippyCommand, Command, CommonBuildArgs, InstallCommand, UuidKind,
+};
+use cargo_optee::common::absolute_from_cwd;
+use cargo_optee::config;
+use cargo_optee::elf_uuid;
+use cargo_optee::ta_builder;
use clap::Parser;
use std::env;
-use std::path::PathBuf;
+use std::io::{self, Write};
+use std::path::{Path, PathBuf};
use std::process;
-mod ca_builder;
-mod cli;
-mod common;
-mod config;
-mod ta_builder;
-
-use cli::{BuildCommand, Cli, Command, CommonBuildArgs, InstallCommand};
-
fn main() {
// Drop extra `optee` argument provided by `cargo`.
let mut found_optee = false;
@@ -46,7 +47,7 @@ fn main() {
let result = execute_command(cli.cmd);
if let Err(e) = result {
- eprintln!("Error: {}", e);
+ eprintln!("Error: {e:#}");
process::exit(1);
}
}
@@ -55,7 +56,6 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
match cmd {
Command::Build(build_cmd) => match build_cmd {
BuildCommand::TA { build_cmd } => {
- // Convert bool flags to Option<bool>: --std -> Some(true), --no-std -> Some(false), neither -> None
let std_mode = match (build_cmd.std, build_cmd.no_std) {
(true, false) => Some(true),
(false, true) => Some(false),
@@ -67,23 +67,23 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
std_mode,
build_cmd.ta_dev_kit_dir,
build_cmd.signing_key,
- build_cmd.uuid_path,
None,
+ false,
)
}
BuildCommand::CA { build_cmd } => execute_ca_command(
build_cmd.common,
build_cmd.optee_client_export,
- None,
false,
None,
+ false,
),
BuildCommand::Plugin { build_cmd } => execute_ca_command(
build_cmd.common,
build_cmd.optee_client_export,
- build_cmd.uuid_path,
true,
None,
+ false,
),
},
Command::Install(install_cmd) => match install_cmd {
@@ -91,7 +91,6 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
target_dir,
build_cmd,
} => {
- // Convert bool flags to Option<bool>: --std -> Some(true), --no-std -> Some(false), neither -> None
let std_mode = match (build_cmd.std, build_cmd.no_std) {
(true, false) => Some(true),
(false, true) => Some(false),
@@ -103,8 +102,8 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
std_mode,
build_cmd.ta_dev_kit_dir,
build_cmd.signing_key,
- build_cmd.uuid_path,
- Some(&target_dir),
+ Some(absolute_from_cwd(&target_dir)?),
+ false,
)
}
InstallCommand::CA {
@@ -113,9 +112,9 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
} => execute_ca_command(
build_cmd.common,
build_cmd.optee_client_export,
- None,
false,
- Some(&target_dir),
+ Some(absolute_from_cwd(&target_dir)?),
+ false,
),
InstallCommand::Plugin {
target_dir,
@@ -123,80 +122,131 @@ fn execute_command(cmd: Command) -> anyhow::Result<()> {
} => execute_ca_command(
build_cmd.common,
build_cmd.optee_client_export,
- build_cmd.uuid_path,
true,
- Some(&target_dir),
+ Some(absolute_from_cwd(&target_dir)?),
+ false,
+ ),
+ },
+ Command::Clippy(clippy_cmd) => match clippy_cmd {
+ ClippyCommand::TA { build_cmd } => {
+ let std_mode = match (build_cmd.std, build_cmd.no_std) {
+ (true, false) => Some(true),
+ (false, true) => Some(false),
+ _ => None,
+ };
+
+ execute_ta_command(
+ build_cmd.common,
+ std_mode,
+ build_cmd.ta_dev_kit_dir,
+ None,
+ None,
+ true,
+ )
+ }
+ ClippyCommand::CA { build_cmd } => execute_ca_command(
+ build_cmd.common,
+ build_cmd.optee_client_export,
+ false,
+ None,
+ true,
+ ),
+ ClippyCommand::Plugin { build_cmd } => execute_ca_command(
+ build_cmd.common,
+ build_cmd.optee_client_export,
+ true,
+ None,
+ true,
),
},
Command::Clean { clean_cmd } => {
let project_path = resolve_project_path(clean_cmd.manifest_path.as_ref())?;
-
- // Clean build artifacts using the common function
- crate::common::clean_project(&project_path)
+ cargo_optee::common::clean_project(&project_path)
}
+ Command::InspectUuid { kind, elf } => inspect_uuid(kind, &elf),
}
}
+fn inspect_uuid(kind: UuidKind, elf: &Path) -> anyhow::Result<()> {
+ let uuid = match kind {
+ UuidKind::Ta => elf_uuid::read_ta_uuid(elf)?,
+ UuidKind::Plugin => elf_uuid::read_plugin_uuid(elf)?,
+ };
+ let mut stdout = io::stdout().lock();
+ writeln!(stdout, "{uuid}")?;
+ Ok(())
+}
+
/// Execute TA build or install (shared logic)
fn execute_ta_command(
common: CommonBuildArgs,
std: Option<bool>,
ta_dev_kit_dir: Option<PathBuf>,
signing_key: Option<PathBuf>,
- uuid_path: Option<PathBuf>,
- install_target_dir: Option<&PathBuf>,
+ install_target_dir: Option<PathBuf>,
+ lint_only: bool,
) -> anyhow::Result<()> {
- // Resolve project path from manifest or current directory
let project_path = resolve_project_path(common.manifest_path.as_ref())?;
- // Resolve TA build configuration with priority: CLI > metadata > default
let ta_config = config::TaBuildConfig::resolve(
&project_path,
- common.arch,
- Some(common.debug),
- uuid_path,
- common.env,
- common.no_default_features,
- common.features,
- std, // None means read from config, Some(true/false) means CLI override
+ config::BuildOverrides {
+ arch: common.arch,
+ debug: cli_debug_override(common.debug),
+ env: common.env,
+ no_default_features: common.no_default_features,
+ features: common.features,
+ },
+ std,
ta_dev_kit_dir,
signing_key,
+ !lint_only,
)?;
- // Print the final configuration being used
- ta_config.print_config();
-
- ta_builder::build_ta(ta_config, install_target_dir.map(|p| p.as_path()))
+ if lint_only {
+ ta_config.print_lint_config();
+ ta_builder::clippy_ta(ta_config)
+ } else {
+ ta_config.print_config();
+ ta_builder::build_ta(ta_config, install_target_dir.as_deref())
+ }
}
/// Execute CA build or install (shared logic)
fn execute_ca_command(
common: CommonBuildArgs,
optee_client_export: Option<PathBuf>,
- uuid_path: Option<PathBuf>,
plugin: bool,
- install_target_dir: Option<&PathBuf>,
+ install_target_dir: Option<PathBuf>,
+ lint_only: bool,
) -> anyhow::Result<()> {
- // Resolve project path from manifest or current directory
let project_path = resolve_project_path(common.manifest_path.as_ref())?;
- // Resolve CA build configuration with priority: CLI > metadata > default
let ca_config = config::CaBuildConfig::resolve(
&project_path,
- common.arch,
- Some(common.debug),
- uuid_path,
- common.env,
- common.no_default_features,
- common.features,
+ config::BuildOverrides {
+ arch: common.arch,
+ debug: cli_debug_override(common.debug),
+ env: common.env,
+ no_default_features: common.no_default_features,
+ features: common.features,
+ },
optee_client_export,
plugin,
)?;
- // Print the final configuration being used
- ca_config.print_config();
+ if lint_only {
+ ca_config.print_lint_config();
+ ca_builder::clippy_ca(ca_config)
+ } else {
+ ca_config.print_config();
+ ca_builder::build_ca(ca_config, install_target_dir.as_deref())
+ }
+}
- ca_builder::build_ca(ca_config, install_target_dir.map(|p| p.as_path()))
+/// `--debug` means force debug. Omitting it leaves metadata/default in place.
+fn cli_debug_override(debug: bool) -> Option<bool> {
+ debug.then_some(true)
}
/// Resolve project path from manifest path or current directory
@@ -206,12 +256,9 @@ fn resolve_project_path(manifest_path: Option<&PathBuf>) -> anyhow::Result<PathB
.parent()
.ok_or_else(|| anyhow::anyhow!("Invalid manifest path"))?;
- // Normalize: if parent is empty (e.g., manifest is just "Cargo.toml"),
- // use current directory instead
if parent.as_os_str().is_empty() {
std::env::current_dir().map_err(Into::into)
} else {
- // Canonicalize must succeed, otherwise treat as invalid manifest path
parent
.canonicalize()
.map_err(|_| anyhow::anyhow!("Invalid manifest path"))
@@ -220,13 +267,3 @@ fn resolve_project_path(manifest_path: Option<&PathBuf>) -> anyhow::Result<PathB
std::env::current_dir().map_err(Into::into)
}
}
-
-// Get Cargo Command.
-// As a Cargo plugin, this tool requires an existing Cargo installation.
-// It also follows standard Cargo conventions by prioritizing the `CARGO`
-// environment variable when invoking the binary.
-fn cargo_command() -> process::Command {
- // https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
- const ENV_CARGO: &str = "CARGO";
- process::Command::new(env::var_os(ENV_CARGO).unwrap_or_else(|| "cargo".into()))
-}
diff --git a/tools/cargo-optee/src/ta_builder.rs b/tools/cargo-optee/src/ta_builder.rs
index 4c9c2b7..1db6358 100644
--- a/tools/cargo-optee/src/ta_builder.rs
+++ b/tools/cargo-optee/src/ta_builder.rs
@@ -15,14 +15,15 @@
// specific language governing permissions and limitations
// under the License.
-use crate::cargo_command;
use crate::common;
use crate::common::{
- BuildMode, ChangeDirectoryGuard, get_package_name, get_target_and_cross_compile,
- get_target_directory_from_metadata, print_cargo_command, print_output_and_bail,
- read_uuid_from_file,
+ BuildArtifact, BuildMode, CargoArtifactKind, absolute_dir, apply_clippy_deny_lints,
+ cargo_command_in, manifest_path, print_cargo_command, print_output_and_bail, publish_tempfile,
+ resolve_target_and_cross_compile, set_ta_file_permissions, unique_cargo_artifact,
+ unique_tempfile_in,
};
use crate::config::TaBuildConfig;
+use crate::elf_uuid;
use anyhow::{Result, bail};
use std::env;
@@ -36,10 +37,10 @@ const AARCH64_TARGET_JSON: &str = include_str!("../aarch64-unknown-optee.json");
const ARM_TARGET_JSON: &str = include_str!("../arm-unknown-optee.json");
// Main function to build the TA, optionally installing to a target directory
-pub fn build_ta(config: TaBuildConfig, install_dir: Option<&Path>) -> Result<()> {
- // Verify we're in a valid Rust project directory
- let manifest_path = config.path.join("Cargo.toml");
- if !manifest_path.exists() {
+pub fn build_ta(mut config: TaBuildConfig, install_dir: Option<&Path>) -> Result<()> {
+ config.path = absolute_dir(&config.path)?;
+ let manifest = manifest_path(&config.path);
+ if !manifest.exists() {
bail!(
"No Cargo.toml found in TA project directory: {:?}\n\
Please run cargo-optee from a TA project directory or specify --manifest-path",
@@ -47,33 +48,20 @@ pub fn build_ta(config: TaBuildConfig, install_dir: Option<&Path>) -> Result<()>
);
}
- // Change to the TA directory (RAII guard ensures we return to original directory)
- let _guard = ChangeDirectoryGuard::new(&config.path)?;
-
// Check if required cross-compile toolchain is available
let build_mode = if config.std {
BuildMode::TaStd
} else {
BuildMode::TaNoStd
};
- let (_, cross_compile_prefix) = get_target_and_cross_compile(config.arch, build_mode)?;
+ let (_, cross_compile_prefix) = resolve_target_and_cross_compile(config.arch, build_mode)?;
check_toolchain_exists(&cross_compile_prefix)?;
- // Get the absolute path for better clarity
- let absolute_path = std::fs::canonicalize(&config.path).unwrap_or_else(|_| config.path.clone());
- println!("Building TA in directory: {}", absolute_path.display());
-
- // Step 1: Run clippy for code quality checks
- run_clippy(&config)?;
-
- // Step 2: Build the TA
- build_binary(&config)?;
-
- // Step 3: Strip the binary
- let (stripped_path, target_dir) = strip_binary(&config)?;
+ println!("Building TA in directory: {}", config.path.display());
- // Step 4: Sign the TA
- sign_ta(&config, &stripped_path, &target_dir)?;
+ let elf_path = build_binary(&config)?;
+ let stripped = strip_binary(&config, &elf_path)?;
+ let artifact = sign_ta(&config, stripped.path())?;
// Step 5: Install if requested
if let Some(install_dir) = install_dir {
@@ -82,20 +70,9 @@ pub fn build_ta(config: TaBuildConfig, install_dir: Option<&Path>) -> Result<()>
bail!("Install directory does not exist: {:?}", install_dir);
}
- let uuid_path = config
- .uuid_path
- .as_ref()
- .ok_or_else(|| anyhow::anyhow!("UUID path is required but not configured"))?;
- let uuid = read_uuid_from_file(uuid_path)?;
- let ta_file = common::join_format_and_check::<&str>(
- &target_dir,
- &[],
- &format!("{}.ta", uuid),
- "Signed TA file",
- )?;
-
- let dest_path = install_dir.join(format!("{}.ta", uuid));
- fs::copy(ta_file, &dest_path)?;
+ let dest_path = install_dir.join(format!("{}.ta", artifact.uuid));
+ fs::copy(&artifact.path, &dest_path)?;
+ set_ta_file_permissions(&dest_path)?;
println!(
"TA installed to: {:?}",
@@ -108,11 +85,30 @@ pub fn build_ta(config: TaBuildConfig, install_dir: Option<&Path>) -> Result<()>
Ok(())
}
+/// Run cargo fmt and clippy with the same target/env as a TA build. Does not
+/// strip or sign, so a signing key is not required.
+pub fn clippy_ta(mut config: TaBuildConfig) -> Result<()> {
+ config.path = absolute_dir(&config.path)?;
+ let manifest = manifest_path(&config.path);
+ if !manifest.exists() {
+ bail!(
+ "No Cargo.toml found in TA project directory: {:?}\n\
+ Please run cargo-optee from a TA project directory or specify --manifest-path",
+ config.path
+ );
+ }
+
+ run_clippy(&config)
+}
+
fn run_clippy(config: &TaBuildConfig) -> Result<()> {
println!("Running cargo fmt and clippy...");
- // Run cargo fmt (we're already in the project directory via ChangeDirectoryGuard)
- let fmt_output = cargo_command().arg("fmt").output()?;
+ let fmt_output = cargo_command_in(&config.path)
+ .arg("fmt")
+ .arg("--manifest-path")
+ .arg(manifest_path(&config.path))
+ .output()?;
if !fmt_output.status.success() {
print_output_and_bail("cargo fmt", &fmt_output)?;
@@ -120,12 +116,7 @@ fn run_clippy(config: &TaBuildConfig) -> Result<()> {
// Setup clippy command with common environment
let (mut clippy_cmd, _temp_dir) = setup_build_command(config, "clippy")?;
-
- clippy_cmd.arg("--");
- clippy_cmd.arg("-D").arg("warnings");
- clippy_cmd.arg("-D").arg("clippy::unwrap_used");
- clippy_cmd.arg("-D").arg("clippy::expect_used");
- clippy_cmd.arg("-D").arg("clippy::panic");
+ apply_clippy_deny_lints(&mut clippy_cmd);
let clippy_output = clippy_cmd.output()?;
@@ -136,16 +127,15 @@ fn run_clippy(config: &TaBuildConfig) -> Result<()> {
Ok(())
}
-fn build_binary(config: &TaBuildConfig) -> Result<()> {
+fn build_binary(config: &TaBuildConfig) -> Result<PathBuf> {
// Determine target and cross-compile based on arch and std mode
let build_mode = if config.std {
BuildMode::TaStd
} else {
BuildMode::TaNoStd
};
- let (target, cross_compile) = get_target_and_cross_compile(config.arch, build_mode)?;
+ let (target, cross_compile) = resolve_target_and_cross_compile(config.arch, build_mode)?;
- // Setup build command with common environment (we're already in the project directory)
let (mut build_cmd, _temp_dir) = setup_build_command(config, "build")?;
if !config.debug {
@@ -156,6 +146,7 @@ fn build_binary(config: &TaBuildConfig) -> Result<()> {
let linker = format!("{}gcc", cross_compile);
let linker_cfg = format!("target.{}.linker=\"{}\"", target, linker);
build_cmd.arg("--config").arg(&linker_cfg);
+ build_cmd.arg("--message-format=json");
// Print the full cargo build command for debugging
print_cargo_command(&build_cmd, "Building TA binary");
@@ -163,60 +154,60 @@ fn build_binary(config: &TaBuildConfig) -> Result<()> {
let build_output = build_cmd.output()?;
if !build_output.status.success() {
+ let _ = unique_cargo_artifact(
+ &build_output.stdout,
+ &manifest_path(&config.path),
+ CargoArtifactKind::Bin,
+ );
print_output_and_bail("build", &build_output)?;
}
- Ok(())
+ unique_cargo_artifact(
+ &build_output.stdout,
+ &manifest_path(&config.path),
+ CargoArtifactKind::Bin,
+ )
}
-fn strip_binary(config: &TaBuildConfig) -> Result<(PathBuf, PathBuf)> {
+fn strip_binary(config: &TaBuildConfig, binary_path: &Path) -> Result<tempfile::NamedTempFile> {
println!("Stripping binary...");
- // Determine target based on arch and std mode
let build_mode = if config.std {
BuildMode::TaStd
} else {
BuildMode::TaNoStd
};
- let (target, cross_compile) = get_target_and_cross_compile(config.arch, build_mode)?;
-
- let profile = if config.debug { "debug" } else { "release" };
-
- // Use cargo metadata to get the target directory (supports workspace and CARGO_TARGET_DIR)
- let target_directory = get_target_directory_from_metadata()?;
- let profile_dir = target_directory.join(target).join(profile);
+ let (_, cross_compile) = resolve_target_and_cross_compile(config.arch, build_mode)?;
- // Get the actual package name from Cargo.toml (we're already in the project directory)
- let package_name = get_package_name()?;
-
- let binary_path = common::join_and_check(&profile_dir, &[&package_name], "Binary")?;
-
- let stripped_path = profile_dir.join(format!("stripped_{}", package_name));
+ let file_name = binary_path
+ .file_name()
+ .and_then(|n| n.to_str())
+ .ok_or_else(|| anyhow::anyhow!("Binary path has no file name: {:?}", binary_path))?;
+ let parent = binary_path
+ .parent()
+ .ok_or_else(|| anyhow::anyhow!("Binary path has no parent: {:?}", binary_path))?;
+ let stripped = unique_tempfile_in(parent, &format!("stripped_{file_name}."), "")?;
let objcopy = format!("{}objcopy", cross_compile);
let strip_output = Command::new(&objcopy)
.arg("--strip-unneeded")
- .arg(&binary_path)
- .arg(&stripped_path)
+ .arg(binary_path)
+ .arg(stripped.path())
.output()?;
if !strip_output.status.success() {
print_output_and_bail(&objcopy, &strip_output)?;
}
- Ok((stripped_path, profile_dir))
+ Ok(stripped)
}
-fn sign_ta(config: &TaBuildConfig, stripped_path: &Path, target_dir: &Path) -> Result<()> {
+fn sign_ta(config: &TaBuildConfig, stripped_path: &Path) -> Result<BuildArtifact> {
println!("Signing TA with signing key {:?}...", config.signing_key);
- // Read UUID from specified file
- let uuid_path = config
- .uuid_path
- .as_ref()
- .ok_or_else(|| anyhow::anyhow!("UUID path is required but not configured"))?;
- let uuid = read_uuid_from_file(uuid_path)?;
+ let uuid = elf_uuid::read_ta_uuid(stripped_path)?;
+ let uuid_str = uuid.to_string();
// Validate signing key exists
if !config.signing_key.exists() {
@@ -230,30 +221,42 @@ fn sign_ta(config: &TaBuildConfig, stripped_path: &Path, target_dir: &Path) -> R
"Sign script",
)?;
- // Output path - use the actual target_dir
- let output_path = target_dir.join(format!("{}.ta", uuid));
+ let parent = stripped_path
+ .parent()
+ .ok_or_else(|| anyhow::anyhow!("Stripped path has no parent: {:?}", stripped_path))?;
+ let output_path = parent.join(format!("{uuid_str}.ta"));
+ let tmp = unique_tempfile_in(parent, &format!("{uuid_str}.ta."), ".partial")?;
let sign_output = Command::new("python3")
.arg(&sign_script)
.arg("--uuid")
- .arg(&uuid)
+ .arg(&uuid_str)
.arg("--key")
.arg(&config.signing_key)
.arg("--in")
.arg(stripped_path)
.arg("--out")
- .arg(&output_path)
+ .arg(tmp.path())
.output()?;
if !sign_output.status.success() {
print_output_and_bail("sign_encrypt.py", &sign_output)?;
}
- println!("SIGN => {}", uuid);
- let absolute_output_path = output_path.canonicalize().unwrap_or(output_path);
+ publish_tempfile(tmp, &output_path)?;
+ // NamedTempFile is 0600; sign_encrypt.py truncates without resetting mode.
+ set_ta_file_permissions(&output_path)?;
+
+ println!("SIGN => {}", uuid_str);
+ let absolute_output_path = output_path
+ .canonicalize()
+ .unwrap_or_else(|_| output_path.clone());
println!("TA signed and saved to: {:?}", absolute_output_path);
- Ok(())
+ Ok(BuildArtifact {
+ uuid,
+ path: output_path,
+ })
}
/// Check if the required cross-compile toolchain is available
@@ -317,7 +320,7 @@ fn setup_build_command(
} else {
BuildMode::TaNoStd
};
- let (target, cross_compile) = get_target_and_cross_compile(config.arch, build_mode)?;
+ let (target, cross_compile) = resolve_target_and_cross_compile(config.arch, build_mode)?;
// Setup custom targets if using std - keep TempDir alive
let temp_dir = if config.std {
@@ -327,8 +330,9 @@ fn setup_build_command(
};
// Always use cargo; std builds use the patched standard library and JSON targets.
- let mut cmd = cargo_command();
+ let mut cmd = cargo_command_in(&config.path);
cmd.arg(command);
+ cmd.arg("--manifest-path").arg(manifest_path(&config.path));
if config.std {
cmd.arg("-Z").arg("build-std=std,panic_abort");
cmd.arg("-Z").arg("json-target-spec");
@@ -445,7 +449,6 @@ mod tests {
arch: Arch::Aarch64,
debug: false,
path: PathBuf::from("/tmp/project"),
- uuid_path: None,
env: Vec::new(),
no_default_features: false,
features: None,
@@ -454,6 +457,16 @@ mod tests {
signing_key: PathBuf::from("/tmp/key.pem"),
};
let (build, _temp) = setup_build_command(&config, "build")?;
+ assert_eq!(build.get_current_dir(), Some(Path::new("/tmp/project")));
+ let args: Vec<_> = build
+ .get_args()
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+ assert!(
+ args.windows(2)
+ .any(|w| w[0] == "--manifest-path" && w[1] == "/tmp/project/Cargo.toml"),
+ "expected --manifest-path /tmp/project/Cargo.toml, got {args:?}"
+ );
let value = build
.get_envs()
.find(|(k, _)| k.to_str() == Some("CROSS_COMPILE"))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org
(teaclave-trustzone-sdk) 02/05: examples: drop uuid.txt and wrap Make with cargo-optee
Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit 1c1a2571ef8b4827615800a9183f1f3ce5e30e5b
Author: ivila <39...@qq.com>
AuthorDate: Mon Sep 21 11:44:22 2026 +0800
examples: drop uuid.txt and wrap Make with cargo-optee
Makefiles invoke cargo-optee with --arch/--std derived from TARGET.
install and emulate call cargo-optee install so artifacts follow the
active std/arch instead of a TARGET_TA scan. proto::UUID remains the
value written into ta_head. Forward STD to sub-makes only when it is
set, so the default stays --no-std.
---
.licenserc.yaml | 3 -
Makefile | 31 +++-----
examples/Makefile | 40 +++++-----
examples/ca/Makefile.include | 52 +++++++------
examples/ca/acipher-rs/Makefile | 1 -
examples/ca/aes-rs/Makefile | 1 -
examples/ca/authentication-rs/Makefile | 1 -
examples/ca/big_int-rs/Makefile | 1 -
examples/ca/client_pool-rs/Makefile | 1 -
examples/ca/diffie_hellman-rs/Makefile | 1 -
examples/ca/digest-rs/Makefile | 1 -
examples/ca/error_handling-rs/Makefile | 1 -
examples/ca/hello_world-rs/Cargo.toml | 5 --
examples/ca/hello_world-rs/Makefile | 1 -
examples/ca/hotp-rs/Makefile | 1 -
examples/ca/inter_ta-rs/Makefile | 1 -
examples/ca/message_passing_interface-rs/Makefile | 1 -
examples/ca/mnist-rs/Makefile | 1 -
examples/ca/property-rs/Makefile | 1 -
examples/ca/random-rs/Makefile | 1 -
examples/ca/secure_db_abstraction-rs/Makefile | 1 -
examples/ca/secure_storage-rs/Makefile | 1 -
examples/ca/serde-rs/Makefile | 1 -
examples/ca/signature_verification-rs/Makefile | 1 -
examples/ca/supp_plugin-rs-plugin/Cargo.toml | 2 -
examples/ca/supp_plugin-rs-plugin/Makefile | 2 -
examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt | 1 -
examples/ca/supp_plugin-rs/Makefile | 1 -
examples/ca/tcp_client-rs/Makefile | 1 -
examples/ca/time-rs/Makefile | 1 -
examples/ca/tls_client-rs/Makefile | 1 -
examples/ca/tls_server-rs/Makefile | 1 -
examples/ca/udp_socket-rs/Makefile | 1 -
examples/ta/Makefile.include | 88 ++++++++++++----------
examples/ta/acipher-rs/Cargo.toml | 2 -
examples/ta/acipher-rs/Makefile | 2 -
examples/ta/acipher-rs/uuid.txt | 1 -
examples/ta/aes-rs/Cargo.toml | 2 -
examples/ta/aes-rs/Makefile | 2 -
examples/ta/aes-rs/uuid.txt | 1 -
examples/ta/authentication-rs/Cargo.toml | 2 -
examples/ta/authentication-rs/Makefile | 2 -
examples/ta/authentication-rs/uuid.txt | 1 -
examples/ta/big_int-rs/Cargo.toml | 2 -
examples/ta/big_int-rs/Makefile | 2 -
examples/ta/big_int-rs/uuid.txt | 1 -
examples/ta/client_pool-rs/Cargo.toml | 2 -
examples/ta/client_pool-rs/Makefile | 2 -
examples/ta/client_pool-rs/uuid.txt | 1 -
examples/ta/diffie_hellman-rs/Cargo.toml | 2 -
examples/ta/diffie_hellman-rs/Makefile | 2 -
examples/ta/diffie_hellman-rs/uuid.txt | 1 -
examples/ta/digest-rs/Cargo.toml | 2 -
examples/ta/digest-rs/Makefile | 2 -
examples/ta/digest-rs/uuid.txt | 1 -
examples/ta/error_handling-rs/Cargo.toml | 2 -
examples/ta/error_handling-rs/Makefile | 2 -
examples/ta/error_handling-rs/uuid.txt | 1 -
examples/ta/hello_world-rs/Cargo.toml | 2 -
examples/ta/hello_world-rs/Makefile | 2 -
examples/ta/hello_world-rs/uuid.txt | 1 -
examples/ta/hotp-rs/Cargo.toml | 2 -
examples/ta/hotp-rs/Makefile | 2 -
examples/ta/hotp-rs/uuid.txt | 1 -
examples/ta/inter_ta-rs/Cargo.toml | 2 -
examples/ta/inter_ta-rs/Makefile | 2 -
examples/ta/inter_ta-rs/uuid.txt | 1 -
.../ta/message_passing_interface-rs/Cargo.toml | 2 -
examples/ta/message_passing_interface-rs/Makefile | 2 -
examples/ta/message_passing_interface-rs/uuid.txt | 1 -
examples/ta/mnist-rs/inference/Cargo.toml | 2 -
examples/ta/mnist-rs/inference/Makefile | 3 -
examples/ta/mnist-rs/inference/build.rs | 2 +-
examples/ta/mnist-rs/inference/uuid.txt | 1 -
examples/ta/mnist-rs/train/Cargo.toml | 2 -
examples/ta/mnist-rs/train/Makefile | 3 -
examples/ta/mnist-rs/train/uuid.txt | 1 -
examples/ta/property-rs/Cargo.toml | 2 -
examples/ta/property-rs/Makefile | 2 -
examples/ta/property-rs/uuid.txt | 1 -
examples/ta/proto/src/acipher.rs | 5 +-
examples/ta/proto/src/aes.rs | 5 +-
examples/ta/proto/src/authentication.rs | 5 +-
examples/ta/proto/src/big_int.rs | 5 +-
examples/ta/proto/src/client_pool.rs | 5 +-
examples/ta/proto/src/diffie_hellman.rs | 5 +-
examples/ta/proto/src/digest.rs | 5 +-
examples/ta/proto/src/error_handling.rs | 5 +-
examples/ta/proto/src/hello_world.rs | 5 +-
examples/ta/proto/src/hotp.rs | 5 +-
examples/ta/proto/src/inter_ta.rs | 5 +-
examples/ta/proto/src/message_passing_interface.rs | 5 +-
examples/ta/proto/src/mnist/inference.rs | 2 +-
examples/ta/proto/src/mnist/train.rs | 2 +-
examples/ta/proto/src/property.rs | 5 +-
examples/ta/proto/src/random.rs | 5 +-
examples/ta/proto/src/secure_db_abstraction.rs | 5 +-
examples/ta/proto/src/secure_storage.rs | 5 +-
examples/ta/proto/src/serde.rs | 5 +-
examples/ta/proto/src/signature_verification.rs | 5 +-
examples/ta/proto/src/supp_plugin.rs | 10 +--
examples/ta/proto/src/tcp_client.rs | 5 +-
examples/ta/proto/src/time.rs | 5 +-
examples/ta/proto/src/tls_client.rs | 5 +-
examples/ta/proto/src/tls_server.rs | 5 +-
examples/ta/proto/src/udp_socket.rs | 5 +-
examples/ta/random-rs/Cargo.toml | 2 -
examples/ta/random-rs/Makefile | 2 -
examples/ta/random-rs/uuid.txt | 1 -
examples/ta/secure_db_abstraction-rs/Cargo.toml | 2 -
examples/ta/secure_db_abstraction-rs/Makefile | 2 -
examples/ta/secure_db_abstraction-rs/uuid.txt | 1 -
examples/ta/secure_storage-rs/Cargo.toml | 2 -
examples/ta/secure_storage-rs/Makefile | 2 -
examples/ta/secure_storage-rs/uuid.txt | 1 -
examples/ta/serde-rs/Cargo.toml | 2 -
examples/ta/serde-rs/Makefile | 2 -
examples/ta/serde-rs/uuid.txt | 1 -
examples/ta/signature_verification-rs/Cargo.toml | 2 -
examples/ta/signature_verification-rs/Makefile | 2 -
examples/ta/signature_verification-rs/uuid.txt | 1 -
examples/ta/supp_plugin-rs/Cargo.toml | 2 -
examples/ta/supp_plugin-rs/Makefile | 2 -
examples/ta/supp_plugin-rs/ta_uuid.txt | 1 -
examples/ta/tcp_client-rs/Cargo.toml | 2 -
examples/ta/tcp_client-rs/Makefile | 2 -
examples/ta/tcp_client-rs/uuid.txt | 1 -
examples/ta/time-rs/Cargo.toml | 2 -
examples/ta/time-rs/Makefile | 2 -
examples/ta/time-rs/uuid.txt | 1 -
examples/ta/tls_client-rs/Cargo.toml | 2 -
examples/ta/tls_client-rs/Makefile | 2 -
examples/ta/tls_client-rs/uuid.txt | 1 -
examples/ta/tls_server-rs/Cargo.toml | 2 -
examples/ta/tls_server-rs/Makefile | 2 -
examples/ta/tls_server-rs/uuid.txt | 1 -
examples/ta/udp_socket-rs/Cargo.toml | 2 -
examples/ta/udp_socket-rs/Makefile | 2 -
examples/ta/udp_socket-rs/uuid.txt | 1 -
projects/web3/eth_wallet/Makefile | 20 ++---
projects/web3/eth_wallet/host/Makefile | 33 +++++---
projects/web3/eth_wallet/proto/src/lib.rs | 5 +-
projects/web3/eth_wallet/ta/Makefile | 48 ++++++------
projects/web3/eth_wallet/uuid.txt | 1 -
144 files changed, 191 insertions(+), 428 deletions(-)
diff --git a/.licenserc.yaml b/.licenserc.yaml
index fd9f521..e2f4dd4 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -31,8 +31,5 @@ header:
- 'DISCLAIMER'
- '**/*.json'
- 'examples/ta/tls_server-rs/test-ca/**'
- - '**/uuid.txt'
- - '**/plugin_uuid.txt'
- - '**/ta_uuid.txt'
- 'optee-version.txt'
- '**/*.stderr'
diff --git a/Makefile b/Makefile
index 851edaf..007a658 100644
--- a/Makefile
+++ b/Makefile
@@ -35,16 +35,14 @@ endif
export q
TARGET ?= aarch64-unknown-linux-gnu
-CROSS_COMPILE ?= aarch64-linux-gnu-
# If _HOST or _TA specific compiler/target are not specified, then use common
-# compiler/target for both
+# compiler/target for both. OP-TEE rust.mk still passes TARGET_* / CROSS_COMPILE_*.
+# Do not default CROSS_COMPILE_*; cargo-optee derives the prefix from --arch.
CROSS_COMPILE_HOST ?= $(CROSS_COMPILE)
CROSS_COMPILE_TA ?= $(CROSS_COMPILE)
TARGET_HOST ?= $(TARGET)
TARGET_TA ?= $(TARGET)
-BUILDER ?= cargo
-FEATURES ?=
.PHONY: all examples std-examples no-std-examples \
install clean examples-clean help
@@ -60,26 +58,19 @@ endif
examples: no-std-examples
# Delegate all examples-related targets to examples/Makefile
-std-examples no-std-examples:
- $(q)$(MAKE) -C examples $@ TARGET_HOST=$(TARGET_HOST) \
+std-examples no-std-examples install:
+ $(q)$(MAKE) -C examples $@ \
+ TA_INSTALL_DIR="$(abspath $(out-dir))/lib/optee_armtz" \
+ CA_INSTALL_DIR="$(abspath $(out-dir))$(bindir)" \
+ PLUGIN_INSTALL_DIR="$(abspath $(out-dir))$(libdir)/tee-supplicant/plugins" \
+ $(if $(STD),STD="$(STD)") \
+ TARGET_HOST=$(TARGET_HOST) \
TARGET_TA=$(TARGET_TA) \
CROSS_COMPILE_HOST=$(CROSS_COMPILE_HOST) \
CROSS_COMPILE_TA=$(CROSS_COMPILE_TA) \
TA_DEV_KIT_DIR=$(TA_DEV_KIT_DIR) \
OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT) \
- BUILDER=$(BUILDER) \
- FEATURES="$(FEATURES)"
-
-install: examples
- $(echo) ' INSTALL ${out-dir}/lib/optee_armtz'
- $(q)mkdir -p ${out-dir}/lib/optee_armtz
- $(q)find examples/ta/target/$(TARGET_TA)/ -name *.ta -exec cp {} ${out-dir}/lib/optee_armtz \;
- $(echo) ' INSTALL ${out-dir}${bindir}'
- $(q)mkdir -p ${out-dir}${bindir}
- $(q)cp examples/ca/target/$(TARGET_HOST)/release/*-rs ${out-dir}${bindir}
- $(echo) ' INSTALL ${out-dir}${libdir}/tee-supplicant/plugins/'
- $(q)mkdir -p ${out-dir}${libdir}/tee-supplicant/plugins/
- $(q)find examples/ca/target/$(TARGET_HOST)/ -name *.plugin.so -exec cp {} ${out-dir}${libdir}/tee-supplicant/plugins/ \;
+ $(if $(TA_SIGN_KEY),TA_SIGN_KEY="$(TA_SIGN_KEY)")
clean: examples-clean out-clean
@@ -94,6 +85,6 @@ help:
@echo " examples - Build no-std examples (default, backward compatible)"
@echo " std-examples - Build std examples (std-only + common)"
@echo " no-std-examples - Build no-std examples (no-std-only + common)"
- @echo " install - Install built examples to out directory"
+ @echo " install - Build and install examples to out directory"
@echo " clean - Clean all examples and output directory"
@echo ""
diff --git a/examples/Makefile b/examples/Makefile
index 880c10c..9988d45 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -15,15 +15,12 @@
# specific language governing permissions and limitations
# under the License.
-# Default build parameters if not specified
+# Default build parameters if not specified.
+# TARGET_* is the OP-TEE / `source environment` interface. --arch is derived
+# from the triple at the cargo-optee invocation.
TARGET ?= aarch64-unknown-linux-gnu
-CROSS_COMPILE ?= aarch64-linux-gnu-
-CROSS_COMPILE_HOST ?= $(CROSS_COMPILE)
-CROSS_COMPILE_TA ?= $(CROSS_COMPILE)
TARGET_HOST ?= $(TARGET)
TARGET_TA ?= $(TARGET)
-FEATURES ?=
-CARGO_FLAGS ?=
# All CA crates and all TA crates now share their respective workspace target
# directories. Do not run multiple per-example Cargo commands concurrently,
@@ -86,17 +83,26 @@ no-std-only-examples: $(NO_STD_ONLY_EXAMPLES)
# Build common examples (always built)
common-examples: $(COMMON_EXAMPLES)
-# Individual example build rules
+# Installation uses cargo-optee to locate artifacts for the active std/arch.
+BUILD_TARGET ?= all
+TA_INSTALL_DIR ?= $(CURDIR)/../out/lib/optee_armtz
+CA_INSTALL_DIR ?= $(CURDIR)/../out/usr/bin
+PLUGIN_INSTALL_DIR ?= $(CURDIR)/../out/usr/lib/tee-supplicant/plugins
+install: BUILD_TARGET = install
+install: $(if $(or $(STD),$(filter %-unknown-optee,$(TARGET_TA))),std-examples,no-std-examples)
+
$(STD_ONLY_EXAMPLES) $(NO_STD_ONLY_EXAMPLES) $(COMMON_EXAMPLES):
- $(q)make -C ca/$@ TARGET=$(TARGET_HOST) \
- CROSS_COMPILE=$(CROSS_COMPILE_HOST) \
- OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT)
- $(q)make -C ta/$@ TARGET=$(TARGET_TA) \
- CROSS_COMPILE=$(CROSS_COMPILE_TA) \
- TA_DEV_KIT_DIR=$(TA_DEV_KIT_DIR) \
- FEATURES="$(FEATURES)" \
- CARGO_FLAGS="$(CARGO_FLAGS)"
- $(if $(filter supp_plugin-rs,$@),$(q)make -C ca/supp_plugin-rs-plugin TARGET=$(TARGET_HOST) CROSS_COMPILE=$(CROSS_COMPILE_HOST) OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT))
+ $(q)$(MAKE) -C ca/$@ $(BUILD_TARGET) TARGET=$(TARGET_HOST) \
+ INSTALL_DIR="$(abspath $(CA_INSTALL_DIR))" \
+ $(if $(CROSS_COMPILE_HOST),CROSS_COMPILE=$(CROSS_COMPILE_HOST))
+ $(q)$(MAKE) -C ta/$@ $(BUILD_TARGET) TARGET=$(TARGET_TA) \
+ INSTALL_DIR="$(abspath $(TA_INSTALL_DIR))" \
+ $(if $(STD),STD="$(STD)") \
+ $(if $(CROSS_COMPILE_TA),CROSS_COMPILE=$(CROSS_COMPILE_TA)) \
+ $(if $(TA_SIGN_KEY),TA_SIGN_KEY="$(TA_SIGN_KEY)")
+ $(if $(filter supp_plugin-rs,$@),$(q)$(MAKE) -C ca/supp_plugin-rs-plugin $(BUILD_TARGET) TARGET=$(TARGET_HOST) \
+ INSTALL_DIR="$(abspath $(PLUGIN_INSTALL_DIR))" \
+ $(if $(CROSS_COMPILE_HOST),CROSS_COMPILE=$(CROSS_COMPILE_HOST)))
# Clean targets
clean: $(STD_ONLY_EXAMPLES_CLEAN) $(NO_STD_ONLY_EXAMPLES_CLEAN) $(COMMON_EXAMPLES_CLEAN)
@@ -116,6 +122,6 @@ help:
@echo " common-examples - Build examples that work in both modes"
@echo " clean - Clean all examples"
-.PHONY: std-examples no-std-examples std-only-examples no-std-only-examples common-examples \
+.PHONY: install std-examples no-std-examples std-only-examples no-std-only-examples common-examples \
$(STD_ONLY_EXAMPLES) $(NO_STD_ONLY_EXAMPLES) $(COMMON_EXAMPLES) \
$(STD_ONLY_EXAMPLES_CLEAN) $(NO_STD_ONLY_EXAMPLES_CLEAN) $(COMMON_EXAMPLES_CLEAN) clean help
diff --git a/examples/ca/Makefile.include b/examples/ca/Makefile.include
index c1e343c..a4dd4e2 100644
--- a/examples/ca/Makefile.include
+++ b/examples/ca/Makefile.include
@@ -15,40 +15,44 @@
# specific language governing permissions and limitations
# under the License.
-TARGET ?= aarch64-unknown-linux-gnu
-CROSS_COMPILE ?= aarch64-linux-gnu-
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
-OUT_DIR ?= $(CURDIR)/../target/$(TARGET)/release
+# TARGET is the OP-TEE rust.mk / `source environment` interface.
+# cargo-optee --arch is derived from that triple.
+TARGET ?= $(or $(TARGET_HOST),aarch64-unknown-linux-gnu)
+ifneq ($(filter arm-unknown-%,$(TARGET)),)
+OPTEE_ARCH := --arch arm
+else
+OPTEE_ARCH := --arch aarch64
+endif
+ifneq ($(CROSS_COMPILE_HOST),)
+CROSS_COMPILE := $(CROSS_COMPILE_HOST)
+endif
+ifneq ($(CROSS_COMPILE),)
+export CROSS_COMPILE
+endif
-CLIPPY_LINTS := -D warnings -D clippy::unwrap_used -D clippy::expect_used -D clippy::panic
+SDK_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
+CARGO_OPTEE ?= cargo run --manifest-path $(SDK_ROOT)/tools/Cargo.toml -q -p cargo-optee --
+OPTEE_COMPONENT := $(if $(filter y,$(PLUGIN)),plugin,ca)
+INSTALL_DIR ?= $(CURDIR)/shared
-.PHONY: all clippy host emulate clean
+.PHONY: all clippy host install emulate clean
-ifeq ($(PLUGIN),y)
+all: host
-all: clippy host
+clippy:
+ @$(CARGO_OPTEE) clippy $(OPTEE_COMPONENT) $(OPTEE_ARCH)
host: clippy
- @cargo build --target $(TARGET) --release --config $(LINKER_CFG)
- @cp $(OUT_DIR)/lib$(NAME).so $(OUT_DIR)/$(PLUGIN_UUID).plugin.so
-
-else
+ @$(CARGO_OPTEE) build $(OPTEE_COMPONENT) $(OPTEE_ARCH)
-all: clippy host
-
-host: clippy
- @cargo build --target $(TARGET) --release --config $(LINKER_CFG)
+install: clippy
+ @mkdir -p "$(INSTALL_DIR)"
+ @$(CARGO_OPTEE) install $(OPTEE_COMPONENT) $(OPTEE_ARCH) --target-dir "$(INSTALL_DIR)"
ifeq ($(EMULATE),y)
-emulate: all
- @sync_to_emulator --host $(OUT_DIR)/$(NAME)
-endif
-
+emulate: INSTALL_DIR = $(if $(QEMU_HOST_SHARE_DIR),$(QEMU_HOST_SHARE_DIR)/$(if $(filter y,$(PLUGIN)),plugin,host),$(error QEMU_HOST_SHARE_DIR must be set))
+emulate: install
endif
-clippy:
- @cargo fmt
- @cargo clippy --target $(TARGET) -- $(CLIPPY_LINTS)
-
clean:
@cargo clean
diff --git a/examples/ca/acipher-rs/Makefile b/examples/ca/acipher-rs/Makefile
index e5e417f..b232ac1 100644
--- a/examples/ca/acipher-rs/Makefile
+++ b/examples/ca/acipher-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := acipher-rs
include ../Makefile.include
diff --git a/examples/ca/aes-rs/Makefile b/examples/ca/aes-rs/Makefile
index e59f067..b232ac1 100644
--- a/examples/ca/aes-rs/Makefile
+++ b/examples/ca/aes-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := aes-rs
include ../Makefile.include
diff --git a/examples/ca/authentication-rs/Makefile b/examples/ca/authentication-rs/Makefile
index b1751c0..b232ac1 100644
--- a/examples/ca/authentication-rs/Makefile
+++ b/examples/ca/authentication-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := authentication-rs
include ../Makefile.include
diff --git a/examples/ca/big_int-rs/Makefile b/examples/ca/big_int-rs/Makefile
index 6083818..b232ac1 100644
--- a/examples/ca/big_int-rs/Makefile
+++ b/examples/ca/big_int-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := big_int-rs
include ../Makefile.include
diff --git a/examples/ca/client_pool-rs/Makefile b/examples/ca/client_pool-rs/Makefile
index 76e5a49..b232ac1 100644
--- a/examples/ca/client_pool-rs/Makefile
+++ b/examples/ca/client_pool-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := client_pool-rs
include ../Makefile.include
diff --git a/examples/ca/diffie_hellman-rs/Makefile b/examples/ca/diffie_hellman-rs/Makefile
index 2cff2d3..b232ac1 100644
--- a/examples/ca/diffie_hellman-rs/Makefile
+++ b/examples/ca/diffie_hellman-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := diffie_hellman-rs
include ../Makefile.include
diff --git a/examples/ca/digest-rs/Makefile b/examples/ca/digest-rs/Makefile
index 624886b..b232ac1 100644
--- a/examples/ca/digest-rs/Makefile
+++ b/examples/ca/digest-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := digest-rs
include ../Makefile.include
diff --git a/examples/ca/error_handling-rs/Makefile b/examples/ca/error_handling-rs/Makefile
index 7b15250..b232ac1 100644
--- a/examples/ca/error_handling-rs/Makefile
+++ b/examples/ca/error_handling-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := error_handling-rs
include ../Makefile.include
diff --git a/examples/ca/hello_world-rs/Cargo.toml b/examples/ca/hello_world-rs/Cargo.toml
index a00ebb6..6c207cb 100644
--- a/examples/ca/hello_world-rs/Cargo.toml
+++ b/examples/ca/hello_world-rs/Cargo.toml
@@ -28,8 +28,3 @@ edition = "2018"
libc = { workspace = true }
proto = { workspace = true }
optee-teec = { workspace = true }
-
-[package.metadata.optee.ca]
-arch = "aarch64"
-debug = false
-optee-client-export = { aarch64 = "/opt/teaclave/optee/optee_client/export_arm64", arm = "/opt/teaclave/optee/optee_client/export_arm32" }
diff --git a/examples/ca/hello_world-rs/Makefile b/examples/ca/hello_world-rs/Makefile
index 58dfb00..d8f05aa 100644
--- a/examples/ca/hello_world-rs/Makefile
+++ b/examples/ca/hello_world-rs/Makefile
@@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-NAME := hello_world-rs
EMULATE := y
include ../Makefile.include
diff --git a/examples/ca/hotp-rs/Makefile b/examples/ca/hotp-rs/Makefile
index e3dcb2a..b232ac1 100644
--- a/examples/ca/hotp-rs/Makefile
+++ b/examples/ca/hotp-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := hotp-rs
include ../Makefile.include
diff --git a/examples/ca/inter_ta-rs/Makefile b/examples/ca/inter_ta-rs/Makefile
index 83a4934..b232ac1 100644
--- a/examples/ca/inter_ta-rs/Makefile
+++ b/examples/ca/inter_ta-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := inter_ta-rs
include ../Makefile.include
diff --git a/examples/ca/message_passing_interface-rs/Makefile b/examples/ca/message_passing_interface-rs/Makefile
index f394c2a..b232ac1 100644
--- a/examples/ca/message_passing_interface-rs/Makefile
+++ b/examples/ca/message_passing_interface-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := message_passing_interface-rs
include ../Makefile.include
diff --git a/examples/ca/mnist-rs/Makefile b/examples/ca/mnist-rs/Makefile
index eaee6fc..b232ac1 100644
--- a/examples/ca/mnist-rs/Makefile
+++ b/examples/ca/mnist-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := mnist-rs
include ../Makefile.include
diff --git a/examples/ca/property-rs/Makefile b/examples/ca/property-rs/Makefile
index 42a1dc3..b232ac1 100644
--- a/examples/ca/property-rs/Makefile
+++ b/examples/ca/property-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := property-rs
include ../Makefile.include
diff --git a/examples/ca/random-rs/Makefile b/examples/ca/random-rs/Makefile
index 19b8397..b232ac1 100644
--- a/examples/ca/random-rs/Makefile
+++ b/examples/ca/random-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := random-rs
include ../Makefile.include
diff --git a/examples/ca/secure_db_abstraction-rs/Makefile b/examples/ca/secure_db_abstraction-rs/Makefile
index 59d3dcc..b232ac1 100644
--- a/examples/ca/secure_db_abstraction-rs/Makefile
+++ b/examples/ca/secure_db_abstraction-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := secure_db_abstraction-rs
include ../Makefile.include
diff --git a/examples/ca/secure_storage-rs/Makefile b/examples/ca/secure_storage-rs/Makefile
index 6507543..b232ac1 100644
--- a/examples/ca/secure_storage-rs/Makefile
+++ b/examples/ca/secure_storage-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := secure_storage-rs
include ../Makefile.include
diff --git a/examples/ca/serde-rs/Makefile b/examples/ca/serde-rs/Makefile
index 68f1903..b232ac1 100644
--- a/examples/ca/serde-rs/Makefile
+++ b/examples/ca/serde-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := serde-rs
include ../Makefile.include
diff --git a/examples/ca/signature_verification-rs/Makefile b/examples/ca/signature_verification-rs/Makefile
index ce67733..b232ac1 100644
--- a/examples/ca/signature_verification-rs/Makefile
+++ b/examples/ca/signature_verification-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := signature_verification-rs
include ../Makefile.include
diff --git a/examples/ca/supp_plugin-rs-plugin/Cargo.toml b/examples/ca/supp_plugin-rs-plugin/Cargo.toml
index 943ab83..32a019d 100644
--- a/examples/ca/supp_plugin-rs-plugin/Cargo.toml
+++ b/examples/ca/supp_plugin-rs-plugin/Cargo.toml
@@ -39,5 +39,3 @@ anyhow = { workspace = true }
crate-type = ["cdylib"]
name = "syslog_plugin"
-[package.metadata.optee.plugin]
-uuid-path = "plugin_uuid.txt"
diff --git a/examples/ca/supp_plugin-rs-plugin/Makefile b/examples/ca/supp_plugin-rs-plugin/Makefile
index ba66919..a2001b0 100644
--- a/examples/ca/supp_plugin-rs-plugin/Makefile
+++ b/examples/ca/supp_plugin-rs-plugin/Makefile
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-NAME := syslog_plugin
-PLUGIN_UUID := $(shell cat plugin_uuid.txt)
PLUGIN := y
include ../Makefile.include
diff --git a/examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt b/examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt
deleted file mode 100644
index 9b4f37a..0000000
--- a/examples/ca/supp_plugin-rs-plugin/plugin_uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-ef620757-fa2b-4f19-a1c4-6e51cfe4c0f9
\ No newline at end of file
diff --git a/examples/ca/supp_plugin-rs/Makefile b/examples/ca/supp_plugin-rs/Makefile
index a24d951..b232ac1 100644
--- a/examples/ca/supp_plugin-rs/Makefile
+++ b/examples/ca/supp_plugin-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := supp_plugin-rs
include ../Makefile.include
diff --git a/examples/ca/tcp_client-rs/Makefile b/examples/ca/tcp_client-rs/Makefile
index 95df49e..b232ac1 100644
--- a/examples/ca/tcp_client-rs/Makefile
+++ b/examples/ca/tcp_client-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := tcp_client-rs
include ../Makefile.include
diff --git a/examples/ca/time-rs/Makefile b/examples/ca/time-rs/Makefile
index 7b45ca0..b232ac1 100644
--- a/examples/ca/time-rs/Makefile
+++ b/examples/ca/time-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := time-rs
include ../Makefile.include
diff --git a/examples/ca/tls_client-rs/Makefile b/examples/ca/tls_client-rs/Makefile
index 77fc183..b232ac1 100644
--- a/examples/ca/tls_client-rs/Makefile
+++ b/examples/ca/tls_client-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := tls_client-rs
include ../Makefile.include
diff --git a/examples/ca/tls_server-rs/Makefile b/examples/ca/tls_server-rs/Makefile
index b9229b9..b232ac1 100644
--- a/examples/ca/tls_server-rs/Makefile
+++ b/examples/ca/tls_server-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := tls_server-rs
include ../Makefile.include
diff --git a/examples/ca/udp_socket-rs/Makefile b/examples/ca/udp_socket-rs/Makefile
index 929f10b..b232ac1 100644
--- a/examples/ca/udp_socket-rs/Makefile
+++ b/examples/ca/udp_socket-rs/Makefile
@@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-NAME := udp_socket-rs
include ../Makefile.include
diff --git a/examples/ta/Makefile.include b/examples/ta/Makefile.include
index 2d0c4c5..4989ec2 100644
--- a/examples/ta/Makefile.include
+++ b/examples/ta/Makefile.include
@@ -15,63 +15,71 @@
# specific language governing permissions and limitations
# under the License.
-TARGET ?= aarch64-unknown-linux-gnu
-CROSS_COMPILE ?= aarch64-linux-gnu-
-OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
-OUT_DIR ?= $(CURDIR)/../target/$(TARGET)/release
-CARGO_FLAGS ?=
-FEATURES ?=
+# TARGET is the OP-TEE rust.mk / `source environment` interface.
+# cargo-optee --arch / --std are derived from that triple.
+TARGET ?= $(or $(TARGET_TA),aarch64-unknown-linux-gnu)
+ifneq ($(filter arm-unknown-%,$(TARGET)),)
+OPTEE_ARCH := --arch arm
+else
+OPTEE_ARCH := --arch aarch64
+endif
+ifneq ($(STD),)
+OPTEE_STD := --std
+else ifneq ($(filter %-unknown-optee,$(TARGET)),)
+OPTEE_STD := --std
+else
+OPTEE_STD := --no-std
+endif
+ifneq ($(CROSS_COMPILE_TA),)
+CROSS_COMPILE := $(CROSS_COMPILE_TA)
+endif
+ifneq ($(CROSS_COMPILE),)
+export CROSS_COMPILE
+endif
+ifneq ($(TA_SIGN_KEY),)
+OPTEE_SIGNING_KEY := --signing-key "$(TA_SIGN_KEY)"
+endif
+
+SDK_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
+CARGO_OPTEE ?= cargo run --manifest-path $(SDK_ROOT)/tools/Cargo.toml -q -p cargo-optee --
+INSTALL_DIR ?= $(CURDIR)/shared
-.PHONY: all clippy ta strip sign emulate clean
+.PHONY: all clippy ta strip sign install emulate clean
ifeq ($(GROUP),y)
-all:
+all clippy ta install clean:
@set -e; for member in $(MEMBERS); do \
- $(MAKE) -C $$member TARGET=$(TARGET) CROSS_COMPILE=$(CROSS_COMPILE) \
- TA_DEV_KIT_DIR=$(TA_DEV_KIT_DIR) FEATURES="$(FEATURES)" CARGO_FLAGS="$(CARGO_FLAGS)"; \
+ $(MAKE) -C $$member $@ TARGET=$(TARGET) \
+ INSTALL_DIR="$(abspath $(INSTALL_DIR))" \
+ $(if $(STD),STD="$(STD)") \
+ $(if $(CROSS_COMPILE),CROSS_COMPILE=$(CROSS_COMPILE)) \
+ $(if $(TA_SIGN_KEY),TA_SIGN_KEY="$(TA_SIGN_KEY)"); \
done
-clean:
- @cargo clean --manifest-path ../Cargo.toml
-
else
-ifeq ($(findstring panic=abort,$(RUSTFLAGS)),)
-RUSTFLAGS += -C panic=abort
-endif
-ifneq ($(findstring json-target-spec,$(CARGO_FLAGS)),)
-ifeq ($(findstring unstable-options,$(RUSTFLAGS)),)
-RUSTFLAGS += -Z unstable-options
-endif
-endif
-TA_SIGN_KEY ?= $(TA_DEV_KIT_DIR)/keys/default_ta.pem
-SIGN := $(TA_DEV_KIT_DIR)/scripts/sign_encrypt.py
-CLIPPY_LINTS := -D warnings -D clippy::unwrap_used -D clippy::expect_used -D clippy::panic
-
-all: clippy ta strip sign
+all: ta
clippy:
- @cargo fmt
- @RUSTFLAGS="$(RUSTFLAGS)" cargo clippy $(CARGO_FLAGS) --target $(TARGET) $(FEATURES) -- $(CLIPPY_LINTS)
+ @$(CARGO_OPTEE) clippy ta $(OPTEE_ARCH) $(OPTEE_STD)
ta: clippy
- @RUSTFLAGS="$(RUSTFLAGS)" cargo build $(CARGO_FLAGS) --target $(TARGET) --release $(FEATURES) --config $(LINKER_CFG)
+ @$(CARGO_OPTEE) build ta $(OPTEE_ARCH) $(OPTEE_STD) $(OPTEE_SIGNING_KEY)
-strip: ta
- @$(OBJCOPY) --strip-unneeded $(OUT_DIR)/$(NAME) $(OUT_DIR)/stripped_$(NAME)
+install: clippy
+ @mkdir -p "$(INSTALL_DIR)"
+ @$(CARGO_OPTEE) install ta $(OPTEE_ARCH) $(OPTEE_STD) $(OPTEE_SIGNING_KEY) --target-dir "$(INSTALL_DIR)"
-sign: strip
- @$(SIGN) --uuid $(UUID) --key $(TA_SIGN_KEY) --in $(OUT_DIR)/stripped_$(NAME) --out $(OUT_DIR)/$(UUID).ta
- @echo "SIGN => $(UUID)"
+clean:
+ @cargo clean
-ifeq ($(EMULATE),y)
-emulate: all
- @sync_to_emulator --ta $(OUT_DIR)/$(UUID).ta
endif
-clean:
- @cargo clean
+# Compatibility aliases: cargo-optee owns stripping and signing.
+strip sign: ta
+ifeq ($(EMULATE),y)
+emulate: INSTALL_DIR = $(if $(QEMU_HOST_SHARE_DIR),$(QEMU_HOST_SHARE_DIR)/ta,$(error QEMU_HOST_SHARE_DIR must be set))
+emulate: install
endif
diff --git a/examples/ta/acipher-rs/Cargo.toml b/examples/ta/acipher-rs/Cargo.toml
index 09e0dc2..1ea45fb 100644
--- a/examples/ta/acipher-rs/Cargo.toml
+++ b/examples/ta/acipher-rs/Cargo.toml
@@ -36,5 +36,3 @@ std = ["optee-utee/std"]
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/acipher-rs/Makefile b/examples/ta/acipher-rs/Makefile
index 076ed6d..b232ac1 100644
--- a/examples/ta/acipher-rs/Makefile
+++ b/examples/ta/acipher-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := acipher-rs-ta
include ../Makefile.include
diff --git a/examples/ta/acipher-rs/uuid.txt b/examples/ta/acipher-rs/uuid.txt
deleted file mode 100644
index cc86ae9..0000000
--- a/examples/ta/acipher-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-057f4b66-bdab-11eb-96cf-33d6e41cc849
\ No newline at end of file
diff --git a/examples/ta/aes-rs/Cargo.toml b/examples/ta/aes-rs/Cargo.toml
index dfdd241..c0572d8 100644
--- a/examples/ta/aes-rs/Cargo.toml
+++ b/examples/ta/aes-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/aes-rs/Makefile b/examples/ta/aes-rs/Makefile
index 24a0a49..b232ac1 100644
--- a/examples/ta/aes-rs/Makefile
+++ b/examples/ta/aes-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := aes-rs-ta
include ../Makefile.include
diff --git a/examples/ta/aes-rs/uuid.txt b/examples/ta/aes-rs/uuid.txt
deleted file mode 100644
index 8def748..0000000
--- a/examples/ta/aes-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-0864c8ec-bdab-11eb-8926-c7fa47a8c92d
\ No newline at end of file
diff --git a/examples/ta/authentication-rs/Cargo.toml b/examples/ta/authentication-rs/Cargo.toml
index 2c05f0f..e7c9434 100644
--- a/examples/ta/authentication-rs/Cargo.toml
+++ b/examples/ta/authentication-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/authentication-rs/Makefile b/examples/ta/authentication-rs/Makefile
index 25045f3..b232ac1 100644
--- a/examples/ta/authentication-rs/Makefile
+++ b/examples/ta/authentication-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := authentication-rs-ta
include ../Makefile.include
diff --git a/examples/ta/authentication-rs/uuid.txt b/examples/ta/authentication-rs/uuid.txt
deleted file mode 100644
index c3756bf..0000000
--- a/examples/ta/authentication-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-0a5a06b2-bdab-11eb-add0-77f29de31296
\ No newline at end of file
diff --git a/examples/ta/big_int-rs/Cargo.toml b/examples/ta/big_int-rs/Cargo.toml
index 38c1184..0e90c1f 100644
--- a/examples/ta/big_int-rs/Cargo.toml
+++ b/examples/ta/big_int-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/big_int-rs/Makefile b/examples/ta/big_int-rs/Makefile
index 5eaf946..b232ac1 100644
--- a/examples/ta/big_int-rs/Makefile
+++ b/examples/ta/big_int-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := big_int-rs-ta
include ../Makefile.include
diff --git a/examples/ta/big_int-rs/uuid.txt b/examples/ta/big_int-rs/uuid.txt
deleted file mode 100644
index 989765b..0000000
--- a/examples/ta/big_int-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-0bef16a2-bdab-11eb-94be-6f9815f37c21
\ No newline at end of file
diff --git a/examples/ta/client_pool-rs/Cargo.toml b/examples/ta/client_pool-rs/Cargo.toml
index 18c8225..88a5dce 100644
--- a/examples/ta/client_pool-rs/Cargo.toml
+++ b/examples/ta/client_pool-rs/Cargo.toml
@@ -37,5 +37,3 @@ hex = { workspace = true, default-features = false }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/client_pool-rs/Makefile b/examples/ta/client_pool-rs/Makefile
index d013209..b232ac1 100644
--- a/examples/ta/client_pool-rs/Makefile
+++ b/examples/ta/client_pool-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := client_pool-rs-ta
include ../Makefile.include
diff --git a/examples/ta/client_pool-rs/uuid.txt b/examples/ta/client_pool-rs/uuid.txt
deleted file mode 100644
index 1f96819..0000000
--- a/examples/ta/client_pool-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-c9d73f40-ba45-4315-92c4-cf1255958729
\ No newline at end of file
diff --git a/examples/ta/diffie_hellman-rs/Cargo.toml b/examples/ta/diffie_hellman-rs/Cargo.toml
index 0e37a5e..f5db7d5 100644
--- a/examples/ta/diffie_hellman-rs/Cargo.toml
+++ b/examples/ta/diffie_hellman-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/diffie_hellman-rs/Makefile b/examples/ta/diffie_hellman-rs/Makefile
index 9446133..b232ac1 100644
--- a/examples/ta/diffie_hellman-rs/Makefile
+++ b/examples/ta/diffie_hellman-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := diffie_hellman-rs-ta
include ../Makefile.include
diff --git a/examples/ta/diffie_hellman-rs/uuid.txt b/examples/ta/diffie_hellman-rs/uuid.txt
deleted file mode 100644
index d5b1c92..0000000
--- a/examples/ta/diffie_hellman-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-0e6bf4fe-bdab-11eb-9bc5-3f4ecb50aee7
\ No newline at end of file
diff --git a/examples/ta/digest-rs/Cargo.toml b/examples/ta/digest-rs/Cargo.toml
index 5ab89c9..c253926 100644
--- a/examples/ta/digest-rs/Cargo.toml
+++ b/examples/ta/digest-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/digest-rs/Makefile b/examples/ta/digest-rs/Makefile
index e2f5ad9..b232ac1 100644
--- a/examples/ta/digest-rs/Makefile
+++ b/examples/ta/digest-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := digest-rs-ta
include ../Makefile.include
diff --git a/examples/ta/digest-rs/uuid.txt b/examples/ta/digest-rs/uuid.txt
deleted file mode 100644
index 322fa1a..0000000
--- a/examples/ta/digest-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-10de87e2-bdab-11eb-b73c-63fec73e597c
\ No newline at end of file
diff --git a/examples/ta/error_handling-rs/Cargo.toml b/examples/ta/error_handling-rs/Cargo.toml
index 1c08d95..7adb112 100644
--- a/examples/ta/error_handling-rs/Cargo.toml
+++ b/examples/ta/error_handling-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/error_handling-rs/Makefile b/examples/ta/error_handling-rs/Makefile
index 20a9489..b232ac1 100644
--- a/examples/ta/error_handling-rs/Makefile
+++ b/examples/ta/error_handling-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := error_handling-rs-ta
include ../Makefile.include
diff --git a/examples/ta/error_handling-rs/uuid.txt b/examples/ta/error_handling-rs/uuid.txt
deleted file mode 100644
index 29d5aa1..0000000
--- a/examples/ta/error_handling-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-ec59c1fc-b9e0-4c3c-8756-0a3cc48f0088
\ No newline at end of file
diff --git a/examples/ta/hello_world-rs/Cargo.toml b/examples/ta/hello_world-rs/Cargo.toml
index 6060717..95e25e6 100644
--- a/examples/ta/hello_world-rs/Cargo.toml
+++ b/examples/ta/hello_world-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/hello_world-rs/Makefile b/examples/ta/hello_world-rs/Makefile
index b0707ed..d8f05aa 100644
--- a/examples/ta/hello_world-rs/Makefile
+++ b/examples/ta/hello_world-rs/Makefile
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := hello_world-rs-ta
EMULATE := y
include ../Makefile.include
diff --git a/examples/ta/hello_world-rs/uuid.txt b/examples/ta/hello_world-rs/uuid.txt
deleted file mode 100644
index 7f63353..0000000
--- a/examples/ta/hello_world-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-133af0ca-bdab-11eb-9130-43bf7873bf67
\ No newline at end of file
diff --git a/examples/ta/hotp-rs/Cargo.toml b/examples/ta/hotp-rs/Cargo.toml
index e01382e..b5fd4c2 100644
--- a/examples/ta/hotp-rs/Cargo.toml
+++ b/examples/ta/hotp-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/hotp-rs/Makefile b/examples/ta/hotp-rs/Makefile
index 6e4260c..b232ac1 100644
--- a/examples/ta/hotp-rs/Makefile
+++ b/examples/ta/hotp-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := hotp-rs-ta
include ../Makefile.include
diff --git a/examples/ta/hotp-rs/uuid.txt b/examples/ta/hotp-rs/uuid.txt
deleted file mode 100644
index 69add6a..0000000
--- a/examples/ta/hotp-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-1585d412-bdab-11eb-ba91-3b085fd2601f
\ No newline at end of file
diff --git a/examples/ta/inter_ta-rs/Cargo.toml b/examples/ta/inter_ta-rs/Cargo.toml
index 2326bfe..5db0608 100644
--- a/examples/ta/inter_ta-rs/Cargo.toml
+++ b/examples/ta/inter_ta-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/inter_ta-rs/Makefile b/examples/ta/inter_ta-rs/Makefile
index 73512b2..b232ac1 100644
--- a/examples/ta/inter_ta-rs/Makefile
+++ b/examples/ta/inter_ta-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := inter_ta-rs-ta
include ../Makefile.include
diff --git a/examples/ta/inter_ta-rs/uuid.txt b/examples/ta/inter_ta-rs/uuid.txt
deleted file mode 100644
index 6c50099..0000000
--- a/examples/ta/inter_ta-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-fa9ea860-ef3b-4d59-8457-5564a60c0379
\ No newline at end of file
diff --git a/examples/ta/message_passing_interface-rs/Cargo.toml b/examples/ta/message_passing_interface-rs/Cargo.toml
index 2eacbb4..5e80b5a 100644
--- a/examples/ta/message_passing_interface-rs/Cargo.toml
+++ b/examples/ta/message_passing_interface-rs/Cargo.toml
@@ -37,5 +37,3 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"]
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/message_passing_interface-rs/Makefile b/examples/ta/message_passing_interface-rs/Makefile
index 75ab81e..b232ac1 100644
--- a/examples/ta/message_passing_interface-rs/Makefile
+++ b/examples/ta/message_passing_interface-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := message_passing_interface-rs-ta
include ../Makefile.include
diff --git a/examples/ta/message_passing_interface-rs/uuid.txt b/examples/ta/message_passing_interface-rs/uuid.txt
deleted file mode 100644
index a455e97..0000000
--- a/examples/ta/message_passing_interface-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-17556a46-bdab-11eb-b325-d38c9a9af725
\ No newline at end of file
diff --git a/examples/ta/mnist-rs/inference/Cargo.toml b/examples/ta/mnist-rs/inference/Cargo.toml
index 42a29b9..b83dc25 100644
--- a/examples/ta/mnist-rs/inference/Cargo.toml
+++ b/examples/ta/mnist-rs/inference/Cargo.toml
@@ -38,5 +38,3 @@ spin = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/mnist-rs/inference/Makefile b/examples/ta/mnist-rs/inference/Makefile
index 5c01b76..e80fbd6 100644
--- a/examples/ta/mnist-rs/inference/Makefile
+++ b/examples/ta/mnist-rs/inference/Makefile
@@ -15,8 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := inference
-OUT_DIR = $(CURDIR)/../../target/$(TARGET)/release
include ../../Makefile.include
diff --git a/examples/ta/mnist-rs/inference/build.rs b/examples/ta/mnist-rs/inference/build.rs
index 72a9266..35c9a52 100644
--- a/examples/ta/mnist-rs/inference/build.rs
+++ b/examples/ta/mnist-rs/inference/build.rs
@@ -18,7 +18,7 @@
use optee_utee_build::{Error, TaConfig};
fn main() -> Result<(), Error> {
- let config = TaConfig::new_default_with_cargo_env(proto::mnist::train::UUID)?
+ let config = TaConfig::new_default_with_cargo_env(proto::mnist::inference::UUID)?
.ta_data_size(1024 * 1024)
.ta_stack_size(1024 * 1024);
optee_utee_build::build(config)
diff --git a/examples/ta/mnist-rs/inference/uuid.txt b/examples/ta/mnist-rs/inference/uuid.txt
deleted file mode 100644
index d00c0a4..0000000
--- a/examples/ta/mnist-rs/inference/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-ff09aa8a-fbb9-4734-ae8c-d7cd1a3f6744
\ No newline at end of file
diff --git a/examples/ta/mnist-rs/train/Cargo.toml b/examples/ta/mnist-rs/train/Cargo.toml
index d20ef41..c782abc 100644
--- a/examples/ta/mnist-rs/train/Cargo.toml
+++ b/examples/ta/mnist-rs/train/Cargo.toml
@@ -38,5 +38,3 @@ bytemuck = { workspace = true, features = ["min_const_generics"] }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/mnist-rs/train/Makefile b/examples/ta/mnist-rs/train/Makefile
index 9ce354e..e80fbd6 100644
--- a/examples/ta/mnist-rs/train/Makefile
+++ b/examples/ta/mnist-rs/train/Makefile
@@ -15,8 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := train
-OUT_DIR = $(CURDIR)/../../target/$(TARGET)/release
include ../../Makefile.include
diff --git a/examples/ta/mnist-rs/train/uuid.txt b/examples/ta/mnist-rs/train/uuid.txt
deleted file mode 100644
index 1c014e8..0000000
--- a/examples/ta/mnist-rs/train/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-1b5f5b74-e9cf-4e62-8c3e-7e41da6d76f6
\ No newline at end of file
diff --git a/examples/ta/property-rs/Cargo.toml b/examples/ta/property-rs/Cargo.toml
index 7406c3d..e83fd8b 100644
--- a/examples/ta/property-rs/Cargo.toml
+++ b/examples/ta/property-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true, features = ["unwind_stubs"] }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/property-rs/Makefile b/examples/ta/property-rs/Makefile
index 599a3bf..b232ac1 100644
--- a/examples/ta/property-rs/Makefile
+++ b/examples/ta/property-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := property-rs-ta
include ../Makefile.include
diff --git a/examples/ta/property-rs/uuid.txt b/examples/ta/property-rs/uuid.txt
deleted file mode 100644
index 870c3f7..0000000
--- a/examples/ta/property-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-a3859d33-b540-4a69-8d29-696dde9115cc
\ No newline at end of file
diff --git a/examples/ta/proto/src/acipher.rs b/examples/ta/proto/src/acipher.rs
index f32c156..f3cfa1e 100644
--- a/examples/ta/proto/src/acipher.rs
+++ b/examples/ta/proto/src/acipher.rs
@@ -28,7 +28,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../acipher-rs/uuid.txt");
+pub const UUID: &str = "057f4b66-bdab-11eb-96cf-33d6e41cc849";
diff --git a/examples/ta/proto/src/aes.rs b/examples/ta/proto/src/aes.rs
index 4d2b5fe..12aeb32 100644
--- a/examples/ta/proto/src/aes.rs
+++ b/examples/ta/proto/src/aes.rs
@@ -56,7 +56,4 @@ pub enum KeySize {
Unknown = 0,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../aes-rs/uuid.txt");
+pub const UUID: &str = "0864c8ec-bdab-11eb-8926-c7fa47a8c92d";
diff --git a/examples/ta/proto/src/authentication.rs b/examples/ta/proto/src/authentication.rs
index 9f89e88..4a6d96c 100644
--- a/examples/ta/proto/src/authentication.rs
+++ b/examples/ta/proto/src/authentication.rs
@@ -42,7 +42,4 @@ pub const KEY_SIZE: usize = 16;
pub const AAD_LEN: usize = 16;
pub const TAG_LEN: usize = 16;
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../authentication-rs/uuid.txt");
+pub const UUID: &str = "0a5a06b2-bdab-11eb-add0-77f29de31296";
diff --git a/examples/ta/proto/src/big_int.rs b/examples/ta/proto/src/big_int.rs
index c8ad635..35217b1 100644
--- a/examples/ta/proto/src/big_int.rs
+++ b/examples/ta/proto/src/big_int.rs
@@ -31,7 +31,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../big_int-rs/uuid.txt");
+pub const UUID: &str = "0bef16a2-bdab-11eb-94be-6f9815f37c21";
diff --git a/examples/ta/proto/src/client_pool.rs b/examples/ta/proto/src/client_pool.rs
index 6792292..9c15b53 100644
--- a/examples/ta/proto/src/client_pool.rs
+++ b/examples/ta/proto/src/client_pool.rs
@@ -25,10 +25,7 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../client_pool-rs/uuid.txt");
+pub const UUID: &str = "c9d73f40-ba45-4315-92c4-cf1255958729";
// the size of the identity bytes;
pub const IDENTITY_SIZE: usize = 32;
diff --git a/examples/ta/proto/src/diffie_hellman.rs b/examples/ta/proto/src/diffie_hellman.rs
index 178673c..99a9b6f 100644
--- a/examples/ta/proto/src/diffie_hellman.rs
+++ b/examples/ta/proto/src/diffie_hellman.rs
@@ -28,7 +28,4 @@ pub enum Command {
pub const KEY_SIZE: usize = 256;
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../diffie_hellman-rs/uuid.txt");
+pub const UUID: &str = "0e6bf4fe-bdab-11eb-9bc5-3f4ecb50aee7";
diff --git a/examples/ta/proto/src/digest.rs b/examples/ta/proto/src/digest.rs
index 5aa2a15..ebed629 100644
--- a/examples/ta/proto/src/digest.rs
+++ b/examples/ta/proto/src/digest.rs
@@ -26,7 +26,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../digest-rs/uuid.txt");
+pub const UUID: &str = "10de87e2-bdab-11eb-b73c-63fec73e597c";
diff --git a/examples/ta/proto/src/error_handling.rs b/examples/ta/proto/src/error_handling.rs
index 460330d..fb7d946 100644
--- a/examples/ta/proto/src/error_handling.rs
+++ b/examples/ta/proto/src/error_handling.rs
@@ -28,7 +28,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../error_handling-rs/uuid.txt");
+pub const UUID: &str = "ec59c1fc-b9e0-4c3c-8756-0a3cc48f0088";
diff --git a/examples/ta/proto/src/hello_world.rs b/examples/ta/proto/src/hello_world.rs
index 71b55d5..52ce7e5 100644
--- a/examples/ta/proto/src/hello_world.rs
+++ b/examples/ta/proto/src/hello_world.rs
@@ -26,7 +26,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../hello_world-rs/uuid.txt");
+pub const UUID: &str = "133af0ca-bdab-11eb-9130-43bf7873bf67";
diff --git a/examples/ta/proto/src/hotp.rs b/examples/ta/proto/src/hotp.rs
index 412e133..9754467 100644
--- a/examples/ta/proto/src/hotp.rs
+++ b/examples/ta/proto/src/hotp.rs
@@ -26,7 +26,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../hotp-rs/uuid.txt");
+pub const UUID: &str = "1585d412-bdab-11eb-ba91-3b085fd2601f";
diff --git a/examples/ta/proto/src/inter_ta.rs b/examples/ta/proto/src/inter_ta.rs
index ee632e5..d5e9cec 100644
--- a/examples/ta/proto/src/inter_ta.rs
+++ b/examples/ta/proto/src/inter_ta.rs
@@ -26,10 +26,7 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../inter_ta-rs/uuid.txt");
+pub const UUID: &str = "fa9ea860-ef3b-4d59-8457-5564a60c0379";
// For TA-TA invocation testcases:
#[derive(FromPrimitive, IntoPrimitive)]
diff --git a/examples/ta/proto/src/message_passing_interface.rs b/examples/ta/proto/src/message_passing_interface.rs
index f3fd873..34f209b 100644
--- a/examples/ta/proto/src/message_passing_interface.rs
+++ b/examples/ta/proto/src/message_passing_interface.rs
@@ -41,7 +41,4 @@ pub struct EnclaveOutput {
pub message: String,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../message_passing_interface-rs/uuid.txt");
+pub const UUID: &str = "17556a46-bdab-11eb-b325-d38c9a9af725";
diff --git a/examples/ta/proto/src/mnist/inference.rs b/examples/ta/proto/src/mnist/inference.rs
index efac714..b8c9757 100644
--- a/examples/ta/proto/src/mnist/inference.rs
+++ b/examples/ta/proto/src/mnist/inference.rs
@@ -15,4 +15,4 @@
// specific language governing permissions and limitations
// under the License.
-pub const UUID: &str = include_str!("../../../mnist-rs/inference/uuid.txt");
+pub const UUID: &str = "ff09aa8a-fbb9-4734-ae8c-d7cd1a3f6744";
diff --git a/examples/ta/proto/src/mnist/train.rs b/examples/ta/proto/src/mnist/train.rs
index fdccbad..4560157 100644
--- a/examples/ta/proto/src/mnist/train.rs
+++ b/examples/ta/proto/src/mnist/train.rs
@@ -30,4 +30,4 @@ pub struct Output {
pub accuracy: f32,
}
-pub const UUID: &str = include_str!("../../../mnist-rs/train/uuid.txt");
+pub const UUID: &str = "1b5f5b74-e9cf-4e62-8c3e-7e41da6d76f6";
diff --git a/examples/ta/proto/src/property.rs b/examples/ta/proto/src/property.rs
index d763ed3..30a4e8b 100644
--- a/examples/ta/proto/src/property.rs
+++ b/examples/ta/proto/src/property.rs
@@ -25,7 +25,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../property-rs/uuid.txt");
+pub const UUID: &str = "a3859d33-b540-4a69-8d29-696dde9115cc";
diff --git a/examples/ta/proto/src/random.rs b/examples/ta/proto/src/random.rs
index b029046..8be1d82 100644
--- a/examples/ta/proto/src/random.rs
+++ b/examples/ta/proto/src/random.rs
@@ -25,7 +25,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../random-rs/uuid.txt");
+pub const UUID: &str = "197c710c-bdab-11eb-8f3f-17a5f698d23b";
diff --git a/examples/ta/proto/src/secure_db_abstraction.rs b/examples/ta/proto/src/secure_db_abstraction.rs
index b20f848..9bfbfb7 100644
--- a/examples/ta/proto/src/secure_db_abstraction.rs
+++ b/examples/ta/proto/src/secure_db_abstraction.rs
@@ -25,7 +25,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../secure_db_abstraction-rs/uuid.txt");
+pub const UUID: &str = "e55291e1-521c-4dca-aa24-51e34ab32ad9";
diff --git a/examples/ta/proto/src/secure_storage.rs b/examples/ta/proto/src/secure_storage.rs
index 99eadc6..3391638 100644
--- a/examples/ta/proto/src/secure_storage.rs
+++ b/examples/ta/proto/src/secure_storage.rs
@@ -27,7 +27,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../secure_storage-rs/uuid.txt");
+pub const UUID: &str = "1cd6d392-bdab-11eb-9082-abc902ac5cd4";
diff --git a/examples/ta/proto/src/serde.rs b/examples/ta/proto/src/serde.rs
index 76de754..b01142f 100644
--- a/examples/ta/proto/src/serde.rs
+++ b/examples/ta/proto/src/serde.rs
@@ -32,7 +32,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../serde-rs/uuid.txt");
+pub const UUID: &str = "1ed47816-bdab-11eb-9ebd-3ffe0648da93";
diff --git a/examples/ta/proto/src/signature_verification.rs b/examples/ta/proto/src/signature_verification.rs
index af6be6d..8013558 100644
--- a/examples/ta/proto/src/signature_verification.rs
+++ b/examples/ta/proto/src/signature_verification.rs
@@ -26,7 +26,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../signature_verification-rs/uuid.txt");
+pub const UUID: &str = "c7e478c2-89b3-46eb-ac19-571e66c3830d";
diff --git a/examples/ta/proto/src/supp_plugin.rs b/examples/ta/proto/src/supp_plugin.rs
index 276fb4c..331e570 100644
--- a/examples/ta/proto/src/supp_plugin.rs
+++ b/examples/ta/proto/src/supp_plugin.rs
@@ -25,10 +25,7 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 ta_uuid.txt`.
-pub const TA_UUID: &str = include_str!("../../supp_plugin-rs/ta_uuid.txt");
+pub const TA_UUID: &str = "255fc838-de89-42d3-9a8e-d044c50fa57c";
//for plugin
#[derive(FromPrimitive, IntoPrimitive)]
@@ -40,7 +37,4 @@ pub enum PluginCommand {
}
pub const PLUGIN_SUBCMD_NULL: u32 = 0xFFFFFFFF;
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 plugin_uuid.txt`.
-pub const PLUGIN_UUID: &str = include_str!("../../../ca/supp_plugin-rs-plugin/plugin_uuid.txt");
+pub const PLUGIN_UUID: &str = "ef620757-fa2b-4f19-a1c4-6e51cfe4c0f9";
diff --git a/examples/ta/proto/src/tcp_client.rs b/examples/ta/proto/src/tcp_client.rs
index 79ff42c..9a3d6fc 100644
--- a/examples/ta/proto/src/tcp_client.rs
+++ b/examples/ta/proto/src/tcp_client.rs
@@ -31,7 +31,4 @@ pub enum IpVersion {
V6 = 2,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../tcp_client-rs/uuid.txt");
+pub const UUID: &str = "59db8536-e5e6-11eb-8e9b-a316ce7a6568";
diff --git a/examples/ta/proto/src/time.rs b/examples/ta/proto/src/time.rs
index c82d067..830c69d 100644
--- a/examples/ta/proto/src/time.rs
+++ b/examples/ta/proto/src/time.rs
@@ -25,7 +25,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../time-rs/uuid.txt");
+pub const UUID: &str = "21b1a1da-bdab-11eb-b614-275a7098826f";
diff --git a/examples/ta/proto/src/tls_client.rs b/examples/ta/proto/src/tls_client.rs
index 01192ca..bab1973 100644
--- a/examples/ta/proto/src/tls_client.rs
+++ b/examples/ta/proto/src/tls_client.rs
@@ -25,7 +25,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../tls_client-rs/uuid.txt");
+pub const UUID: &str = "ec55bfe2-d9c7-11eb-8b0e-f3f8fad927f7";
diff --git a/examples/ta/proto/src/tls_server.rs b/examples/ta/proto/src/tls_server.rs
index 7f6c2c9..a1fb30a 100644
--- a/examples/ta/proto/src/tls_server.rs
+++ b/examples/ta/proto/src/tls_server.rs
@@ -28,7 +28,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../tls_server-rs/uuid.txt");
+pub const UUID: &str = "69547de6-f47e-11eb-994e-f34e88d5c2b4";
diff --git a/examples/ta/proto/src/udp_socket.rs b/examples/ta/proto/src/udp_socket.rs
index 911fdef..d8523dd 100644
--- a/examples/ta/proto/src/udp_socket.rs
+++ b/examples/ta/proto/src/udp_socket.rs
@@ -31,7 +31,4 @@ pub enum IpVersion {
V6 = 2,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = include_str!("../../udp_socket-rs/uuid.txt");
+pub const UUID: &str = "87c2d78e-eb7b-11eb-8d25-df4d5338f285";
diff --git a/examples/ta/random-rs/Cargo.toml b/examples/ta/random-rs/Cargo.toml
index ac081e1..04ebe70 100644
--- a/examples/ta/random-rs/Cargo.toml
+++ b/examples/ta/random-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/random-rs/Makefile b/examples/ta/random-rs/Makefile
index 2286677..b232ac1 100644
--- a/examples/ta/random-rs/Makefile
+++ b/examples/ta/random-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := random-rs-ta
include ../Makefile.include
diff --git a/examples/ta/random-rs/uuid.txt b/examples/ta/random-rs/uuid.txt
deleted file mode 100644
index 39776a0..0000000
--- a/examples/ta/random-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-197c710c-bdab-11eb-8f3f-17a5f698d23b
\ No newline at end of file
diff --git a/examples/ta/secure_db_abstraction-rs/Cargo.toml b/examples/ta/secure_db_abstraction-rs/Cargo.toml
index f82d40b..3948e52 100644
--- a/examples/ta/secure_db_abstraction-rs/Cargo.toml
+++ b/examples/ta/secure_db_abstraction-rs/Cargo.toml
@@ -40,5 +40,3 @@ serde = { workspace = true, features = ["derive"] }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/secure_db_abstraction-rs/Makefile b/examples/ta/secure_db_abstraction-rs/Makefile
index e8a9864..841f752 100644
--- a/examples/ta/secure_db_abstraction-rs/Makefile
+++ b/examples/ta/secure_db_abstraction-rs/Makefile
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := secure_db_abstraction-rs-ta
TARGET ?= aarch64-unknown-optee
include ../Makefile.include
diff --git a/examples/ta/secure_db_abstraction-rs/uuid.txt b/examples/ta/secure_db_abstraction-rs/uuid.txt
deleted file mode 100644
index 8467254..0000000
--- a/examples/ta/secure_db_abstraction-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-e55291e1-521c-4dca-aa24-51e34ab32ad9
\ No newline at end of file
diff --git a/examples/ta/secure_storage-rs/Cargo.toml b/examples/ta/secure_storage-rs/Cargo.toml
index 7339d1a..91aee24 100644
--- a/examples/ta/secure_storage-rs/Cargo.toml
+++ b/examples/ta/secure_storage-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/secure_storage-rs/Makefile b/examples/ta/secure_storage-rs/Makefile
index da906d1..b232ac1 100644
--- a/examples/ta/secure_storage-rs/Makefile
+++ b/examples/ta/secure_storage-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := secure_storage-rs-ta
include ../Makefile.include
diff --git a/examples/ta/secure_storage-rs/uuid.txt b/examples/ta/secure_storage-rs/uuid.txt
deleted file mode 100644
index 6a20bc4..0000000
--- a/examples/ta/secure_storage-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-1cd6d392-bdab-11eb-9082-abc902ac5cd4
\ No newline at end of file
diff --git a/examples/ta/serde-rs/Cargo.toml b/examples/ta/serde-rs/Cargo.toml
index 9ed4aef..7128489 100644
--- a/examples/ta/serde-rs/Cargo.toml
+++ b/examples/ta/serde-rs/Cargo.toml
@@ -38,5 +38,3 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"]
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/serde-rs/Makefile b/examples/ta/serde-rs/Makefile
index 5506d5a..b232ac1 100644
--- a/examples/ta/serde-rs/Makefile
+++ b/examples/ta/serde-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := serde-rs-ta
include ../Makefile.include
diff --git a/examples/ta/serde-rs/uuid.txt b/examples/ta/serde-rs/uuid.txt
deleted file mode 100644
index f4e878a..0000000
--- a/examples/ta/serde-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-1ed47816-bdab-11eb-9ebd-3ffe0648da93
\ No newline at end of file
diff --git a/examples/ta/signature_verification-rs/Cargo.toml b/examples/ta/signature_verification-rs/Cargo.toml
index 523a9a2..02320b1 100644
--- a/examples/ta/signature_verification-rs/Cargo.toml
+++ b/examples/ta/signature_verification-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/signature_verification-rs/Makefile b/examples/ta/signature_verification-rs/Makefile
index e507a30..b232ac1 100644
--- a/examples/ta/signature_verification-rs/Makefile
+++ b/examples/ta/signature_verification-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := signature_verification-rs-ta
include ../Makefile.include
diff --git a/examples/ta/signature_verification-rs/uuid.txt b/examples/ta/signature_verification-rs/uuid.txt
deleted file mode 100644
index 7fc436c..0000000
--- a/examples/ta/signature_verification-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-c7e478c2-89b3-46eb-ac19-571e66c3830d
\ No newline at end of file
diff --git a/examples/ta/supp_plugin-rs/Cargo.toml b/examples/ta/supp_plugin-rs/Cargo.toml
index 9927ce4..40578bb 100644
--- a/examples/ta/supp_plugin-rs/Cargo.toml
+++ b/examples/ta/supp_plugin-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "ta_uuid.txt"
diff --git a/examples/ta/supp_plugin-rs/Makefile b/examples/ta/supp_plugin-rs/Makefile
index 8bbf19d..b232ac1 100644
--- a/examples/ta/supp_plugin-rs/Makefile
+++ b/examples/ta/supp_plugin-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat ta_uuid.txt)
-NAME := supp_plugin-rs-ta
include ../Makefile.include
diff --git a/examples/ta/supp_plugin-rs/ta_uuid.txt b/examples/ta/supp_plugin-rs/ta_uuid.txt
deleted file mode 100644
index 3665046..0000000
--- a/examples/ta/supp_plugin-rs/ta_uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-255fc838-de89-42d3-9a8e-d044c50fa57c
\ No newline at end of file
diff --git a/examples/ta/tcp_client-rs/Cargo.toml b/examples/ta/tcp_client-rs/Cargo.toml
index 9883ed1..266ec7f 100644
--- a/examples/ta/tcp_client-rs/Cargo.toml
+++ b/examples/ta/tcp_client-rs/Cargo.toml
@@ -37,5 +37,3 @@ cfg_block = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/tcp_client-rs/Makefile b/examples/ta/tcp_client-rs/Makefile
index a238563..b232ac1 100644
--- a/examples/ta/tcp_client-rs/Makefile
+++ b/examples/ta/tcp_client-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := tcp_client-rs-ta
include ../Makefile.include
diff --git a/examples/ta/tcp_client-rs/uuid.txt b/examples/ta/tcp_client-rs/uuid.txt
deleted file mode 100644
index 43c8d01..0000000
--- a/examples/ta/tcp_client-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-59db8536-e5e6-11eb-8e9b-a316ce7a6568
\ No newline at end of file
diff --git a/examples/ta/time-rs/Cargo.toml b/examples/ta/time-rs/Cargo.toml
index adbcad8..55239d6 100644
--- a/examples/ta/time-rs/Cargo.toml
+++ b/examples/ta/time-rs/Cargo.toml
@@ -36,5 +36,3 @@ optee-utee = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/time-rs/Makefile b/examples/ta/time-rs/Makefile
index 399a7af..b232ac1 100644
--- a/examples/ta/time-rs/Makefile
+++ b/examples/ta/time-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := time-rs-ta
include ../Makefile.include
diff --git a/examples/ta/time-rs/uuid.txt b/examples/ta/time-rs/uuid.txt
deleted file mode 100644
index 3ca6db5..0000000
--- a/examples/ta/time-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-21b1a1da-bdab-11eb-b614-275a7098826f
\ No newline at end of file
diff --git a/examples/ta/tls_client-rs/Cargo.toml b/examples/ta/tls_client-rs/Cargo.toml
index 1b8be72..217de70 100644
--- a/examples/ta/tls_client-rs/Cargo.toml
+++ b/examples/ta/tls_client-rs/Cargo.toml
@@ -44,5 +44,3 @@ getrandom = { workspace = true, default-features = false, features = ["custom"]
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/tls_client-rs/Makefile b/examples/ta/tls_client-rs/Makefile
index b29515f..841f752 100644
--- a/examples/ta/tls_client-rs/Makefile
+++ b/examples/ta/tls_client-rs/Makefile
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := tls_client-rs-ta
TARGET ?= aarch64-unknown-optee
include ../Makefile.include
diff --git a/examples/ta/tls_client-rs/uuid.txt b/examples/ta/tls_client-rs/uuid.txt
deleted file mode 100644
index ba279ad..0000000
--- a/examples/ta/tls_client-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-ec55bfe2-d9c7-11eb-8b0e-f3f8fad927f7
\ No newline at end of file
diff --git a/examples/ta/tls_server-rs/Cargo.toml b/examples/ta/tls_server-rs/Cargo.toml
index f28e717..c97e246 100644
--- a/examples/ta/tls_server-rs/Cargo.toml
+++ b/examples/ta/tls_server-rs/Cargo.toml
@@ -44,5 +44,3 @@ getrandom = { workspace = true, default-features = false, features = ["custom"]
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/tls_server-rs/Makefile b/examples/ta/tls_server-rs/Makefile
index 8b11f60..841f752 100644
--- a/examples/ta/tls_server-rs/Makefile
+++ b/examples/ta/tls_server-rs/Makefile
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := tls_server-rs-ta
TARGET ?= aarch64-unknown-optee
include ../Makefile.include
diff --git a/examples/ta/tls_server-rs/uuid.txt b/examples/ta/tls_server-rs/uuid.txt
deleted file mode 100644
index 53f20f0..0000000
--- a/examples/ta/tls_server-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-69547de6-f47e-11eb-994e-f34e88d5c2b4
\ No newline at end of file
diff --git a/examples/ta/udp_socket-rs/Cargo.toml b/examples/ta/udp_socket-rs/Cargo.toml
index 2d3a282..dee6546 100644
--- a/examples/ta/udp_socket-rs/Cargo.toml
+++ b/examples/ta/udp_socket-rs/Cargo.toml
@@ -37,5 +37,3 @@ cfg_block = { workspace = true }
proto = { workspace = true }
optee-utee-build = { workspace = true }
-[package.metadata.optee.ta]
-uuid-path = "uuid.txt"
diff --git a/examples/ta/udp_socket-rs/Makefile b/examples/ta/udp_socket-rs/Makefile
index ac05ae9..b232ac1 100644
--- a/examples/ta/udp_socket-rs/Makefile
+++ b/examples/ta/udp_socket-rs/Makefile
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-UUID ?= $(shell cat uuid.txt)
-NAME := udp_socket-rs-ta
include ../Makefile.include
diff --git a/examples/ta/udp_socket-rs/uuid.txt b/examples/ta/udp_socket-rs/uuid.txt
deleted file mode 100644
index b6c1c19..0000000
--- a/examples/ta/udp_socket-rs/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-87c2d78e-eb7b-11eb-8d25-df4d5338f285
\ No newline at end of file
diff --git a/projects/web3/eth_wallet/Makefile b/projects/web3/eth_wallet/Makefile
index e3fa437..eb84857 100644
--- a/projects/web3/eth_wallet/Makefile
+++ b/projects/web3/eth_wallet/Makefile
@@ -15,14 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-# If _HOST or _TA specific compiler/target are not specified, then use common
-# compiler/target for both
-CROSS_COMPILE_HOST ?= aarch64-linux-gnu-
-CROSS_COMPILE_TA ?= aarch64-linux-gnu-
-TARGET_HOST ?= aarch64-unknown-linux-gnu
-TARGET_TA ?= aarch64-unknown-linux-gnu
-FEATURES ?=
-CARGO_FLAGS ?=
+TARGET ?= aarch64-unknown-linux-gnu
+TARGET_HOST ?= $(TARGET)
+TARGET_TA ?= $(TARGET)
.PHONY: host ta all clean
@@ -30,14 +25,13 @@ all: host ta
host:
$(q)make -C host TARGET=$(TARGET_HOST) \
- CROSS_COMPILE=$(CROSS_COMPILE_HOST)
+ $(if $(CROSS_COMPILE_HOST),CROSS_COMPILE=$(CROSS_COMPILE_HOST))
ta:
$(q)make -C ta TARGET=$(TARGET_TA) \
- CROSS_COMPILE=$(CROSS_COMPILE_TA) \
- FEATURES="$(FEATURES)" \
- CARGO_FLAGS="$(CARGO_FLAGS)"
+ $(if $(CROSS_COMPILE_TA),CROSS_COMPILE=$(CROSS_COMPILE_TA)) \
+ $(if $(TA_SIGN_KEY),TA_SIGN_KEY="$(TA_SIGN_KEY)")
clean:
$(q)make -C host clean
- $(q)make -C ta clean
\ No newline at end of file
+ $(q)make -C ta clean
diff --git a/projects/web3/eth_wallet/host/Makefile b/projects/web3/eth_wallet/host/Makefile
index 3faa2dd..54097e1 100644
--- a/projects/web3/eth_wallet/host/Makefile
+++ b/projects/web3/eth_wallet/host/Makefile
@@ -15,21 +15,32 @@
# specific language governing permissions and limitations
# under the License.
-NAME := eth_wallet-rs
+TARGET ?= $(or $(TARGET_HOST),aarch64-unknown-linux-gnu)
+ifneq ($(filter arm-unknown-%,$(TARGET)),)
+OPTEE_ARCH := --arch arm
+else
+OPTEE_ARCH := --arch aarch64
+endif
+ifneq ($(CROSS_COMPILE_HOST),)
+CROSS_COMPILE := $(CROSS_COMPILE_HOST)
+endif
+ifneq ($(CROSS_COMPILE),)
+export CROSS_COMPILE
+endif
+SDK_ROOT := $(abspath $(CURDIR)/../../../..)
+CARGO_OPTEE ?= cargo run --manifest-path $(SDK_ROOT)/tools/Cargo.toml -q -p cargo-optee --
-TARGET ?= aarch64-unknown-linux-gnu
-CROSS_COMPILE ?= aarch64-linux-gnu-
-OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
+.PHONY: all clippy host strip clean
-OUT_DIR := $(CURDIR)/target/$(TARGET)/release
-all: host strip
+all: host
-host:
- @cargo build --target $(TARGET_HOST) --release --config $(LINKER_CFG)
+clippy:
+ @$(CARGO_OPTEE) clippy ca $(OPTEE_ARCH)
+
+host: clippy
+ @$(CARGO_OPTEE) build ca $(OPTEE_ARCH)
strip: host
- @$(OBJCOPY) --strip-unneeded $(OUT_DIR)/$(NAME) $(OUT_DIR)/$(NAME)
clean:
- @cargo clean
\ No newline at end of file
+ @cargo clean
diff --git a/projects/web3/eth_wallet/proto/src/lib.rs b/projects/web3/eth_wallet/proto/src/lib.rs
index 88393c1..a77d3c9 100644
--- a/projects/web3/eth_wallet/proto/src/lib.rs
+++ b/projects/web3/eth_wallet/proto/src/lib.rs
@@ -32,7 +32,4 @@ pub enum Command {
Unknown,
}
-// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
-// newline in your uuid.txt file. You can remove it by running
-// `truncate -s 36 uuid.txt`.
-pub const UUID: &str = &include_str!("../../uuid.txt");
+pub const UUID: &str = "be2dc9a0-02b4-4b33-ba21-9964dbdf1573";
diff --git a/projects/web3/eth_wallet/ta/Makefile b/projects/web3/eth_wallet/ta/Makefile
index 5cda70e..f83b1e5 100644
--- a/projects/web3/eth_wallet/ta/Makefile
+++ b/projects/web3/eth_wallet/ta/Makefile
@@ -17,39 +17,37 @@
# STD-ONLY example
-UUID ?= $(shell cat "../uuid.txt")
-
-TARGET ?= aarch64-unknown-optee
-CROSS_COMPILE ?= aarch64-linux-gnu-
-OBJCOPY := $(CROSS_COMPILE_TA)objcopy
-# Configure the linker to use GCC, which works on both cross-compilation and ARM machines
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
-
-# fix for the error: "unwinding panics are not supported without std" reported by clippy
-# Set panic=abort for std and no-std
-RUSTFLAGS := -C panic=abort -Z unstable-options
-# CARGO_FLAGS is set by sourcing environment (e.g. -Z build-std=std,panic_abort for std builds)
-CARGO_FLAGS ?=
-
-TA_SIGN_KEY ?= $(TA_DEV_KIT_DIR)/keys/default_ta.pem
-SIGN := $(TA_DEV_KIT_DIR)/scripts/sign_encrypt.py
-OUT_DIR := $(CURDIR)/target/$(TARGET_TA)/release
-
-all: clippy ta strip sign
+TARGET ?= $(or $(TARGET_TA),aarch64-unknown-linux-gnu)
+ifneq ($(filter arm-unknown-%,$(TARGET)),)
+OPTEE_ARCH := --arch arm
+else
+OPTEE_ARCH := --arch aarch64
+endif
+ifneq ($(CROSS_COMPILE_TA),)
+CROSS_COMPILE := $(CROSS_COMPILE_TA)
+endif
+ifneq ($(CROSS_COMPILE),)
+export CROSS_COMPILE
+endif
+ifneq ($(TA_SIGN_KEY),)
+OPTEE_SIGNING_KEY := --signing-key "$(TA_SIGN_KEY)"
+endif
+SDK_ROOT := $(abspath $(CURDIR)/../../../..)
+CARGO_OPTEE ?= cargo run --manifest-path $(SDK_ROOT)/tools/Cargo.toml -q -p cargo-optee --
+
+.PHONY: all clippy ta strip sign clean
+
+all: ta
clippy:
- @cargo fmt
- @RUSTFLAGS="$(RUSTFLAGS)" cargo clippy $(CARGO_FLAGS) --target $(TARGET) -- -D warnings
+ @$(CARGO_OPTEE) clippy ta $(OPTEE_ARCH) --std
ta: clippy
- @RUSTFLAGS="$(RUSTFLAGS)" cargo build $(CARGO_FLAGS) --target $(TARGET) --release --config $(LINKER_CFG)
+ @$(CARGO_OPTEE) build ta $(OPTEE_ARCH) --std $(OPTEE_SIGNING_KEY)
strip: ta
- @$(OBJCOPY) --strip-unneeded $(OUT_DIR)/ta $(OUT_DIR)/stripped_ta
sign: strip
- @$(SIGN) --uuid $(UUID) --key $(TA_SIGN_KEY) --in $(OUT_DIR)/stripped_ta --out $(OUT_DIR)/$(UUID).ta
- @echo "SIGN => ${UUID}"
clean:
@cargo clean
diff --git a/projects/web3/eth_wallet/uuid.txt b/projects/web3/eth_wallet/uuid.txt
deleted file mode 100644
index d0d0843..0000000
--- a/projects/web3/eth_wallet/uuid.txt
+++ /dev/null
@@ -1 +0,0 @@
-be2dc9a0-02b4-4b33-ba21-9964dbdf1573
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org