From f61250ce65566e955fdc3a4bd0a1a0da3718039a Mon Sep 17 00:00:00 2001
From: Wei Gao <gaw1lud@bosch.com>
Date: Thu, 15 Feb 2024 17:30:47 +0100
Subject: [PATCH] Add build profiles for QEMU with and without virtualization.

---
 debian/changelog            |  6 +++++
 debian/control              | 10 +++++++-
 debian/optee-os-sdk.install |  4 ++++
 debian/optee-os.install     |  9 +++++++
 debian/rules                | 48 +++++++++++++++++++++++++++++++++----
 5 files changed, 71 insertions(+), 6 deletions(-)
 create mode 100644 debian/optee-os-sdk.install

diff --git a/debian/changelog b/debian/changelog
index be46d8e..db850f8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+optee-os (4.0.0-0+apertis2) apertis; urgency=medium
+
+  * Add build profiles for QEMU with and without virtualization
+
+ -- Wei Gao <gaw1lud@bosch.com>  Thu, 15 Feb 2024 17:28:12 +0100
+
 optee-os (4.0.0-0+apertis1) apertis; urgency=medium
 
   * New upstream release (Closes: #868212)
diff --git a/debian/control b/debian/control
index 918ff56..5bc1233 100644
--- a/debian/control
+++ b/debian/control
@@ -6,7 +6,8 @@ Standards-Version: 4.6.2
 Build-Depends: debhelper-compat (= 13),
                python3,
                python3-cryptography,
-               python3-pyelftools
+               python3-pyelftools,
+               device-tree-compiler
 Vcs-Browser: https://salsa.debian.org/debian/optee-os
 Vcs-Git: https://salsa.debian.org/debian/optee-os.git
 Homepage: https://www.trustedfirmware.org/projects/op-tee
@@ -23,3 +24,10 @@ Description: OP-TEE Trusted OS
  exposed to Trusted Applications and the TEE Client API v1.0, which is the API
  describing how to communicate with a TEE. Those APIs are defined in the
  GlobalPlatform API specifications.
+
+Package: optee-os-sdk
+Architecture: arm64
+Depends:    ${misc:Depends}
+Description: SDK of OP-TEE Trusted OS
+ SDK is used for TA development.
+
diff --git a/debian/optee-os-sdk.install b/debian/optee-os-sdk.install
new file mode 100644
index 0000000..d1b0fab
--- /dev/null
+++ b/debian/optee-os-sdk.install
@@ -0,0 +1,4 @@
+out/arm-plat-k3/export-ta_arm64/*                    usr/share/optee-sdk/arm-plat-k3/
+out/arm-plat-vexpress/export-ta_arm64/*              usr/share/optee-sdk/vexpress-qemu_armv8a/
+out/arm-plat-vexpress-virtualized/export-ta_arm64/*  usr/share/optee-sdk/vexpress-qemu_armv8a-virtualized/
+
diff --git a/debian/optee-os.install b/debian/optee-os.install
index a0edef7..2d1382b 100644
--- a/debian/optee-os.install
+++ b/debian/optee-os.install
@@ -1 +1,10 @@
 out/arm-plat-k3/core/tee-raw.bin		usr/lib/optee/k3-am62x
+
+out/arm-plat-vexpress/core/tee-pager_v2.bin     usr/lib/optee/vexpress-qemu_armv8a
+out/arm-plat-vexpress/core/tee-header_v2.bin    usr/lib/optee/vexpress-qemu_armv8a
+out/arm-plat-vexpress/core/tee-pageable_v2.bin  usr/lib/optee/vexpress-qemu_armv8a
+
+out/arm-plat-vexpress-virtualized/core/tee-pager_v2.bin     usr/lib/optee/vexpress-qemu_armv8a-virtualized
+out/arm-plat-vexpress-virtualized/core/tee-header_v2.bin    usr/lib/optee/vexpress-qemu_armv8a-virtualized
+out/arm-plat-vexpress-virtualized/core/tee-pageable_v2.bin  usr/lib/optee/vexpress-qemu_armv8a-virtualized
+
diff --git a/debian/rules b/debian/rules
index e1c4b66..433cc01 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,13 +1,51 @@
 #!/usr/bin/make -f
 
+# export COMPILE = aarch64-linux-gnu-
+
+profiles := k3-am62x vexpress-qemu_armv8a vexpress-qemu_armv8a-virtualized
+
+# Build only 64-bit TAs
+export CFG_USER_TA_TARGETS = ta_arm64
+
+# Build options for k3-am62x
+k3-am62x_options := O=out/arm-plat-k3
+k3-am62x_options += PLATFORM=k3-am62x
+k3-am62x_options += CFG_ARM64_core=y
+
+# Build options for vexpress-qemu_armv8a
+vexpress-qemu_armv8a_options := O=out/arm-plat-vexpress
+vexpress-qemu_armv8a_options += PLATFORM=vexpress-qemu_armv8a
+vexpress-qemu_armv8a_options += CFG_TEE_CORE_LOG_LEVEL=3 DEBUG=0 CFG_TEE_BENCHMARK=n  CFG_ARM_GICV3=y CFG_ARM64_core=y CFG_VIRTUALIZATION=n
+
+# Build options for vexpress-qemu_armv8a-virtualized
+vexpress-qemu_armv8a-virtualized_options := O=out/arm-plat-vexpress-virtualized
+vexpress-qemu_armv8a-virtualized_options += PLATFORM=vexpress-qemu_armv8a
+vexpress-qemu_armv8a-virtualized_options += CFG_TEE_CORE_LOG_LEVEL=3 DEBUG=0 CFG_TEE_BENCHMARK=n  CFG_ARM_GICV3=y CFG_ARM64_core=y CFG_VIRTUALIZATION=y
+
+# vexpress-qemu_armv8a_options += V=1
+
 # hardening -> relro breaks compilation with error "'-Wl,-z,relro' unknown"
-export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-relro
+export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-relro,-stackprotector,-format
 
 %:
 	dh $@
 
 override_dh_auto_build:
-	# Build for k3-am62x platform
-	make PLATFORM=k3-am62x \
-	     CFG_ARM64_core=y \
-	     CFG_USER_TA_TARGETS=ta_arm64
+	$(foreach profile, $(profiles), \
+	  make $($(profile)_options) ; \
+      )
+
+
+override_dh_auto_clean:
+	$(foreach profile, $(profiles), \
+	  make $($(profile)_options) \
+	    clean ; \
+      )
+
+override_dh_auto_install:
+	dh_auto_install -- CFG_USER_TA_TARGETS=
+
+override_dh_auto_test:
+	dh_auto_test -- CFG_USER_TA_TARGETS=
+
+
-- 
GitLab