This is an automated email from the ASF dual-hosted git repository.

yuanz pushed a commit to branch no-std
in repository 
https://gitbox.apache.org/repos/asf/incubator-teaclave-trustzone-sdk.git


The following commit(s) were added to refs/heads/no-std by this push:
     new 689a239  Polish setup process
689a239 is described below

commit 689a2392416ceecc980b592e48cd4aee5049a9c2
Author: Yuan Zhuang <[email protected]>
AuthorDate: Fri May 10 08:44:29 2024 +0000

    Polish setup process
    
    - Add `build_optee_libraries.sh`, `environment` for quick setup on
    QEMUv8;
    - Simplify ci.yml;
    - Update README.
    
    Signed-off-by: Yuan Zhuang <[email protected]>
    Reviewed-by: Sumit Garg <[email protected]>
---
 .github/workflows/ci.yml             | 50 +++++++++++------------------
 README.md                            | 44 +++++++++++++------------
 setup.sh => build_optee_libraries.sh | 40 ++++++++++++-----------
 environment                          | 62 ++++++++++++++++++++++++++++++++++++
 setup.sh                             |  9 +++++-
 5 files changed, 134 insertions(+), 71 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index de5a936..5880518 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 17cd7ee..1e2de80 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/setup.sh b/build_optee_libraries.sh
similarity index 53%
copy from setup.sh
copy to build_optee_libraries.sh
index 7e439d1..f88a846 100755
--- a/setup.sh
+++ b/build_optee_libraries.sh
@@ -17,24 +17,26 @@
 # specific language governing permissions and limitations
 # under the License.
 
-set -xe
-
-##########################################
-# move to project root
-cd "$(dirname "$0")"
-
-##########################################
-# install rustup and stable Rust if needed
-if command -v rustup &>/dev/null ; then
-       rustup install stable
-else
-       curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
-       source "$HOME/.cargo/env"
+set -e
+
+OPTEE_VERSION=4.2.0
+
+TARGET_PATH=$1
+
+# check arguments
+if [ -z "$TARGET_PATH" ]; then
+    echo "Usage: $0 <path_for_storage>"
+    exit 1
 fi
 
-# Ensure the toolchain, components, and targets we've specified in
-# rust-toolchain.toml are ready to go. Since that file sets rustup's default
-# toolchain for the entire directory, all we need to do is run any
-# rustup-wrapped command to trigger installation. We've arbitrarily chosen
-# "cargo --version" since it has no other effect.
-cargo --version >/dev/null
+# 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 0000000..9c1396a
--- /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 7e439d1..d12b817 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to