Apply Patches if Needed

TF-M needs to apply some patches to dependency repos.
Apply these patches if they exist in specific folders.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I0cc7245a7e8a3614b26e1d6649d2d0d0c287ce45
diff --git a/run-build.sh b/run-build.sh
index 5bfd354..5dc83fa 100755
--- a/run-build.sh
+++ b/run-build.sh
@@ -45,11 +45,22 @@
 	exit 1
 fi
 
-cd mbedtls
-git apply ../trusted-firmware-m/lib/ext/mbedcrypto/*.patch
+cnt=$(ls trusted-firmware-m/lib/ext/mbedcrypto/*.patch 2> /dev/null | wc -l)
+if [ "$cnt" != "0" ] ; then
+	cd mbedtls
+	git apply ../trusted-firmware-m/lib/ext/mbedcrypto/*.patch
+	cd -
+fi
 
-rm -rf ../trusted-firmware-m/build
-mkdir ../trusted-firmware-m/build
-cd ../trusted-firmware-m/build
+cnt=$(ls trusted-firmware-m/lib/ext/psa_arch_tests/*.patch 2> /dev/null | wc -l)
+if [ "$cnt" != "0" ] ; then
+	cd psa-arch-tests
+	git apply ../trusted-firmware-m/lib/ext/psa_arch_tests/*.patch
+	cd -
+fi
+
+rm -rf trusted-firmware-m/build
+mkdir trusted-firmware-m/build
+cd trusted-firmware-m/build
 
 eval "set -ex ; $build_commands"