Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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 | # |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 22 | # * u-boot:do_install_append |
| 23 | # Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for |
| 24 | # signing, and kernel will deploy UBOOT_DTB_BINARY after signs it. |
| 25 | # |
| 26 | # * virtual/kernel:do_assemble_fitimage |
| 27 | # Sign the image |
| 28 | # |
| 29 | # * u-boot:do_deploy[postfuncs] |
| 30 | # Deploy files like UBOOT_DTB_IMAGE, UBOOT_DTB_SYMLINK and others. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 31 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | # For more details on signature process, please refer to U-Boot documentation. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | |
| 34 | # Signature activation. |
| 35 | UBOOT_SIGN_ENABLE ?= "0" |
| 36 | |
| 37 | # Default value for deployment filenames. |
| 38 | UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb" |
| 39 | UBOOT_DTB_BINARY ?= "u-boot.dtb" |
| 40 | UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb" |
| 41 | UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}" |
| 42 | UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}" |
| 43 | UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}" |
| 44 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 45 | # Functions in this bbclass is for u-boot only |
| 46 | UBOOT_PN = "${@d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | concat_dtb() { |
| 49 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" ]; then |
| 50 | mkdir -p ${DEPLOYDIR} |
| 51 | if [ -e ${B}/${UBOOT_DTB_BINARY} ]; then |
| 52 | ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY} |
| 53 | ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK} |
| 54 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 56 | if [ -f ${B}/${UBOOT_NODTB_BINARY} ]; then |
| 57 | install ${B}/${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE} |
| 58 | ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_SYMLINK} |
| 59 | ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_BINARY} |
| 60 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 61 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 62 | # Concatenate U-Boot w/o DTB & DTB with public key |
| 63 | # (cf. kernel-fitimage.bbclass for more details) |
| 64 | deployed_uboot_dtb_binary='${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_IMAGE}' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 65 | if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 66 | [ -e "$deployed_uboot_dtb_binary" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 67 | cd ${B} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 68 | oe_runmake EXT_DTB=$deployed_uboot_dtb_binary |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 69 | install ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 70 | elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "$deployed_uboot_dtb_binary" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 71 | cd ${DEPLOYDIR} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 72 | cat ${UBOOT_NODTB_IMAGE} $deployed_uboot_dtb_binary | tee ${B}/${UBOOT_BINARY} > ${UBOOT_IMAGE} |
| 73 | elif [ -n "${UBOOT_DTB_BINARY}" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 74 | bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available." |
| 75 | fi |
| 76 | fi |
| 77 | } |
| 78 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 79 | # Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for |
| 80 | # signing, and kernel will deploy UBOOT_DTB_BINARY after signs it. |
| 81 | do_install_append() { |
| 82 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" ]; then |
| 83 | if [ -f ${B}/${UBOOT_DTB_BINARY} ]; then |
| 84 | install -d ${D}${datadir} |
| 85 | # UBOOT_DTB_BINARY is a symlink to UBOOT_DTB_IMAGE, so we |
| 86 | # need both of them. |
| 87 | install ${B}/${UBOOT_DTB_BINARY} ${D}${datadir}/${UBOOT_DTB_IMAGE} |
| 88 | ln -sf ${UBOOT_DTB_IMAGE} ${D}${datadir}/${UBOOT_DTB_BINARY} |
| 89 | elif [ -n "${UBOOT_DTB_BINARY}" ]; then |
| 90 | bbwarn "${B}/${UBOOT_DTB_BINARY} not found" |
| 91 | fi |
| 92 | fi |
| 93 | } |
| 94 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 95 | python () { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 96 | if d.getVar('UBOOT_SIGN_ENABLE') == '1' and d.getVar('PN') == d.getVar('UBOOT_PN'): |
| 97 | kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 98 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 99 | # Make "bitbake u-boot -cdeploy" deploys the signed u-boot.dtb |
| 100 | d.appendVarFlag('do_deploy', 'depends', ' %s:do_deploy' % kernel_pn) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 101 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 102 | # kernerl's do_deploy is a litle special, so we can't use |
| 103 | # do_deploy_append, otherwise it would override |
| 104 | # kernel_do_deploy. |
| 105 | d.appendVarFlag('do_deploy', 'prefuncs', ' concat_dtb') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 106 | } |