Move libc_init interface into separate component
Move libc_init interface into a separate component as it is independent
from the environment. Each libc implementation should hide its
initialization sequence in this function so SPs can remain libc
agnostic.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I8c72e2fe102ec2054b31fac50f467e9e8f8bdf94
diff --git a/components/common/libc/component.cmake b/components/common/libc/component.cmake
new file mode 100644
index 0000000..042117b
--- /dev/null
+++ b/components/common/libc/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_include_directories(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/include"
+)
diff --git a/components/common/libc/include/libc_init.h b/components/common/libc/include/libc_init.h
new file mode 100644
index 0000000..28988d5
--- /dev/null
+++ b/components/common/libc/include/libc_init.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ */
+
+#ifndef LIBC_INIT_H_
+#define LIBC_INIT_H_
+
+/*
+ * Generic libc init function. Implemented by the newlib external, should be called by the
+ * environment on boot.
+ */
+void libc_init(void);
+
+#endif /* LIBC_INIT_H_ */
diff --git a/environments/opteesp/include/libc_init.h b/environments/opteesp/include/libc_init.h
deleted file mode 100644
index 232c3c0..0000000
--- a/environments/opteesp/include/libc_init.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause */
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- */
-
-#ifndef LIBC_INIT_H_
-#define LIBC_INIT_H_
-
-void libc_init(void);
-
-#endif /* LIBC_INIT_H_ */
diff --git a/external/newlib/newlib.cmake b/external/newlib/newlib.cmake
index 05bc93e..48736e5 100644
--- a/external/newlib/newlib.cmake
+++ b/external/newlib/newlib.cmake
@@ -10,6 +10,13 @@
message(FATAL_ERROR "mandatory parameter TGT is not defined.")
endif()
+# Adding libc interface
+add_components(TARGET ${TGT}
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ components/common/libc
+)
+
# Compile TS specific newlib porting files.
target_sources(${TGT} PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/newlib_init.c"