summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2018-11-30 10:26:14 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-12-08 17:17:01 +0000
commit67628ea66b7d04ed2a726fe58e5fd3ecc314b8da (patch)
tree71b2119246a8e257ec9e54230e4f76135380b6ce
parent3eda00b42e3f0bacedba5bd6e8fbe01b8994b80d (diff)
downloadpoky-67628ea66b7d04ed2a726fe58e5fd3ecc314b8da.tar.gz
uboot-sign.bbclass: fix signature and deployment
Fixed: MACHINE = "beaglebone-yocto" KERNEL_CLASSES += "kernel-fitimage" KERNEL_IMAGETYPE_beaglebone-yocto = "fitImage" UBOOT_MACHINE_beaglebone-yocto = "am335x_boneblack_vboot_config" UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000" UBOOT_SIGN_KEYDIR = "${TOPDIR}/conf" UBOOT_SIGN_KEYNAME = "dev" UBOOT_SIGN_ENABLE = "1" IMAGE_INSTALL_remove = "kernel-image-zimage" $ cd conf $ openssl genrsa -F4 -out dev.key 2048 $ openssl req -batch -new -x509 -key dev.key -out dev.crt $ cd ../ $ bitbake u-boot linux-yocto $ grep signature tmp/deploy/images/beaglebone-yocto/*.dtb Binary file tmp/deploy/images/beaglebone-yocto/u-boot-beaglebone-yocto-2018.07-r0.dtb matches Binary file tmp/deploy/images/beaglebone-yocto/u-boot-beaglebone-yocto.dtb matches Binary file tmp/deploy/images/beaglebone-yocto/u-boot.dtb matches And there would be no signature info when rebuild from sstate: $ bitbake u-boot linux-yocto -cclean $ bitbake u-boot linux-yocto $ grep signature tmp/deploy/images/beaglebone-yocto/*.dtb No result This s because kernel directly edit ${DEPLOY_DIR_IMAGE}/u-boot.dtb, (Note, it is global ${DEPLOY_DIR_IMAGE}, not recipe's DEPLOYDIR), so that the modified info is not in sstate, and would be lost when rebuild from sstate. There are other problems in previouse code: - The u-boot.dtb is provided by u-boot, but edited by kernel during signing, so it should be deployed by kernel rather than u-boot. - The u-boot.do_concat_dtb directly install files to global ${DEPLOY_DIR_IMAGE}, this is incorrect, the ${DEPLOY_DIR_IMAGE} should be installed by do_deploy. - It seems that it assumes do_deploy depends on do_install according the comments, but they have no relationships: # do_concat_dtb is scheduled _before_ do_install as it overwrite the # u-boot.bin in both DEPLOYDIR and DEPLOY_IMAGE_DIR. - The do_concat_dtb should be run after do_compile, but it doesn't have this dependency. Make u-boot install u-boot.dtb to ${datadir}, kernel copies u-boot.dtb from ${STAGING_DATADIR} to ${B} and deploy it can fix the problem. [YOCTO #12112] Reported-by: Christian Andersen <c.andersen@kostal.com> (From OE-Core rev: 493f70cfb177f1d452a13329647a38642bf2b161) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/kernel-fitimage.bbclass17
-rw-r--r--meta/classes/uboot-sign.bbclass95
-rw-r--r--meta/recipes-bsp/u-boot/u-boot.inc2
3 files changed, 69 insertions, 45 deletions
diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass
index 548699e978..718162a861 100644
--- a/meta/classes/kernel-fitimage.bbclass
+++ b/meta/classes/kernel-fitimage.bbclass
@@ -35,7 +35,7 @@ python __anonymous () {
35 # the fitImage: 35 # the fitImage:
36 if d.getVar('UBOOT_SIGN_ENABLE') == "1": 36 if d.getVar('UBOOT_SIGN_ENABLE') == "1":
37 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot' 37 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
38 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_deploy' % uboot_pn) 38 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
39} 39}
40 40
41# Options for the device tree compiler passed to mkimage '-D' feature: 41# Options for the device tree compiler passed to mkimage '-D' feature:
@@ -456,10 +456,17 @@ fitimage_assemble() {
456 # Step 7: Sign the image and add public key to U-Boot dtb 456 # Step 7: Sign the image and add public key to U-Boot dtb
457 # 457 #
458 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then 458 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
459 add_key_to_u_boot=""
460 if [ -n "${UBOOT_DTB_BINARY}" ]; then
461 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
462 # both of them, and don't dereference the symlink.
463 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
464 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
465 fi
459 uboot-mkimage \ 466 uboot-mkimage \
460 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ 467 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
461 -F -k "${UBOOT_SIGN_KEYDIR}" \ 468 -F -k "${UBOOT_SIGN_KEYDIR}" \
462 ${@'-K "${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_BINARY}"' if len('${UBOOT_DTB_BINARY}') else ''} \ 469 $add_key_to_u_boot \
463 -r arch/${ARCH}/boot/${2} 470 -r arch/${ARCH}/boot/${2}
464 fi 471 fi
465} 472}
@@ -505,5 +512,11 @@ kernel_do_deploy_append() {
505 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin 512 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin
506 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME} 513 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}
507 fi 514 fi
515 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
516 # UBOOT_DTB_IMAGE is a realfile, but we can't use
517 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
518 # for u-boot, but we are in kernel env now.
519 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb ${DEPLOYDIR}/
520 fi
508 fi 521 fi
509} 522}
diff --git a/meta/classes/uboot-sign.bbclass b/meta/classes/uboot-sign.bbclass
index afaf46fe14..03100b8a5f 100644
--- a/meta/classes/uboot-sign.bbclass
+++ b/meta/classes/uboot-sign.bbclass
@@ -19,11 +19,15 @@
19# The tasks sequence is set as below, using DEPLOY_IMAGE_DIR as common place to 19# The tasks sequence is set as below, using DEPLOY_IMAGE_DIR as common place to
20# treat the device tree blob: 20# treat the device tree blob:
21# 21#
22# u-boot:do_deploy_dtb 22# * u-boot:do_install_append
23# u-boot:do_deploy 23# Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for
24# virtual/kernel:do_assemble_fitimage 24# signing, and kernel will deploy UBOOT_DTB_BINARY after signs it.
25# u-boot:do_concat_dtb 25#
26# u-boot:do_install 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.
27# 31#
28# For more details on signature process, please refer to U-Boot documentation. 32# For more details on signature process, please refer to U-Boot documentation.
29 33
@@ -38,58 +42,65 @@ UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}"
38UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}" 42UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}"
39UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}" 43UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}"
40 44
41# 45# Functions in this bbclass is for u-boot only
42# Following is relevant only for u-boot recipes: 46UBOOT_PN = "${@d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'}"
43#
44 47
45do_deploy_dtb () { 48concat_dtb() {
46 mkdir -p ${DEPLOYDIR} 49 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" ]; then
47 cd ${DEPLOYDIR} 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
48 55
49 if [ -f ${B}/${UBOOT_DTB_BINARY} ]; then 56 if [ -f ${B}/${UBOOT_NODTB_BINARY} ]; then
50 install ${B}/${UBOOT_DTB_BINARY} ${DEPLOYDIR}/${UBOOT_DTB_IMAGE} 57 install ${B}/${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
51 rm -f ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SYMLINK} 58 ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_SYMLINK}
52 ln -sf ${UBOOT_DTB_IMAGE} ${UBOOT_DTB_SYMLINK} 59 ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_BINARY}
53 ln -sf ${UBOOT_DTB_IMAGE} ${UBOOT_DTB_BINARY} 60 fi
54 fi
55 if [ -f ${B}/${UBOOT_NODTB_BINARY} ]; then
56 install ${B}/${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
57 rm -f ${UBOOT_NODTB_BINARY} ${UBOOT_NODTB_SYMLINK}
58 ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_SYMLINK}
59 ln -sf ${UBOOT_NODTB_IMAGE} ${UBOOT_NODTB_BINARY}
60 fi
61}
62 61
63do_concat_dtb () { 62 # Concatenate U-Boot w/o DTB & DTB with public key
64 # Concatenate U-Boot w/o DTB & DTB with public key 63 # (cf. kernel-fitimage.bbclass for more details)
65 # (cf. kernel-fitimage.bbclass for more details) 64 deployed_uboot_dtb_binary='${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_IMAGE}'
66 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ]; then
67 if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \ 65 if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \
68 [ -e "${DEPLOYDIR}/${UBOOT_DTB_IMAGE}" ]; then 66 [ -e "$deployed_uboot_dtb_binary" ]; then
69 cd ${B} 67 cd ${B}
70 oe_runmake EXT_DTB=${DEPLOYDIR}/${UBOOT_DTB_IMAGE} 68 oe_runmake EXT_DTB=$deployed_uboot_dtb_binary
71 install ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE} 69 install ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
72 install ${B}/${UBOOT_BINARY} ${DEPLOY_DIR_IMAGE}/${UBOOT_IMAGE} 70 elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "$deployed_uboot_dtb_binary" ]; then
73 elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "${DEPLOYDIR}/${UBOOT_DTB_IMAGE}" ]; then
74 cd ${DEPLOYDIR} 71 cd ${DEPLOYDIR}
75 cat ${UBOOT_NODTB_IMAGE} ${UBOOT_DTB_IMAGE} | tee ${B}/${UBOOT_BINARY} > ${UBOOT_IMAGE} 72 cat ${UBOOT_NODTB_IMAGE} $deployed_uboot_dtb_binary | tee ${B}/${UBOOT_BINARY} > ${UBOOT_IMAGE}
76 else 73 else
77 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available." 74 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
78 fi 75 fi
79 fi 76 fi
80} 77}
81 78
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.
81do_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 else
90 bbwarn "${B}/${UBOOT_DTB_BINARY} not found"
91 fi
92 fi
93}
94
82python () { 95python () {
83 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot' 96 if d.getVar('UBOOT_SIGN_ENABLE') == '1' and d.getVar('PN') == d.getVar('UBOOT_PN'):
84 if d.getVar('UBOOT_SIGN_ENABLE') == '1' and d.getVar('PN') == uboot_pn:
85 kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel') 97 kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel')
86 98
87 # u-boot.dtb and u-boot-nodtb.bin are deployed _before_ do_deploy 99 # Make "bitbake u-boot -cdeploy" deploys the signed u-boot.dtb
88 # Thus, do_deploy_setscene will also populate them in DEPLOY_IMAGE_DIR 100 d.appendVarFlag('do_deploy', 'depends', ' %s:do_deploy' % kernel_pn)
89 bb.build.addtask('do_deploy_dtb', 'do_deploy', 'do_compile', d)
90 101
91 # do_concat_dtb is scheduled _before_ do_install as it overwrite the 102 # kernerl's do_deploy is a litle special, so we can't use
92 # u-boot.bin in both DEPLOYDIR and DEPLOY_IMAGE_DIR. 103 # do_deploy_append, otherwise it would override
93 bb.build.addtask('do_concat_dtb', 'do_install', None, d) 104 # kernel_do_deploy.
94 d.appendVarFlag('do_concat_dtb', 'depends', ' %s:do_assemble_fitimage' % kernel_pn) 105 d.appendVarFlag('do_deploy', 'prefuncs', ' concat_dtb')
95} 106}
diff --git a/meta/recipes-bsp/u-boot/u-boot.inc b/meta/recipes-bsp/u-boot/u-boot.inc
index 48fbc57215..bbdbc25cfe 100644
--- a/meta/recipes-bsp/u-boot/u-boot.inc
+++ b/meta/recipes-bsp/u-boot/u-boot.inc
@@ -201,7 +201,7 @@ do_install () {
201 201
202} 202}
203 203
204FILES_${PN} = "/boot ${sysconfdir}" 204FILES_${PN} = "/boot ${sysconfdir} ${datadir}"
205 205
206do_deploy () { 206do_deploy () {
207 if [ -n "${UBOOT_CONFIG}" ] 207 if [ -n "${UBOOT_CONFIG}" ]