julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | # Driver source location and version |
| 9 | set(ARM_TZTRNG_URL "https://github.com/ARM-software/TZ-TRNG.git" CACHE STRING "Arm TZ-TRNG driver repository URL") |
| 10 | set(ARM_TZTRNG_REFSPEC "1.0.0" CACHE STRING "Arm TZ-TRNG driver git refspec") |
| 11 | |
| 12 | # Fetch driver source code from remote repository |
| 13 | include(FetchContent) |
| 14 | |
| 15 | FetchContent_Declare( |
| 16 | arm-tztrng |
| 17 | GIT_REPOSITORY ${ARM_TZTRNG_URL} |
| 18 | GIT_TAG ${ARM_TZTRNG_REFSPEC} |
| 19 | GIT_SHALLOW TRUE |
| 20 | ) |
| 21 | |
| 22 | # FetchContent_GetProperties exports arm-tztrng_SOURCE_DIR and arm-tztrng_BINARY_DIR variables |
| 23 | FetchContent_GetProperties(arm-tztrng) |
| 24 | if(NOT arm-tztrng_POPULATED) |
| 25 | message(STATUS "Fetching arm-tztrng") |
| 26 | FetchContent_Populate(arm-tztrng) |
| 27 | endif() |
| 28 | |
| 29 | # The driver has no cmake build support so it is necessary to bridge cmake variables to |
| 30 | # driver build parameters. |
| 31 | |
| 32 | # Determine ARCH parameter |
| 33 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") |
| 34 | set(_arm-tztrng_ARCH "arm64") |
| 35 | set(_arm-tztrng_builddir "build-aarch64-linux-gnu") |
| 36 | else() |
| 37 | message(FATAL_ERROR "Only arm builds of TZ-TRNG supported.") |
| 38 | endif() |
| 39 | |
| 40 | # Determine the full path for the generated library and public header |
| 41 | set(_arm-tztrng_genlib "${arm-tztrng_SOURCE_DIR}/host/src/tztrng_lib/${_arm-tztrng_builddir}/libcc_tztrng.a") |
| 42 | set(_arm-tztrng_host_incpath "${arm-tztrng_SOURCE_DIR}/host/src/tztrng_lib/include") |
| 43 | set(_arm-tztrng_shared_incpath "${arm-tztrng_SOURCE_DIR}/shared/hw/include") |
| 44 | |
| 45 | # Set HOST_PROJ_ROOT parameter to use TS provided build defines |
| 46 | set(_arm-tztrng_HOST_PROJ_ROOT ${CMAKE_CURRENT_LIST_DIR}) |
| 47 | |
| 48 | # Add custom command to build the driver library using the TZ-TRNG provided makefile |
| 49 | add_custom_command( |
| 50 | OUTPUT ${_arm-tztrng_genlib} |
| 51 | COMMAND make ARGS "ARCH=${_arm-tztrng_ARCH}" |
| 52 | WORKING_DIRECTORY "${arm-tztrng_SOURCE_DIR}/host/src/tztrng_lib/" |
| 53 | ) |
| 54 | |
| 55 | # Define target for the library |
| 56 | add_custom_target( |
| 57 | libcc_tztrng |
| 58 | DEPENDS ${_arm-tztrng_genlib} |
| 59 | ) |
| 60 | |
| 61 | # Add generated library to build target |
| 62 | target_include_directories(${TGT} PRIVATE "${_arm-tztrng_host_incpath}") |
| 63 | target_include_directories(${TGT} PRIVATE "${_arm-tztrng_shared_incpath}") |
| 64 | target_link_libraries(${TGT} PRIVATE ${_arm-tztrng_genlib}) |
| 65 | add_dependencies(${TGT} libcc_tztrng) |
| 66 | |
| 67 | # Add adapter to map platform trng interface to tz-trng driver |
| 68 | target_sources(${TGT} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/tztrng_trng.c") |