Skip to content

Commit

Permalink
Polish setup process
Browse files Browse the repository at this point in the history
- Add `build_optee_libraries.sh`, `environment` for quick setup on
QEMUv8;
- Simplify ci.yml;
- Update README.

Signed-off-by: Yuan Zhuang <yuanz@apache.org>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
  • Loading branch information
DemesneGH committed May 13, 2024
1 parent 8265917 commit 16783cf
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 52 deletions.
50 changes: 19 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -68,34 +62,28 @@ 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
export TARGET_HOST="aarch64-unknown-linux-gnu"
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
Expand All @@ -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
Expand Down
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
42 changes: 42 additions & 0 deletions build_optee_libraries.sh
Original file line number Diff line number Diff line change
@@ -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 <path_for_storage>"
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)
62 changes: 62 additions & 0 deletions environment
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

0 comments on commit 16783cf

Please sign in to comment.