Platform: Move GNUARM C library to UNPRIV section

Details:
 - To enable any secure service to use the standard C library
   functions.
 - Only read-only(code&ro-data) section was moved.
 - Data section of C library remains in the data section of
   secure test service to make possible the usage of printf.

Change-Id: Iff106b72af3cc0cc4c0f1ebdab668886644b777c
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 513b5ef..51ddc6a 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -124,6 +124,8 @@
 if (CORE_TEST)
 	set(CORE_TEST_POSITIVE ON)
 	set(CORE_TEST_INTERACTIVE OFF)
+	set (TFM_PARTITION_TEST_SECURE_SERVICES ON)
+	add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
 endif()
 
 if (CORE_TEST_INTERACTIVE)
diff --git a/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld b/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld
index 53a7337..3eb51ff 100644
--- a/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld
+++ b/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld
@@ -180,6 +180,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -289,8 +291,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION : ALIGN(32)
     {
-        *libc_nano*:*(.text*)
-        *libc_nano*:*(.rodata*)
         *tfm_secure_client_service.*(.text*)
         *test_framework*(.text*)
         *uart_stdout.*(.text*)
@@ -394,6 +394,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -605,7 +614,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
-        *libc_nano*:*(.data*)
         *tfm_secure_client_service.*(.data*)
         *test_framework*(.data*)
         *uart_stdout.*(.data*)
@@ -620,8 +628,6 @@
 
     .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
     {
-        *libc_nano*:*(.bss*)
-        *libc_nano*:*(COMMON)
         *tfm_secure_client_service.*(.bss*)
         *test_framework*(.bss*)
         *uart_stdout.*(.bss*)
@@ -649,10 +655,26 @@
     Image$$TFM_SP_SECURE_TEST_PARTITION_STACK$$ZI$$Limit = ADDR(.TFM_SP_SECURE_TEST_PARTITION_STACK) + SIZEOF(.TFM_SP_SECURE_TEST_PARTITION_STACK);
 
 #endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -662,6 +684,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld.template b/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld.template
index 738344d..8f79b92 100644
--- a/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld.template
+++ b/platform/ext/target/mps2/an519/gcc/mps2_an519_s.ld.template
@@ -131,6 +131,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -253,6 +255,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -330,10 +341,26 @@
 #endif /* @@attr.conditional@@ */
 @!GENERATOR_CONDITIONAL_END!@
 @!GENERATOR_BLOCK_END!@
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -343,6 +370,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld b/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld
index 4334f92..b0d7208 100644
--- a/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld
+++ b/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld
@@ -180,6 +180,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -289,8 +291,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION : ALIGN(32)
     {
-        *libc_nano*:*(.text*)
-        *libc_nano*:*(.rodata*)
         *tfm_secure_client_service.*(.text*)
         *test_framework*(.text*)
         *uart_stdout.*(.text*)
@@ -394,6 +394,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -605,7 +614,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
-        *libc_nano*:*(.data*)
         *tfm_secure_client_service.*(.data*)
         *test_framework*(.data*)
         *uart_stdout.*(.data*)
@@ -620,8 +628,6 @@
 
     .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
     {
-        *libc_nano*:*(.bss*)
-        *libc_nano*:*(COMMON)
         *tfm_secure_client_service.*(.bss*)
         *test_framework*(.bss*)
         *uart_stdout.*(.bss*)
@@ -649,10 +655,26 @@
     Image$$TFM_SP_SECURE_TEST_PARTITION_STACK$$ZI$$Limit = ADDR(.TFM_SP_SECURE_TEST_PARTITION_STACK) + SIZEOF(.TFM_SP_SECURE_TEST_PARTITION_STACK);
 
 #endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -662,6 +684,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld.template b/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld.template
index 029a428..6089ceb 100644
--- a/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld.template
+++ b/platform/ext/target/mps2/an521/gcc/mps2_an521_s.ld.template
@@ -131,6 +131,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -253,6 +255,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -330,10 +341,26 @@
 #endif /* @@attr.conditional@@ */
 @!GENERATOR_CONDITIONAL_END!@
 @!GENERATOR_BLOCK_END!@
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -343,6 +370,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld b/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld
index 53a7337..3eb51ff 100644
--- a/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld
+++ b/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld
@@ -180,6 +180,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -289,8 +291,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION : ALIGN(32)
     {
-        *libc_nano*:*(.text*)
-        *libc_nano*:*(.rodata*)
         *tfm_secure_client_service.*(.text*)
         *test_framework*(.text*)
         *uart_stdout.*(.text*)
@@ -394,6 +394,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -605,7 +614,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
-        *libc_nano*:*(.data*)
         *tfm_secure_client_service.*(.data*)
         *test_framework*(.data*)
         *uart_stdout.*(.data*)
@@ -620,8 +628,6 @@
 
     .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
     {
-        *libc_nano*:*(.bss*)
-        *libc_nano*:*(COMMON)
         *tfm_secure_client_service.*(.bss*)
         *test_framework*(.bss*)
         *uart_stdout.*(.bss*)
@@ -649,10 +655,26 @@
     Image$$TFM_SP_SECURE_TEST_PARTITION_STACK$$ZI$$Limit = ADDR(.TFM_SP_SECURE_TEST_PARTITION_STACK) + SIZEOF(.TFM_SP_SECURE_TEST_PARTITION_STACK);
 
 #endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -662,6 +684,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld.template b/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld.template
index 738344d..8f79b92 100644
--- a/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld.template
+++ b/platform/ext/target/musca_a/Device/Source/gcc/musca_s.ld.template
@@ -131,6 +131,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -253,6 +255,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -330,10 +341,26 @@
 #endif /* @@attr.conditional@@ */
 @!GENERATOR_CONDITIONAL_END!@
 @!GENERATOR_BLOCK_END!@
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -343,6 +370,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld b/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld
index 7cc9551..6139050 100644
--- a/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld
+++ b/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld
@@ -180,6 +180,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -289,8 +291,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION : ALIGN(32)
     {
-        *libc_nano*:*(.text*)
-        *libc_nano*:*(.rodata*)
         *tfm_secure_client_service.*(.text*)
         *test_framework*(.text*)
         *uart_stdout.*(.text*)
@@ -394,6 +394,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -605,7 +614,6 @@
 #ifdef TFM_PARTITION_TEST_SECURE_SERVICES
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
-        *libc_nano*:*(.data*)
         *tfm_secure_client_service.*(.data*)
         *test_framework*(.data*)
         *uart_stdout.*(.data*)
@@ -620,8 +628,6 @@
 
     .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
     {
-        *libc_nano*:*(.bss*)
-        *libc_nano*:*(COMMON)
         *tfm_secure_client_service.*(.bss*)
         *test_framework*(.bss*)
         *uart_stdout.*(.bss*)
@@ -649,10 +655,26 @@
     Image$$TFM_SP_SECURE_TEST_PARTITION_STACK$$ZI$$Limit = ADDR(.TFM_SP_SECURE_TEST_PARTITION_STACK) + SIZEOF(.TFM_SP_SECURE_TEST_PARTITION_STACK);
 
 #endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -662,6 +684,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld.template b/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld.template
index b5dbc1f..4abc2e1 100644
--- a/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld.template
+++ b/platform/ext/target/musca_b1/Device/Source/gcc/musca_s.ld.template
@@ -131,6 +131,8 @@
 
     .TFM_UNPRIV_CODE : ALIGN(32)
     {
+        *libc_nano*:*(.text*)
+        *libc_nano*:*(.rodata*)
         *tfm_unpriv_api.o(.text*)
         *tfm_unpriv_api.o(.rodata*)
         *dummy_crypto_keys.o(.text*)
@@ -253,6 +255,15 @@
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Base = ADDR(.TFM_UNPRIV_SCRATCH);
     Image$$TFM_UNPRIV_SCRATCH$$ZI$$Limit = ADDR(.TFM_UNPRIV_SCRATCH) + SIZEOF(.TFM_UNPRIV_SCRATCH);
 
+    .heap : ALIGN(8)
+    {
+        __end__ = .;
+        PROVIDE(end = .);
+        __HeapBase = .;
+        . += __heap_size__;
+        __HeapLimit = .;
+        __heap_limit = .; /* Add for _sbrk */
+    } > RAM AT> FLASH
 #else /* TFM_LVL == 1 */
     .TFM_UNPRIV_RO_DATA :
     {
@@ -330,10 +341,26 @@
 #endif /* @@attr.conditional@@ */
 @!GENERATOR_CONDITIONAL_END!@
 @!GENERATOR_BLOCK_END!@
-#endif /* TFM_LVL == 1 */
 
     .TFM_SP_SECURE_TEST_PARTITION_DATA : ALIGN(32)
     {
+        *libc_nano*:*(.data*)
+        . = ALIGN(32);
+    } > RAM AT> FLASH
+
+    .TFM_SP_SECURE_TEST_PARTITION_BSS : ALIGN(32)
+    {
+        /* FixMe:
+         * Test framework use printf to print out test result. Implementation of
+         * printf in GCC libc use static data and heap as well. To be able to
+         * execute test suites with TFM_LVL=3 this workaround is needed to
+         * allocate libc static data and heap within the data section of secure
+         * test partition. This can be removed if test service will be executed
+         * in privileged mode.
+         */
+        *libc_nano*:*(.bss*)
+        *libc_nano*:*(COMMON)
+
         __end__ = .;
         PROVIDE(end = .);
         __HeapBase = .;
@@ -343,6 +370,7 @@
 
         . = ALIGN(32);
     } > RAM AT> FLASH
+#endif /* TFM_LVL == 1 */
 
     .TFM_DATA :
     {
diff --git a/test/test_services/tfm_secure_client_service/manifest.yaml b/test/test_services/tfm_secure_client_service/manifest.yaml
index 6a35efb..b772232 100644
--- a/test/test_services/tfm_secure_client_service/manifest.yaml
+++ b/test/test_services/tfm_secure_client_service/manifest.yaml
@@ -47,9 +47,6 @@
       "*arm_uart_drv.*",   # MPS2-AN521, MPS2-AN519
       "*uart_pl011_drv.*", # Musca-A1, Musca-B1
       "*secure_suites.*",
-    ],
-    "library_list": [
-      "*libc_nano*"
     ]
   }
 }