Build OpenAMP from recipe

Change-Id: Id36d97fa3aa4a60179bedbdc078c4e1e75486a49
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85470f9..c13c954 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
 #
-# SPDX-FileCopyrightText: Copyright 2019-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2019-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
 #
 # SPDX-License-Identifier: Apache-2.0
 #
@@ -79,6 +79,9 @@
 # Build libs
 add_subdirectory(lib)
 
+# OpenAMP
+add_subdirectory(openamp)
+
 # Build applications
 add_subdirectory(applications)
 
diff --git a/openamp/.clang-format b/openamp/.clang-format
new file mode 100644
index 0000000..e88e143
--- /dev/null
+++ b/openamp/.clang-format
@@ -0,0 +1,23 @@
+#
+# SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the License); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an AS IS BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+---
+Language: Cpp
+SortIncludes: false
+DisableFormat: true
+---
diff --git a/openamp/.gitignore b/openamp/.gitignore
new file mode 100644
index 0000000..445cd4f
--- /dev/null
+++ b/openamp/.gitignore
@@ -0,0 +1,2 @@
+/openamp/
+/libmetal/
diff --git a/openamp/CMakeLists.txt b/openamp/CMakeLists.txt
new file mode 100644
index 0000000..801c0c8
--- /dev/null
+++ b/openamp/CMakeLists.txt
@@ -0,0 +1,72 @@
+#
+# SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the License); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an AS IS BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+function(build_openamp PROJECT_SYSTEM)
+    set(PROJECT_PROCESSOR "arm")
+    set(PROJECT_MACHINE "cortexm")
+
+    file(GLOB SRCS
+        # libmetal
+        libmetal/lib/*.c
+        libmetal/lib/system/${PROJECT_SYSTEM}/*.c
+        libmetal/lib/compiler/gcc/*.c
+
+        # Extra sources
+        src/system/${PROJECT_SYSTEM}/${PROJECT_MACHINE}/*.c
+
+        # OpenAMP
+#        openamp/lib/proxy/*.c
+        openamp/lib/remoteproc/*.c
+        openamp/lib/rpmsg/*.c
+#        openamp/lib/service/*.c
+        openamp/lib/virtio/*.c)
+
+    add_library(openamp-${PROJECT_SYSTEM} STATIC
+        ${SRCS})
+
+    target_include_directories(openamp-${PROJECT_SYSTEM}
+        PUBLIC
+            ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_SYSTEM}
+            openamp/lib/include
+            src/system/${PROJECT_SYSTEM})
+
+    target_compile_definitions(openamp-${PROJECT_SYSTEM} PRIVATE
+        OPENAMP_VERSION_MAJOR=0
+        OPENAMP_VERSION_MINOR=0
+        OPENAMP_VERSION_PATCH=0
+        OPENAMP_VERSION=0
+        $<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},ARMClang>:__ICCARM__>
+        METAL_INTERNAL)
+
+    target_link_libraries(openamp-${PROJECT_SYSTEM} PRIVATE
+        cmsis_device
+        $<$<STREQUAL:${PROJECT_SYSTEM},freertos>:freertos_kernel>)
+
+    # Generate libmetal headers
+    file(GLOB_RECURSE HDRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/libmetal/lib" "libmetal/lib/*.h")
+
+    foreach(HDR ${HDRS})
+        configure_file("libmetal/lib/${HDR}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_SYSTEM}/metal/${HDR}")
+    endforeach()
+endfunction()
+
+build_openamp(generic)
+
+if (TARGET freertos_kernel)
+    build_openamp(freertos)
+endif()
diff --git a/openamp/src/system/freertos/cortexm/sys.c b/openamp/src/system/freertos/cortexm/sys.c
new file mode 100644
index 0000000..172ae3a
--- /dev/null
+++ b/openamp/src/system/freertos/cortexm/sys.c
@@ -0,0 +1,69 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * @file	freertos/cortexm/sys.c
+ * @brief	cortex m system primitives implementation.
+ */
+
+#include <metal/io.h>
+#include <metal/sys.h>
+#include <metal/utilities.h>
+#include <stdint.h>
+
+void sys_irq_restore_enable(unsigned int flags)
+{
+	metal_unused(flags);
+	/* we disable/enable all IRQs */
+	__enable_irq();
+}
+
+unsigned int sys_irq_save_disable(void)
+{
+	/* we disable/enable all IRQs */
+	__disable_irq();
+	return 0;
+}
+
+void sys_irq_enable(unsigned int vector)
+{
+	NVIC_EnableIRQ(vector);
+}
+
+void sys_irq_disable(unsigned int vector)
+{
+	NVIC_DisableIRQ(vector);
+}
+
+void metal_machine_cache_flush(void *addr, unsigned int len)
+{
+#if (defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))
+	SCB_CleanDCache_by_Addr(addr, len);
+#else
+	metal_unused(addr);
+	metal_unused(len);
+#endif
+}
+
+void metal_machine_cache_invalidate(void *addr, unsigned int len)
+{
+#if (defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))
+	SCB_InvalidateDCache_by_Addr(addr, len);
+#else
+	metal_unused(addr);
+	metal_unused(len);
+#endif
+}
+
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
+			       size_t size, unsigned int flags)
+{
+	metal_unused(pa);
+	metal_unused(size);
+	metal_unused(flags);
+
+	return va;
+}
diff --git a/openamp/src/system/freertos/cortexm/sys.h b/openamp/src/system/freertos/cortexm/sys.h
new file mode 100644
index 0000000..041fbd7
--- /dev/null
+++ b/openamp/src/system/freertos/cortexm/sys.h
@@ -0,0 +1,35 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * @file	freertos/cortexm/sys.h
+ * @brief	cortexm system primitives for libmetal.
+ */
+
+#ifndef __METAL_FREERTOS_SYS__H__
+#error "Include metal/freertos/sys.h instead of metal/freertos/cortexm/sys.h"
+#endif
+
+#ifndef __METAL_FREERTOS_CORTEXM_SYS__H__
+#define __METAL_FREERTOS_CORTEXM_SYS__H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef METAL_INTERNAL
+
+void sys_irq_enable(unsigned int vector);
+
+void sys_irq_disable(unsigned int vector);
+
+#endif /* METAL_INTERNAL */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __METAL_FREERTOS_CORTEXM_SYS__H__ */
diff --git a/openamp/src/system/generic/cortexm/sys.c b/openamp/src/system/generic/cortexm/sys.c
new file mode 100644
index 0000000..7034663
--- /dev/null
+++ b/openamp/src/system/generic/cortexm/sys.c
@@ -0,0 +1,69 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * @file	generic/cortexm/sys.c
+ * @brief	cortex m system primitives implementation.
+ */
+
+#include <metal/io.h>
+#include <metal/sys.h>
+#include <metal/utilities.h>
+#include <stdint.h>
+
+void sys_irq_restore_enable(unsigned int flags)
+{
+	metal_unused(flags);
+	/* we disable/enable all IRQs */
+	__enable_irq();
+}
+
+unsigned int sys_irq_save_disable(void)
+{
+	/* we disable/enable all IRQs */
+	__disable_irq();
+	return 0;
+}
+
+void sys_irq_enable(unsigned int vector)
+{
+	NVIC_EnableIRQ(vector);
+}
+
+void sys_irq_disable(unsigned int vector)
+{
+	NVIC_DisableIRQ(vector);
+}
+
+void metal_machine_cache_flush(void *addr, unsigned int len)
+{
+#if (defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))
+	SCB_CleanDCache_by_Addr(addr, len);
+#else
+	metal_unused(addr);
+	metal_unused(len);
+#endif
+}
+
+void metal_machine_cache_invalidate(void *addr, unsigned int len)
+{
+#if (defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))
+	SCB_InvalidateDCache_by_Addr(addr, len);
+#else
+	metal_unused(addr);
+	metal_unused(len);
+#endif
+}
+
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
+			       size_t size, unsigned int flags)
+{
+	metal_unused(pa);
+	metal_unused(size);
+	metal_unused(flags);
+
+	return va;
+}
diff --git a/openamp/src/system/generic/cortexm/sys.h b/openamp/src/system/generic/cortexm/sys.h
new file mode 100644
index 0000000..35a8aa0
--- /dev/null
+++ b/openamp/src/system/generic/cortexm/sys.h
@@ -0,0 +1,31 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * @file	generic/cortexm/sys.h
+ * @brief	cortexm system primitives for libmetal.
+ */
+
+#ifndef __METAL_GENERIC_CORTEXM_SYS__H__
+#define __METAL_GENERIC_CORTEXM_SYS__H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef METAL_INTERNAL
+
+void sys_irq_enable(unsigned int vector);
+
+void sys_irq_disable(unsigned int vector);
+
+#endif /* METAL_INTERNAL */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __METAL_GENERIC_CORTEXM_SYS__H__ */
diff --git a/rtos/freertos_config/FreeRTOSConfig.h.in b/rtos/freertos_config/FreeRTOSConfig.h.in
index 005519f..1c45c96 100644
--- a/rtos/freertos_config/FreeRTOSConfig.h.in
+++ b/rtos/freertos_config/FreeRTOSConfig.h.in
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020-2021 Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -77,7 +77,7 @@
 #define INCLUDE_xTaskResumeFromISR                      0
 #define INCLUDE_xTaskGetCurrentTaskHandle               1
 #define INCLUDE_xTaskGetSchedulerState                  0
-#define INCLUDE_xSemaphoreGetMutexHolder                0
+#define INCLUDE_xSemaphoreGetMutexHolder                1
 #define INCLUDE_xTimerPendFunctionCall                  1
 #define configUSE_STATS_FORMATTING_FUNCTIONS            1
 #define configCOMMAND_INT_MAX_OUTPUT_SIZE               2048