trusted-firmware-a.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. DESCRIPTION = "Trusted Firmware-A"
  2. LICENSE = "BSD-2-Clause & BSD-3-Clause & MIT & Apache-2.0"
  3. PACKAGE_ARCH = "${MACHINE_ARCH}"
  4. inherit deploy
  5. SRC_URI_TRUSTED_FIRMWARE_A ?= "git://review.trustedfirmware.org/TF-A/trusted-firmware-a;protocol=https"
  6. SRCBRANCH = "master"
  7. SRC_URI = "${SRC_URI_TRUSTED_FIRMWARE_A};name=tfa;branch=${SRCBRANCH}"
  8. UPSTREAM_CHECK_GITTAGREGEX = "^(lts-)?v(?P<pver>\d+(\.\d+)+)$"
  9. SRCREV_FORMAT = "tfa"
  10. COMPATIBLE_MACHINE ?= "invalid"
  11. # Platform must be set for each machine
  12. TFA_PLATFORM ?= "invalid"
  13. # Some platforms can have multiple board configurations
  14. # Leave empty for default behavior
  15. TFA_BOARD ?= ""
  16. # Some platforms use SPD (Secure Payload Dispatcher) services
  17. # Few options are "opteed", "tlkd", "trusty", "tspd", "spmd"...
  18. # Leave empty to not use SPD
  19. TFA_SPD ?= ""
  20. # Variable used when TFA_SPD=spmd
  21. TFA_SPMD_SPM_AT_SEL2 ?= "1"
  22. # SP layout file location. Used when TFA_SPD=spmd and TFA_SPMD_SPM_AT_SEL2=1
  23. TFA_SP_LAYOUT_FILE ?= ""
  24. # SPMC manifest file location. Used when TFA_SPD=spmd and TFA_SPMD_SPM_AT_SEL2=1
  25. TFA_ARM_SPMC_MANIFEST_DTS ?= ""
  26. # Build for debug (set TFA_DEBUG to 1 to activate)
  27. TFA_DEBUG ?= "0"
  28. S = "${WORKDIR}/git"
  29. B = "${WORKDIR}/build"
  30. # mbed TLS support (set TFA_MBEDTLS to 1 to activate)
  31. TFA_MBEDTLS ?= "0"
  32. # sub-directory in which mbedtls will be downloaded
  33. TFA_MBEDTLS_DIR ?= "mbedtls"
  34. # This should be set to MBEDTLS download URL if MBEDTLS is needed
  35. SRC_URI_MBEDTLS ??= ""
  36. # This should be set to MBEDTLS LIC FILES checksum
  37. LIC_FILES_CHKSUM_MBEDTLS ??= ""
  38. # add MBEDTLS to our sources if activated
  39. SRC_URI:append = " ${@bb.utils.contains('TFA_MBEDTLS', '1', '${SRC_URI_MBEDTLS}', '', d)}"
  40. # Update license variables
  41. LICENSE:append = "${@bb.utils.contains('TFA_MBEDTLS', '1', ' & Apache-2.0', '', d)}"
  42. LIC_FILES_CHKSUM:append = "${@bb.utils.contains('TFA_MBEDTLS', '1', ' ${LIC_FILES_CHKSUM_MBEDTLS}', '', d)}"
  43. # add mbed TLS to version
  44. SRCREV_FORMAT:append = "${@bb.utils.contains('TFA_MBEDTLS', '1', '_mbedtls', '', d)}"
  45. # U-boot support (set TFA_UBOOT to 1 to activate)
  46. # When U-Boot support is activated BL33 is activated with u-boot.bin file
  47. TFA_UBOOT ??= "0"
  48. # UEFI support (set TFA_UEFI to 1 to activate)
  49. # When UEFI support is activated BL33 is activated with uefi.bin file
  50. TFA_UEFI ??= "0"
  51. # What to build
  52. # By default we only build bl1, do_deploy will copy
  53. # everything listed in this variable (by default bl1.bin)
  54. TFA_BUILD_TARGET ?= "bl1"
  55. # What to install
  56. # do_install and do_deploy will install everything listed in this
  57. # variable. It is set by default to TFA_BUILD_TARGET
  58. TFA_INSTALL_TARGET ?= "${TFA_BUILD_TARGET}"
  59. # Requires CROSS_COMPILE set by hand as there is no configure script
  60. export CROSS_COMPILE = "${TARGET_PREFIX}"
  61. # Let the Makefile handle setting up the CFLAGS and LDFLAGS as it is a standalone application
  62. CFLAGS[unexport] = "1"
  63. LDFLAGS[unexport] = "1"
  64. AS[unexport] = "1"
  65. LD[unexport] = "1"
  66. # No configure
  67. do_configure[noexec] = "1"
  68. # Baremetal, just need a compiler
  69. DEPENDS:remove = "virtual/${TARGET_PREFIX}compilerlibs virtual/libc"
  70. # We need dtc for dtbs compilation
  71. # We need openssl for fiptool
  72. DEPENDS = "dtc-native openssl-native"
  73. DEPENDS:append:toolchain-clang = " compiler-rt"
  74. # CC and LD introduce arguments which conflict with those otherwise provided by
  75. # this recipe. The heads of these variables excluding those arguments
  76. # are therefore used instead.
  77. def remove_options_tail (in_string):
  78. from itertools import takewhile
  79. return ' '.join(takewhile(lambda x: not x.startswith('-'), in_string.split(' ')))
  80. EXTRA_OEMAKE += "LD='${@remove_options_tail(d.getVar('LD'))}'"
  81. EXTRA_OEMAKE += "CC='${@remove_options_tail(d.getVar('CC'))}'"
  82. # Verbose builds, no -Werror
  83. EXTRA_OEMAKE += "V=1 E=0"
  84. # Add platform parameter
  85. EXTRA_OEMAKE += "BUILD_BASE=${B} PLAT=${TFA_PLATFORM}"
  86. # Handle TFA_BOARD parameter
  87. EXTRA_OEMAKE += "${@'TARGET_BOARD=${TFA_BOARD}' if d.getVar('TFA_BOARD') else ''}"
  88. # Handle TFA_SPD parameter
  89. EXTRA_OEMAKE += "${@'SPD=${TFA_SPD}' if d.getVar('TFA_SPD') else ''}"
  90. # If TFA_SPD is spmd, set SPMD_SPM_AT_SEL2
  91. EXTRA_OEMAKE += "${@'SPMD_SPM_AT_SEL2=${TFA_SPMD_SPM_AT_SEL2}' if d.getVar('TFA_SPD', True) == 'spmd' else ''}"
  92. # Handle TFA_DEBUG parameter
  93. EXTRA_OEMAKE += "${@bb.utils.contains('TFA_DEBUG', '1', 'DEBUG=${TFA_DEBUG}', '', d)}"
  94. # Handle MBEDTLS
  95. EXTRA_OEMAKE += "${@bb.utils.contains('TFA_MBEDTLS', '1', 'MBEDTLS_DIR=${TFA_MBEDTLS_DIR}', '', d)}"
  96. # Uboot support
  97. DEPENDS += " ${@bb.utils.contains('TFA_UBOOT', '1', 'u-boot', '', d)}"
  98. do_compile[depends] += " ${@bb.utils.contains('TFA_UBOOT', '1', 'u-boot:do_deploy', '', d)}"
  99. EXTRA_OEMAKE += "${@bb.utils.contains('TFA_UBOOT', '1', 'BL33=${DEPLOY_DIR_IMAGE}/u-boot.bin', '', d)}"
  100. # UEFI support
  101. DEPENDS += " ${@bb.utils.contains('TFA_UEFI', '1', 'edk2-firmware', '', d)}"
  102. EXTRA_OEMAKE += "${@bb.utils.contains('TFA_UEFI', '1', 'BL33=${RECIPE_SYSROOT}/firmware/uefi.bin', '', d)}"
  103. # TFTF test support
  104. DEPENDS += " ${@bb.utils.contains('TFTF_TESTS', '1', 'tf-a-tests', '', d)}"
  105. EXTRA_OEMAKE += "${@bb.utils.contains('TFTF_TESTS', '1', 'BL33=${RECIPE_SYSROOT}/firmware/tftf.bin', '',d)}"
  106. # Hafnium support
  107. SEL2_SPMC = "${@'${TFA_SPMD_SPM_AT_SEL2}' if d.getVar('TFA_SPD', True) == 'spmd' else ''}"
  108. DEPENDS += " ${@bb.utils.contains('SEL2_SPMC', '1', 'hafnium', '', d)}"
  109. EXTRA_OEMAKE += "${@bb.utils.contains('SEL2_SPMC', '1', 'CTX_INCLUDE_EL2_REGS=1 ARM_ARCH_MINOR=4 BL32=${RECIPE_SYSROOT}/firmware/hafnium.bin', '', d)}"
  110. # Add SP layout file and spmc manifest for hafnium
  111. EXTRA_OEMAKE += "${@bb.utils.contains('SEL2_SPMC', '1', 'SP_LAYOUT_FILE=${TFA_SP_LAYOUT_FILE}' if d.getVar('TFA_SP_LAYOUT_FILE') else '', '', d)}"
  112. EXTRA_OEMAKE += "${@bb.utils.contains('SEL2_SPMC', '1', 'ARM_SPMC_MANIFEST_DTS=${TFA_ARM_SPMC_MANIFEST_DTS}' if d.getVar('TFA_ARM_SPMC_MANIFEST_DTS') else '', '', d)}"
  113. # Tell the tools where the native OpenSSL is located
  114. EXTRA_OEMAKE += "OPENSSL_DIR=${STAGING_DIR_NATIVE}/${prefix_native}"
  115. # Use the correct native compiler
  116. EXTRA_OEMAKE += "HOSTCC='${BUILD_CC}'"
  117. # Runtime variables
  118. EXTRA_OEMAKE += "RUNTIME_SYSROOT=${STAGING_DIR_HOST}"
  119. BUILD_DIR = "${B}/${TFA_PLATFORM}"
  120. BUILD_DIR .= "${@'/${TFA_BOARD}' if d.getVar('TFA_BOARD') else ''}"
  121. BUILD_DIR .= "/${@'debug' if d.getVar("TFA_DEBUG") == '1' else 'release'}"
  122. do_compile() {
  123. # This is still needed to have the native tools executing properly by
  124. # setting the RPATH
  125. sed -i '/^LDOPTS/ s,$, \$\{BUILD_LDFLAGS},' ${S}/tools/fiptool/Makefile
  126. sed -i '/^INCLUDE_PATHS/ s,$, \$\{BUILD_CFLAGS},' ${S}/tools/fiptool/Makefile
  127. sed -i '/^LIB/ s,$, \$\{BUILD_LDFLAGS},' ${S}/tools/cert_create/Makefile
  128. # Currently there are races if you build all the targets at once in parallel
  129. for T in ${TFA_BUILD_TARGET}; do
  130. oe_runmake -C ${S} $T
  131. done
  132. }
  133. do_compile[cleandirs] = "${B}"
  134. do_install() {
  135. install -d -m 755 ${D}/firmware
  136. for atfbin in ${TFA_INSTALL_TARGET}; do
  137. processed="0"
  138. if [ "$atfbin" = "all" ]; then
  139. # Target all is not handled by default
  140. bberror "all as TFA_INSTALL_TARGET is not handled by do_install"
  141. bberror "Please specify valid targets in TFA_INSTALL_TARGET or"
  142. bberror "rewrite or turn off do_install"
  143. exit 1
  144. fi
  145. if [ -f ${BUILD_DIR}/$atfbin.bin ]; then
  146. echo "Install $atfbin.bin"
  147. install -m 0644 ${BUILD_DIR}/$atfbin.bin \
  148. ${D}/firmware/$atfbin-${TFA_PLATFORM}.bin
  149. ln -sf $atfbin-${TFA_PLATFORM}.bin ${D}/firmware/$atfbin.bin
  150. processed="1"
  151. fi
  152. if [ -f ${BUILD_DIR}/$atfbin/$atfbin.elf ]; then
  153. echo "Install $atfbin.elf"
  154. install -m 0644 ${BUILD_DIR}/$atfbin/$atfbin.elf \
  155. ${D}/firmware/$atfbin-${TFA_PLATFORM}.elf
  156. ln -sf $atfbin-${TFA_PLATFORM}.elf ${D}/firmware/$atfbin.elf
  157. processed="1"
  158. fi
  159. if [ -f ${BUILD_DIR}/$atfbin ]; then
  160. echo "Install $atfbin"
  161. install -m 0644 ${BUILD_DIR}/$atfbin \
  162. ${D}/firmware/$atfbin-${TFA_PLATFORM}
  163. ln -sf $atfbin-${TFA_PLATFORM} ${D}/firmware/$atfbin
  164. processed="1"
  165. fi
  166. if [ -f ${BUILD_DIR}/fdts/$atfbin.dtb ]; then
  167. echo "Install $atfbin.dtb"
  168. install -m 0644 "${BUILD_DIR}/fdts/$atfbin.dtb" \
  169. "${D}/firmware/$atfbin.dtb"
  170. processed="1"
  171. elif [ "$atfbin" = "dtbs" ]; then
  172. echo "dtbs install, skipped: set dtbs in TFA_INSTALL_TARGET"
  173. elif [ -f ${B}/tools/$atfbin/$atfbin ]; then
  174. echo "Tools $atfbin install, skipped"
  175. elif [ "$processed" = "0" ]; then
  176. bberror "Unsupported TFA_INSTALL_TARGET target $atfbin"
  177. exit 1
  178. fi
  179. done
  180. }
  181. FILES:${PN} = "/firmware"
  182. SYSROOT_DIRS += "/firmware"
  183. FILES:${PN}-dbg = "/firmware/*.elf"
  184. # Skip QA check for relocations in .text of elf binaries
  185. INSANE_SKIP:${PN}-dbg += "textrel"
  186. # Build paths are currently embedded
  187. INSANE_SKIP:${PN} += "buildpaths"
  188. INSANE_SKIP:${PN}-dbg += "buildpaths"
  189. do_deploy() {
  190. cp -rf ${D}/firmware/* ${DEPLOYDIR}/
  191. }
  192. addtask deploy after do_install
  193. CVE_PRODUCT = "arm:arm-trusted-firmware \
  194. arm:trusted_firmware-a \
  195. arm:arm_trusted_firmware \
  196. arm_trusted_firmware_project:arm_trusted_firmware"