spm_test: allow configuring mem-region base addr.

Allow platform specific configuration of the base address of the memory
region used to test manifest handling of the SPMC.
The default platform specific value can optionally be overridden from
the command line using -DCFG_TEST_MEM_REGION_ADDRESS=<value>.

Change-Id: I08d0e419e453cdb7944d52395228b4d973f9e31a
Signed-off-by: Gyorgy Szing <gyorgy.szing@arm.com>
diff --git a/components/service/spm_test/spm_test.cmake b/components/service/spm_test/spm_test.cmake
index ed81d5f..b99bf10 100644
--- a/components/service/spm_test/spm_test.cmake
+++ b/components/service/spm_test/spm_test.cmake
@@ -61,6 +61,15 @@
 			RUNTIME DESTINATION ${TS_ENV}/bin
 		)
 
+
+# Convert the base address used for memory region testing for the manifest file. The manifest template will use
+# MEM_REG_LO and MEM_REG_HI.
+# This value is either defined in platform.cmake or on the command line.
+if (NOT DEFINED CFG_TEST_MEM_REGION_ADDRESS)
+	message(FATAL_ERROR "Mandatory variable CFG_TEST_MEM_REGION_ADDRESS is not defined.")
+endif()
+uint64_split(VALUE ${CFG_TEST_MEM_REGION_ADDRESS} OUT_PREFIX MEM_REG)
+
 include(${TS_ROOT}/tools/cmake/common/ExportSp.cmake)
 export_sp(
 	SP_FFA_UUID_CANON ${SP_FFA_UUID_CANON}
diff --git a/deployments/spm-test1/opteesp/default_spm_test1.dts.in b/deployments/spm-test1/opteesp/default_spm_test1.dts.in
index 9d1f719..8ade9fd 100644
--- a/deployments/spm-test1/opteesp/default_spm_test1.dts.in
+++ b/deployments/spm-test1/opteesp/default_spm_test1.dts.in
@@ -26,7 +26,7 @@
 
 		test-region {
 			/* Armv8 A Foundation Platform values */
-			base-address = <0x00000000 0x6248000>;
+			base-address = <@MEM_REG_HI@ @MEM_REG_LO@>;
 			pages-count = <1>;
 			attributes = <0x3>; /* read-write */
 		};
diff --git a/platform/providers/arm/fvp/fvp_base_revc-2xaemv8a/platform.cmake b/platform/providers/arm/fvp/fvp_base_revc-2xaemv8a/platform.cmake
index 143ea46..c71ed09 100644
--- a/platform/providers/arm/fvp/fvp_base_revc-2xaemv8a/platform.cmake
+++ b/platform/providers/arm/fvp/fvp_base_revc-2xaemv8a/platform.cmake
@@ -15,6 +15,9 @@
 
 set(CFG_SFS_FLASH_AREA_SIZE "32*1024" CACHE STRING "Size of SFS ram store")
 
+# Test memory region base address for manifest testing in spm_test deployments.
+set(CFG_TEST_MEM_REGION_ADDRESS  0x6248000 CACHE STRING "Base address of memory region used to test mainfest processing.")
+
 #-------------------------------------------------------------------------------
 #  Map platform dependencies to suitable drivers for this platform
 #
diff --git a/tools/cmake/common/Utils.cmake b/tools/cmake/common/Utils.cmake
index 256bbf9..6471619 100644
--- a/tools/cmake/common/Utils.cmake
+++ b/tools/cmake/common/Utils.cmake
@@ -106,3 +106,62 @@
 		set_target_properties(${_MY_PARAMS_TGT} PROPERTIES OUTPUT_NAME "${_out_name}")
 	endif()
 endfunction()
+
+#[===[.rst:
+.. cmake:command:: uint64_split
+
+	.. code-block:: cmake
+
+		uint64_split(VALUE 4294967296 OUT_PREFIX RES)
+		message("RES_LO=${RES_LO} RES_HI=${RES_HI}")
+
+		uint64_split(VALUE 0x1122334455667788 OUT_PREFIX RES DECIMAL)
+		message("RES_LO=${RES_LO} RES_HI=${RES_HI}")
+
+	Split an uint64 integer to uint32 integers. The returned values will be hexadecimal unless the 	``DECIMAL``
+	argument is passed.
+	The result is returned in two values <OUT_PREFIX>_LO and <OUT_PREFIX>_HI.
+
+	INPUTS:
+
+	``VALUE``
+	Mandatory. uint64 value to be converted. The value shall either be an integer (e.g. 123) or a string representing
+	an integer (e.g. "123"). Hexadecimal numbers can be specified with "0x" prefix.
+
+	``DECIMAL``
+	Optional. Set the format of the returned values to be decimal instead of hexadecimal.
+
+	OUTPUTS:
+
+	``OUT_PREFIX``
+	Mandatory. The prefix of the output variables. Two variable will be created in the callers scope. <OUT_PREFIX>_LO
+	is the lower 32 bits and <OUT_PREFIX>_HI is the higher 32 bits.
+
+#]===]
+function(uint64_split )
+	set(options DECIMAL)
+	set(oneValueArgs VALUE OUT_PREFIX)
+	set(multiValueArgs)
+	cmake_parse_arguments(_MY_PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+	check_args(uint64_split VALUE OUT_PREFIX)
+
+	# Ensure the input is a valid uint64 integer
+	if (NOT "${_MY_PARAMS_VALUE}" MATCHES "^(0x[0-9a-fA-F]+)|([0-9]+)$")
+		message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid uint64 integer: ${_MY_PARAMS_VALUE}")
+	endif()
+
+	if (_MY_PARAMS_DECIMAL)
+		set(_out_format "DECIMAL")
+	else()
+		set(_out_format "HEXADECIMAL")
+	endif()
+
+	# Split the uint64 integer into two uint32 integers
+	math(EXPR _high_uint32 "(${_MY_PARAMS_VALUE} >> 32) & 0xFFFFFFFF" OUTPUT_FORMAT ${_out_format})
+	math(EXPR _low_uint32 "${_MY_PARAMS_VALUE} & 0xFFFFFFFF" OUTPUT_FORMAT ${_out_format})
+
+	# Return the results
+	set(${_MY_PARAMS_OUT_PREFIX}_LO ${_low_uint32} PARENT_SCOPE)
+	set(${_MY_PARAMS_OUT_PREFIX}_HI ${_high_uint32} PARENT_SCOPE)
+endfunction()