zephyr_init.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /** @file
  2. * @brief mbed TLS initialization
  3. *
  4. * Initialize the mbed TLS library like setup the heap etc.
  5. */
  6. /*
  7. * Copyright (c) 2017 Intel Corporation
  8. *
  9. * SPDX-License-Identifier: Apache-2.0
  10. */
  11. #include <init.h>
  12. #include <app_memory/app_memdomain.h>
  13. #if defined(CONFIG_MBEDTLS)
  14. #if !defined(CONFIG_MBEDTLS_CFG_FILE)
  15. #include "mbedtls/config.h"
  16. #else
  17. #include CONFIG_MBEDTLS_CFG_FILE
  18. #endif /* CONFIG_MBEDTLS_CFG_FILE */
  19. #endif
  20. #if defined(CONFIG_MBEDTLS_ENABLE_HEAP) && \
  21. defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
  22. #include <mbedtls/memory_buffer_alloc.h>
  23. #if !defined(CONFIG_MBEDTLS_HEAP_SIZE)
  24. #error "Please set heap size to be used. Set value to CONFIG_MBEDTLS_HEAP_SIZE \
  25. option."
  26. #endif
  27. static unsigned char _mbedtls_heap[CONFIG_MBEDTLS_HEAP_SIZE];
  28. static void init_heap(void)
  29. {
  30. mbedtls_memory_buffer_alloc_init(_mbedtls_heap, sizeof(_mbedtls_heap));
  31. }
  32. #else
  33. #define init_heap(...)
  34. #endif /* CONFIG_MBEDTLS_ENABLE_HEAP && MBEDTLS_MEMORY_BUFFER_ALLOC_C */
  35. static int _mbedtls_init(const struct device *device)
  36. {
  37. ARG_UNUSED(device);
  38. init_heap();
  39. return 0;
  40. }
  41. SYS_INIT(_mbedtls_init, POST_KERNEL, 0);