Copilot commented on code in PR #206:
URL:
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#discussion_r2192208817
##########
scripts/runtime/environment:
##########
@@ -15,104 +17,78 @@
# specific language governing permissions and limitations
# under the License.
-# This script is written into .bashrc to set up toolchains when enter the
docker, like:
-# docker run -it \
-# -e TA_ARCH=aarch64 \
-# -e CA_ARCH=arm \
-# -e STD=y \
-# teaclave-dev bash
+# =============================================================================
+# config/environment (Main configuration - loads active configs)
+# =============================================================================
+
+# Get config script directory
+SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")/config"
-#export RUST_STD_DIR=${TEACLAVE_TOOLCHAIN_BASE}/rust
-#export RUST_TARGET_PATH=${TEACLAVE_TOOLCHAIN_BASE}/scripts/std
+echo "Loading OP-TEE environment configuration..."
-# validate environment variables
+# Validate required environment variables
: "${TEACLAVE_TOOLCHAIN_BASE:?TEACLAVE_TOOLCHAIN_BASE must be set - directory
where Teaclave toolchain is installed}"
: "${OPTEE_DIR:?OPTEE_DIR must be set - directory where OPTEE will be built}"
: "${OPTEE_OS_DIR:?OPTEE_OS_DIR must be set - directory where OPTEE OS will be
built}"
: "${OPTEE_CLIENT_DIR:?OPTEE_CLIENT_DIR must be set - directory where OPTEE
Client will be built}"
: "${IMG_DIRECTORY:?IMG_DIRECTORY must be set - directory where images will be
stored}"
: "${IMG_NAME:?IMG_NAME must be set - name of the image to download}"
-# Default ARCH_TA, ARCH_HOST, STD combination
-export ARCH_TA="${ARCH_TA:-aarch64}"
-export ARCH_HOST="${ARCH_HOST:-aarch64}"
-
-export CROSS_COMPILE32="${CROSS_COMPILE32:-arm-linux-gnueabihf-}"
-export CROSS_COMPILE64="${CROSS_COMPILE64:-aarch64-linux-gnu-}"
-
-if [ "$ARCH_TA" = "arm" ]
-then
- # build TA as 32-bit
- export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
- if [ "$STD" ]
- then
- export TARGET_TA="arm-unknown-optee"
- echo "set TARGET_TA=$TARGET_TA (std)"
- else
- export TARGET_TA="arm-unknown-linux-gnueabihf"
- echo "set TARGET_TA=$TARGET_TA (no-std)"
- 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"
- echo "set TARGET_TA=$TARGET_TA (std)"
- else
- export TARGET_TA="aarch64-unknown-linux-gnu"
- echo "set TARGET_TA=$TARGET_TA (no-std)"
- fi
- export CROSS_COMPILE_TA="$CROSS_COMPILE64"
- echo "set CROSS_COMPILE_TA=$CROSS_COMPILE_TA"
+# Check if active configurations exist, set defaults if not
+if [ ! -f "$SCRIPT_DIR/ta/active" ]; then
+ echo "No active TA configuration found, setting default to no-std/aarch64"
+ (cd "$SCRIPT_DIR/ta" && ln -sf "no-std/aarch64" active)
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
+if [ ! -f "$SCRIPT_DIR/host/active" ]; then
Review Comment:
Use `-L` instead of `-f` to check for the presence of the `active` symlink
itself; that way broken links will also trigger recreation of the default
config.
##########
scripts/runtime/environment:
##########
@@ -1,3 +1,5 @@
+#!/bin/bash
Review Comment:
Add `set -euo pipefail` immediately after the shebang to ensure the script
exits on unhandled errors, unset variables, and pipe failures.
##########
Dockerfile.dev:
##########
@@ -33,6 +33,7 @@ RUN . ./environment && ./build_optee_libraries.sh
# Set up shell environment and link useful scripts
COPY scripts/runtime/bin ${TEACLAVE_TOOLCHAIN_BASE}/bin
+COPY scripts/runtime/config ${TEACLAVE_TOOLCHAIN_BASE}/config
Review Comment:
The new `switch_config` script isn't included in the image; consider adding
a `COPY` for `scripts/runtime/switch_config` (or its location) into
`${TEACLAVE_TOOLCHAIN_BASE}/bin` so it’s available inside the container.
```suggestion
COPY scripts/runtime/config ${TEACLAVE_TOOLCHAIN_BASE}/config
COPY scripts/runtime/switch_config
${TEACLAVE_TOOLCHAIN_BASE}/bin/switch_config
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]