u-boot: Support SPL Verified Boot
cover u-boot: Support SPL Verified Boot
This patch series aims at extending U-Boot's verified boot support to also include SPL signing.
The proposal is to some of the infrastructure (variables, functions) used to sign the Kernel FitImage to more common locations, and then essentially duplicate the method currently used to sign the Kernel fitImage to also sign the U-Boot fitImage.
In the UBOOT_SIGN_ENABLE = "1" scenario, nothing really changes: The Kernel fitImage is created, then signed, and the pubkey is added to u-boot.dtb which is concatenated with the u-boot-nodtb.bin to create the u-boot final image.
In case SPL_SIGN_ENABLE = "1", The U-Boot PN will take care of (re-) creating the U-Boot fitImage (using custom .its script) after compile, sign it, and contatenate the u-boot-spl.dtb (with the public key) with u-boot-spl-nodtb.bin to create the final U-Boot SPl on deploy.
In case both UBOOT_SIGN_ENABLE and SPL_SIGN_ENABLE are set, the Kernel PN will take care of creating and signing the U-Boot fitImage (becase we need to also sign the FDT image containing the Kernel pubkey), and take care of deploying it.
I tested all three scenarios using OpenBMC upstream, and although there might be some areas of improvement (like deploying the new binaries and symlinks with more useful names), it appears to work well.
One caveat is that when moving between the scenarios above, the user might need to remove the tmp/ directory, since there could be a collision for some of the files deployed into the images directory, since the configuration may determine which PN does that.
Reviews, thoughts and comments are very very welcome,
Thanks,
-Klaus
RFC 1/3 u-boot: Move definitions to common locations
Move some definitions from u-boot.inc into uboot-config.bbclass and similarly from kernel-fitimage.bbclass into uboot-sign.bbclass, so that they can be useful when signing the U-boot proper fitimage, for a verified-boot SPL.
--- meta/classes/kernel-fitimage.bbclass | 58 ---------------------------- meta/classes/uboot-config.bbclass | 56 +++++++++++++++++++++++++++ meta/classes/uboot-sign.bbclass | 35 +++++++++++++++++ meta/recipes-bsp/u-boot/u-boot.inc | 46 ---------------------- 4 files changed, 91 insertions(+), 104 deletions(-)
meta/classes/kernel-fitimage.bbclass +0 -58
@@ -53,30 +53,6 @@ python __anonymous () { d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' %s:do_populate_sysroot' % uboot_pn) } -# Options for the device tree compiler passed to mkimage '-D' feature: -UBOOT_MKIMAGE_DTCOPTS ??= "" - -# fitImage Hash Algo -FIT_HASH_ALG ?= "sha256" - -# fitImage Signature Algo -FIT_SIGN_ALG ?= "rsa2048" - -# Generate keys for signing fitImage -FIT_GENERATE_KEYS ?= "0" - -# Size of private key in number of bits -FIT_SIGN_NUMBITS ?= "2048" - -# args to openssl genrsa (Default is just the public exponent) -FIT_KEY_GENRSA_ARGS ?= "-F4" - -# args to openssl req (Default is -batch for non interactive mode and -# -new for new certificate) -FIT_KEY_REQ_ARGS ?= "-batch -new" - -# Standard format for public key certificate -FIT_KEY_SIGN_PKCS ?= "-x509" # Description string FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"
@@ -84,13 +60,6 @@ FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" # Sign individual images as well FIT_SIGN_INDIVIDUAL ?= "0" -# mkimage command -UBOOT_MKIMAGE ?= "uboot-mkimage" -UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" - -# Arguments passed to mkimage for signing -UBOOT_MKIMAGE_SIGN_ARGS ?= "" - # # Emit the fitImage ITS header #
@@ -692,33 +661,6 @@ do_assemble_fitimage_initramfs() { addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs -do_generate_rsa_keys() { - if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then - bbwarn "FIT_GENERATE_KEYS is set to 1 eventhough UBOOT_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used." - fi - - if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then - - # Generate keys only if they don't already exist - if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \ - [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt]; then - - # make directory if it does not already exist - mkdir -p "${UBOOT_SIGN_KEYDIR}" - - echo "Generating RSA private key for signing fitImage" - openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \ - "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ - "${FIT_SIGN_NUMBITS}" - - echo "Generating certificate for signing fitImage" - openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \ - -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ - -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt - fi - fi -} - addtask generate_rsa_keys before do_assemble_fitimage after do_compile kernel_do_deploy[vardepsexclude] = "DATETIME"
meta/classes/uboot-config.bbclass +56 -0
63 lines not on this page · raw message
meta/classes/uboot-sign.bbclass +35 -0
@@ -31,6 +31,9 @@ # # For more details on signature process, please refer to U-Boot documentation. +# We need some variables from u-boot-config +inherit uboot-config + # Signature activation. UBOOT_SIGN_ENABLE ?= "0"
@@ -41,6 +44,38 @@ UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb" UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}" UBOOT_NODTB_BINARY ?= "u-boot-nodtb.${UBOOT_SUFFIX}" UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.${UBOOT_SUFFIX}" +UBOOT_ITS_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.its" +UBOOT_ITS ?= "u-boot.its" +UBOOT_ITS_SYMLINK ?= "u-boot-${MACHINE}.its" +SPL_DIR ?= "${@os.path.dirname(d.getVar("SPL_BINARY")) or '.'}" +SPL_DTB_IMAGE ?= "u-boot-spl-${MACHINE}-${PV}-${PR}.dtb" +SPL_DTB_BINARY ?= "u-boot-spl.dtb" +SPL_DTB_SYMLINK ?= "u-boot-spl-${MACHINE}.dtb" +SPL_NODTB_IMAGE ?= "${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[0]}-nodtb-${MACHINE}-${PV}-${PR}${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[1]}" +SPL_NODTB_BINARY ?= "${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[0]}-nodtb${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[1]}" +SPL_NODTB_SYMLINK ?= "${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[0]}-nodtb-${MACHINE}${@os.path.splitext(d.getVar("SPL_BINARYNAME"))[1]}" + +# fitImage Hash Algo +FIT_HASH_ALG ?= "sha256" + +# fitImage Signature Algo +FIT_SIGN_ALG ?= "rsa2048" + +# Generate keys for signing fitImage +FIT_GENERATE_KEYS ?= "0" + +# Size of private key in number of bits +FIT_SIGN_NUMBITS ?= "2048" + +# args to openssl genrsa (Default is just the public exponent) +FIT_KEY_GENRSA_ARGS ?= "-F4" + +# args to openssl req (Default is -batch for non interactive mode and +# -new for new certificate) +FIT_KEY_REQ_ARGS ?= "-batch -new" + +# Standard format for public key certificate +FIT_KEY_SIGN_PKCS ?= "-x509" # Functions in this bbclass is for u-boot only UBOOT_PN = "${@d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'}"
meta/recipes-bsp/u-boot/u-boot.inc +0 -46
52 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC 2/3 u-boot: Add infrastructure to SPL verified boot
In reply to Klaus Heinrich KiwiAdd the necessary infrastructure to create a U-boot proper fitimage, sign it (using the same keys as the kernel-fitimage), and put the public key in the SPL binary so that verified SPL boot can be accomplished.
--- meta/classes/kernel-fitimage.bbclass | 7 + meta/classes/uboot-sign.bbclass | 306 +++++++++++++++++++++++++-- 2 files changed, 296 insertions(+), 17 deletions(-)
meta/classes/kernel-fitimage.bbclass +7 -0
@@ -694,6 +694,13 @@ kernel_do_deploy_append() { # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed # for u-boot, but we are in kernel env now. install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/" + if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${UBOOT_BINARY}" -a -n "${SPL_DTB_BINARY}" ] ; then + # If we're also signing the uboot fit, now we need to + # deploy it, as well as u-boot-spl.dtb + install -m 0644 ${B}/u-boot-spl-${MACHINE}*.dtb "$deployDir/" + echo "Copying u-boot-fitImage file..." + install -m 0644 ${B}/u-boot-fitImage "$deployDir/u-boot-fitImage-${MACHINE}.${UBOOT_SUFFIX}" + fi fi fi }
meta/classes/uboot-sign.bbclass +289 -17
360 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC 3/3 u-boot: Use a different Key for SPL signing
In reply to Klaus Heinrich KiwiDuplicate the variables governing u-boot signing so that we can have a different set of keys/parameters signing the SPL.
--- meta/classes/uboot-config.bbclass | 2 ++ meta/classes/uboot-sign.bbclass | 55 ++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 11 deletions(-)
meta/classes/uboot-config.bbclass +2 -0
@@ -61,6 +61,7 @@ UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}" # Options for the device tree compiler passed to mkimage '-D' feature: UBOOT_MKIMAGE_DTCOPTS ??= "" +SPL_MKIMAGE_DTCOPTS ??= "" # mkimage command UBOOT_MKIMAGE ?= "uboot-mkimage"
@@ -68,6 +69,7 @@ UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" # Arguments passed to mkimage for signing UBOOT_MKIMAGE_SIGN_ARGS ?= "" +SPL_MKIMAGE_SIGN_ARGS ?= "" python () { ubootmachine = d.getVar("UBOOT_MACHINE")
meta/classes/uboot-sign.bbclass +44 -11
104 lines not on this page · raw message
Signature · 1 line
2.25.1
Hello,
Quoted 2 lines · Klaus Heinrich Kiwi
This patch series aims at extending U-Boot's verified boot support to also include SPL signing.
If u-boot is signed, which part is responsible of the signature verification ?
doesn't each CPU vendor provide it's own way of signing the first component that will be loader by the ROM code ?
so I'm wondering in which case does this apply ?
Quoted 30 lines
The proposal is to some of the infrastructure (variables, functions) used to sign the Kernel FitImage to more common locations, and then essentially duplicate the method currently used to sign the Kernel fitImage to also sign the U-Boot fitImage.
In the
UBOOT_SIGN_ENABLE= "1" scenario, nothing really changes: The Kernel fitImage is created, then signed, and the pubkey is added to u-boot.dtb which is concatenated with the u-boot-nodtb.bin to create the u-boot final image.In case
SPL_SIGN_ENABLE= "1", The U-Boot PN will take care of (re-) creating the U-Boot fitImage (using custom .its script) after compile, sign it, and contatenate the u-boot-spl.dtb (with the public key) with u-boot-spl-nodtb.bin to create the final U-Boot SPl on deploy.In case both
UBOOT_SIGN_ENABLEandSPL_SIGN_ENABLEare set, the Kernel PN will take care of creating and signing the U-Boot fitImage (becase we need to also sign the FDT image containing the Kernel pubkey), and take care of deploying it.I tested all three scenarios using OpenBMC upstream, and although there might be some areas of improvement (like deploying the new binaries and symlinks with more useful names), it appears to work well.
One caveat is that when moving between the scenarios above, the user might need to remove the tmp/ directory, since there could be a collision for some of the files deployed into the images directory, since the configuration may determine which PN does that.
Quoted 10 lines
Reviews, thoughts and comments are very very welcome,
Thanks,
-Klaus
Mit freundlichen Grüßen / Kind regards
Signature · 10 lines
Ayoub Zaki Embedded Systems Consultant Vaihinger Straße 2/1 D-71634 Ludwigsburg Mobile : +4917662901545 Email : [email protected] Homepage : https://embexus.com VAT No. : DE313902634