Add Rust examples
Add OPTEE_RUST_ENABLE option to common.mk and define buildroot packages
for OP-TEE Rust examples
Build Rust examples in optee_rust/examples:
$ cd build && make OPTEE_RUST_ENABLE=y CFG_TEE_RAM_VA_SIZE=0x00300000
Signed-off-by: Rong Fan <fanrong03@baidu.com>
Signed-off-by: Yuan Zhuang <zhuangyuan04@baidu.com>
Acked-by: Joakim Bech <joakim.bech@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Ruchika Gupta <ruchika.gupta@linaro.org>
Acked-by: Jerome Forissier <jerome@forissier.org>
diff --git a/br-ext/Config.in b/br-ext/Config.in
index db39e6d..8b96f99 100644
--- a/br-ext/Config.in
+++ b/br-ext/Config.in
@@ -2,6 +2,7 @@
source "$BR2_EXTERNAL_OPTEE_PATH/package/optee_client_ext/Config.in"
source "$BR2_EXTERNAL_OPTEE_PATH/package/optee_test_ext/Config.in"
source "$BR2_EXTERNAL_OPTEE_PATH/package/optee_examples_ext/Config.in"
+source "$BR2_EXTERNAL_OPTEE_PATH/package/optee_rust_examples_ext/Config.in"
source "$BR2_EXTERNAL_OPTEE_PATH/package/optee_benchmark_ext/Config.in"
source "$BR2_EXTERNAL_OPTEE_PATH/package/opensc/Config.in"
source "$BR2_EXTERNAL_OPTEE_PATH/package/ftpm_optee_ext/Config.in"
diff --git a/br-ext/package/optee_rust_examples_ext/Config.in b/br-ext/package/optee_rust_examples_ext/Config.in
new file mode 100644
index 0000000..8aa0f71
--- /dev/null
+++ b/br-ext/package/optee_rust_examples_ext/Config.in
@@ -0,0 +1,20 @@
+config BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT
+ bool "optee_rust_examples"
+ help
+ https://github.com/apache/incubator-teaclave-trustzone-sdk
+
+config BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT_SITE
+ string "OP-TEE Rust examples path"
+ default ""
+ help
+ The path to the source directory of OP-TEE Rust SDK
+
+if BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT
+
+config BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT_CROSS_COMPILE
+ string "OP-TEE Rust examples cross compiler"
+ default ""
+ help
+ some help
+
+endif
diff --git a/br-ext/package/optee_rust_examples_ext/optee_rust_examples_ext.mk b/br-ext/package/optee_rust_examples_ext/optee_rust_examples_ext.mk
new file mode 100644
index 0000000..09918f0
--- /dev/null
+++ b/br-ext/package/optee_rust_examples_ext/optee_rust_examples_ext.mk
@@ -0,0 +1,46 @@
+OPTEE_RUST_EXAMPLES_EXT_VERSION = 1.0
+OPTEE_RUST_EXAMPLES_EXT_SOURCE = local
+OPTEE_RUST_EXAMPLES_EXT_SITE = $(BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT_SITE)
+OPTEE_RUST_EXAMPLES_EXT_SITE_METHOD = local
+OPTEE_RUST_EXAMPLES_EXT_INSTALL_STAGING = YES
+
+EXAMPLE = $(wildcard examples/*)
+
+HOST_TARGET := aarch64-unknown-linux-gnu
+TA_TARGET := aarch64-unknown-optee-trustzone
+
+export RUST_TARGET_PATH = $(@D)
+export RUST_COMPILER_RT_ROOT = $(RUST_TARGET_PATH)/rust/rust/src/llvm-project/compiler-rt
+export OPTEE_DIR = $(@D)/../../..
+export OPTEE_OS_DIR = $(OPTEE_DIR)/optee_os
+export OPTEE_CLIENT_DIR = $(OPTEE_DIR)/out-br/build/optee_client_ext-1.0
+export OPTEE_CLIENT_INCLUDE = $(OPTEE_CLIENT_DIR)/out/export/usr/include
+export PATH += :$(OPTEE_DIR)/toolchains/aarch64/bin
+export VENDOR = qemu_v8.mk
+export OPTEE_OS_INCLUDE = $(OPTEE_DIR)/optee_os/out/arm/export-ta_arm64/include
+
+define OPTEE_RUST_EXAMPLES_EXT_BUILD_CMDS
+ @$(foreach f,$(wildcard $(@D)/examples/*/Makefile), \
+ echo Building $f && \
+ $(MAKE) -C $(dir $f) &&) true
+endef
+
+define OPTEE_RUST_EXAMPLES_EXT_INSTALL_TARGET_CMDS
+ @$(foreach f,$(wildcard $(@D)/examples/*/ta/target/$(TA_TARGET)/release/*.ta), \
+ mkdir -p $(TARGET_DIR)/lib/optee_armtz && \
+ echo Installing $f && \
+ $(INSTALL) -v -p --mode=444 \
+ --target-directory=$(TARGET_DIR)/lib/optee_armtz $f \
+ &&) true
+ @$(foreach f,$(wildcard $(@D)/examples/*/host/target/$(HOST_TARGET)/release/*-rs), \
+ echo Installing $f && \
+ $(INSTALL) -v -p --target-directory=$(TARGET_DIR)/usr/bin $f \
+ &&) true
+ @$(foreach f,$(wildcard $(@D)/examples/*/plugin/target/$(HOST_TARGET)/release/*.plugin.so), \
+ mkdir -p $(TARGET_DIR)/usr/lib/tee-supplicant/plugins && \
+ echo Installing $f && \
+ $(INSTALL) -v -p --target-directory=$(TARGET_DIR)/usr/lib/tee-supplicant/plugins $f \
+ &&) true
+endef
+
+$(eval $(generic-package))
diff --git a/common.mk b/common.mk
index f72ea86..388fd85 100644
--- a/common.mk
+++ b/common.mk
@@ -34,6 +34,7 @@
OPTEE_CLIENT_PATH ?= $(ROOT)/optee_client
OPTEE_TEST_PATH ?= $(ROOT)/optee_test
OPTEE_EXAMPLES_PATH ?= $(ROOT)/optee_examples
+OPTEE_RUST_PATH ?= $(ROOT)/optee_rust
BUILDROOT_TARGET_ROOT ?= $(ROOT)/out-br/target
# default high verbosity. slow uarts shall specify lower if prefered
@@ -275,6 +276,12 @@
BR2_PACKAGE_OPTEE_EXAMPLES_EXT_CROSS_COMPILE ?= $(CROSS_COMPILE_S_USER)
BR2_PACKAGE_OPTEE_EXAMPLES_EXT_SDK ?= $(OPTEE_OS_TA_DEV_KIT_DIR)
BR2_PACKAGE_OPTEE_EXAMPLES_EXT_SITE ?= $(OPTEE_EXAMPLES_PATH)
+OPTEE_RUST_ENABLE ?= n
+ifeq ($(OPTEE_RUST_ENABLE),y)
+BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT ?= y
+BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT_CROSS_COMPILE ?= $(CROSS_COMPILE_S_USER)
+BR2_PACKAGE_OPTEE_RUST_EXAMPLES_EXT_SITE ?= $(OPTEE_RUST_PATH)
+endif
# The OPTEE_OS package builds nothing, it just installs files into the
# root FS when applicable (for example: shared libraries)
BR2_PACKAGE_OPTEE_OS_EXT ?= y
@@ -307,7 +314,7 @@
append-br2-vars = $(foreach var,$(filter BR2_%,$(.VARIABLES)),$(call append-var,$(var),$(1)))
.PHONY: buildroot
-buildroot: optee-os
+buildroot: optee-os optee-rust
@mkdir -p ../out-br
@rm -f ../out-br/build/optee_*/.stamp_*
@rm -f ../out-br/extra.conf
@@ -325,7 +332,7 @@
$(DEFCONFIG_FTPM) \
--br-defconfig out-br/extra.conf \
--make-cmd $(MAKE))
- @$(MAKE) -C ../out-br all
+ @$(OPTEE_RUST_SET_ENV) $(MAKE) -C ../out-br all
.PHONY: buildroot-clean
buildroot-clean:
@@ -504,6 +511,16 @@
$(MAKE) -C $(OPTEE_OS_PATH) $(OPTEE_OS_COMMON_FLAGS) clean
################################################################################
+# OP-TEE Rust
+################################################################################
+.PHONY: optee-rust
+optee-rust:
+ifeq ($(OPTEE_RUST_ENABLE),y)
+ @(cd $(OPTEE_RUST_PATH) && ./setup.sh)
+OPTEE_RUST_SET_ENV = source ~/.cargo/env &&
+endif
+
+################################################################################
# fTPM Rules
################################################################################