diff options
author | Sean Anderson <sean.anderson@seco.com> | 2022-10-21 19:37:26 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-10-26 12:28:40 +0100 |
commit | d6858c9f45d25cfec6defec17f62139593ae87f3 (patch) | |
tree | ac07edf4808e2d172481e13e861f148e8ccb6cb3 /meta/lib/oeqa/selftest/cases | |
parent | 930dc57fc8dcbf9ca8a3a431a8c4c02901f63182 (diff) | |
download | poky-d6858c9f45d25cfec6defec17f62139593ae87f3.tar.gz |
u-boot: Rework signing to remove interdependencies
The U-Boot signing code is a bit of a mess. The problem is that mkimage
determines the public keys to embed into a device tree based on an image
that it is signing. This results in all sorts of contortions: U-Boot has to
be available to the kernel recipe so that it can have the correct public
keys embedded. Then, the signed U-Boot has to be made available to U-Boot's
do_deploy. This same dance is then repeated for SPL. To complicate matters,
signing for U-Boot and U-Boot SPL is optional, so the whole process must be
seamlessly integrated with a non-signed build.
The complexity and interdependency of this process makes it difficult to
extend. For example, it is not possible to install a signed U-Boot binary
into the root filesystem. This is first because u-boot:do_install must run
before linux:do_assemble_fitimage, which must run before u-boot:do_deploy.
But aside from infrastructure issues, installing a signed U-Boot also can't
happen, because the kernel image might have an embedded initramfs
(containing the signed U-Boot).
However, all of this complexity is accidental. It is not necessary to embed
the public keys into U-Boot and sign the kernel in one fell swoop. Instead,
we can sign the kernel, stage it, and sign the staged kernel again to embed
the public keys into U-Boot [1]. This twice-signed kernel serves only to
provide the correct parameters to mkimage, and does not have to be
installed or deployed. By cutting the dependency of
linux:do_assemble_fitimage on u-boot:do_install, we can drastically
simplify the build process, making it much more extensible.
The process of doing this conversion is a bit involved, since the U-Boot
and Linux recipes are so intertwined at the moment. The most major change
is that uboot-sign is no longer inherited by kernel-fitimage. Similarly,
all U-Boot-related tasks have been removed from kernel-fitimage. We add a
new step to the install task to stage the kernel in /sysroot-only. The
logic to disable assemble_fitimage has been removed. We always assemble it,
even if the final fitImage will use a bundled initramfs, because U-Boot
will need it.
On the U-Boot side, much of the churn stems from multiple config support.
Previously, we took a fairly ad-hoc approach to UBOOT_CONFIG and
UBOOT_MACHINE, introducing for loops wherever we needed to deal with them.
However, I have chosen to use a much more structured approach. Each task
which needs to use the build directory uses the following pseudocode:
do_mytask() {
if ${UBOOT_CONFIG}; then
for config, type in zip(${UBOOT_CONFIG}, ${UBOOT_MACHINE}); do
cd ${config}
mytask_helper ${type}
done
else
cd ${B}
mytask_helper ""
fi
}
By explicitly placing the work in mytask_helper, we make it easier to
ensure that everything is covered, and we also allow bbappends files to
more easily extend the task (as otherwise they would need to reimplement
the loop themselves).
[1] It doesn't particularly matter what we sign. Any FIT will do, but I
chose the kernel's because we already went to the trouble of setting it up
with the correct hashes and signatures. In the future, we could create a
"dummy" image and sign that instead, but it would probably have to happen
in the kernel recipe anyway (so we have access to the appropriate
variables).
(From OE-Core rev: 5e12dc911d0c541f43aa6d0c046fb87e8b7c1f7e)
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/fitimage.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/meta/lib/oeqa/selftest/cases/fitimage.py b/meta/lib/oeqa/selftest/cases/fitimage.py index 14267dbaaa..1570d54dfb 100644 --- a/meta/lib/oeqa/selftest/cases/fitimage.py +++ b/meta/lib/oeqa/selftest/cases/fitimage.py | |||
@@ -277,8 +277,8 @@ FIT_SIGN_INDIVIDUAL = "1" | |||
277 | """ | 277 | """ |
278 | self.write_config(config) | 278 | self.write_config(config) |
279 | 279 | ||
280 | # The U-Boot fitImage is created as part of linux recipe | 280 | # The U-Boot fitImage is created as part of the U-Boot recipe |
281 | bitbake("virtual/kernel") | 281 | bitbake("virtual/bootloader") |
282 | 282 | ||
283 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 283 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
284 | machine = get_bb_var('MACHINE') | 284 | machine = get_bb_var('MACHINE') |
@@ -350,7 +350,8 @@ UBOOT_LOADADDRESS = "0x80080000" | |||
350 | UBOOT_ENTRYPOINT = "0x80080000" | 350 | UBOOT_ENTRYPOINT = "0x80080000" |
351 | UBOOT_FIT_DESC = "A model description" | 351 | UBOOT_FIT_DESC = "A model description" |
352 | KERNEL_IMAGETYPES += " fitImage " | 352 | KERNEL_IMAGETYPES += " fitImage " |
353 | KERNEL_CLASSES = " kernel-fitimage test-mkimage-wrapper " | 353 | KERNEL_CLASSES = " kernel-fitimage " |
354 | INHERIT += "test-mkimage-wrapper" | ||
354 | UBOOT_SIGN_ENABLE = "1" | 355 | UBOOT_SIGN_ENABLE = "1" |
355 | FIT_GENERATE_KEYS = "1" | 356 | FIT_GENERATE_KEYS = "1" |
356 | UBOOT_SIGN_KEYDIR = "${TOPDIR}/signing-keys" | 357 | UBOOT_SIGN_KEYDIR = "${TOPDIR}/signing-keys" |
@@ -361,8 +362,8 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c 'a smart U-Boot comment'" | |||
361 | """ | 362 | """ |
362 | self.write_config(config) | 363 | self.write_config(config) |
363 | 364 | ||
364 | # The U-Boot fitImage is created as part of linux recipe | 365 | # The U-Boot fitImage is created as part of the U-Boot recipe |
365 | bitbake("virtual/kernel") | 366 | bitbake("virtual/bootloader") |
366 | 367 | ||
367 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 368 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
368 | machine = get_bb_var('MACHINE') | 369 | machine = get_bb_var('MACHINE') |
@@ -432,7 +433,8 @@ UBOOT_MACHINE = "am57xx_evm_defconfig" | |||
432 | SPL_BINARY = "MLO" | 433 | SPL_BINARY = "MLO" |
433 | # The kernel-fitimage class is a dependency even if we're only | 434 | # The kernel-fitimage class is a dependency even if we're only |
434 | # creating/signing the U-Boot fitImage | 435 | # creating/signing the U-Boot fitImage |
435 | KERNEL_CLASSES = " kernel-fitimage test-mkimage-wrapper " | 436 | KERNEL_CLASSES = " kernel-fitimage" |
437 | INHERIT += "test-mkimage-wrapper" | ||
436 | # Enable creation and signing of the U-Boot fitImage | 438 | # Enable creation and signing of the U-Boot fitImage |
437 | UBOOT_FITIMAGE_ENABLE = "1" | 439 | UBOOT_FITIMAGE_ENABLE = "1" |
438 | SPL_SIGN_ENABLE = "1" | 440 | SPL_SIGN_ENABLE = "1" |
@@ -451,8 +453,8 @@ UBOOT_FIT_HASH_ALG = "sha256" | |||
451 | """ | 453 | """ |
452 | self.write_config(config) | 454 | self.write_config(config) |
453 | 455 | ||
454 | # The U-Boot fitImage is created as part of linux recipe | 456 | # The U-Boot fitImage is created as part of the U-Boot recipe |
455 | bitbake("virtual/kernel") | 457 | bitbake("virtual/bootloader") |
456 | 458 | ||
457 | image_type = "core-image-minimal" | 459 | image_type = "core-image-minimal" |
458 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 460 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
@@ -540,7 +542,7 @@ UBOOT_FIT_HASH_ALG = "sha256" | |||
540 | self.assertEqual(len(value), 512, 'Signature value for section %s not expected length' % signed_section) | 542 | self.assertEqual(len(value), 512, 'Signature value for section %s not expected length' % signed_section) |
541 | 543 | ||
542 | # Check for SPL_MKIMAGE_SIGN_ARGS | 544 | # Check for SPL_MKIMAGE_SIGN_ARGS |
543 | result = runCmd('bitbake -e virtual/kernel | grep ^T=') | 545 | result = runCmd('bitbake -e virtual/bootloader | grep ^T=') |
544 | tempdir = result.output.split('=', 1)[1].strip().strip('') | 546 | tempdir = result.output.split('=', 1)[1].strip().strip('') |
545 | result = runCmd('grep "a smart U-Boot comment" %s/run.do_uboot_assemble_fitimage' % tempdir, ignore_status=True) | 547 | result = runCmd('grep "a smart U-Boot comment" %s/run.do_uboot_assemble_fitimage' % tempdir, ignore_status=True) |
546 | self.assertEqual(result.status, 0, 'SPL_MKIMAGE_SIGN_ARGS value did not get used') | 548 | self.assertEqual(result.status, 0, 'SPL_MKIMAGE_SIGN_ARGS value did not get used') |
@@ -595,7 +597,8 @@ UBOOT_EXTLINUX = "0" | |||
595 | UBOOT_FIT_GENERATE_KEYS = "1" | 597 | UBOOT_FIT_GENERATE_KEYS = "1" |
596 | UBOOT_FIT_HASH_ALG = "sha256" | 598 | UBOOT_FIT_HASH_ALG = "sha256" |
597 | KERNEL_IMAGETYPES += " fitImage " | 599 | KERNEL_IMAGETYPES += " fitImage " |
598 | KERNEL_CLASSES = " kernel-fitimage test-mkimage-wrapper " | 600 | KERNEL_CLASSES = " kernel-fitimage " |
601 | INHERIT += "test-mkimage-wrapper" | ||
599 | UBOOT_SIGN_ENABLE = "1" | 602 | UBOOT_SIGN_ENABLE = "1" |
600 | FIT_GENERATE_KEYS = "1" | 603 | FIT_GENERATE_KEYS = "1" |
601 | UBOOT_SIGN_KEYDIR = "${TOPDIR}/signing-keys" | 604 | UBOOT_SIGN_KEYDIR = "${TOPDIR}/signing-keys" |
@@ -605,8 +608,8 @@ FIT_SIGN_INDIVIDUAL = "1" | |||
605 | """ | 608 | """ |
606 | self.write_config(config) | 609 | self.write_config(config) |
607 | 610 | ||
608 | # The U-Boot fitImage is created as part of linux recipe | 611 | # The U-Boot fitImage is created as part of the U-Boot recipe |
609 | bitbake("virtual/kernel") | 612 | bitbake("virtual/bootloader") |
610 | 613 | ||
611 | image_type = "core-image-minimal" | 614 | image_type = "core-image-minimal" |
612 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 615 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
@@ -694,7 +697,7 @@ FIT_SIGN_INDIVIDUAL = "1" | |||
694 | self.assertEqual(len(value), 512, 'Signature value for section %s not expected length' % signed_section) | 697 | self.assertEqual(len(value), 512, 'Signature value for section %s not expected length' % signed_section) |
695 | 698 | ||
696 | # Check for SPL_MKIMAGE_SIGN_ARGS | 699 | # Check for SPL_MKIMAGE_SIGN_ARGS |
697 | result = runCmd('bitbake -e virtual/kernel | grep ^T=') | 700 | result = runCmd('bitbake -e virtual/bootloader | grep ^T=') |
698 | tempdir = result.output.split('=', 1)[1].strip().strip('') | 701 | tempdir = result.output.split('=', 1)[1].strip().strip('') |
699 | result = runCmd('grep "a smart cascaded U-Boot comment" %s/run.do_uboot_assemble_fitimage' % tempdir, ignore_status=True) | 702 | result = runCmd('grep "a smart cascaded U-Boot comment" %s/run.do_uboot_assemble_fitimage' % tempdir, ignore_status=True) |
700 | self.assertEqual(result.status, 0, 'SPL_MKIMAGE_SIGN_ARGS value did not get used') | 703 | self.assertEqual(result.status, 0, 'SPL_MKIMAGE_SIGN_ARGS value did not get used') |