Build: Add stub functions of system calls

GNU Arm compiler version greater equal than *11.3.Rel1*
has a linker issue that required system calls are missing,
such as _read and _write. Add stub functions of required
system calls to solve this issue.

Signed-off-by: Chendi Sun <chendi.sun@arm.com>
Change-Id: I1384a405174097639e4c7bb71f19d01a66318a2d
diff --git a/bl2/CMakeLists.txt b/bl2/CMakeLists.txt
index 92e696b..eb6d66f 100644
--- a/bl2/CMakeLists.txt
+++ b/bl2/CMakeLists.txt
@@ -15,6 +15,7 @@
     $<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:src/default_flash_map.c>
     $<$<BOOL:${MCUBOOT_DATA_SHARING}>:src/shared_data.c>
     $<$<BOOL:${PLATFORM_DEFAULT_PROVISIONING}>:src/provisioning.c>
+    $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
 )
 
 add_subdirectory(ext/mcuboot)
diff --git a/docs/getting_started/tfm_getting_started.rst b/docs/getting_started/tfm_getting_started.rst
index 88a786a..35d4eda 100644
--- a/docs/getting_started/tfm_getting_started.rst
+++ b/docs/getting_started/tfm_getting_started.rst
@@ -217,9 +217,6 @@
           support. The bug is reported in `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157>`__.
           Select other GNU Arm compiler versions instead.
 
-          GNU Arm compiler version greater and equal than *11.3.Rel1* has a linker issue in syscall.
-          Select other GNU Arm compiler versions instead.
-
     - IAR Arm compiler v8.42.x, v8.50.x
 
       .. tabs::
diff --git a/lib/ext/tf-m-tests/repo_config_default.cmake b/lib/ext/tf-m-tests/repo_config_default.cmake
index 943cbff..e857a0d 100644
--- a/lib/ext/tf-m-tests/repo_config_default.cmake
+++ b/lib/ext/tf-m-tests/repo_config_default.cmake
@@ -9,6 +9,6 @@
 
 # Default configs of tf-m-tests repo
 
-set(TFM_TEST_REPO_PATH                  "DOWNLOAD"  CACHE PATH      "Path to TFM-TEST repo (or DOWNLOAD to fetch automatically")
-set(TFM_TEST_REPO_VERSION               "03864fc"   CACHE STRING    "The version of tf-m-tests to use")
-set(CMSIS_5_PATH                        "DOWNLOAD"  CACHE PATH      "Path to CMSIS_5 (or DOWNLOAD to fetch automatically")
+set(TFM_TEST_REPO_PATH                  "DOWNLOAD" CACHE PATH      "Path to TFM-TEST repo (or DOWNLOAD to fetch automatically")
+set(TFM_TEST_REPO_VERSION               "a985c00"  CACHE STRING    "The version of tf-m-tests to use")
+set(CMSIS_5_PATH                        "DOWNLOAD" CACHE PATH      "Path to CMSIS_5 (or DOWNLOAD to fetch automatically")
diff --git a/platform/ext/common/syscalls_stub.c b/platform/ext/common/syscalls_stub.c
new file mode 100755
index 0000000..9ebe78e
--- /dev/null
+++ b/platform/ext/common/syscalls_stub.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * NOTE: When GNU Arm compiler version greater equal than *11.3.Rel1*, there is a linker issue that
+ * some system calls are not implemented, such as _close, _fstat and _getpid etc. So add this file
+ * including stub functions of system calls to avoid the above linker issue.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+__attribute__((weak))
+void _close(void)
+{
+}
+
+__attribute__((weak))
+void _fstat(void)
+{
+}
+
+__attribute__((weak))
+void _getpid(void)
+{
+}
+
+__attribute__((weak))
+void _isatty(void)
+{
+}
+
+__attribute__((weak))
+void _kill(void)
+{
+}
+
+__attribute__((weak))
+void _lseek(void)
+{
+}
+
+__attribute__((weak))
+void _read(void)
+{
+}
+
+__attribute__((weak))
+void _write(void)
+{
+}
diff --git a/secure_fw/partitions/lib/runtime/CMakeLists.txt b/secure_fw/partitions/lib/runtime/CMakeLists.txt
index 04b906c..9472784 100644
--- a/secure_fw/partitions/lib/runtime/CMakeLists.txt
+++ b/secure_fw/partitions/lib/runtime/CMakeLists.txt
@@ -18,6 +18,8 @@
 )
 
 target_sources(tfm_sprt
+    PUBLIC
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
     PRIVATE
         ./crt_memcmp.c
         ./crt_memmove.c
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index 1c4d3c7..d905e30 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -170,9 +170,12 @@
                             " See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157 for the issue detail.")
     endif()
 
+    # GNU Arm compiler version greater equal than *11.3.Rel1*
+    # has a linker issue that required system calls are missing,
+    # such as _read and _write. Add stub functions of required
+    # system calls to solve this issue.
     if (GCC_VERSION VERSION_GREATER_EQUAL 11.3.1)
-        message(FATAL_ERROR "GNU Arm compiler version greater and equal than *11.3.Rel1* has a linker issue in syscall."
-                            " Select other GNU Arm compiler versions instead.")
+        set(CONFIG_GNU_SYSCALL_STUB_ENABLED TRUE)
     endif()
 
     unset(CMAKE_C_FLAGS_INIT)