Remove newlib

Remove newlib component and depending deployments.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I86dbc5e1eb5ab55afaf679de40c2fcfbb81a5132
diff --git a/deployments/newlib/opteesp/CMakeLists.txt b/deployments/newlib/opteesp/CMakeLists.txt
deleted file mode 100644
index 5363d84..0000000
--- a/deployments/newlib/opteesp/CMakeLists.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-cmake_minimum_required(VERSION 3.14)
-include(../../deployment.cmake REQUIRED)
-
-#-------------------------------------------------------------------------------
-#  The CMakeLists.txt for building the newlib deployment for opteesp
-#
-#  Can be used to build the newlib library, which can be used to build SPs.
-#-------------------------------------------------------------------------------
-include(${TS_ROOT}/environments/opteesp/env.cmake)
-
-project(newlib C)
-
-# This is a dummy library not intended to be compiled ever.
-add_library(dummy EXCLUDE_FROM_ALL)
-set(TGT dummy)
-# Build newlib as an external component.
-include(${TS_ROOT}/external/newlib/newlib.cmake)
-
-######################################## install
-if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
-endif()
-
-# export the newlib install content from CMAKE_BINARY_DIR.
-install(DIRECTORY ${NEWLIB_INSTALL_DIR}/ DESTINATION ${TS_ENV}/newlib)
diff --git a/external/newlib/0001-Allow-aarch64-linux-gcc-to-compile-bare-metal-lib.patch b/external/newlib/0001-Allow-aarch64-linux-gcc-to-compile-bare-metal-lib.patch
deleted file mode 100644
index f87ed5a..0000000
--- a/external/newlib/0001-Allow-aarch64-linux-gcc-to-compile-bare-metal-lib.patch
+++ /dev/null
@@ -1,46 +0,0 @@
-From 64d4a8a9b59ed79bc78658d7edf1bdd9bc4f084d Mon Sep 17 00:00:00 2001
-From: Imre Kis <imre.kis@arm.com>
-Date: Tue, 19 Oct 2021 11:48:10 +0200
-Subject: [PATCH 1/1] Allow aarch64-linux-gcc to compile bare metal lib
-
-Newlib build system determines the target (i.e. Linux, BSD, bare metal,
-etc.) according to the toolchain triplet. This patch changes the
-configure script to treat the aarch64-linux-gnu and the
-aarch64-linux-musl triplets as bare-metal compilers.
-
-Signed-off-by: Imre Kis <imre.kis@arm.com>
-Signed-off-by: Gyorgy Szing <gyorgy.szing@arm.com>
----
- configure                  | 2 +-
- libgloss/aarch64/configure | 2 +-
- 2 files changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/configure b/configure
-index 5db52701..1eb71a80 100755
---- a/configure
-+++ b/configure
-@@ -3659,7 +3659,7 @@ case "${target}" in
-   *-*-freebsd*)
-     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
-     ;;
--  *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu | *-*-kopensolaris*-gnu)
-+  *-*-k*bsd*-gnu | *-*-kopensolaris*-gnu)
-     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
-     ;;
-   *-*-lynxos*)
-diff --git a/libgloss/aarch64/configure b/libgloss/aarch64/configure
-index b45256f3..25c9d5f7 100755
---- a/libgloss/aarch64/configure
-+++ b/libgloss/aarch64/configure
-@@ -2521,7 +2521,7 @@ test "${CCASFLAGS+set}" = set || CCASFLAGS=$CFLAGS
- 
- 
- case "${target}" in
--  *-*-elf)
-+  *-*-elf | *-linux-gnu | *-linux-musl)
- 	objtype=elf-
- 	;;
- esac
--- 
-2.17.1
-
diff --git a/external/newlib/0002-Disable-unnecessary-targets.patch b/external/newlib/0002-Disable-unnecessary-targets.patch
deleted file mode 100644
index 61f1813..0000000
--- a/external/newlib/0002-Disable-unnecessary-targets.patch
+++ /dev/null
@@ -1,31 +0,0 @@
-From a8c7c58679126dd4c75538aeedfee0c501df6548 Mon Sep 17 00:00:00 2001
-From: Anton Antonov <anton.antonov@arm.com>
-Date: Mon, 19 Sep 2022 23:37:31 +0200
-Subject: [PATCH 2/2] Disable unnecessary targets
-
-For Trusted Services we require only newlib and libgloss built for
-target. We don't need to build any host tools and we can use a
-cross-compiler only. This patch removes skipping newlib and libgloss for
-this case.
-
-Signed-off-by: Anton Antonov <anton.antonov@arm.com>
----
- configure | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/configure b/configure
-index 1eb71a806..dce91609e 100755
---- a/configure
-+++ b/configure
-@@ -2886,7 +2886,7 @@ esac
- 
- # Some are only suitable for cross toolchains.
- # Remove these if host=target.
--cross_only="target-libgloss target-newlib target-opcodes"
-+cross_only="target-opcodes"
- 
- case $is_cross_compiler in
-   no) skipdirs="${skipdirs} ${cross_only}" ;;
--- 
-2.37.0.windows.1
-
diff --git a/external/newlib/newlib.cmake b/external/newlib/newlib.cmake
deleted file mode 100644
index 3a0eb23..0000000
--- a/external/newlib/newlib.cmake
+++ /dev/null
@@ -1,269 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-# Add newlib specific porting files to the project.
-if (NOT DEFINED TGT)
-	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"
-	"${CMAKE_CURRENT_LIST_DIR}/newlib_sp_assert.c"
-	"${CMAKE_CURRENT_LIST_DIR}/newlib_sp_heap.c"
-)
-
-# Fetch newlib from external repository
-set(NEWLIB_URL "https://sourceware.org/git/newlib-cygwin.git"
-		CACHE STRING "newlib repository URL")
-set(NEWLIB_REFSPEC "newlib-4.1.0"
-		CACHE STRING "newlib git refspec")
-set(NEWLIB_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/newlib-src"
-		CACHE PATH "newlib source-code location")
-set(NEWLIB_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/newlib_install"
-		CACHE PATH "newlib installation directory")
-# Supported build types: "Release" "Debug" "RelWithDebInfo" "Off"
-# If set to "Off" -DNEWLIB_CFLAGS_TARGET can be used to set compiler
-# switches from the command line.
-set(NEWLIB_BUILD_TYPE "Release"	CACHE STRING "newlib build type")
-
-# Extracting compiler prefix without the trailing hyphen from the C compiler name
-get_filename_component(COMPILER_PATH ${CMAKE_C_COMPILER} DIRECTORY)
-get_filename_component(COMPILER_NAME ${CMAKE_C_COMPILER} NAME)
-string(REGEX REPLACE "(.*)-[^-]+$" "\\1" COMPILER_PREFIX ${COMPILER_NAME})
-
-find_library(NEWLIB_LIBC_PATH
-				NAMES libc.a c.a libc.lib c.lib
-				PATHS ${NEWLIB_INSTALL_DIR}
-				PATH_SUFFIXES "${COMPILER_PREFIX}/lib"
-				DOC "Location of newlib::libc library."
-				NO_DEFAULT_PATH
-)
-set(NEWLIB_LIBC_PATH ${NEWLIB_LIBC_PATH})
-unset(NEWLIB_LIBC_PATH CACHE)
-
-find_library(NEWLIB_LIBNOSYS_PATH
-				NAMES libnosys.a nosys.a nosys.lib nosys.lib
-				PATHS ${NEWLIB_INSTALL_DIR}
-				PATH_SUFFIXES "${COMPILER_PREFIX}/lib"
-				DOC "Location of newlib::libnosys library."
-				NO_DEFAULT_PATH
-)
-set(NEWLIB_LIBNOSYS_PATH ${NEWLIB_LIBNOSYS_PATH})
-unset(NEWLIB_LIBNOSYS_PATH CACHE)
-
-# libc - get compiler specific configuration from GCC
-add_library(c STATIC IMPORTED)
-# We need "freestandig" mode. Ask the compile to do the needed configurations.
-include(${TS_ROOT}/tools/cmake/compiler/GCC.cmake)
-compiler_set_freestanding(TARGET c)
-
-if (NOT NEWLIB_LIBC_PATH)
-	# Determine the number of processes to run while running parallel builds.
-	# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
-	if(NOT DEFINED PROCESSOR_COUNT)
-		include(ProcessorCount)
-		ProcessorCount(PROCESSOR_COUNT)
-		set(PROCESSOR_COUNT ${PROCESSOR_COUNT}
-				CACHE STRING "Number of cores to use for parallel builds.")
-	endif()
-
-	# See if the source is available locally
-	find_file(NEWLIB_HEADER_FILE
-		NAMES newlib.h
-		PATHS ${NEWLIB_SOURCE_DIR}
-		PATH_SUFFIXES "newlib/libc/include"
-		NO_DEFAULT_PATH
-	)
-	set(NEWLIB_HEADER_FILE ${NEWLIB_HEADER_FILE})
-	unset(NEWLIB_HEADER_FILE CACHE)
-
-	# Source not found, fetch it.
-	if (NOT NEWLIB_HEADER_FILE)
-		include(FetchContent)
-
-		# Checking git
-		find_program(GIT_COMMAND "git")
-		if (NOT GIT_COMMAND)
-			message(FATAL_ERROR "Please install git")
-		endif()
-
-		# List patch files.
-		file(GLOB _patch_files LIST_DIRECTORIES false "${CMAKE_CURRENT_LIST_DIR}/[0-9]*-[!0-9]*.patch")
-		# Sort items in natural order to ensure patches are amended in the right order.
-		list(SORT _patch_files COMPARE NATURAL)
-		# Convert the list to a string of concatenated quoted list items.
-		string(REPLACE ";" "\" \"" _patch_files "${_patch_files}")
-		set(_patch_files "\"${_patch_files}\"")
-		# Create a shell script patching newlib with the files listed above
-		string(APPEND _patch_script "#!/bin/sh\n"
-			" ${GIT_COMMAND} stash\n"
-			" ${GIT_COMMAND} branch ts-bf-am\n"
-			" ${GIT_COMMAND} am ${_patch_files}\n"
-			" ${GIT_COMMAND} reset ts-bf-am\n"
-			" ${GIT_COMMAND} branch -D ts-bf-am\n"
-		)
-		file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/patch-newlib "${_patch_script}")
-
-		# Fetching newlib
-		FetchContent_Declare(
-			newlib
-			SOURCE_DIR ${NEWLIB_SOURCE_DIR}
-			GIT_REPOSITORY ${NEWLIB_URL}
-			GIT_TAG ${NEWLIB_REFSPEC}
-			GIT_SHALLOW FALSE
-			PATCH_COMMAND sh ${CMAKE_CURRENT_BINARY_DIR}/patch-newlib
-		)
-
-		# FetchContent_GetProperties exports newlib_SOURCE_DIR and newlib_BINARY_DIR variables
-		FetchContent_GetProperties(newlib)
-		# FetchContent_Populate will fail if the source directory is removed since it will try to
-		# do an "update" and not a "populate" action. As a workaround, remove the subbuild directory.
-		# Note: this fix assumes, the default subbuild location is used.
-		file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/_deps/newlib-subbuild")
-
-		if(NOT newlib_POPULATED)
-			message(STATUS "Fetching newlib")
-			FetchContent_Populate(newlib)
-		endif()
-		set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NEWLIB_SOURCE_DIR})
-	endif()
-
-	# Get NEWLIB_EXTRA_PARAMS value from environment
-	set(NEWLIB_EXTRA_PARAMS $ENV{NEWLIB_EXTRA_PARAMS} CACHE STRING "")
-
-	# Split a newlib extra build parameter into a list of parameters
-	set(_extra_params ${NEWLIB_EXTRA_PARAMS})
-	separate_arguments(_extra_params)
-
-	# Transfer libgcc specific settings to newlib, and set position independent compilation
-	string(REPLACE ";" " -I" _more_cflags_target "${LIBGCC_INCLUDE_DIRS}" )
-	set(_more_cflags_target "-fpic -I${_more_cflags_target}")
-
-	string(TOUPPER ${NEWLIB_BUILD_TYPE} UC_NEWLIB_BUILD_TYPE)
-	if ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "DEBUG")
-		set(_more_cflags_target "${_more_cflags_target} -g -O0")
-	elseif ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "RELEASE")
-		set(_more_cflags_target "${_more_cflags_target} -O2")
-	elseif ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO")
-		set(_more_cflags_target "${_more_cflags_target} -g -O2")
-	elseif (NOT "${UC_NEWLIB_BUILD_TYPE}" STREQUAL "OFF")
-		message(FATAL_ERROR "unsupported build type to newlib.")
-	endif()
-
-	# Get external extra flags for target from environment.
-	set(NEWLIB_CFLAGS_TARGET $ENV{NEWLIB_CFLAGS_TARGET} CACHE STRING "")
-
-	# Merge our CFLAGS with external CFLAGS
-	if (NOT "${NEWLIB_CFLAGS_TARGET}" STREQUAL "")
-		# Add a space separator if external value is not empty
-		string(APPEND NEWLIB_CFLAGS_TARGET " ")
-	endif()
-	# Concatenate, and override CACHE value
-	set(NEWLIB_CFLAGS_TARGET "${NEWLIB_CFLAGS_TARGET}${_more_cflags_target}" CACHE STRING "" FORCE)
-
-	# Get extra external CFLAGS for host from environment
-	set(NEWLIB_CFLAGS $ENV{NEWLIB_CFLAGS} CACHE STRING "")
-
-	# Newlib is keeping build artifacts in the source directory. If the source is pre-fetched,
-	# intermediate files of previoud build migth be still present.
-	# Run distclean to avoid build errors due to reconfiguration.
-	execute_process(COMMAND
-		${CMAKE_COMMAND} -E env --unset=CC PATH=${COMPILER_PATH}:$ENV{PATH}
-			make -j${PROCESSOR_COUNT} distclean
-		WORKING_DIRECTORY
-			${NEWLIB_SOURCE_DIR}
-		RESULT_VARIABLE _newlib_error
-	)
-	#ignore error as distclean-host is failing.
-	#if (_newlib_error)
-	#	message(FATAL_ERROR "\"distclean\" step of newlib failed with ${_newlib_error}.")
-	#endif()
-
-	# Newlib configure step
-	# CC env var must be unset otherwise configure will assume the cross compiler is the host
-	# compiler.
-	# The configure options are set to minimize code size and memory usage.
-	execute_process(COMMAND
-		${CMAKE_COMMAND} -E env --unset=CC PATH=${COMPILER_PATH}:$ENV{PATH} ./configure
-			--target=${COMPILER_PREFIX}
-			--host=${COMPILER_PREFIX}
-			--prefix=${NEWLIB_INSTALL_DIR}
-			--enable-newlib-nano-formatted-io
-			--enable-newlib-nano-malloc
-			--enable-lite-exit
-			--enable-newlib-reent-small
-			--enable-newlib-global-atexit
-			--disable-multilib
-			${_extra_params}
-			CFLAGS_FOR_TARGET=${NEWLIB_CFLAGS_TARGET}
-			CFLAGS=${NEWLIB_CFLAGS}
-			LDFLAGS_FOR_TARGET=-fpie
-		WORKING_DIRECTORY
-			${NEWLIB_SOURCE_DIR}
-		RESULT_VARIABLE _newlib_error
-	)
-
-	if (_newlib_error)
-		message(FATAL_ERROR "Configuration step of newlib failed with ${_newlib_error}.")
-	endif()
-
-	# Newlib build step
-	execute_process(COMMAND
-		${CMAKE_COMMAND} -E env --unset=CC PATH=${COMPILER_PATH}:$ENV{PATH}
-			make -j${PROCESSOR_COUNT}
-		WORKING_DIRECTORY
-			${NEWLIB_SOURCE_DIR}
-		RESULT_VARIABLE _newlib_error
-	)
-
-	if (_newlib_error)
-		message(FATAL_ERROR "Build step of newlib failed with ${_newlib_error}.")
-	endif()
-
-	# Newlib install step
-	execute_process(COMMAND
-		${CMAKE_COMMAND} -E env --unset=CC PATH=${COMPILER_PATH}:$ENV{PATH} make install
-		WORKING_DIRECTORY
-			${NEWLIB_SOURCE_DIR}
-		RESULT_VARIABLE _newlib_error
-	)
-
-	if (_newlib_error)
-		message(FATAL_ERROR "Install step of newlib failed with ${_newlib_error}.")
-	endif()
-
-	set(NEWLIB_LIBC_PATH "${NEWLIB_INSTALL_DIR}/${COMPILER_PREFIX}/lib/libc.a")
-	set(NEWLIB_LIBNOSYS_PATH "${NEWLIB_INSTALL_DIR}/${COMPILER_PREFIX}/lib/libnosys.a")
-endif()
-
-set_property(DIRECTORY ${CMAKE_SOURCE_DIR}
-	APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NEWLIB_LIBC_PATH})
-
-# libc - continue configuration
-set_property(TARGET c PROPERTY IMPORTED_LOCATION "${NEWLIB_LIBC_PATH}")
-target_compile_definitions(c INTERFACE ENABLE_CDEFSH_FIX)
-set_property(TARGET c PROPERTY
-		INTERFACE_INCLUDE_DIRECTORIES "${NEWLIB_INSTALL_DIR}/${COMPILER_PREFIX}/include")
-
-# Make standard library available in the build system.
-add_library(stdlib::c ALIAS c)
-
-# libnosys
-add_library(nosys STATIC IMPORTED)
-set_property(TARGET nosys PROPERTY IMPORTED_LOCATION "${NEWLIB_LIBNOSYS_PATH}")
-set_property(TARGET nosys PROPERTY
-		INTERFACE_INCLUDE_DIRECTORIES "${NEWLIB_INSTALL_DIR}/${COMPILER_PREFIX}/include")
-compiler_set_freestanding(TARGET nosys)
-target_link_libraries(c INTERFACE nosys)
diff --git a/external/newlib/newlib_init.c b/external/newlib/newlib_init.c
deleted file mode 100644
index 9450a68..0000000
--- a/external/newlib/newlib_init.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- */
-
-#include "libc_init.h"
-
-/* Comes from libc */
-void __libc_init_array(void);
-
-void _init(void)
-{
-	/* Dummy */
-}
-
-void libc_init(void)
-{
-	/* Initializing global variables, calling constructors */
-	__libc_init_array();
-}
diff --git a/external/newlib/newlib_sp_assert.c b/external/newlib/newlib_sp_assert.c
deleted file mode 100644
index f386bb4..0000000
--- a/external/newlib/newlib_sp_assert.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
- */
-
-#include "assert_fail_handler.h"
-#include "compiler.h"
-#include <assert.h>
-
-/*
- * This function implements newlib's assert fail handler function by calling the
- * generic assert fail handler function that should be implemented by the
- * environment.
- */
-void __noreturn __assert_func(const char *file, int line, const char *func,
-			      const char *failedexpr)
-{
-	assert_fail_handler(file, line, func, failedexpr);
-	while (1)
-		;
-}
diff --git a/external/newlib/newlib_sp_heap.c b/external/newlib/newlib_sp_heap.c
deleted file mode 100644
index 20b9ce3..0000000
--- a/external/newlib/newlib_sp_heap.c
+++ /dev/null
@@ -1,36 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
- */
-
-#include "compiler.h"
-#include <errno.h>
-#include <stdint.h>
-#include <unistd.h>
-
-/* Allocating heap area */
-#ifndef SP_HEAP_SIZE
-#error "SP_HEAP_SIZE is undefined, please define it in the build system"
-#endif
-
-static uint8_t sp_heap[SP_HEAP_SIZE] __aligned(16);
-static uint8_t *program_break = sp_heap;
-
-/**
- * Basic sbrk implementation which increases the program break through the
- * sp_heap buffer.
- */
-void *_sbrk(ptrdiff_t incr)
-{
-	uint8_t *previous_break = program_break;
-	uint8_t *new_break = program_break + incr;
-
-	if ((new_break < sp_heap) || (new_break > (sp_heap + sizeof(sp_heap)))) {
-		errno = ENOMEM;
-		return (void *)(uintptr_t) -1;
-	}
-
-	program_break += incr;
-
-	return (void *) previous_break;
-}
diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
index 9167312..1fd72ed 100644
--- a/tools/b-test/test_data.yaml
+++ b/tools/b-test/test_data.yaml
@@ -104,10 +104,6 @@
       os_id : "GNU/Linux"
       params:
             - "-GUnix Makefiles"
-    - name: "newlib-opteesp"
-      src: "$TS_ROOT/deployments/newlib/opteesp"
-      params:
-            - "-GUnix Makefiles"
     - name: "platform-inspect-arm-linux"
       src: "$TS_ROOT/deployments/platform-inspect/arm-linux"
       os_id : "GNU/Linux"