blob: 713196df41604949b8c8662a4c7aa38dfd334410 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# 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 Bishop19323692019-04-05 15:28:33 -040022# * 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 Williamsc0f7c042017-02-23 20:41:17 -060031#
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032# For more details on signature process, please refer to U-Boot documentation.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033
34# Signature activation.
35UBOOT_SIGN_ENABLE ?= "0"
36
37# Default value for deployment filenames.
38UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb"
39UBOOT_DTB_BINARY ?= "u-boot.dtb"
40UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb"
41UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}"
42UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}"
43UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}"
44
Brad Bishop19323692019-04-05 15:28:33 -040045# Functions in this bbclass is for u-boot only
46UBOOT_PN = "${@d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060047
Brad Bishopc342db32019-05-15 21:57:59 -040048concat_dtb_helper() {
49 if [ -e "${UBOOT_DTB_BINARY}" ]; then
50 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY}
51 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK}
52 fi
53
54 if [ -f "${UBOOT_NODTB_BINARY}" ]; then
55 install ${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
56 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK}
57 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_BINARY}
58 fi
59
60 # Concatenate U-Boot w/o DTB & DTB with public key
61 # (cf. kernel-fitimage.bbclass for more details)
62 deployed_uboot_dtb_binary='${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_IMAGE}'
63 if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \
64 [ -e "$deployed_uboot_dtb_binary" ]; then
65 oe_runmake EXT_DTB=$deployed_uboot_dtb_binary
66 install ${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
67 elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "$deployed_uboot_dtb_binary" ]; then
68 cd ${DEPLOYDIR}
Brad Bishop96ff1982019-08-19 13:50:42 -040069 cat ${UBOOT_NODTB_IMAGE} $deployed_uboot_dtb_binary | tee ${B}/${CONFIG_B_PATH}/${UBOOT_BINARY} > ${UBOOT_IMAGE}
Brad Bishopc342db32019-05-15 21:57:59 -040070 else
71 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
72 fi
73}
74
Brad Bishop19323692019-04-05 15:28:33 -040075concat_dtb() {
Brad Bishopc342db32019-05-15 21:57:59 -040076 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" -a -n "${UBOOT_DTB_BINARY}" ]; then
Brad Bishop19323692019-04-05 15:28:33 -040077 mkdir -p ${DEPLOYDIR}
Brad Bishopc342db32019-05-15 21:57:59 -040078 if [ -n "${UBOOT_CONFIG}" ]; then
79 for config in ${UBOOT_MACHINE}; do
Brad Bishop96ff1982019-08-19 13:50:42 -040080 CONFIG_B_PATH="${config}"
Brad Bishopc342db32019-05-15 21:57:59 -040081 cd ${B}/${config}
82 concat_dtb_helper
83 done
84 else
Brad Bishop96ff1982019-08-19 13:50:42 -040085 CONFIG_B_PATH=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060086 cd ${B}
Brad Bishopc342db32019-05-15 21:57:59 -040087 concat_dtb_helper
Patrick Williamsc0f7c042017-02-23 20:41:17 -060088 fi
89 fi
90}
91
Brad Bishop19323692019-04-05 15:28:33 -040092# Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for
93# signing, and kernel will deploy UBOOT_DTB_BINARY after signs it.
Brad Bishopc342db32019-05-15 21:57:59 -040094install_helper() {
95 if [ -f "${UBOOT_DTB_BINARY}" ]; then
96 install -d ${D}${datadir}
97 # UBOOT_DTB_BINARY is a symlink to UBOOT_DTB_IMAGE, so we
98 # need both of them.
99 install ${UBOOT_DTB_BINARY} ${D}${datadir}/${UBOOT_DTB_IMAGE}
100 ln -sf ${UBOOT_DTB_IMAGE} ${D}${datadir}/${UBOOT_DTB_BINARY}
101 else
102 bbwarn "${UBOOT_DTB_BINARY} not found"
103 fi
104}
105
Brad Bishop19323692019-04-05 15:28:33 -0400106do_install_append() {
Brad Bishopc342db32019-05-15 21:57:59 -0400107 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" -a -n "${UBOOT_DTB_BINARY}" ]; then
108 if [ -n "${UBOOT_CONFIG}" ]; then
109 for config in ${UBOOT_MACHINE}; do
110 cd ${B}/${config}
111 install_helper
112 done
113 else
114 cd ${B}
115 install_helper
Brad Bishop19323692019-04-05 15:28:33 -0400116 fi
117 fi
118}
119
Andrew Geissler475cb722020-07-10 16:00:51 -0500120do_deploy_prepend_pn-${UBOOT_PN}() {
121 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ]; then
122 concat_dtb
123 fi
124}
125
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126python () {
Brad Bishop15ae2502019-06-18 21:44:24 -0400127 if d.getVar('UBOOT_SIGN_ENABLE') == '1' and d.getVar('PN') == d.getVar('UBOOT_PN') and d.getVar('UBOOT_DTB_BINARY'):
Brad Bishop19323692019-04-05 15:28:33 -0400128 kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129
Brad Bishop19323692019-04-05 15:28:33 -0400130 # Make "bitbake u-boot -cdeploy" deploys the signed u-boot.dtb
131 d.appendVarFlag('do_deploy', 'depends', ' %s:do_deploy' % kernel_pn)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132}