summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel-fitimage.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/kernel-fitimage.bbclass')
-rw-r--r--meta/classes/kernel-fitimage.bbclass772
1 files changed, 0 insertions, 772 deletions
diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass
deleted file mode 100644
index f5082c93df..0000000000
--- a/meta/classes/kernel-fitimage.bbclass
+++ /dev/null
@@ -1,772 +0,0 @@
1inherit kernel-uboot kernel-artifact-names uboot-sign
2
3KERNEL_IMAGETYPE_REPLACEMENT = ""
4
5python __anonymous () {
6 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
7 if 'fitImage' in kerneltypes.split():
8 depends = d.getVar("DEPENDS")
9 depends = "%s u-boot-tools-native dtc-native" % depends
10 d.setVar("DEPENDS", depends)
11
12 uarch = d.getVar("UBOOT_ARCH")
13 if uarch == "arm64":
14 replacementtype = "Image"
15 elif uarch == "riscv":
16 replacementtype = "Image"
17 elif uarch == "mips":
18 replacementtype = "vmlinuz.bin"
19 elif uarch == "x86":
20 replacementtype = "bzImage"
21 elif uarch == "microblaze":
22 replacementtype = "linux.bin"
23 else:
24 replacementtype = "zImage"
25
26 d.setVar("KERNEL_IMAGETYPE_REPLACEMENT", replacementtype)
27
28 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
29 # to kernel.bbclass . We have to override it, since we pack zImage
30 # (at least for now) into the fitImage .
31 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
32 if 'fitImage' in typeformake.split():
33 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', replacementtype))
34
35 image = d.getVar('INITRAMFS_IMAGE')
36 if image:
37 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
38
39 #check if there are any dtb providers
40 providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
41 if providerdtb:
42 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot')
43 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot')
44 d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree")
45
46 # Verified boot will sign the fitImage and append the public key to
47 # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling
48 # the fitImage:
49 if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'):
50 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
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)
54}
55
56# Options for the device tree compiler passed to mkimage '-D' feature:
57UBOOT_MKIMAGE_DTCOPTS ??= ""
58
59# fitImage Hash Algo
60FIT_HASH_ALG ?= "sha256"
61
62# fitImage Signature Algo
63FIT_SIGN_ALG ?= "rsa2048"
64
65# Generate keys for signing fitImage
66FIT_GENERATE_KEYS ?= "0"
67
68# Size of private key in number of bits
69FIT_SIGN_NUMBITS ?= "2048"
70
71# args to openssl genrsa (Default is just the public exponent)
72FIT_KEY_GENRSA_ARGS ?= "-F4"
73
74# args to openssl req (Default is -batch for non interactive mode and
75# -new for new certificate)
76FIT_KEY_REQ_ARGS ?= "-batch -new"
77
78# Standard format for public key certificate
79FIT_KEY_SIGN_PKCS ?= "-x509"
80
81# Description string
82FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"
83
84# Sign individual images as well
85FIT_SIGN_INDIVIDUAL ?= "0"
86
87# mkimage command
88UBOOT_MKIMAGE ?= "uboot-mkimage"
89UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}"
90
91# Arguments passed to mkimage for signing
92UBOOT_MKIMAGE_SIGN_ARGS ?= ""
93
94#
95# Emit the fitImage ITS header
96#
97# $1 ... .its filename
98fitimage_emit_fit_header() {
99 cat << EOF >> ${1}
100/dts-v1/;
101
102/ {
103 description = "${FIT_DESC}";
104 #address-cells = <1>;
105EOF
106}
107
108#
109# Emit the fitImage section bits
110#
111# $1 ... .its filename
112# $2 ... Section bit type: imagestart - image section start
113# confstart - configuration section start
114# sectend - section end
115# fitend - fitimage end
116#
117fitimage_emit_section_maint() {
118 case $2 in
119 imagestart)
120 cat << EOF >> ${1}
121
122 images {
123EOF
124 ;;
125 confstart)
126 cat << EOF >> ${1}
127
128 configurations {
129EOF
130 ;;
131 sectend)
132 cat << EOF >> ${1}
133 };
134EOF
135 ;;
136 fitend)
137 cat << EOF >> ${1}
138};
139EOF
140 ;;
141 esac
142}
143
144#
145# Emit the fitImage ITS kernel section
146#
147# $1 ... .its filename
148# $2 ... Image counter
149# $3 ... Path to kernel image
150# $4 ... Compression type
151fitimage_emit_section_kernel() {
152
153 kernel_csum="${FIT_HASH_ALG}"
154 kernel_sign_algo="${FIT_SIGN_ALG}"
155 kernel_sign_keyname="${UBOOT_SIGN_KEYNAME}"
156
157 ENTRYPOINT="${UBOOT_ENTRYPOINT}"
158 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
159 ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \
160 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'`
161 fi
162
163 cat << EOF >> ${1}
164 kernel-${2} {
165 description = "Linux kernel";
166 data = /incbin/("${3}");
167 type = "kernel";
168 arch = "${UBOOT_ARCH}";
169 os = "linux";
170 compression = "${4}";
171 load = <${UBOOT_LOADADDRESS}>;
172 entry = <${ENTRYPOINT}>;
173 hash-1 {
174 algo = "${kernel_csum}";
175 };
176 };
177EOF
178
179 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${kernel_sign_keyname}" ] ; then
180 sed -i '$ d' ${1}
181 cat << EOF >> ${1}
182 signature-1 {
183 algo = "${kernel_csum},${kernel_sign_algo}";
184 key-name-hint = "${kernel_sign_keyname}";
185 };
186 };
187EOF
188 fi
189}
190
191#
192# Emit the fitImage ITS DTB section
193#
194# $1 ... .its filename
195# $2 ... Image counter
196# $3 ... Path to DTB image
197fitimage_emit_section_dtb() {
198
199 dtb_csum="${FIT_HASH_ALG}"
200 dtb_sign_algo="${FIT_SIGN_ALG}"
201 dtb_sign_keyname="${UBOOT_SIGN_KEYNAME}"
202
203 dtb_loadline=""
204 dtb_ext=${DTB##*.}
205 if [ "${dtb_ext}" = "dtbo" ]; then
206 if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then
207 dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;"
208 fi
209 elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then
210 dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;"
211 fi
212 cat << EOF >> ${1}
213 fdt-${2} {
214 description = "Flattened Device Tree blob";
215 data = /incbin/("${3}");
216 type = "flat_dt";
217 arch = "${UBOOT_ARCH}";
218 compression = "none";
219 ${dtb_loadline}
220 hash-1 {
221 algo = "${dtb_csum}";
222 };
223 };
224EOF
225
226 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${dtb_sign_keyname}" ] ; then
227 sed -i '$ d' ${1}
228 cat << EOF >> ${1}
229 signature-1 {
230 algo = "${dtb_csum},${dtb_sign_algo}";
231 key-name-hint = "${dtb_sign_keyname}";
232 };
233 };
234EOF
235 fi
236}
237
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#
276# Emit the fitImage ITS setup section
277#
278# $1 ... .its filename
279# $2 ... Image counter
280# $3 ... Path to setup image
281fitimage_emit_section_setup() {
282
283 setup_csum="${FIT_HASH_ALG}"
284
285 cat << EOF >> ${1}
286 setup-${2} {
287 description = "Linux setup.bin";
288 data = /incbin/("${3}");
289 type = "x86_setup";
290 arch = "${UBOOT_ARCH}";
291 os = "linux";
292 compression = "none";
293 load = <0x00090000>;
294 entry = <0x00090000>;
295 hash-1 {
296 algo = "${setup_csum}";
297 };
298 };
299EOF
300}
301
302#
303# Emit the fitImage ITS ramdisk section
304#
305# $1 ... .its filename
306# $2 ... Image counter
307# $3 ... Path to ramdisk image
308fitimage_emit_section_ramdisk() {
309
310 ramdisk_csum="${FIT_HASH_ALG}"
311 ramdisk_sign_algo="${FIT_SIGN_ALG}"
312 ramdisk_sign_keyname="${UBOOT_SIGN_KEYNAME}"
313 ramdisk_loadline=""
314 ramdisk_entryline=""
315
316 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
317 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
318 fi
319 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
320 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
321 fi
322
323 cat << EOF >> ${1}
324 ramdisk-${2} {
325 description = "${INITRAMFS_IMAGE}";
326 data = /incbin/("${3}");
327 type = "ramdisk";
328 arch = "${UBOOT_ARCH}";
329 os = "linux";
330 compression = "none";
331 ${ramdisk_loadline}
332 ${ramdisk_entryline}
333 hash-1 {
334 algo = "${ramdisk_csum}";
335 };
336 };
337EOF
338
339 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${ramdisk_sign_keyname}" ] ; then
340 sed -i '$ d' ${1}
341 cat << EOF >> ${1}
342 signature-1 {
343 algo = "${ramdisk_csum},${ramdisk_sign_algo}";
344 key-name-hint = "${ramdisk_sign_keyname}";
345 };
346 };
347EOF
348 fi
349}
350
351#
352# Emit the fitImage ITS configuration section
353#
354# $1 ... .its filename
355# $2 ... Linux kernel ID
356# $3 ... DTB image name
357# $4 ... ramdisk ID
358# $5 ... u-boot script ID
359# $6 ... config ID
360# $7 ... default flag
361fitimage_emit_section_config() {
362
363 conf_csum="${FIT_HASH_ALG}"
364 conf_sign_algo="${FIT_SIGN_ALG}"
365 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
366 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
367 fi
368
369 its_file="${1}"
370 kernel_id="${2}"
371 dtb_image="${3}"
372 ramdisk_id="${4}"
373 bootscr_id="${5}"
374 config_id="${6}"
375 default_flag="${7}"
376
377 # Test if we have any DTBs at all
378 sep=""
379 conf_desc=""
380 conf_node="conf-"
381 kernel_line=""
382 fdt_line=""
383 ramdisk_line=""
384 bootscr_line=""
385 setup_line=""
386 default_line=""
387
388 # conf node name is selected based on dtb ID if it is present,
389 # otherwise its selected based on kernel ID
390 if [ -n "${dtb_image}" ]; then
391 conf_node=$conf_node${dtb_image}
392 else
393 conf_node=$conf_node${kernel_id}
394 fi
395
396 if [ -n "${kernel_id}" ]; then
397 conf_desc="Linux kernel"
398 sep=", "
399 kernel_line="kernel = \"kernel-${kernel_id}\";"
400 fi
401
402 if [ -n "${dtb_image}" ]; then
403 conf_desc="${conf_desc}${sep}FDT blob"
404 sep=", "
405 fdt_line="fdt = \"fdt-${dtb_image}\";"
406 fi
407
408 if [ -n "${ramdisk_id}" ]; then
409 conf_desc="${conf_desc}${sep}ramdisk"
410 sep=", "
411 ramdisk_line="ramdisk = \"ramdisk-${ramdisk_id}\";"
412 fi
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
420 if [ -n "${config_id}" ]; then
421 conf_desc="${conf_desc}${sep}setup"
422 setup_line="setup = \"setup-${config_id}\";"
423 fi
424
425 if [ "${default_flag}" = "1" ]; then
426 # default node is selected based on dtb ID if it is present,
427 # otherwise its selected based on kernel ID
428 if [ -n "${dtb_image}" ]; then
429 default_line="default = \"conf-${dtb_image}\";"
430 else
431 default_line="default = \"conf-${kernel_id}\";"
432 fi
433 fi
434
435 cat << EOF >> ${its_file}
436 ${default_line}
437 $conf_node {
438 description = "${default_flag} ${conf_desc}";
439 ${kernel_line}
440 ${fdt_line}
441 ${ramdisk_line}
442 ${bootscr_line}
443 ${setup_line}
444 hash-1 {
445 algo = "${conf_csum}";
446 };
447EOF
448
449 if [ ! -z "${conf_sign_keyname}" ] ; then
450
451 sign_line="sign-images = "
452 sep=""
453
454 if [ -n "${kernel_id}" ]; then
455 sign_line="${sign_line}${sep}\"kernel\""
456 sep=", "
457 fi
458
459 if [ -n "${dtb_image}" ]; then
460 sign_line="${sign_line}${sep}\"fdt\""
461 sep=", "
462 fi
463
464 if [ -n "${ramdisk_id}" ]; then
465 sign_line="${sign_line}${sep}\"ramdisk\""
466 sep=", "
467 fi
468
469 if [ -n "${bootscr_id}" ]; then
470 sign_line="${sign_line}${sep}\"bootscr\""
471 sep=", "
472 fi
473
474 if [ -n "${config_id}" ]; then
475 sign_line="${sign_line}${sep}\"setup\""
476 fi
477
478 sign_line="${sign_line};"
479
480 cat << EOF >> ${its_file}
481 signature-1 {
482 algo = "${conf_csum},${conf_sign_algo}";
483 key-name-hint = "${conf_sign_keyname}";
484 ${sign_line}
485 };
486EOF
487 fi
488
489 cat << EOF >> ${its_file}
490 };
491EOF
492}
493
494#
495# Assemble fitImage
496#
497# $1 ... .its filename
498# $2 ... fitImage name
499# $3 ... include ramdisk
500fitimage_assemble() {
501 kernelcount=1
502 dtbcount=""
503 DTBS=""
504 ramdiskcount=${3}
505 setupcount=""
506 bootscr_id=""
507 rm -f ${1} arch/${ARCH}/boot/${2}
508
509 fitimage_emit_fit_header ${1}
510
511 #
512 # Step 1: Prepare a kernel image section.
513 #
514 fitimage_emit_section_maint ${1} imagestart
515
516 uboot_prep_kimage
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
533
534 #
535 # Step 2: Prepare a DTB image section
536 #
537
538 if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then
539 dtbcount=1
540 for DTB in ${KERNEL_DEVICETREE}; do
541 if echo ${DTB} | grep -q '/dts/'; then
542 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
543 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
544 fi
545 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
546 if [ ! -e "${DTB_PATH}" ]; then
547 DTB_PATH="arch/${ARCH}/boot/${DTB}"
548 fi
549
550 DTB=$(echo "${DTB}" | tr '/' '_')
551 DTBS="${DTBS} ${DTB}"
552 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
553 done
554 fi
555
556 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
557 dtbcount=1
558 for DTB in $(find "${EXTERNAL_KERNEL_DEVICETREE}" \( -name '*.dtb' -o -name '*.dtbo' \) -printf '%P\n' | sort); do
559 DTB=$(echo "${DTB}" | tr '/' '_')
560 DTBS="${DTBS} ${DTB}"
561 fitimage_emit_section_dtb ${1} ${DTB} "${EXTERNAL_KERNEL_DEVICETREE}/${DTB}"
562 done
563 fi
564
565 #
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)
581 #
582 if [ -e arch/${ARCH}/boot/setup.bin ]; then
583 setupcount=1
584 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
585 fi
586
587 #
588 # Step 5: Prepare a ramdisk section.
589 #
590 if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
591 # Find and use the first initramfs image archive type we find
592 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
593 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
594 echo "Using $initramfs_path"
595 if [ -e "${initramfs_path}" ]; then
596 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
597 break
598 fi
599 done
600 fi
601
602 fitimage_emit_section_maint ${1} sectend
603
604 # Force the first Kernel and DTB in the default config
605 kernelcount=1
606 if [ -n "${dtbcount}" ]; then
607 dtbcount=1
608 fi
609
610 #
611 # Step 6: Prepare a configurations section
612 #
613 fitimage_emit_section_maint ${1} confstart
614
615 # kernel-fitimage.bbclass currently only supports a single kernel (no less or
616 # more) to be added to the FIT image along with 0 or more device trees and
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.
620 # If a device tree is to be part of the FIT image, then select
621 # the default configuration to be used is based on the dtbcount. If there is
622 # no dtb present than select the default configuation to be based on
623 # the kernelcount.
624 if [ -n "${DTBS}" ]; then
625 i=1
626 for DTB in ${DTBS}; do
627 dtb_ext=${DTB##*.}
628 if [ "${dtb_ext}" = "dtbo" ]; then
629 fitimage_emit_section_config ${1} "" "${DTB}" "" "${bootscr_id}" "" "`expr ${i} = ${dtbcount}`"
630 else
631 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
632 fi
633 i=`expr ${i} + 1`
634 done
635 else
636 defaultconfigcount=1
637 fitimage_emit_section_config ${1} "${kernelcount}" "" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "${defaultconfigcount}"
638 fi
639
640 fitimage_emit_section_maint ${1} sectend
641
642 fitimage_emit_section_maint ${1} fitend
643
644 #
645 # Step 7: Assemble the image
646 #
647 ${UBOOT_MKIMAGE} \
648 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
649 -f ${1} \
650 arch/${ARCH}/boot/${2}
651
652 #
653 # Step 8: Sign the image and add public key to U-Boot dtb
654 #
655 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
656 add_key_to_u_boot=""
657 if [ -n "${UBOOT_DTB_BINARY}" ]; then
658 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
659 # both of them, and don't dereference the symlink.
660 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
661 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
662 fi
663 ${UBOOT_MKIMAGE_SIGN} \
664 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
665 -F -k "${UBOOT_SIGN_KEYDIR}" \
666 $add_key_to_u_boot \
667 -r arch/${ARCH}/boot/${2} \
668 ${UBOOT_MKIMAGE_SIGN_ARGS}
669 fi
670}
671
672do_assemble_fitimage() {
673 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
674 cd ${B}
675 fitimage_assemble fit-image.its fitImage
676 fi
677}
678
679addtask assemble_fitimage before do_install after do_compile
680
681do_assemble_fitimage_initramfs() {
682 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
683 test -n "${INITRAMFS_IMAGE}" ; then
684 cd ${B}
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
690 fi
691}
692
693addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
694
695do_generate_rsa_keys() {
696 if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
697 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."
698 fi
699
700 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
701
702 # Generate keys only if they don't already exist
703 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \
704 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt]; then
705
706 # make directory if it does not already exist
707 mkdir -p "${UBOOT_SIGN_KEYDIR}"
708
709 echo "Generating RSA private key for signing fitImage"
710 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
711 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
712 "${FIT_SIGN_NUMBITS}"
713
714 echo "Generating certificate for signing fitImage"
715 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
716 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
717 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt
718 fi
719 fi
720}
721
722addtask generate_rsa_keys before do_assemble_fitimage after do_compile
723
724kernel_do_deploy[vardepsexclude] = "DATETIME"
725kernel_do_deploy_append() {
726 # Update deploy directory
727 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
728
729 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
730 echo "Copying fit-image.its source file..."
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
738
739 if [ -n "${INITRAMFS_IMAGE}" ]; then
740 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
741 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its"
742 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
743
744 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
745 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
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
749 fi
750 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
751 # UBOOT_DTB_IMAGE is a realfile, but we can't use
752 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
753 # for u-boot, but we are in kernel env now.
754 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/"
755 fi
756 fi
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