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))