App: Add no TZ context API support

Don't call tfm_nspm_register_client_id API if the NS OS doesn't support
TZ context management API.

Also update os_migration_guide_armv8m.md.

Change-Id: I44079f0414252ea4822f7623148ea351bb685d5f
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 00f7b00..5edb868 100755
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -101,6 +101,12 @@
 	target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE CORE_TEST)
 endif()
 
+if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
+elseif (TFM_NS_CLIENT_IDENTIFICATION)
+	target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION)
+endif()
+
 # For the non-swapping BL2 configuration two executables need to be built.
 # One can be executed from flash partition slot_0 and other from slot_1.
 # Only the linking phase is different. This function captures common settings
diff --git a/app/tfm_integ_test.c b/app/tfm_integ_test.c
index 0707737..367847c 100644
--- a/app/tfm_integ_test.c
+++ b/app/tfm_integ_test.c
@@ -219,7 +219,9 @@
     osThreadState_t thread_pri_state;
     uint32_t idx;
 
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
     tfm_nspm_register_client_id();
+#endif /* TFM_NS_CLIENT_IDENTIFICATION */
 
     thread_id_pri = *((osThreadId_t *)argument);
 
@@ -252,7 +254,9 @@
 __attribute__((noreturn))
 static void pri_task(void *argument)
 {
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
     tfm_nspm_register_client_id();
+#endif /* TFM_NS_CLIENT_IDENTIFICATION */
 
     /* go to sleep */
     osDelay(100U);
@@ -280,7 +284,9 @@
     struct tfm_ns_lock_options ns_lock_opt_pri =
                                   {.use_ns_lock=true, .timeout=osWaitForever};
 
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
     tfm_nspm_register_client_id();
+#endif /* TFM_NS_CLIENT_IDENTIFICATION */
 
     test_type = *((enum test_type *)argument);
 
diff --git a/docs/user_guides/os_migration_guide_armv8m.md b/docs/user_guides/os_migration_guide_armv8m.md
index cd2a34c..9a14094 100644
--- a/docs/user_guides/os_migration_guide_armv8m.md
+++ b/docs/user_guides/os_migration_guide_armv8m.md
@@ -14,6 +14,15 @@
 * If the OS manipulates directly the Link Register, the default Link Register
 value used in Handler mode transitions needs to be differentiated between Secure
 and Non Secure builds, i.e. `0xFD` and `0xBC`, respectively.
+* If the OS supports the Thread Context Management for Armv8-M TrustZone APIs,
+as described
+[here](https://www.keil.com/pack/doc/CMSIS/Core/html/group__context__trustzone__functions.html)
+, and would like to use the non-secure client identification feature of TF-M,
+then it also have to use the `enum tfm_status_e tfm_register_client_id (int32_t
+ns_client_id)` API function provided by TF-M, as described in
+[NS client identification documentation](tfm_ns_client_identification.md).
+* if the OS doesn't support the API mentioned above, it should set
+`TFM_NS_CLIENT_IDENTIFICATION` to `OFF` in the cmake system.
 * **_Note: This is NOT REQUIRED when the Non Secure OS build is meant to be
 integrated with TF-M running in Secure world._** If generic function calls into
 Secure world have to be supported in Non Secure builds, integrate an API for
diff --git a/test/suites/sst/non_secure/ns_test_helpers.c b/test/suites/sst/non_secure/ns_test_helpers.c
index a07a356..d86a8cd 100644
--- a/test/suites/sst/non_secure/ns_test_helpers.c
+++ b/test/suites/sst/non_secure/ns_test_helpers.c
@@ -30,7 +30,9 @@
 {
     struct test_task_t *test = arg;
 
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
     tfm_nspm_register_client_id();
+#endif /* TFM_NS_CLIENT_IDENTIFICATION */
 
     /* Call the test function */
     test->func(test->ret);