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

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


The following commit(s) were added to refs/heads/main by this push:
     new d78853b  build-env: introduce build config with management
d78853b is described below

commit d78853be32c6271d8040888e859a9ed4c8e6cf55
Author: Zhaofeng Chen <[email protected]>
AuthorDate: Tue Jul 8 04:08:09 2025 +0000

    build-env: introduce build config with management
    
    Signed-off-by: Zhaofeng Chen <[email protected]>
---
 Dockerfile.dev                           |   1 +
 scripts/runtime/bin/switch_config        | 132 +++++++++++++++++++++++++++++++
 scripts/runtime/bin/sync_to_emulator     |   0
 scripts/runtime/config/host/aarch64      |  20 +++++
 scripts/runtime/config/host/arm32        |  20 +++++
 scripts/runtime/config/ta/no-std/aarch64 |  20 +++++
 scripts/runtime/config/ta/no-std/arm32   |  20 +++++
 scripts/runtime/config/ta/std/aarch64    |  20 +++++
 scripts/runtime/config/ta/std/arm32      |  20 +++++
 scripts/runtime/environment              | 128 ++++++++++++------------------
 10 files changed, 305 insertions(+), 76 deletions(-)

diff --git a/Dockerfile.dev b/Dockerfile.dev
index d7e45ff..400ea02 100644
--- a/Dockerfile.dev
+++ b/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
 COPY scripts/runtime/environment ${TEACLAVE_TOOLCHAIN_BASE}/environment
 
 RUN chmod +x ${TEACLAVE_TOOLCHAIN_BASE}/bin/* 
diff --git a/scripts/runtime/bin/switch_config 
b/scripts/runtime/bin/switch_config
new file mode 100755
index 0000000..9ccde1f
--- /dev/null
+++ b/scripts/runtime/bin/switch_config
@@ -0,0 +1,132 @@
+#!/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.
+
+# Switch active configurations
+
+SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")/../config"
+
+# Function to show usage
+show_usage() {
+    echo "Usage: $0 [OPTIONS]"
+    echo ""
+    echo "Options:"
+    echo "  --ta <config>     Switch TA configuration only"
+    echo "  --host <config>   Switch Host configuration only"
+    echo "  --status          Show current active configuration"
+    echo "  --list            List all available configurations"
+    echo "  --help            Show this help message"
+    echo ""
+    echo "Examples:"
+    echo "  $0 --ta std/aarch64           # Switch TA only"
+    echo "  $0 --host aarch64             # Switch Host only"
+    echo "  $0 --status                   # Show current status"
+    echo "  $0 --list                     # List available configs"
+}
+
+# Function to show current status
+show_status() {
+    echo "=== Current Active Configuration ==="
+    echo "TA:   $(readlink "$SCRIPT_DIR/ta/active" 2>/dev/null || echo "NOT 
SET")"
+    echo "Host: $(readlink "$SCRIPT_DIR/host/active" 2>/dev/null || echo "NOT 
SET")"
+}
+
+# Function to get available configs for a directory
+get_available_configs() {
+    local config_dir="$1"
+    find "$config_dir" -type f ! -name "active" | sed "s|$config_dir/||" | sort
+}
+
+# Function to list available configurations
+list_configs() {
+    echo "Available TA configurations:"
+    get_available_configs "$SCRIPT_DIR/ta"
+    echo ""
+    echo "Available Host configurations:"
+    get_available_configs "$SCRIPT_DIR/host"
+}
+
+# Function to check if config exists
+check_existence() {
+    local config_path="$1"
+    [ -n "$config_path" ] && [ -f "$SCRIPT_DIR/$config_path" ]
+}
+
+# Function to switch config
+switch_config() {
+    local config_type="$1"
+    local config_name="$2"
+    echo "Switching $config_type to: $config_name"
+    (cd "$SCRIPT_DIR/$config_type" && ln -sf "$config_name" active)
+}
+
+# Function to show config error
+show_config_error() {
+    local config_type="$1"
+    local config_name="$2"
+    if [ -z "$config_name" ]; then
+        echo "Error: --$config_type requires a configuration argument" >&2
+    else
+        echo "Error: $config_type config '$config_name' not found" >&2
+    fi
+    echo "Run '$0 --list' to see available configurations" >&2
+    exit 1
+}
+
+# Parse command line arguments
+case "$1" in
+    --ta)
+        if check_existence "ta/$2"; then
+            switch_config "ta" "$2"
+            echo ""
+            show_status
+        else
+            show_config_error "ta" "$2"
+        fi
+        ;;
+    --host)
+        if check_existence "host/$2"; then
+            switch_config "host" "$2"
+            echo ""
+            show_status
+        else
+            show_config_error "host" "$2"
+        fi
+        ;;
+    --status)
+        show_status
+        ;;
+    --list)
+        list_configs
+        ;;
+    --help|-h)
+        show_usage
+        ;;
+    "")
+        echo "Error: No option specified" >&2
+        echo "" >&2
+        show_usage >&2
+        exit 1
+        ;;
+    *)
+        echo "Error: Unknown option '$1'" >&2
+        echo "" >&2
+        show_usage >&2
+        exit 1
+        ;;
+esac
diff --git a/scripts/runtime/bin/sync_to_emulator 
b/scripts/runtime/bin/sync_to_emulator
old mode 100644
new mode 100755
diff --git a/scripts/runtime/config/host/aarch64 
b/scripts/runtime/config/host/aarch64
new file mode 100644
index 0000000..e94789b
--- /dev/null
+++ b/scripts/runtime/config/host/aarch64
@@ -0,0 +1,20 @@
+# 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 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
new file mode 100644
index 0000000..9462f03
--- /dev/null
+++ b/scripts/runtime/config/host/arm32
@@ -0,0 +1,20 @@
+# 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 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
new file mode 100644
index 0000000..26223f6
--- /dev/null
+++ b/scripts/runtime/config/ta/no-std/aarch64
@@ -0,0 +1,20 @@
+# 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 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-"
diff --git a/scripts/runtime/config/ta/no-std/arm32 
b/scripts/runtime/config/ta/no-std/arm32
new file mode 100644
index 0000000..3fbf564
--- /dev/null
+++ b/scripts/runtime/config/ta/no-std/arm32
@@ -0,0 +1,20 @@
+# 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 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-"
diff --git a/scripts/runtime/config/ta/std/aarch64 
b/scripts/runtime/config/ta/std/aarch64
new file mode 100644
index 0000000..7b3ec04
--- /dev/null
+++ b/scripts/runtime/config/ta/std/aarch64
@@ -0,0 +1,20 @@
+# 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 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-"
diff --git a/scripts/runtime/config/ta/std/arm32 
b/scripts/runtime/config/ta/std/arm32
new file mode 100644
index 0000000..2dd2ead
--- /dev/null
+++ b/scripts/runtime/config/ta/std/arm32
@@ -0,0 +1,20 @@
+# 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 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-"
diff --git a/scripts/runtime/environment b/scripts/runtime/environment
old mode 100644
new mode 100755
index 9a6e68e..33633af
--- a/scripts/runtime/environment
+++ b/scripts/runtime/environment
@@ -1,3 +1,5 @@
+#!/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
@@ -15,17 +17,16 @@
 # 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}"
@@ -33,81 +34,37 @@
 : "${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
+    echo "No active Host configuration found, setting default to aarch64"
+    (cd "$SCRIPT_DIR/host" && ln -sf "aarch64" active)
 fi
 
-if [ "$ARCH_HOST" = "arm" ]
-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"
-fi
+# Load active TA configuration
+source "$SCRIPT_DIR/ta/active"
 
-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
+# Load active Host configuration  
+source "$SCRIPT_DIR/host/active"
+
+# 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
+    exit 1
 fi
 
-echo "[env] Configured Successfully for building OP-TEE applications."
+if [ ! -d "$OPTEE_CLIENT_EXPORT" ]; then
+    echo "Error: OPTEE_CLIENT_EXPORT=$OPTEE_CLIENT_EXPORT does not exist" >&2
+    exit 1
+fi
 
+# Setup QEMU shared directory
+export QEMU_HOST_SHARE_DIR="${TEACLAVE_TOOLCHAIN_BASE}/shared"
 
-export QEMU_HOST_SHARE_DIR=${TEACLAVE_TOOLCHAIN_BASE}/shared
-# Create QEMU shared dir if it does not exist, it used for sharing CA and TA 
between host and QEMU emulator.
 if [ -d "$QEMU_HOST_SHARE_DIR" ]; then
     echo "QEMU shared directory already exists: $QEMU_HOST_SHARE_DIR"
 else
@@ -115,4 +72,23 @@ else
     mkdir -p "$QEMU_HOST_SHARE_DIR/host"
     mkdir -p "$QEMU_HOST_SHARE_DIR/ta"
     mkdir -p "$QEMU_HOST_SHARE_DIR/plugin"
-fi
\ No newline at end of file
+fi
+
+# Show configuration summary
+echo "=== OP-TEE Environment Configuration ==="
+echo "TA:   $(readlink "$SCRIPT_DIR/ta/active")"
+echo "Host: $(readlink "$SCRIPT_DIR/host/active")"
+echo ""
+echo "TA Configuration:"
+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"
+echo ""
+echo "[env] Configured Successfully for building OP-TEE applications."


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

Reply via email to