From 27dc8c8ef4072418f38becba0b9f9955739bf297 Mon Sep 17 00:00:00 2001 From: Yuan Zhuang Date: Fri, 10 May 2024 08:44:29 +0000 Subject: [PATCH] Polish setup process - Add `build_optee_libraries.sh`, `environment` for quick setup on QEMUv8; - Simplify ci.yml; - Update README. Signed-off-by: Yuan Zhuang --- .github/workflows/ci.yml | 50 ++++++++++++-------------------- README.md | 44 +++++++++++++++------------- build_optee_libraries.sh | 42 +++++++++++++++++++++++++++ environment | 62 ++++++++++++++++++++++++++++++++++++++++ setup.sh | 9 +++++- 5 files changed, 155 insertions(+), 52 deletions(-) create mode 100755 build_optee_libraries.sh create mode 100644 environment diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de5a9365..58805184 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,23 +35,17 @@ jobs: ln -sf /root/.cargo ~/.cargo - name: Building run: | - export CARGO_NET_GIT_FETCH_WITH_CLI=true - apt update && apt -y install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf - export CROSS_COMPILE="aarch64-linux-gnu-" - export CROSS_COMPILE32="arm-linux-gnueabihf-" - export CROSS_COMPILE64="aarch64-linux-gnu-" - + # Setup Rust and toolchains + ./setup.sh + # Build optee_os and optee_client for qemu_v8 - git clone https://github.com/OP-TEE/optee_os.git -b 4.0.0 ~/optee_os - git clone https://github.com/OP-TEE/optee_client.git -b 4.0.0 ~/optee_client - (cd ~/optee_os && make PLATFORM=vexpress-qemu_armv8a) - (cd ~/optee_client && make WITH_TEEACL=0) + ./build_optee_libraries.sh $HOME - # Build rust optee-utee and optee-teec - ./setup.sh - . ~/.cargo/env - export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm64/ - export OPTEE_CLIENT_EXPORT=~/optee_client/out/export/ + # Setup environment + export OPTEE_DIR=$HOME + source environment + + # Build Rust optee-utee and optee-teec (cd optee-utee && cargo build --target aarch64-unknown-linux-gnu --no-default-features -vv) (cd optee-teec && cargo build --target aarch64-unknown-linux-gnu -vv) @@ -68,26 +62,20 @@ jobs: ln -sf /root/.cargo ~/.cargo - name: Building run: | - export CARGO_NET_GIT_FETCH_WITH_CLI=true - apt update && apt -y install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf - export CROSS_COMPILE="aarch64-linux-gnu-" - export CROSS_COMPILE32="arm-linux-gnueabihf-" - export CROSS_COMPILE64="aarch64-linux-gnu-" - export OPTEE_CLIENT_EXPORT=~/optee_client/out/export/ + # Setup Rust and toolchains ./setup.sh - . ~/.cargo/env # Build optee_os and optee_client for qemu_v8 - git clone https://github.com/OP-TEE/optee_os.git -b 4.0.0 ~/optee_os - git clone https://github.com/OP-TEE/optee_client.git -b 4.0.0 ~/optee_client - (cd ~/optee_os && make PLATFORM=vexpress-qemu_armv8a) - (cd ~/optee_client && make WITH_TEEACL=0) + ./build_optee_libraries.sh $HOME - # Build OP-TEE rust examples for Arm 64-bit both host and TA - export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm64/ + # Setup environment + export OPTEE_DIR=$HOME + source environment + + # Build OP-TEE Rust examples for Arm 64-bit both host and TA make -j`nproc` - # Build OP-TEE rust examples for Arm 64-bit host and 32-bit TA + # Build OP-TEE Rust examples for Arm 64-bit host and 32-bit TA export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm32/ export CROSS_COMPILE_HOST=$CROSS_COMPILE64 export CROSS_COMPILE_TA=$CROSS_COMPILE32 @@ -95,7 +83,7 @@ jobs: export TARGET_TA="arm-unknown-linux-gnueabihf" make clean && make -j`nproc` - # Build OP-TEE rust examples for Arm 32-bit both host and TA + # Build OP-TEE Rust examples for Arm 32-bit both host and TA export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm32/ export CROSS_COMPILE_HOST=$CROSS_COMPILE32 export CROSS_COMPILE_TA=$CROSS_COMPILE32 @@ -104,7 +92,7 @@ jobs: (cd ~/optee_client && make clean && make CROSS_COMPILE=$CROSS_COMPILE32 WITH_TEEACL=0) make clean && make -j`nproc` - # Build OP-TEE rust examples for Arm 32-bit host and 64-bit TA + # Build OP-TEE Rust examples for Arm 32-bit host and 64-bit TA export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm64/ export CROSS_COMPILE_HOST=$CROSS_COMPILE32 export CROSS_COMPILE_TA=$CROSS_COMPILE64 diff --git a/README.md b/README.md index 17cd7ee8..1e2de802 100644 --- a/README.md +++ b/README.md @@ -154,29 +154,25 @@ cd incubator-teaclave-trustzone-sdk To build the project, the Rust environment and several related submodules are required. -1. By default, the `OPTEE_DIR` is `incubator-teaclave-trustzone-sdk/optee/`. - OP-TEE submodules (`optee_os`, `optee_client` and `build`) will be initialized -automatically in `setup.sh`. - -If you are building within QEMUv8 or already have the [OP-TEE -repository](https://github.com/OP-TEE) cloned somewhere, you can set the OP-TEE -root directory with: +1. Run the script as follows to install the Rust environment and toolchains: ```sh -export OPTEE_DIR=[YOUR_OPTEE_DIR] +./setup.sh ``` -Note: your OPTEE root directory should have `build/`, `optee_os/` and -`optee_client/` as sub-directory. +2. Build OP-TEE libraries -2. Run the script as follows to install the Rust environment and initialize - submodules: +- for QEMUv8: -```sh -./setup.sh +By default, the `OPTEE_DIR` is `incubator-teaclave-trustzone-sdk/optee/`. + OP-TEE submodules (`optee_os` and `optee_client`) will be initialized +automatically by executing: + +``` +./build_optee_libraries.sh optee/ ``` -3. Before building examples, the environment should be properly set up with: +Then the environment should be properly set up before building applications: ``` sh source environment @@ -190,14 +186,22 @@ export ARCH=arm source environment ``` -4. Before building rust examples and applications, you need to build OP-TEE - libraries using: +- for other platforms: -``` sh -make optee +You should set these environment variables for building, e.g: + +``` +export CROSS_COMPILE_HOST="aarch64-linux-gnu-" +export CROSS_COMPILE_TA="arm-linux-gnueabihf-" + +export TARGET_HOST="aarch64-unknown-linux-gnu" +export TARGET_TA="arm-unknown-linux-gnueabihf" + +export TA_DEV_KIT_DIR=~/optee_os/out/arm-plat-vexpress/export-ta_arm32/ +export OPTEE_CLIENT_EXPORT=~/optee_client/out/export/ ``` -5. Run this command to build all Rust examples: +3. Run this command to build all Rust examples: ``` sh make examples diff --git a/build_optee_libraries.sh b/build_optee_libraries.sh new file mode 100755 index 00000000..f88a8466 --- /dev/null +++ b/build_optee_libraries.sh @@ -0,0 +1,42 @@ +#!/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 + +OPTEE_VERSION=4.2.0 + +TARGET_PATH=$1 + +# check arguments +if [ -z "$TARGET_PATH" ]; then + echo "Usage: $0 " + exit 1 +fi + +# set toolchain +export CROSS_COMPILE="aarch64-linux-gnu-" +export CROSS_COMPILE32="arm-linux-gnueabihf-" +export CROSS_COMPILE64="aarch64-linux-gnu-" + +# build optee_os and optee_client for qemu_v8 +git clone https://github.com/OP-TEE/optee_os.git -b $OPTEE_VERSION $TARGET_PATH/optee_os +(cd $TARGET_PATH/optee_os && make PLATFORM=vexpress-qemu_armv8a) + +git clone https://github.com/OP-TEE/optee_client.git -b $OPTEE_VERSION $TARGET_PATH/optee_client +(cd $TARGET_PATH/optee_client && make WITH_TEEACL=0) diff --git a/environment b/environment new file mode 100644 index 00000000..9c1396af --- /dev/null +++ b/environment @@ -0,0 +1,62 @@ +# 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. + +export PATH=$PATH:$HOME/.cargo/bin + +if [ -z "$OPTEE_DIR" ] +then + echo -e "OPTEE_DIR has not set, use $PWD/optee/ as default\n" + export OPTEE_DIR=$PWD/optee +fi + +export OPTEE_OS_DIR="$OPTEE_DIR/optee_os" +export OPTEE_CLIENT_DIR="$OPTEE_DIR/optee_client" + +export CROSS_COMPILE="aarch64-linux-gnu-" +export CROSS_COMPILE32="arm-linux-gnueabihf-" +export CROSS_COMPILE64="aarch64-linux-gnu-" + +if [ "$ARCH" = "arm" ] +then + # build host and TA as 32-bit + export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32" + export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/out/export" + export TARGET="arm-unknown-linux-gnueabihf" +else + # build host and TA as 64-bit by default + unset ARCH + export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64" + export OPTEE_CLIENT_EXPORT="$OPTEE_CLIENT_DIR/out/export" + export TARGET="aarch64-unknown-linux-gnu" +fi + +# check if libraries exist +if [ -d "$TA_DEV_KIT_DIR" ] +then + echo "set TA_DEV_KIT_DIR=$TA_DEV_KIT_DIR" +else + echo -e "Error: TA_DEV_KIT_DIR=$TA_DEV_KIT_DIR does not exist, please set the correct TA_DEV_KIT_DIR or run \"$ ./build_optee_libraries.sh optee/\" then try again\n" + unset OPTEE_DIR +fi + +if [ -d "$OPTEE_CLIENT_EXPORT" ] +then + echo "set OPTEE_CLIENT_EXPORT=$OPTEE_CLIENT_EXPORT" +else + echo -e "Error: OPTEE_CLIENT_EXPORT=$OPTEE_CLIENT_EXPORT does not exist, please set the correct OPTEE_CLIENT_EXPORT or run \"$ ./build_optee_libraries.sh optee/\" then try again\n" + unset OPTEE_DIR +fi \ No newline at end of file diff --git a/setup.sh b/setup.sh index 7e439d1f..d12b817b 100755 --- a/setup.sh +++ b/setup.sh @@ -24,9 +24,12 @@ set -xe cd "$(dirname "$0")" ########################################## +export CARGO_NET_GIT_FETCH_WITH_CLI=true + # install rustup and stable Rust if needed if command -v rustup &>/dev/null ; then - rustup install stable + # uninstall to avoid file corruption + rustup uninstall stable && rustup install stable else curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source "$HOME/.cargo/env" @@ -38,3 +41,7 @@ fi # rustup-wrapped command to trigger installation. We've arbitrarily chosen # "cargo --version" since it has no other effect. cargo --version >/dev/null + +########################################## +# install toolchain +apt update && apt -y install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf