fix: check and initialise spm submodules

As part of the tf-a-job-configs we may clone the spm module to sync
it to the other repos based on the topic however we don't clone
the submodules at this stage. Therefore even if the spm directory
exist we still want to clone the submodules. This patch makes the
checks if the submodules have been initialsied and if not does it.

Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: If07fb5c721b699bf80bd7fe5f54fad5ad16ed33d
(cherry picked from commit 25385ab4ed41e89ae8c61e5db2f2607074f6a7f7)
diff --git a/script/build_package.sh b/script/build_package.sh
index c63db61..87407d6 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -1263,16 +1263,22 @@
 	fi
 fi
 
-if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
-	# If the SPM repository has already been checked out, use
-	# that location. Otherwise, clone one ourselves.
-	echo "Cloning SPM..."
-	clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
-		refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
+if [ "$spm_config" ] ; then
+	if assert_can_git_clone "spm_root"; then
+		# If the SPM repository has already been checked out, use
+		# that location. Otherwise, clone one ourselves.
+		echo "Cloning SPM..."
+		clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
+			where="$spm_root" refspec="$SPM_REFSPEC" \
+			clone_repo &>>"$build_log"
+	fi
 
 	# Query git submodules
 	pushd "$spm_root"
-	git submodule update --init
+	# Check if submodules need initialising
+	if git submodule status | grep '^-'; then
+		git submodule update --init
+	fi
 	popd
 
 	show_head "$spm_root"