summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbdellatif El Khlifi <abdellatif.elkhlifi@arm.com>2021-01-19 10:53:01 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-01-20 00:45:05 +0000
commit8a2f4e143b52109fbd0ee8d792e327d460b8c1e6 (patch)
tree4ad8ed01c9f074f74dcce4338537b8f9e5915816
parent5875637ed24f5186bc82763a6fd88b42a52d5ec8 (diff)
downloadpoky-8a2f4e143b52109fbd0ee8d792e327d460b8c1e6.tar.gz
kernel-fitimage: adding support for Initramfs bundle and u-boot script
This commit adds Initramfs bundle support to the FIT image in addition to u-boot boot script capability. These new features are selectable. In case of Initramfs, the kernel is configured to be bundled with the rootfs in the same binary (ie: zImage-initramfs-<machine>.bin). When the kernel is copied to RAM and executed, it unpacks the Initramfs rootfs. For more information about Initramfs please read: https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt For more details about the Initramfs bundle and boot script implementation please check the kernel-fitimage.bbclass paragraph in Yocto reference or mega manual. Current limitations: - Initramfs bundle FIT support has been tested on ARM 32-bit - The kernel image type in case of ARM 32-bit is zImage Change-Id: I901bfd899e8d733c5b9a2b6645b1d4748f4b1fda (From OE-Core rev: 19fa415c8769a67b52babd80f71d68bf36a21db2) Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/kernel-fitimage.bbclass160
1 files changed, 137 insertions, 23 deletions
diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass
index 9fa302a5c8..87ed8bd892 100644
--- a/meta/classes/kernel-fitimage.bbclass
+++ b/meta/classes/kernel-fitimage.bbclass
@@ -1,5 +1,7 @@
1inherit kernel-uboot kernel-artifact-names uboot-sign 1inherit kernel-uboot kernel-artifact-names uboot-sign
2 2
3KERNEL_IMAGETYPE_REPLACEMENT = ""
4
3python __anonymous () { 5python __anonymous () {
4 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or "" 6 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
5 if 'fitImage' in kerneltypes.split(): 7 if 'fitImage' in kerneltypes.split():
@@ -21,6 +23,8 @@ python __anonymous () {
21 else: 23 else:
22 replacementtype = "zImage" 24 replacementtype = "zImage"
23 25
26 d.setVar("KERNEL_IMAGETYPE_REPLACEMENT", replacementtype)
27
24 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal 28 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
25 # to kernel.bbclass . We have to override it, since we pack zImage 29 # to kernel.bbclass . We have to override it, since we pack zImage
26 # (at least for now) into the fitImage . 30 # (at least for now) into the fitImage .
@@ -45,6 +49,8 @@ python __anonymous () {
45 if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'): 49 if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'):
46 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot' 50 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
47 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn) 51 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
52 if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1":
53 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
48} 54}
49 55
50# Options for the device tree compiler passed to mkimage '-D' feature: 56# Options for the device tree compiler passed to mkimage '-D' feature:
@@ -230,6 +236,43 @@ EOF
230} 236}
231 237
232# 238#
239# Emit the fitImage ITS u-boot script section
240#
241# $1 ... .its filename
242# $2 ... Image counter
243# $3 ... Path to boot script image
244fitimage_emit_section_boot_script() {
245
246 bootscr_csum="${FIT_HASH_ALG}"
247 bootscr_sign_algo="${FIT_SIGN_ALG}"
248 bootscr_sign_keyname="${UBOOT_SIGN_KEYNAME}"
249
250 cat << EOF >> ${1}
251 bootscr@${2} {
252 description = "U-boot script";
253 data = /incbin/("${3}");
254 type = "script";
255 arch = "${UBOOT_ARCH}";
256 compression = "none";
257 hash@1 {
258 algo = "${bootscr_csum}";
259 };
260 };
261EOF
262
263 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${bootscr_sign_keyname}" ] ; then
264 sed -i '$ d' ${1}
265 cat << EOF >> ${1}
266 signature@1 {
267 algo = "${bootscr_csum},${bootscr_sign_algo}";
268 key-name-hint = "${bootscr_sign_keyname}";
269 };
270 };
271EOF
272 fi
273}
274
275#
233# Emit the fitImage ITS setup section 276# Emit the fitImage ITS setup section
234# 277#
235# $1 ... .its filename 278# $1 ... .its filename
@@ -312,8 +355,9 @@ EOF
312# $2 ... Linux kernel ID 355# $2 ... Linux kernel ID
313# $3 ... DTB image name 356# $3 ... DTB image name
314# $4 ... ramdisk ID 357# $4 ... ramdisk ID
315# $5 ... config ID 358# $5 ... u-boot script ID
316# $6 ... default flag 359# $6 ... config ID
360# $7 ... default flag
317fitimage_emit_section_config() { 361fitimage_emit_section_config() {
318 362
319 conf_csum="${FIT_HASH_ALG}" 363 conf_csum="${FIT_HASH_ALG}"
@@ -326,8 +370,9 @@ fitimage_emit_section_config() {
326 kernel_id="${2}" 370 kernel_id="${2}"
327 dtb_image="${3}" 371 dtb_image="${3}"
328 ramdisk_id="${4}" 372 ramdisk_id="${4}"
329 config_id="${5}" 373 bootscr_id="${5}"
330 default_flag="${6}" 374 config_id="${6}"
375 default_flag="${7}"
331 376
332 # Test if we have any DTBs at all 377 # Test if we have any DTBs at all
333 sep="" 378 sep=""
@@ -336,6 +381,7 @@ fitimage_emit_section_config() {
336 kernel_line="" 381 kernel_line=""
337 fdt_line="" 382 fdt_line=""
338 ramdisk_line="" 383 ramdisk_line=""
384 bootscr_line=""
339 setup_line="" 385 setup_line=""
340 default_line="" 386 default_line=""
341 387
@@ -365,6 +411,12 @@ fitimage_emit_section_config() {
365 ramdisk_line="ramdisk = \"ramdisk@${ramdisk_id}\";" 411 ramdisk_line="ramdisk = \"ramdisk@${ramdisk_id}\";"
366 fi 412 fi
367 413
414 if [ -n "${bootscr_id}" ]; then
415 conf_desc="${conf_desc}${sep}u-boot script"
416 sep=", "
417 bootscr_line="bootscr = \"bootscr@${bootscr_id}\";"
418 fi
419
368 if [ -n "${config_id}" ]; then 420 if [ -n "${config_id}" ]; then
369 conf_desc="${conf_desc}${sep}setup" 421 conf_desc="${conf_desc}${sep}setup"
370 setup_line="setup = \"setup@${config_id}\";" 422 setup_line="setup = \"setup@${config_id}\";"
@@ -387,6 +439,7 @@ fitimage_emit_section_config() {
387 ${kernel_line} 439 ${kernel_line}
388 ${fdt_line} 440 ${fdt_line}
389 ${ramdisk_line} 441 ${ramdisk_line}
442 ${bootscr_line}
390 ${setup_line} 443 ${setup_line}
391 hash@1 { 444 hash@1 {
392 algo = "${conf_csum}"; 445 algo = "${conf_csum}";
@@ -413,6 +466,11 @@ EOF
413 sep=", " 466 sep=", "
414 fi 467 fi
415 468
469 if [ -n "${bootscr_id}" ]; then
470 sign_line="${sign_line}${sep}\"bootscr\""
471 sep=", "
472 fi
473
416 if [ -n "${config_id}" ]; then 474 if [ -n "${config_id}" ]; then
417 sign_line="${sign_line}${sep}\"setup\"" 475 sign_line="${sign_line}${sep}\"setup\""
418 fi 476 fi
@@ -445,6 +503,7 @@ fitimage_assemble() {
445 DTBS="" 503 DTBS=""
446 ramdiskcount=${3} 504 ramdiskcount=${3}
447 setupcount="" 505 setupcount=""
506 bootscr_id=""
448 rm -f ${1} arch/${ARCH}/boot/${2} 507 rm -f ${1} arch/${ARCH}/boot/${2}
449 508
450 fitimage_emit_fit_header ${1} 509 fitimage_emit_fit_header ${1}
@@ -455,7 +514,22 @@ fitimage_assemble() {
455 fitimage_emit_section_maint ${1} imagestart 514 fitimage_emit_section_maint ${1} imagestart
456 515
457 uboot_prep_kimage 516 uboot_prep_kimage
458 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" 517
518 if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then
519 initramfs_bundle_path="arch/"${UBOOT_ARCH}"/boot/"${KERNEL_IMAGETYPE_REPLACEMENT}".initramfs"
520 if [ -e "${initramfs_bundle_path}" ]; then
521
522 #
523 # Include the kernel/rootfs bundle.
524 #
525
526 fitimage_emit_section_kernel ${1} "${kernelcount}" "${initramfs_bundle_path}" "${linux_comp}"
527 else
528 bbwarn "${initramfs_bundle_path} not found."
529 fi
530 else
531 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
532 fi
459 533
460 # 534 #
461 # Step 2: Prepare a DTB image section 535 # Step 2: Prepare a DTB image section
@@ -489,7 +563,21 @@ fitimage_assemble() {
489 fi 563 fi
490 564
491 # 565 #
492 # Step 3: Prepare a setup section. (For x86) 566 # Step 3: Prepare a u-boot script section
567 #
568
569 if [ -n "${UBOOT_ENV}" ] && [ -d "${STAGING_DIR_HOST}/boot" ]; then
570 if [ -e "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY}" ]; then
571 cp ${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} ${B}
572 bootscr_id="${UBOOT_ENV_BINARY}"
573 fitimage_emit_section_boot_script ${1} "${bootscr_id}" ${UBOOT_ENV_BINARY}
574 else
575 bbwarn "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} not found."
576 fi
577 fi
578
579 #
580 # Step 4: Prepare a setup section. (For x86)
493 # 581 #
494 if [ -e arch/${ARCH}/boot/setup.bin ]; then 582 if [ -e arch/${ARCH}/boot/setup.bin ]; then
495 setupcount=1 583 setupcount=1
@@ -497,9 +585,9 @@ fitimage_assemble() {
497 fi 585 fi
498 586
499 # 587 #
500 # Step 4: Prepare a ramdisk section. 588 # Step 5: Prepare a ramdisk section.
501 # 589 #
502 if [ "x${ramdiskcount}" = "x1" ] ; then 590 if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
503 # Find and use the first initramfs image archive type we find 591 # Find and use the first initramfs image archive type we find
504 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do 592 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
505 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" 593 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
@@ -520,13 +608,15 @@ fitimage_assemble() {
520 fi 608 fi
521 609
522 # 610 #
523 # Step 5: Prepare a configurations section 611 # Step 6: Prepare a configurations section
524 # 612 #
525 fitimage_emit_section_maint ${1} confstart 613 fitimage_emit_section_maint ${1} confstart
526 614
527 # kernel-fitimage.bbclass currently only supports a single kernel (no less or 615 # kernel-fitimage.bbclass currently only supports a single kernel (no less or
528 # more) to be added to the FIT image along with 0 or more device trees and 616 # more) to be added to the FIT image along with 0 or more device trees and
529 # 0 or 1 ramdisk. 617 # 0 or 1 ramdisk.
618 # It is also possible to include an initramfs bundle (kernel and rootfs in one binary)
619 # When the initramfs bundle is used ramdisk is disabled.
530 # If a device tree is to be part of the FIT image, then select 620 # If a device tree is to be part of the FIT image, then select
531 # the default configuration to be used is based on the dtbcount. If there is 621 # the default configuration to be used is based on the dtbcount. If there is
532 # no dtb present than select the default configuation to be based on 622 # no dtb present than select the default configuation to be based on
@@ -538,13 +628,13 @@ fitimage_assemble() {
538 if [ "${dtb_ext}" = "dtbo" ]; then 628 if [ "${dtb_ext}" = "dtbo" ]; then
539 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" 629 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`"
540 else 630 else
541 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`" 631 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
542 fi 632 fi
543 i=`expr ${i} + 1` 633 i=`expr ${i} + 1`
544 done 634 done
545 else 635 else
546 defaultconfigcount=1 636 defaultconfigcount=1
547 fitimage_emit_section_config ${1} "${kernelcount}" "" "${ramdiskcount}" "${setupcount}" "${defaultconfigcount}" 637 fitimage_emit_section_config ${1} "${kernelcount}" "" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "${defaultconfigcount}"
548 fi 638 fi
549 639
550 fitimage_emit_section_maint ${1} sectend 640 fitimage_emit_section_maint ${1} sectend
@@ -552,7 +642,7 @@ fitimage_assemble() {
552 fitimage_emit_section_maint ${1} fitend 642 fitimage_emit_section_maint ${1} fitend
553 643
554 # 644 #
555 # Step 6: Assemble the image 645 # Step 7: Assemble the image
556 # 646 #
557 ${UBOOT_MKIMAGE} \ 647 ${UBOOT_MKIMAGE} \
558 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ 648 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
@@ -560,7 +650,7 @@ fitimage_assemble() {
560 arch/${ARCH}/boot/${2} 650 arch/${ARCH}/boot/${2}
561 651
562 # 652 #
563 # Step 7: Sign the image and add public key to U-Boot dtb 653 # Step 8: Sign the image and add public key to U-Boot dtb
564 # 654 #
565 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then 655 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
566 add_key_to_u_boot="" 656 add_key_to_u_boot=""
@@ -592,7 +682,11 @@ do_assemble_fitimage_initramfs() {
592 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ 682 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
593 test -n "${INITRAMFS_IMAGE}" ; then 683 test -n "${INITRAMFS_IMAGE}" ; then
594 cd ${B} 684 cd ${B}
595 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 685 if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then
686 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage ""
687 else
688 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
689 fi
596 fi 690 fi
597} 691}
598 692
@@ -631,22 +725,27 @@ kernel_do_deploy[vardepsexclude] = "DATETIME"
631kernel_do_deploy_append() { 725kernel_do_deploy_append() {
632 # Update deploy directory 726 # Update deploy directory
633 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then 727 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
634 echo "Copying fit-image.its source file..."
635 install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its"
636 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}"
637 728
638 echo "Copying linux.bin file..." 729 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
639 install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin 730 echo "Copying fit-image.its source file..."
640 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}" 731 install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its"
732 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}"
733
734 echo "Copying linux.bin file..."
735 install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin
736 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}"
737 fi
641 738
642 if [ -n "${INITRAMFS_IMAGE}" ]; then 739 if [ -n "${INITRAMFS_IMAGE}" ]; then
643 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." 740 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
644 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" 741 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its"
645 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" 742 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
646 743
647 echo "Copying fitImage-${INITRAMFS_IMAGE} file..." 744 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
648 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin" 745 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
649 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" 746 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin"
747 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
748 fi
650 fi 749 fi
651 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then 750 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
652 # UBOOT_DTB_IMAGE is a realfile, but we can't use 751 # UBOOT_DTB_IMAGE is a realfile, but we can't use
@@ -656,3 +755,18 @@ kernel_do_deploy_append() {
656 fi 755 fi
657 fi 756 fi
658} 757}
758
759# The function below performs the following in case of initramfs bundles:
760# - Removes do_assemble_fitimage. FIT generation is done through
761# do_assemble_fitimage_initramfs. do_assemble_fitimage is not needed
762# and should not be part of the tasks to be executed.
763# - Since do_generate_rsa_keys is inserted by default
764# between do_compile and do_assemble_fitimage, this is
765# not suitable in case of initramfs bundles. do_generate_rsa_keys
766# should be between do_bundle_initramfs and do_assemble_fitimage_initramfs.
767python () {
768 if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1":
769 bb.build.deltask('do_assemble_fitimage', d)
770 bb.build.deltask('generate_rsa_keys', d)
771 bb.build.addtask('generate_rsa_keys', 'do_assemble_fitimage_initramfs', 'do_bundle_initramfs', d)
772} \ No newline at end of file