kernel-fitimage extensions
cover kernel-fitimage extensions
Some minor extensions to the kernel-fitimage class, mostly for signing, with associated oe-selftest tests.
(Separate docs patch is queued and will follow once these changes are pass review).
The following changes since commit 6012fffa99b600956ea1076d60e050d0737b4c4f:
systemd: Fix reallocarray check (2020-12-16 19:44:45 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib paule/fitimage
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=paule/fitimage
Easwar Hariharan (1):
classes/kernel-fitimage: make fitimage_emit_section_config more
readable
Luca Boccassi (1):
classes/kernel-fitimage: add ability to sign individual images
Paul Eggleton (6):
classes/kernel-fitimage: add variable for description classes/kernel-fitimage: allow substituting mkimage command classes/kernel-fitimage: add ability to add additional signing options
oe-selftest: move FIT image tests to their own module
oe-selftest: fitimage: Test for FIT_DESC
oe-selftest: fitimage: add test for signing FIT images
meta-selftest/classes/test-mkimage-wrapper.bbclass | 19 ++ meta/classes/kernel-fitimage.bbclass | 114 +++++++--- meta/lib/oeqa/selftest/cases/fitimage.py | 233 +++++++++++++++++++++ meta/lib/oeqa/selftest/cases/imagefeatures.py | 74 ------- 4 files changed, 339 insertions(+), 101 deletions(-) create mode 100644 meta-selftest/classes/test-mkimage-wrapper.bbclass create mode 100644 meta/lib/oeqa/selftest/cases/fitimage.py
Signature · 1 line
1.8.3.1
PATCH 1/8 classes/kernel-fitimage: add variable for description
From: Paul Eggleton <[email protected]>
Add a FIT_DESC variable to make it possible to change how the description is set in the FIT image.
--- meta/classes/kernel-fitimage.bbclass | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
meta/classes/kernel-fitimage.bbclass +4 -1
@@ -72,6 +72,9 @@ 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}" + # # Emit the fitImage ITS header #
@@ -81,7 +84,7 @@ fitimage_emit_fit_header() { /dts-v1/; / { - description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; + description = "${FIT_DESC}"; #address-cells = <1>; EOF }
Signature · 1 line
1.8.3.1
PATCH 2/8 classes/kernel-fitimage: make fitimage_emit_section_config more readable
In reply to Paul EggletonFrom: Easwar Hariharan <[email protected]>
fitimage_emit_section_config() has a number of arguments, add named variables to make the function a bit more readable.
--- meta/classes/kernel-fitimage.bbclass | 53 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-)
meta/classes/kernel-fitimage.bbclass +30 -23
@@ -273,6 +273,13 @@ fitimage_emit_section_config() { conf_sign_keyname="${UBOOT_SIGN_KEYNAME}" fi + its_file="${1}" + kernel_id="${2}" + dtb_image="${3}" + ramdisk_id="${4}" + config_id="${5}" + default_flag="${6}" + # Test if we have any DTBs at all sep="" conf_desc=""
@@ -285,49 +292,49 @@ fitimage_emit_section_config() { # conf node name is selected based on dtb ID if it is present, # otherwise its selected based on kernel ID - if [ -n "${3}" ]; then - conf_node=$conf_node${3} + if [ -n "${dtb_image}" ]; then + conf_node=$conf_node${dtb_image} else - conf_node=$conf_node${2} + conf_node=$conf_node${kernel_id} fi - if [ -n "${2}" ]; then + if [ -n "${kernel_id}" ]; then conf_desc="Linux kernel" sep=", " - kernel_line="kernel = \"kernel@${2}\";" + kernel_line="kernel = \"kernel@${kernel_id}\";" fi - if [ -n "${3}" ]; then + if [ -n "${dtb_image}" ]; then conf_desc="${conf_desc}${sep}FDT blob" sep=", " - fdt_line="fdt = \"fdt@${3}\";" + fdt_line="fdt = \"fdt@${dtb_image}\";" fi - if [ -n "${4}" ]; then + if [ -n "${ramdisk_id}" ]; then conf_desc="${conf_desc}${sep}ramdisk" sep=", " - ramdisk_line="ramdisk = \"ramdisk@${4}\";" + ramdisk_line="ramdisk = \"ramdisk@${ramdisk_id}\";" fi - if [ -n "${5}" ]; then + if [ -n "${config_id}" ]; then conf_desc="${conf_desc}${sep}setup" - setup_line="setup = \"setup@${5}\";" + setup_line="setup = \"setup@${config_id}\";" fi - if [ "${6}" = "1" ]; then + if [ "${default_flag}" = "1" ]; then # default node is selected based on dtb ID if it is present, # otherwise its selected based on kernel ID - if [ -n "${3}" ]; then - default_line="default = \"conf@${3}\";" + if [ -n "${dtb_image}" ]; then + default_line="default = \"conf@${dtb_image}\";" else - default_line="default = \"conf@${2}\";" + default_line="default = \"conf@${kernel_id}\";" fi fi - cat << EOF >> ${1} + cat << EOF >> ${its_file} ${default_line} $conf_node { - description = "${6} ${conf_desc}"; + description = "${default_flag} ${conf_desc}"; ${kernel_line} ${fdt_line} ${ramdisk_line}
@@ -342,28 +349,28 @@ EOF sign_line="sign-images = " sep="" - if [ -n "${2}" ]; then + if [ -n "${kernel_id}" ]; then sign_line="${sign_line}${sep}\"kernel\"" sep=", " fi - if [ -n "${3}" ]; then + if [ -n "${dtb_image}" ]; then sign_line="${sign_line}${sep}\"fdt\"" sep=", " fi - if [ -n "${4}" ]; then + if [ -n "${ramdisk_id}" ]; then sign_line="${sign_line}${sep}\"ramdisk\"" sep=", " fi - if [ -n "${5}" ]; then + if [ -n "${config_id}" ]; then sign_line="${sign_line}${sep}\"setup\"" fi sign_line="${sign_line};" - cat << EOF >> ${1} + cat << EOF >> ${its_file} signature@1 { algo = "${conf_csum},${conf_sign_algo}"; key-name-hint = "${conf_sign_keyname}";
@@ -372,7 +379,7 @@ EOF EOF fi - cat << EOF >> ${1} + cat << EOF >> ${its_file} }; EOF }
Signature · 1 line
1.8.3.1
PATCH 3/8 classes/kernel-fitimage: allow substituting mkimage command
In reply to Paul EggletonFrom: Paul Eggleton <[email protected]>
Add a UBOOT_MKIMAGE and UBOOT_MKIMAGE_SIGN variables to allow specifying an alternative uboot-mkimage executable (or wrapper script/function).
--- meta/classes/kernel-fitimage.bbclass | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
meta/classes/kernel-fitimage.bbclass +6 -2
@@ -75,6 +75,10 @@ FIT_KEY_SIGN_PKCS ?= "-x509" # Description string FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" +# mkimage command +UBOOT_MKIMAGE ?= "uboot-mkimage" +UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" + # # Emit the fitImage ITS header #
@@ -505,7 +509,7 @@ fitimage_assemble() { # # Step 6: Assemble the image # - uboot-mkimage \ + ${UBOOT_MKIMAGE} \ ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ -f ${1} \ arch/${ARCH}/boot/${2}
@@ -521,7 +525,7 @@ fitimage_assemble() { cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B} add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}" fi - uboot-mkimage \ + ${UBOOT_MKIMAGE_SIGN} \ ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ -F -k "${UBOOT_SIGN_KEYDIR}" \ $add_key_to_u_boot \
Signature · 1 line
1.8.3.1
PATCH 4/8 classes/kernel-fitimage: add ability to add additional signing options
In reply to Paul EggletonFrom: Paul Eggleton <[email protected]>
Add a UBOOT_MKIMAGE_SIGN_ARGS variable to enable passing additional options to uboot-mkimage when it is run the second time to perform signing.
--- meta/classes/kernel-fitimage.bbclass | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
meta/classes/kernel-fitimage.bbclass +5 -1
@@ -79,6 +79,9 @@ FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" UBOOT_MKIMAGE ?= "uboot-mkimage" UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" +# Arguments passed to mkimage for signing +UBOOT_MKIMAGE_SIGN_ARGS ?= "" + # # Emit the fitImage ITS header #
@@ -529,7 +532,8 @@ fitimage_assemble() { ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ -F -k "${UBOOT_SIGN_KEYDIR}" \ $add_key_to_u_boot \ - -r arch/${ARCH}/boot/${2} + -r arch/${ARCH}/boot/${2} \ + ${UBOOT_MKIMAGE_SIGN_ARGS} fi }
Signature · 1 line
1.8.3.1
PATCH 5/8 classes/kernel-fitimage: add ability to sign individual images
In reply to Paul EggletonFrom: Luca Boccassi <[email protected]>
Add the ability to have the kernel, dtb and ramdisk individually signed by setting FIT_SIGN_INDIVIDUAL = "1". This could be useful if you are intending to verify signatures before using kexec for example.
--- meta/classes/kernel-fitimage.bbclass | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
meta/classes/kernel-fitimage.bbclass +42 -0
@@ -75,6 +75,9 @@ FIT_KEY_SIGN_PKCS ?= "-x509" # Description string 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}"
@@ -142,6 +145,8 @@ EOF fitimage_emit_section_kernel() { kernel_csum="${FIT_HASH_ALG}" + kernel_sign_algo="${FIT_SIGN_ALG}" + kernel_sign_keyname="${UBOOT_SIGN_KEYNAME}" ENTRYPOINT="${UBOOT_ENTRYPOINT}" if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
@@ -164,6 +169,17 @@ fitimage_emit_section_kernel() { }; }; EOF + + if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${kernel_sign_keyname}" ] ; then + sed -i '$ d' ${1} + cat << EOF >> ${1} + signature@1 { + algo = "${kernel_csum},${kernel_sign_algo}"; + key-name-hint = "${kernel_sign_keyname}"; + }; + }; +EOF + fi } #
@@ -175,6 +191,8 @@ EOF fitimage_emit_section_dtb() { dtb_csum="${FIT_HASH_ALG}" + dtb_sign_algo="${FIT_SIGN_ALG}" + dtb_sign_keyname="${UBOOT_SIGN_KEYNAME}" dtb_loadline="" dtb_ext=${DTB##*.}
@@ -198,6 +216,17 @@ fitimage_emit_section_dtb() { }; }; EOF + + if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${dtb_sign_keyname}" ] ; then + sed -i '$ d' ${1} + cat << EOF >> ${1} + signature@1 { + algo = "${dtb_csum},${dtb_sign_algo}"; + key-name-hint = "${dtb_sign_keyname}"; + }; + }; +EOF + fi } #
@@ -236,6 +265,8 @@ EOF fitimage_emit_section_ramdisk() { ramdisk_csum="${FIT_HASH_ALG}" + ramdisk_sign_algo="${FIT_SIGN_ALG}" + ramdisk_sign_keyname="${UBOOT_SIGN_KEYNAME}" ramdisk_loadline="" ramdisk_entryline=""
@@ -261,6 +292,17 @@ fitimage_emit_section_ramdisk() { }; }; EOF + + if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${ramdisk_sign_keyname}" ] ; then + sed -i '$ d' ${1} + cat << EOF >> ${1} + signature@1 { + algo = "${ramdisk_csum},${ramdisk_sign_algo}"; + key-name-hint = "${ramdisk_sign_keyname}"; + }; + }; +EOF + fi } #
Signature · 1 line
1.8.3.1
PATCH 6/8 oe-selftest: move FIT image tests to their own module
In reply to Paul EggletonFrom: Paul Eggleton <[email protected]>
I'm about to add an additional test, and on the assumption that we might also add more in future it seems reasonable to have the tests in their own module.
--- meta/lib/oeqa/selftest/cases/fitimage.py | 84 +++++++++++++++++++++++++++ meta/lib/oeqa/selftest/cases/imagefeatures.py | 74 ----------------------- 2 files changed, 84 insertions(+), 74 deletions(-) create mode 100644 meta/lib/oeqa/selftest/cases/fitimage.py
meta/lib/oeqa/selftest/cases/fitimage.py new file +84 -0
@@ -0,0 +1,84 @@ +# +# SPDX-License-Identifier: MIT +# + +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu +import os +import json + +class FitImageTests(OESelftestTestCase): + + def test_fit_image(self): + """ + Summary: Check if FIT image and Image Tree Source (its) are built + and the Image Tree Source has the correct fields. + Expected: 1. fitImage and fitImage-its can be built + 2. The type, load address, entrypoint address and + default values of kernel and ramdisk are as expected + in the Image Tree Source. Not all the fields are tested, + only the key fields that wont vary between different + architectures. + Product: oe-core + Author: Usama Arif <[email protected]> + """ + config = """ +# Enable creation of fitImage +KERNEL_IMAGETYPE = "Image" +KERNEL_IMAGETYPES += " fitImage " +KERNEL_CLASSES = " kernel-fitimage " + +# RAM disk variables including load address and entrypoint for kernel and RAM disk +IMAGE_FSTYPES += "cpio.gz" +INITRAMFS_IMAGE = "core-image-minimal" +UBOOT_RD_LOADADDRESS = "0x88000000" +UBOOT_RD_ENTRYPOINT = "0x88000000" +UBOOT_LOADADDRESS = "0x80080000" +UBOOT_ENTRYPOINT = "0x80080000" +""" + self.write_config(config) + + # fitImage is created as part of linux recipe + bitbake("virtual/kernel") + + image_type = "core-image-minimal" + deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') + machine = get_bb_var('MACHINE') + fitimage_its_path = os.path.join(deploy_dir_image, + "fitImage-its-%s-%s-%s" % (image_type, machine, machine)) + fitimage_path = os.path.join(deploy_dir_image, + "fitImage-%s-%s-%s" % (image_type, machine, machine)) + + self.assertTrue(os.path.exists(fitimage_its_path), + "%s image tree source doesn't exist" % (fitimage_its_path)) + self.assertTrue(os.path.exists(fitimage_path), + "%s FIT image doesn't exist" % (fitimage_path)) + + # Check that the type, load address, entrypoint address and default + # values for kernel and ramdisk in Image Tree Source are as expected. + # The order of fields in the below array is important. Not all the + # fields are tested, only the key fields that wont vary between + # different architectures. + its_field_check = ['type = "kernel";', + 'load = <0x80080000>;', + 'entry = <0x80080000>;', + 'type = "ramdisk";', + 'load = <0x88000000>;', + 'entry = <0x88000000>;', + 'default = "conf@1";', + 'kernel = "kernel@1";', + 'ramdisk = "ramdisk@1";' + ] + + with open(fitimage_its_path) as its_file: + field_index = 0 + for line in its_file: + if field_index == len(its_field_check): + break + if its_field_check[field_index] in line: + field_index +=1 + + if field_index != len(its_field_check): # if its equal, the test passed + self.assertTrue(field_index == len(its_field_check), + "Fields in Image Tree Source File %s did not match, error in finding %s" + % (fitimage_its_path, its_field_check[field_index]))
meta/lib/oeqa/selftest/cases/imagefeatures.py +0 -74
80 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 7/8 oe-selftest: fitimage: Test for FIT_DESC
In reply to Paul EggletonFrom: Paul Eggleton <[email protected]>
Add verification of FIT_DESC to the existing test for kernel-fitimage.
--- meta/lib/oeqa/selftest/cases/fitimage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/fitimage.py +4 -1
@@ -35,6 +35,7 @@ UBOOT_RD_LOADADDRESS = "0x88000000" UBOOT_RD_ENTRYPOINT = "0x88000000" UBOOT_LOADADDRESS = "0x80080000" UBOOT_ENTRYPOINT = "0x80080000" +FIT_DESC = "A model description" """ self.write_config(config)
@@ -59,7 +60,9 @@ UBOOT_ENTRYPOINT = "0x80080000" # The order of fields in the below array is important. Not all the # fields are tested, only the key fields that wont vary between # different architectures. - its_field_check = ['type = "kernel";', + its_field_check = [ + 'description = "A model description";', + 'type = "kernel";', 'load = <0x80080000>;', 'entry = <0x80080000>;', 'type = "ramdisk";',
Signature · 1 line
1.8.3.1
PATCH 8/8 oe-selftest: fitimage: add test for signing FIT images
In reply to Paul EggletonFrom: Paul Eggleton <[email protected]>
Add a new test to verify signing FIT images. Also includes testing for the newly introduced FIT_SIGN_INDIVIDUAL, UBOOT_MKIMAGE, UBOOT_MKIMAGE_SIGN, and UBOOT_MKIMAGE_SIGN_ARGS variables.
--- meta-selftest/classes/test-mkimage-wrapper.bbclass | 19 +++ meta/lib/oeqa/selftest/cases/fitimage.py | 146 +++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 meta-selftest/classes/test-mkimage-wrapper.bbclass
meta-selftest/classes/test-mkimage-wrapper.bbclass new file +19 -0
@@ -0,0 +1,19 @@ +# Class to test UBOOT_MKIMAGE and UBOOT_MKIMAGE_SIGN +# (in conjunction with kernel-fitimage.bbclass) +# +# SPDX-License-Identifier: MIT +# + +UBOOT_MKIMAGE = "test_mkimage_wrapper" +UBOOT_MKIMAGE_SIGN = "test_mkimage_signing_wrapper" + +test_mkimage_wrapper() { + echo "### uboot-mkimage wrapper message" + uboot-mkimage "$@" +} + +test_mkimage_signing_wrapper() { + echo "### uboot-mkimage signing wrapper message" + uboot-mkimage "$@" +} +
meta/lib/oeqa/selftest/cases/fitimage.py +146 -0
155 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Hi,
I have reviewed the patches and they look good to me.
Thanks,
Usama
Quoted 31 lines · Paul Eggleton
Some minor extensions to the kernel-fitimage class, mostly for signing, with associated oe-selftest tests.
(Separate docs patch is queued and will follow once these changes are pass review).
The following changes since commit
6012fffa99b600956ea1076d60e050d0737b4c4f:systemd: Fix reallocarray check (2020-12-16 19:44:45 +0000)are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribpaule/fitimage
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=paule/fitimageEaswar Hariharan (1):
classes/kernel-fitimage: makefitimage_emit_section_configmore
readableLuca Boccassi (1):
classes/kernel-fitimage: add ability to sign individual imagesPaul Eggleton (6):
classes/kernel-fitimage: add variable for description classes/kernel-fitimage: allow substituting mkimage command classes/kernel-fitimage: add ability to add additional signing options
oe-selftest: move FIT image tests to their own module
oe-selftest: fitimage: Test forFIT_DESC
oe-selftest: fitimage: add test for signing FIT images
Quoted 8 lines
meta-selftest/classes/test-mkimage-wrapper.bbclass | 19 ++ meta/classes/kernel-fitimage.bbclass | 114 +++++++--- meta/lib/oeqa/selftest/cases/fitimage.py | 233 +++++++++++++++++++++ meta/lib/oeqa/selftest/cases/imagefeatures.py | 74 ------- 4 files changed, 339 insertions(+), 101 deletions(-)create mode 100644 meta-selftest/classes/test-mkimage-wrapper.bbclass create mode 100644
meta/lib/oeqa/selftest/cases/fitimage.py
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.