Build: Add mbedtls patch to help code sharing

Adds a patch file that, when applied to mbedtls, will remove the
'static' keyword from some function pointers related to memory
allocation. This allows more functions to be shared between MCUboot
and the secure firmware.

Signed-off-by: Balint Matyi <Balint.Matyi@arm.com>
Change-Id: Ibc6cbb3ab18fccc92a5b8608b9f1ef54c1136d2f
diff --git a/bl2/CMakeLists.txt b/bl2/CMakeLists.txt
index 42cd65f..b809587 100644
--- a/bl2/CMakeLists.txt
+++ b/bl2/CMakeLists.txt
@@ -105,4 +105,11 @@
 
 if (TFM_CODE_SHARING)
     compiler_create_shared_code(bl2 ${CMAKE_CURRENT_SOURCE_DIR}/src/shared_symbol_template.txt)
+
+    if (NOT EXISTS ${MBEDCRYPTO_PATH}/library/code_share.c)
+        message(FATAL_ERROR "File ${MBEDCRYPTO_PATH}/library/code_share.c does not exist.
+        Have the patch ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/0005-Enable-crypto-code-sharing-between-independent-binar.patch
+        been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH}?
+        Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`")
+    endif()
 endif()