uboot-sign.bbclass 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # This file is part of U-Boot verified boot support and is intended to be
  2. # inherited from u-boot recipe and from kernel-fitimage.bbclass.
  3. #
  4. # The signature procedure requires the user to generate an RSA key and
  5. # certificate in a directory and to define the following variable:
  6. #
  7. # UBOOT_SIGN_KEYDIR = "/keys/directory"
  8. # UBOOT_SIGN_KEYNAME = "dev" # keys name in keydir (eg. "dev.crt", "dev.key")
  9. # UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
  10. # UBOOT_SIGN_ENABLE = "1"
  11. #
  12. # As verified boot depends on fitImage generation, following is also required:
  13. #
  14. # KERNEL_CLASSES ?= " kernel-fitimage "
  15. # KERNEL_IMAGETYPE ?= "fitImage"
  16. #
  17. # The signature support is limited to the use of CONFIG_OF_SEPARATE in U-Boot.
  18. #
  19. # The tasks sequence is set as below, using DEPLOY_IMAGE_DIR as common place to
  20. # treat the device tree blob:
  21. #
  22. # u-boot:do_deploy_dtb
  23. # u-boot:do_deploy
  24. # virtual/kernel:do_assemble_fitimage
  25. # u-boot:do_concat_dtb
  26. # u-boot:do_install
  27. #
  28. # For more details on signature process, please refer to U-Boot documentation.
  29. # Signature activation.
  30. UBOOT_SIGN_ENABLE ?= "0"
  31. # Default value for deployment filenames.
  32. UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb"
  33. UBOOT_DTB_BINARY ?= "u-boot.dtb"
  34. UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb"
  35. UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}"
  36. UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}"
  37. UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}"
  38. #
  39. # Following is relevant only for u-boot recipes:
  40. #
  41. do_deploy_dtb () {
  42. mkdir -p ${DEPLOYDIR}
  43. cd ${DEPLOYDIR}
  44. if [ -f ${B}/${UBOOT_DTB_BINARY} ]; then
  45. install ${B}/${UBOOT_DTB_BINARY} ${DEPLOYDIR}/${UBOOT_DTB_IMAGE}
  46. rm -f ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SYMLINK}
  47. ln -sf ${UBOOT_DTB_IMAGE} ${UBOOT_DTB_SYMLINK}
  48. ln -sf ${UBOOT_DTB_IMAGE} ${UBOOT_DTB_BINARY}
  49. fi
  50. if [ -f ${B}/${UBOOT_NODTB_BINARY} ]; then
  51. install ${B}/${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
  52. rm -f ${UBOOT_NODTB_BINARY} ${UBOOT_NODTB_SYMLINK}
  53. ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_SYMLINK}
  54. ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_BINARY}
  55. fi
  56. }
  57. do_concat_dtb () {
  58. # Concatenate U-Boot w/o DTB & DTB with public key
  59. # (cf. kernel-fitimage.bbclass for more details)
  60. if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ]; then
  61. if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \
  62. [ -e "${DEPLOYDIR}/${UBOOT_DTB_IMAGE}" ]; then
  63. cd ${B}
  64. oe_runmake EXT_DTB=${DEPLOYDIR}/${UBOOT_DTB_IMAGE}
  65. install ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
  66. install ${B}/${UBOOT_BINARY} ${DEPLOY_DIR_IMAGE}/${UBOOT_IMAGE}
  67. elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "${DEPLOYDIR}/${UBOOT_DTB_IMAGE}" ]; then
  68. cd ${DEPLOYDIR}
  69. cat ${UBOOT_NODTB_IMAGE} ${UBOOT_DTB_IMAGE} | tee ${B}/${UBOOT_BINARY} > ${UBOOT_IMAGE}
  70. else
  71. bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
  72. fi
  73. fi
  74. }
  75. python () {
  76. uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
  77. if d.getVar('UBOOT_SIGN_ENABLE') == '1' and d.getVar('PN') == uboot_pn:
  78. kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel')
  79. # u-boot.dtb and u-boot-nodtb.bin are deployed _before_ do_deploy
  80. # Thus, do_deploy_setscene will also populate them in DEPLOY_IMAGE_DIR
  81. bb.build.addtask('do_deploy_dtb', 'do_deploy', 'do_compile', d)
  82. # do_concat_dtb is scheduled _before_ do_install as it overwrite the
  83. # u-boot.bin in both DEPLOYDIR and DEPLOY_IMAGE_DIR.
  84. bb.build.addtask('do_concat_dtb', 'do_install', None, d)
  85. d.appendVarFlag('do_concat_dtb', 'depends', ' %s:do_assemble_fitimage' % kernel_pn)
  86. }