diff options
-rw-r--r-- | meta/classes/kernel-fitimage.bbclass | 157 |
1 files changed, 134 insertions, 23 deletions
diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass index e0dd215167..3b23138628 100644 --- a/meta/classes/kernel-fitimage.bbclass +++ b/meta/classes/kernel-fitimage.bbclass | |||
@@ -1,5 +1,7 @@ | |||
1 | inherit kernel-uboot kernel-artifact-names uboot-sign | 1 | inherit kernel-uboot kernel-artifact-names uboot-sign |
2 | 2 | ||
3 | KERNEL_IMAGETYPE_REPLACEMENT = "" | ||
4 | |||
3 | python __anonymous () { | 5 | python __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: |
@@ -181,6 +187,43 @@ EOF | |||
181 | } | 187 | } |
182 | 188 | ||
183 | # | 189 | # |
190 | # Emit the fitImage ITS u-boot script section | ||
191 | # | ||
192 | # $1 ... .its filename | ||
193 | # $2 ... Image counter | ||
194 | # $3 ... Path to boot script image | ||
195 | fitimage_emit_section_boot_script() { | ||
196 | |||
197 | bootscr_csum="${FIT_HASH_ALG}" | ||
198 | bootscr_sign_algo="${FIT_SIGN_ALG}" | ||
199 | bootscr_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}" | ||
200 | |||
201 | cat << EOF >> $1 | ||
202 | bootscr-$2 { | ||
203 | description = "U-boot script"; | ||
204 | data = /incbin/("$3"); | ||
205 | type = "script"; | ||
206 | arch = "${UBOOT_ARCH}"; | ||
207 | compression = "none"; | ||
208 | hash-1 { | ||
209 | algo = "$bootscr_csum"; | ||
210 | }; | ||
211 | }; | ||
212 | EOF | ||
213 | |||
214 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$bootscr_sign_keyname" ] ; then | ||
215 | sed -i '$ d' $1 | ||
216 | cat << EOF >> $1 | ||
217 | signature-1 { | ||
218 | algo = "$bootscr_csum,$bootscr_sign_algo"; | ||
219 | key-name-hint = "$bootscr_sign_keyname"; | ||
220 | }; | ||
221 | }; | ||
222 | EOF | ||
223 | fi | ||
224 | } | ||
225 | |||
226 | # | ||
184 | # Emit the fitImage ITS setup section | 227 | # Emit the fitImage ITS setup section |
185 | # | 228 | # |
186 | # $1 ... .its filename | 229 | # $1 ... .its filename |
@@ -250,8 +293,9 @@ EOF | |||
250 | # $2 ... Linux kernel ID | 293 | # $2 ... Linux kernel ID |
251 | # $3 ... DTB image name | 294 | # $3 ... DTB image name |
252 | # $4 ... ramdisk ID | 295 | # $4 ... ramdisk ID |
253 | # $5 ... config ID | 296 | # $5 ... u-boot script ID |
254 | # $6 ... default flag | 297 | # $6 ... config ID |
298 | # $7 ... default flag | ||
255 | fitimage_emit_section_config() { | 299 | fitimage_emit_section_config() { |
256 | 300 | ||
257 | conf_csum="${FIT_HASH_ALG}" | 301 | conf_csum="${FIT_HASH_ALG}" |
@@ -267,6 +311,7 @@ fitimage_emit_section_config() { | |||
267 | kernel_line="" | 311 | kernel_line="" |
268 | fdt_line="" | 312 | fdt_line="" |
269 | ramdisk_line="" | 313 | ramdisk_line="" |
314 | bootscr_line="" | ||
270 | setup_line="" | 315 | setup_line="" |
271 | default_line="" | 316 | default_line="" |
272 | 317 | ||
@@ -289,21 +334,28 @@ fitimage_emit_section_config() { | |||
289 | fi | 334 | fi |
290 | 335 | ||
291 | if [ -n "${5}" ]; then | 336 | if [ -n "${5}" ]; then |
337 | conf_desc="${conf_desc}${sep}u-boot script" | ||
338 | sep=", " | ||
339 | bootscr_line="bootscr = \"bootscr-${5}\";" | ||
340 | fi | ||
341 | |||
342 | if [ -n "${6}" ]; then | ||
292 | conf_desc="${conf_desc}${sep}setup" | 343 | conf_desc="${conf_desc}${sep}setup" |
293 | setup_line="setup = \"setup-${5}\";" | 344 | setup_line="setup = \"setup-${6}\";" |
294 | fi | 345 | fi |
295 | 346 | ||
296 | if [ "${6}" = "1" ]; then | 347 | if [ "${7}" = "1" ]; then |
297 | default_line="default = \"conf-${3}\";" | 348 | default_line="default = \"conf-${3}\";" |
298 | fi | 349 | fi |
299 | 350 | ||
300 | cat << EOF >> ${1} | 351 | cat << EOF >> ${1} |
301 | ${default_line} | 352 | ${default_line} |
302 | conf-${3} { | 353 | conf-${3} { |
303 | description = "${6} ${conf_desc}"; | 354 | description = "${7} ${conf_desc}"; |
304 | ${kernel_line} | 355 | ${kernel_line} |
305 | ${fdt_line} | 356 | ${fdt_line} |
306 | ${ramdisk_line} | 357 | ${ramdisk_line} |
358 | ${bootscr_line} | ||
307 | ${setup_line} | 359 | ${setup_line} |
308 | hash-1 { | 360 | hash-1 { |
309 | algo = "${conf_csum}"; | 361 | algo = "${conf_csum}"; |
@@ -331,6 +383,11 @@ EOF | |||
331 | fi | 383 | fi |
332 | 384 | ||
333 | if [ -n "${5}" ]; then | 385 | if [ -n "${5}" ]; then |
386 | sign_line="${sign_line}${sep}\"bootscr\"" | ||
387 | sep=", " | ||
388 | fi | ||
389 | |||
390 | if [ -n "${6}" ]; then | ||
334 | sign_line="${sign_line}${sep}\"setup\"" | 391 | sign_line="${sign_line}${sep}\"setup\"" |
335 | fi | 392 | fi |
336 | 393 | ||
@@ -363,6 +420,7 @@ fitimage_assemble() { | |||
363 | DTBS="" | 420 | DTBS="" |
364 | ramdiskcount=${3} | 421 | ramdiskcount=${3} |
365 | setupcount="" | 422 | setupcount="" |
423 | bootscr_id="" | ||
366 | rm -f ${1} arch/${ARCH}/boot/${2} | 424 | rm -f ${1} arch/${ARCH}/boot/${2} |
367 | 425 | ||
368 | fitimage_emit_fit_header ${1} | 426 | fitimage_emit_fit_header ${1} |
@@ -373,7 +431,22 @@ fitimage_assemble() { | |||
373 | fitimage_emit_section_maint ${1} imagestart | 431 | fitimage_emit_section_maint ${1} imagestart |
374 | 432 | ||
375 | uboot_prep_kimage | 433 | uboot_prep_kimage |
376 | fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" | 434 | |
435 | if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then | ||
436 | initramfs_bundle_path="arch/"${UBOOT_ARCH}"/boot/"${KERNEL_IMAGETYPE_REPLACEMENT}".initramfs" | ||
437 | if [ -e "${initramfs_bundle_path}" ]; then | ||
438 | |||
439 | # | ||
440 | # Include the kernel/rootfs bundle. | ||
441 | # | ||
442 | |||
443 | fitimage_emit_section_kernel ${1} "${kernelcount}" "${initramfs_bundle_path}" "${linux_comp}" | ||
444 | else | ||
445 | bbwarn "${initramfs_bundle_path} not found." | ||
446 | fi | ||
447 | else | ||
448 | fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" | ||
449 | fi | ||
377 | 450 | ||
378 | # | 451 | # |
379 | # Step 2: Prepare a DTB image section | 452 | # Step 2: Prepare a DTB image section |
@@ -407,7 +480,21 @@ fitimage_assemble() { | |||
407 | fi | 480 | fi |
408 | 481 | ||
409 | # | 482 | # |
410 | # Step 3: Prepare a setup section. (For x86) | 483 | # Step 3: Prepare a u-boot script section |
484 | # | ||
485 | |||
486 | if [ -n "${UBOOT_ENV}" ] && [ -d "${STAGING_DIR_HOST}/boot" ]; then | ||
487 | if [ -e "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY}" ]; then | ||
488 | cp ${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} ${B} | ||
489 | bootscr_id="${UBOOT_ENV_BINARY}" | ||
490 | fitimage_emit_section_boot_script ${1} "${bootscr_id}" ${UBOOT_ENV_BINARY} | ||
491 | else | ||
492 | bbwarn "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} not found." | ||
493 | fi | ||
494 | fi | ||
495 | |||
496 | # | ||
497 | # Step 4: Prepare a setup section. (For x86) | ||
411 | # | 498 | # |
412 | if [ -e arch/${ARCH}/boot/setup.bin ]; then | 499 | if [ -e arch/${ARCH}/boot/setup.bin ]; then |
413 | setupcount=1 | 500 | setupcount=1 |
@@ -415,9 +502,9 @@ fitimage_assemble() { | |||
415 | fi | 502 | fi |
416 | 503 | ||
417 | # | 504 | # |
418 | # Step 4: Prepare a ramdisk section. | 505 | # Step 5: Prepare a ramdisk section. |
419 | # | 506 | # |
420 | if [ "x${ramdiskcount}" = "x1" ] ; then | 507 | if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
421 | # Find and use the first initramfs image archive type we find | 508 | # Find and use the first initramfs image archive type we find |
422 | for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do | 509 | for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do |
423 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" | 510 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" |
@@ -438,7 +525,7 @@ fitimage_assemble() { | |||
438 | fi | 525 | fi |
439 | 526 | ||
440 | # | 527 | # |
441 | # Step 5: Prepare a configurations section | 528 | # Step 6: Prepare a configurations section |
442 | # | 529 | # |
443 | fitimage_emit_section_maint ${1} confstart | 530 | fitimage_emit_section_maint ${1} confstart |
444 | 531 | ||
@@ -449,7 +536,7 @@ fitimage_assemble() { | |||
449 | if [ "${dtb_ext}" = "dtbo" ]; then | 536 | if [ "${dtb_ext}" = "dtbo" ]; then |
450 | fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" | 537 | fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" |
451 | else | 538 | else |
452 | fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`" | 539 | fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "`expr ${i} = ${dtbcount}`" |
453 | fi | 540 | fi |
454 | i=`expr ${i} + 1` | 541 | i=`expr ${i} + 1` |
455 | done | 542 | done |
@@ -460,7 +547,7 @@ fitimage_assemble() { | |||
460 | fitimage_emit_section_maint ${1} fitend | 547 | fitimage_emit_section_maint ${1} fitend |
461 | 548 | ||
462 | # | 549 | # |
463 | # Step 6: Assemble the image | 550 | # Step 7: Assemble the image |
464 | # | 551 | # |
465 | uboot-mkimage \ | 552 | uboot-mkimage \ |
466 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ | 553 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
@@ -468,7 +555,7 @@ fitimage_assemble() { | |||
468 | arch/${ARCH}/boot/${2} | 555 | arch/${ARCH}/boot/${2} |
469 | 556 | ||
470 | # | 557 | # |
471 | # Step 7: Sign the image and add public key to U-Boot dtb | 558 | # Step 8: Sign the image and add public key to U-Boot dtb |
472 | # | 559 | # |
473 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then | 560 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
474 | add_key_to_u_boot="" | 561 | add_key_to_u_boot="" |
@@ -500,7 +587,11 @@ do_assemble_fitimage_initramfs() { | |||
500 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ | 587 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
501 | test -n "${INITRAMFS_IMAGE}" ; then | 588 | test -n "${INITRAMFS_IMAGE}" ; then |
502 | cd ${B} | 589 | cd ${B} |
503 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 | 590 | if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then |
591 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage "" | ||
592 | else | ||
593 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 | ||
594 | fi | ||
504 | fi | 595 | fi |
505 | } | 596 | } |
506 | 597 | ||
@@ -511,22 +602,32 @@ kernel_do_deploy[vardepsexclude] = "DATETIME" | |||
511 | kernel_do_deploy_append() { | 602 | kernel_do_deploy_append() { |
512 | # Update deploy directory | 603 | # Update deploy directory |
513 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then | 604 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
514 | echo "Copying fit-image.its source file..." | 605 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
515 | install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its" | 606 | echo "Copying fit-image.its source file..." |
516 | ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}" | 607 | install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its" |
608 | if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then | ||
609 | ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}" | ||
610 | fi | ||
517 | 611 | ||
518 | echo "Copying linux.bin file..." | 612 | echo "Copying linux.bin file..." |
519 | install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin | 613 | install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin |
520 | ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}" | 614 | if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then |
615 | ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}" | ||
616 | fi | ||
617 | fi | ||
521 | 618 | ||
522 | if [ -n "${INITRAMFS_IMAGE}" ]; then | 619 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
523 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." | 620 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
524 | install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" | 621 | install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" |
525 | ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" | 622 | ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" |
526 | 623 | ||
527 | echo "Copying fitImage-${INITRAMFS_IMAGE} file..." | 624 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
528 | install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin" | 625 | echo "Copying fitImage-${INITRAMFS_IMAGE} file..." |
529 | ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" | 626 | install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin" |
627 | if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then | ||
628 | ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" | ||
629 | fi | ||
630 | fi | ||
530 | fi | 631 | fi |
531 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then | 632 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
532 | # UBOOT_DTB_IMAGE is a realfile, but we can't use | 633 | # UBOOT_DTB_IMAGE is a realfile, but we can't use |
@@ -536,3 +637,13 @@ kernel_do_deploy_append() { | |||
536 | fi | 637 | fi |
537 | fi | 638 | fi |
538 | } | 639 | } |
640 | |||
641 | # The function below performs the following in case of initramfs bundles: | ||
642 | # - Removes do_assemble_fitimage. FIT generation is done through | ||
643 | # do_assemble_fitimage_initramfs. do_assemble_fitimage is not needed | ||
644 | # and should not be part of the tasks to be executed. | ||
645 | python () { | ||
646 | d.appendVarFlag('do_compile', 'vardeps', ' INITRAMFS_IMAGE_BUNDLE') | ||
647 | if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1": | ||
648 | bb.build.deltask('do_assemble_fitimage', d) | ||
649 | } | ||