uboot-sign.bbclass 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. # This file is part of U-Boot verified boot support and is intended to be
  7. # inherited from the u-boot recipe.
  8. #
  9. # The signature procedure requires the user to generate an RSA key and
  10. # certificate in a directory and to define the following variable:
  11. #
  12. # UBOOT_SIGN_KEYDIR = "/keys/directory"
  13. # UBOOT_SIGN_KEYNAME = "dev" # keys name in keydir (eg. "dev.crt", "dev.key")
  14. # UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
  15. # UBOOT_SIGN_ENABLE = "1"
  16. #
  17. # As verified boot depends on fitImage generation, following is also required:
  18. #
  19. # KERNEL_CLASSES ?= " kernel-fitimage "
  20. # KERNEL_IMAGETYPE ?= "fitImage"
  21. #
  22. # The signature support is limited to the use of CONFIG_OF_SEPARATE in U-Boot.
  23. #
  24. # For more details on signature process, please refer to U-Boot documentation.
  25. # We need some variables from u-boot-config
  26. inherit uboot-config
  27. require conf/image-fitimage.conf
  28. # Enable use of a U-Boot fitImage
  29. UBOOT_FITIMAGE_ENABLE ?= "0"
  30. # Signature activation - this requires UBOOT_FITIMAGE_ENABLE = "1"
  31. SPL_SIGN_ENABLE ?= "0"
  32. # Default value for deployment filenames.
  33. UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb"
  34. UBOOT_DTB_BINARY ?= "u-boot.dtb"
  35. UBOOT_DTB_SIGNED ?= "${UBOOT_DTB_BINARY}-signed"
  36. UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb"
  37. UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.bin"
  38. UBOOT_NODTB_BINARY ?= "u-boot-nodtb.bin"
  39. UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.bin"
  40. UBOOT_ITS_IMAGE ?= "u-boot-its-${MACHINE}-${PV}-${PR}"
  41. UBOOT_ITS ?= "u-boot.its"
  42. UBOOT_ITS_SYMLINK ?= "u-boot-its-${MACHINE}"
  43. UBOOT_FITIMAGE_IMAGE ?= "u-boot-fitImage-${MACHINE}-${PV}-${PR}"
  44. UBOOT_FITIMAGE_BINARY ?= "u-boot-fitImage"
  45. UBOOT_FITIMAGE_SYMLINK ?= "u-boot-fitImage-${MACHINE}"
  46. SPL_DIR ?= "spl"
  47. SPL_DTB_IMAGE ?= "u-boot-spl-${MACHINE}-${PV}-${PR}.dtb"
  48. # When SPL is not used, set SPL_DTB_BINARY ?= "" to explicitly indicate
  49. # that no SPL DTB should be created or signed.
  50. SPL_DTB_BINARY ?= "u-boot-spl.dtb"
  51. SPL_DTB_SIGNED ?= "${SPL_DTB_BINARY}-signed"
  52. SPL_DTB_SYMLINK ?= "u-boot-spl-${MACHINE}.dtb"
  53. SPL_NODTB_IMAGE ?= "u-boot-spl-nodtb-${MACHINE}-${PV}-${PR}.bin"
  54. SPL_NODTB_BINARY ?= "u-boot-spl-nodtb.bin"
  55. SPL_NODTB_SYMLINK ?= "u-boot-spl-nodtb-${MACHINE}.bin"
  56. # U-Boot fitImage description
  57. UBOOT_FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"
  58. # U-Boot fitImage Hash Algo
  59. UBOOT_FIT_HASH_ALG ?= "sha256"
  60. # U-Boot fitImage Signature Algo
  61. UBOOT_FIT_SIGN_ALG ?= "rsa2048"
  62. # Generate keys for signing U-Boot fitImage
  63. UBOOT_FIT_GENERATE_KEYS ?= "0"
  64. # Size of private keys in number of bits
  65. UBOOT_FIT_SIGN_NUMBITS ?= "2048"
  66. # args to openssl genrsa (Default is just the public exponent)
  67. UBOOT_FIT_KEY_GENRSA_ARGS ?= "-F4"
  68. # args to openssl req (Default is -batch for non interactive mode and
  69. # -new for new certificate)
  70. UBOOT_FIT_KEY_REQ_ARGS ?= "-batch -new"
  71. # Standard format for public key certificate
  72. UBOOT_FIT_KEY_SIGN_PKCS ?= "-x509"
  73. # length of address in number of <u32> cells
  74. # ex: 1 32bits address, 2 64bits address
  75. UBOOT_FIT_ADDRESS_CELLS ?= "1"
  76. # ARM Trusted Firmware(ATF) is a reference implementation of secure world
  77. # software for Arm A-Profile architectures, (Armv8-A and Armv7-A), including
  78. # an Exception Level 3 (EL3) Secure Monitor.
  79. UBOOT_FIT_ARM_TRUSTED_FIRMWARE ?= "0"
  80. UBOOT_FIT_ARM_TRUSTED_FIRMWARE_IMAGE ?= "bl31.bin"
  81. # A Trusted Execution Environment(TEE) is an environment for executing code,
  82. # in which those executing the code can have high levels of trust in the asset
  83. # management of that surrounding environment.
  84. UBOOT_FIT_TEE ?= "0"
  85. UBOOT_FIT_TEE_IMAGE ?= "tee-raw.bin"
  86. # User specific settings
  87. UBOOT_FIT_USER_SETTINGS ?= ""
  88. # Sets the firmware property to select the image to boot first.
  89. # If not set, the first entry in "loadables" is used instead.
  90. UBOOT_FIT_CONF_FIRMWARE ?= ""
  91. # Unit name containing a list of users additional binaries to be loaded.
  92. # It is a comma-separated list of strings.
  93. UBOOT_FIT_CONF_USER_LOADABLES ?= ''
  94. UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}"
  95. UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}"
  96. DEPENDS:append = " ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''}"
  97. python() {
  98. # We need u-boot-tools-native if we're creating a U-Boot fitImage
  99. sign = d.getVar('UBOOT_SIGN_ENABLE') == '1'
  100. if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' or sign:
  101. d.appendVar('DEPENDS', " u-boot-tools-native dtc-native")
  102. }
  103. concat_dtb() {
  104. type="$1"
  105. binary="$2"
  106. if [ -e "${UBOOT_DTB_BINARY}" ]; then
  107. # Signing individual images is not recommended as that
  108. # makes fitImage susceptible to mix-and-match attack.
  109. #
  110. # OE FIT_SIGN_INDIVIDUAL is implemented in an unusual manner,
  111. # where the resulting signed fitImage contains both signed
  112. # images and signed configurations. This is redundant. In
  113. # order to prevent mix-and-match attack, it is sufficient
  114. # to sign configurations. The FIT_SIGN_INDIVIDUAL = "1"
  115. # support is kept to avoid breakage of existing layers, but
  116. # it is highly recommended to avoid FIT_SIGN_INDIVIDUAL = "1",
  117. # i.e. set FIT_SIGN_INDIVIDUAL = "0" .
  118. if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then
  119. # Sign dummy image images in order to
  120. # add the image signing keys to our dtb
  121. ${UBOOT_MKIMAGE_SIGN} \
  122. ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
  123. -f auto \
  124. -k "${UBOOT_SIGN_KEYDIR}" \
  125. -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
  126. -g "${UBOOT_SIGN_IMG_KEYNAME}" \
  127. -K "${UBOOT_DTB_BINARY}" \
  128. -d /dev/null \
  129. -r ${B}/unused.itb \
  130. ${UBOOT_MKIMAGE_SIGN_ARGS}
  131. fi
  132. # Sign dummy image configurations in order to
  133. # add the configuration signing keys to our dtb
  134. ${UBOOT_MKIMAGE_SIGN} \
  135. ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
  136. -f auto-conf \
  137. -k "${UBOOT_SIGN_KEYDIR}" \
  138. -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
  139. -g "${UBOOT_SIGN_KEYNAME}" \
  140. -K "${UBOOT_DTB_BINARY}" \
  141. -d /dev/null \
  142. -r ${B}/unused.itb \
  143. ${UBOOT_MKIMAGE_SIGN_ARGS}
  144. # Verify the dummy fitImage signature against u-boot.dtb
  145. # augmented using public key material.
  146. #
  147. # This only works for FIT_SIGN_INDIVIDUAL = "0", because
  148. # mkimage -f auto-conf does not support -F to extend the
  149. # existing unused.itb , and instead rewrites unused.itb
  150. # from scratch.
  151. #
  152. # Using two separate unused.itb for mkimage -f auto and
  153. # mkimage -f auto-conf invocation above would not help, as
  154. # the signature verification process below checks whether
  155. # all keys inserted into u-boot.dtb /signature node pass
  156. # the verification. Separate unused.itb would each miss one
  157. # of the signatures.
  158. #
  159. # The FIT_SIGN_INDIVIDUAL = "1" support is kept to avoid
  160. # breakage of existing layers, but it is highly recommended
  161. # to not use FIT_SIGN_INDIVIDUAL = "1", i.e. set
  162. # FIT_SIGN_INDIVIDUAL = "0" .
  163. if [ "${FIT_SIGN_INDIVIDUAL}" != "1" ] ; then
  164. ${UBOOT_FIT_CHECK_SIGN} \
  165. -k "${UBOOT_DTB_BINARY}" \
  166. -f ${B}/unused.itb
  167. fi
  168. cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED}
  169. fi
  170. # If we're not using a signed u-boot fit, concatenate SPL w/o DTB & U-Boot DTB
  171. # with public key (otherwise U-Boot will be packaged by uboot_fitimage_assemble)
  172. if [ "${SPL_SIGN_ENABLE}" != "1" ] ; then
  173. if [ ! -e "${UBOOT_DTB_BINARY}" ]; then
  174. bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
  175. return
  176. fi
  177. if [ "x${UBOOT_SUFFIX}" = "ximg" ] || [ "x${UBOOT_SUFFIX}" = "xrom" ]; then
  178. oe_runmake EXT_DTB="${UBOOT_DTB_SIGNED}" ${UBOOT_MAKE_TARGET}
  179. if [ -n "${binary}" ]; then
  180. cp ${binary} ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX}
  181. fi
  182. elif [ -e "${UBOOT_NODTB_BINARY}" ]; then
  183. if [ -n "${binary}" ]; then
  184. cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} | tee ${binary} > \
  185. ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX}
  186. else
  187. cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} > ${UBOOT_BINARY}
  188. fi
  189. fi
  190. fi
  191. }
  192. deploy_dtb() {
  193. type="$1"
  194. if [ -n "${type}" ]; then
  195. uboot_dtb_binary="u-boot-${type}-${PV}-${PR}.dtb"
  196. uboot_nodtb_binary="u-boot-nodtb-${type}-${PV}-${PR}.bin"
  197. else
  198. uboot_dtb_binary="${UBOOT_DTB_IMAGE}"
  199. uboot_nodtb_binary="${UBOOT_NODTB_IMAGE}"
  200. fi
  201. if [ -e "${UBOOT_DTB_SIGNED}" ]; then
  202. install -Dm644 ${UBOOT_DTB_SIGNED} ${DEPLOYDIR}/${uboot_dtb_binary}
  203. if [ -n "${type}" ]; then
  204. ln -sf ${uboot_dtb_binary} ${DEPLOYDIR}/${UBOOT_DTB_IMAGE}
  205. fi
  206. fi
  207. if [ -f "${UBOOT_NODTB_BINARY}" ]; then
  208. install -Dm644 ${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${uboot_nodtb_binary}
  209. if [ -n "${type}" ]; then
  210. ln -sf ${uboot_nodtb_binary} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
  211. fi
  212. fi
  213. }
  214. concat_spl_dtb() {
  215. if [ -e "${SPL_DIR}/${SPL_NODTB_BINARY}" ] && [ -e "${SPL_DIR}/${SPL_DTB_BINARY}" ] ; then
  216. cat ${SPL_DIR}/${SPL_NODTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED} > "${SPL_BINARY}"
  217. else
  218. bbwarn "Failure while adding public key to spl binary. Verified U-Boot boot won't be available."
  219. fi
  220. }
  221. deploy_spl_dtb() {
  222. type="$1"
  223. if [ -n "${type}" ]; then
  224. spl_dtb_binary="u-boot-spl-${type}-${PV}-${PR}.dtb"
  225. spl_nodtb_binary="u-boot-spl-nodtb-${type}-${PV}-${PR}.bin"
  226. else
  227. spl_dtb_binary="${SPL_DTB_IMAGE}"
  228. spl_nodtb_binary="${SPL_NODTB_IMAGE}"
  229. fi
  230. if [ -e "${SPL_DIR}/${SPL_DTB_SIGNED}" ] ; then
  231. install -Dm644 ${SPL_DIR}/${SPL_DTB_SIGNED} ${DEPLOYDIR}/${spl_dtb_binary}
  232. if [ -n "${type}" ]; then
  233. ln -sf ${spl_dtb_binary} ${DEPLOYDIR}/${SPL_DTB_IMAGE}
  234. fi
  235. fi
  236. if [ -f "${SPL_DIR}/${SPL_NODTB_BINARY}" ] ; then
  237. install -Dm644 ${SPL_DIR}/${SPL_NODTB_BINARY} ${DEPLOYDIR}/${spl_nodtb_binary}
  238. if [ -n "${type}" ]; then
  239. ln -sf ${spl_nodtb_binary} ${DEPLOYDIR}/${SPL_NODTB_IMAGE}
  240. fi
  241. fi
  242. # For backwards compatibility...
  243. install -Dm644 ${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE}
  244. }
  245. do_uboot_generate_rsa_keys() {
  246. if [ "${SPL_SIGN_ENABLE}" = "0" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then
  247. bbwarn "UBOOT_FIT_GENERATE_KEYS is set to 1 eventhough SPL_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used."
  248. fi
  249. if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then
  250. # Generate keys only if they don't already exist
  251. if [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key ] || \
  252. [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt ]; then
  253. # make directory if it does not already exist
  254. mkdir -p "${SPL_SIGN_KEYDIR}"
  255. echo "Generating RSA private key for signing U-Boot fitImage"
  256. openssl genrsa ${UBOOT_FIT_KEY_GENRSA_ARGS} -out \
  257. "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \
  258. "${UBOOT_FIT_SIGN_NUMBITS}"
  259. echo "Generating certificate for signing U-Boot fitImage"
  260. openssl req ${UBOOT_FIT_KEY_REQ_ARGS} "${UBOOT_FIT_KEY_SIGN_PKCS}" \
  261. -key "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \
  262. -out "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt
  263. fi
  264. fi
  265. }
  266. addtask uboot_generate_rsa_keys before do_uboot_assemble_fitimage after do_compile
  267. # Create a ITS file for the atf
  268. uboot_fitimage_atf() {
  269. cat << EOF >> ${UBOOT_ITS}
  270. atf {
  271. description = "ARM Trusted Firmware";
  272. data = /incbin/("${UBOOT_FIT_ARM_TRUSTED_FIRMWARE_IMAGE}");
  273. type = "firmware";
  274. arch = "${UBOOT_ARCH}";
  275. os = "arm-trusted-firmware";
  276. load = <${UBOOT_FIT_ARM_TRUSTED_FIRMWARE_LOADADDRESS}>;
  277. entry = <${UBOOT_FIT_ARM_TRUSTED_FIRMWARE_ENTRYPOINT}>;
  278. compression = "none";
  279. EOF
  280. if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
  281. cat << EOF >> ${UBOOT_ITS}
  282. signature {
  283. algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
  284. key-name-hint = "${SPL_SIGN_KEYNAME}";
  285. };
  286. EOF
  287. fi
  288. cat << EOF >> ${UBOOT_ITS}
  289. };
  290. EOF
  291. }
  292. # Create a ITS file for the tee
  293. uboot_fitimage_tee() {
  294. cat << EOF >> ${UBOOT_ITS}
  295. tee {
  296. description = "Trusted Execution Environment";
  297. data = /incbin/("${UBOOT_FIT_TEE_IMAGE}");
  298. type = "tee";
  299. arch = "${UBOOT_ARCH}";
  300. os = "tee";
  301. load = <${UBOOT_FIT_TEE_LOADADDRESS}>;
  302. entry = <${UBOOT_FIT_TEE_ENTRYPOINT}>;
  303. compression = "none";
  304. EOF
  305. if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
  306. cat << EOF >> ${UBOOT_ITS}
  307. signature {
  308. algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
  309. key-name-hint = "${SPL_SIGN_KEYNAME}";
  310. };
  311. EOF
  312. fi
  313. cat << EOF >> ${UBOOT_ITS}
  314. };
  315. EOF
  316. }
  317. # Create a ITS file for the U-boot FIT, for use when
  318. # we want to sign it so that the SPL can verify it
  319. uboot_fitimage_assemble() {
  320. conf_loadables="\"uboot\""
  321. conf_firmware=""
  322. rm -f ${UBOOT_ITS} ${UBOOT_FITIMAGE_BINARY}
  323. # First we create the ITS script
  324. cat << EOF >> ${UBOOT_ITS}
  325. /dts-v1/;
  326. / {
  327. description = "${UBOOT_FIT_DESC}";
  328. #address-cells = <${UBOOT_FIT_ADDRESS_CELLS}>;
  329. images {
  330. uboot {
  331. description = "U-Boot image";
  332. data = /incbin/("${UBOOT_NODTB_BINARY}");
  333. type = "standalone";
  334. os = "u-boot";
  335. arch = "${UBOOT_ARCH}";
  336. compression = "none";
  337. load = <${UBOOT_FIT_UBOOT_LOADADDRESS}>;
  338. entry = <${UBOOT_FIT_UBOOT_ENTRYPOINT}>;
  339. EOF
  340. if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
  341. cat << EOF >> ${UBOOT_ITS}
  342. signature {
  343. algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
  344. key-name-hint = "${SPL_SIGN_KEYNAME}";
  345. };
  346. EOF
  347. fi
  348. cat << EOF >> ${UBOOT_ITS}
  349. };
  350. fdt {
  351. description = "U-Boot FDT";
  352. data = /incbin/("${UBOOT_DTB_BINARY}");
  353. type = "flat_dt";
  354. arch = "${UBOOT_ARCH}";
  355. compression = "none";
  356. EOF
  357. if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
  358. cat << EOF >> ${UBOOT_ITS}
  359. signature {
  360. algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
  361. key-name-hint = "${SPL_SIGN_KEYNAME}";
  362. };
  363. EOF
  364. fi
  365. cat << EOF >> ${UBOOT_ITS}
  366. };
  367. EOF
  368. if [ "${UBOOT_FIT_TEE}" = "1" ] ; then
  369. conf_loadables="\"tee\", ${conf_loadables}"
  370. uboot_fitimage_tee
  371. fi
  372. if [ "${UBOOT_FIT_ARM_TRUSTED_FIRMWARE}" = "1" ] ; then
  373. conf_loadables="\"atf\", ${conf_loadables}"
  374. uboot_fitimage_atf
  375. fi
  376. if [ -n "${UBOOT_FIT_USER_SETTINGS}" ] ; then
  377. printf "%b" "${UBOOT_FIT_USER_SETTINGS}" >> ${UBOOT_ITS}
  378. fi
  379. if [ -n "${UBOOT_FIT_CONF_USER_LOADABLES}" ] ; then
  380. conf_loadables="${conf_loadables}${UBOOT_FIT_CONF_USER_LOADABLES}"
  381. fi
  382. if [ -n "${UBOOT_FIT_CONF_FIRMWARE}" ] ; then
  383. conf_firmware="firmware = \"${UBOOT_FIT_CONF_FIRMWARE}\";"
  384. fi
  385. cat << EOF >> ${UBOOT_ITS}
  386. };
  387. configurations {
  388. default = "conf";
  389. conf {
  390. description = "Boot with signed U-Boot FIT";
  391. ${conf_firmware}
  392. loadables = ${conf_loadables};
  393. fdt = "fdt";
  394. };
  395. };
  396. };
  397. EOF
  398. #
  399. # Assemble the U-boot FIT image
  400. #
  401. ${UBOOT_MKIMAGE} \
  402. ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \
  403. -f ${UBOOT_ITS} \
  404. ${UBOOT_FITIMAGE_BINARY}
  405. if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
  406. if [ -n "${SPL_DTB_BINARY}" ] ; then
  407. #
  408. # Sign the U-boot FIT image and add public key to SPL dtb
  409. #
  410. ${UBOOT_MKIMAGE_SIGN} \
  411. ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \
  412. -F -k "${SPL_SIGN_KEYDIR}" \
  413. -K "${SPL_DIR}/${SPL_DTB_BINARY}" \
  414. -r ${UBOOT_FITIMAGE_BINARY} \
  415. ${SPL_MKIMAGE_SIGN_ARGS}
  416. # Verify the U-boot FIT image and SPL dtb
  417. ${UBOOT_FIT_CHECK_SIGN} \
  418. -k "${SPL_DIR}/${SPL_DTB_BINARY}" \
  419. -f ${UBOOT_FITIMAGE_BINARY}
  420. cp ${SPL_DIR}/${SPL_DTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED}
  421. else
  422. # Sign the U-boot FIT image
  423. ${UBOOT_MKIMAGE_SIGN} \
  424. ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \
  425. -F -k "${SPL_SIGN_KEYDIR}" \
  426. -r ${UBOOT_FITIMAGE_BINARY} \
  427. ${SPL_MKIMAGE_SIGN_ARGS}
  428. fi
  429. fi
  430. }
  431. uboot_assemble_fitimage_helper() {
  432. type="$1"
  433. binary="$2"
  434. if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_BINARY}" ] ; then
  435. concat_dtb "$type" "$binary"
  436. fi
  437. if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ]; then
  438. uboot_fitimage_assemble
  439. fi
  440. if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
  441. concat_spl_dtb
  442. fi
  443. }
  444. do_uboot_assemble_fitimage() {
  445. if [ -n "${UBOOT_CONFIG}" ]; then
  446. unset i
  447. for config in ${UBOOT_MACHINE}; do
  448. unset j k
  449. i=$(expr $i + 1);
  450. for type in ${UBOOT_CONFIG}; do
  451. j=$(expr $j + 1);
  452. if [ $j -eq $i ]; then
  453. break;
  454. fi
  455. done
  456. builddir="${config}-${type}"
  457. for binary in ${UBOOT_BINARIES}; do
  458. k=$(expr $k + 1);
  459. if [ $k -eq $i ]; then
  460. break;
  461. fi
  462. done
  463. cd ${B}/${builddir}
  464. uboot_assemble_fitimage_helper ${type} ${binary}
  465. done
  466. else
  467. cd ${B}
  468. uboot_assemble_fitimage_helper "" ${UBOOT_BINARY}
  469. fi
  470. }
  471. addtask uboot_assemble_fitimage before do_install do_deploy after do_compile
  472. deploy_helper() {
  473. type="$1"
  474. if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_SIGNED}" ] ; then
  475. deploy_dtb $type
  476. fi
  477. if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ]; then
  478. if [ -n "${type}" ]; then
  479. uboot_its_image="u-boot-its-${type}-${PV}-${PR}"
  480. uboot_fitimage_image="u-boot-fitImage-${type}-${PV}-${PR}"
  481. else
  482. uboot_its_image="${UBOOT_ITS_IMAGE}"
  483. uboot_fitimage_image="${UBOOT_FITIMAGE_IMAGE}"
  484. fi
  485. install -Dm644 ${UBOOT_FITIMAGE_BINARY} ${DEPLOYDIR}/$uboot_fitimage_image
  486. install -Dm644 ${UBOOT_ITS} ${DEPLOYDIR}/$uboot_its_image
  487. if [ -n "${type}" ]; then
  488. ln -sf $uboot_its_image ${DEPLOYDIR}/${UBOOT_ITS_IMAGE}
  489. ln -sf $uboot_fitimage_image ${DEPLOYDIR}/${UBOOT_FITIMAGE_IMAGE}
  490. fi
  491. fi
  492. if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
  493. deploy_spl_dtb $type
  494. fi
  495. }
  496. do_deploy:prepend() {
  497. if [ -n "${UBOOT_CONFIG}" ]; then
  498. unset i j k
  499. for config in ${UBOOT_MACHINE}; do
  500. i=$(expr $i + 1);
  501. for type in ${UBOOT_CONFIG}; do
  502. j=$(expr $j + 1);
  503. if [ $j -eq $i ]; then
  504. builddir="${config}-${type}"
  505. cd ${B}/${builddir}
  506. deploy_helper ${type}
  507. fi
  508. done
  509. unset j
  510. done
  511. unset i
  512. else
  513. cd ${B}
  514. deploy_helper ""
  515. fi
  516. if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_BINARY}" ] ; then
  517. ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY}
  518. ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK}
  519. ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK}
  520. ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_BINARY}
  521. fi
  522. if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then
  523. ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS}
  524. ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS_SYMLINK}
  525. ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_BINARY}
  526. ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_SYMLINK}
  527. fi
  528. if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
  529. ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_SYMLINK}
  530. ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_BINARY}
  531. ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_SYMLINK}
  532. ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_BINARY}
  533. fi
  534. }
  535. do_deploy:append() {
  536. # If we're creating a u-boot fitImage, point u-boot.bin
  537. # symlink since it might get used by image recipes
  538. if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then
  539. ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_BINARY}
  540. ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_SYMLINK}
  541. fi
  542. }