blob: 1bcb09c59885178b0288ea61ceca609669345742 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001inherit kernel-uboot kernel-artifact-names uboot-sign
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3python __anonymous () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
He Zhefe76b1e2016-05-25 04:47:16 -04005 if 'fitImage' in kerneltypes.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006 depends = d.getVar("DEPENDS")
Brad Bishop19323692019-04-05 15:28:33 -04007 depends = "%s u-boot-tools-native dtc-native" % depends
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008 d.setVar("DEPENDS", depends)
9
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010 uarch = d.getVar("UBOOT_ARCH")
11 if uarch == "arm64":
12 replacementtype = "Image"
Brad Bishopc342db32019-05-15 21:57:59 -040013 elif uarch == "riscv":
14 replacementtype = "Image"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015 elif uarch == "mips":
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 replacementtype = "vmlinuz.bin"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 elif uarch == "x86":
Patrick Williamsc0f7c042017-02-23 20:41:17 -060018 replacementtype = "bzImage"
Brad Bishop316dfdd2018-06-25 12:45:53 -040019 elif uarch == "microblaze":
20 replacementtype = "linux.bin"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021 else:
22 replacementtype = "zImage"
23
Brad Bishop19323692019-04-05 15:28:33 -040024 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
25 # to kernel.bbclass . We have to override it, since we pack zImage
26 # (at least for now) into the fitImage .
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
He Zhefe76b1e2016-05-25 04:47:16 -040028 if 'fitImage' in typeformake.split():
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', replacementtype))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 image = d.getVar('INITRAMFS_IMAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032 if image:
George McCollister185c8ae2016-05-26 08:55:16 -050033 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
34
Brad Bishop19323692019-04-05 15:28:33 -040035 #check if there are any dtb providers
36 providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
37 if providerdtb:
38 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot')
39 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot')
40 d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree")
41
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042 # Verified boot will sign the fitImage and append the public key to
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044 # the fitImage:
Brad Bishop15ae2502019-06-18 21:44:24 -040045 if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
Brad Bishop19323692019-04-05 15:28:33 -040047 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048}
49
Yannick Gicqueld5813b42016-04-27 16:20:55 +020050# Options for the device tree compiler passed to mkimage '-D' feature:
51UBOOT_MKIMAGE_DTCOPTS ??= ""
52
Brad Bishopf3fd2882019-06-21 08:06:37 -040053# fitImage Hash Algo
54FIT_HASH_ALG ?= "sha256"
55
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056#
57# Emit the fitImage ITS header
58#
George McCollister185c8ae2016-05-26 08:55:16 -050059# $1 ... .its filename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060fitimage_emit_fit_header() {
George McCollister185c8ae2016-05-26 08:55:16 -050061 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062/dts-v1/;
63
64/ {
65 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
66 #address-cells = <1>;
67EOF
68}
69
70#
71# Emit the fitImage section bits
72#
George McCollister185c8ae2016-05-26 08:55:16 -050073# $1 ... .its filename
74# $2 ... Section bit type: imagestart - image section start
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075# confstart - configuration section start
76# sectend - section end
77# fitend - fitimage end
78#
79fitimage_emit_section_maint() {
George McCollister185c8ae2016-05-26 08:55:16 -050080 case $2 in
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 imagestart)
George McCollister185c8ae2016-05-26 08:55:16 -050082 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083
84 images {
85EOF
86 ;;
87 confstart)
George McCollister185c8ae2016-05-26 08:55:16 -050088 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
90 configurations {
91EOF
92 ;;
93 sectend)
George McCollister185c8ae2016-05-26 08:55:16 -050094 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 };
96EOF
97 ;;
98 fitend)
George McCollister185c8ae2016-05-26 08:55:16 -050099 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100};
101EOF
102 ;;
103 esac
104}
105
106#
107# Emit the fitImage ITS kernel section
108#
George McCollister185c8ae2016-05-26 08:55:16 -0500109# $1 ... .its filename
110# $2 ... Image counter
111# $3 ... Path to kernel image
112# $4 ... Compression type
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113fitimage_emit_section_kernel() {
114
Brad Bishopf3fd2882019-06-21 08:06:37 -0400115 kernel_csum="${FIT_HASH_ALG}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116
Brad Bishop316dfdd2018-06-25 12:45:53 -0400117 ENTRYPOINT="${UBOOT_ENTRYPOINT}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
119 ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \
120 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121 fi
122
George McCollister185c8ae2016-05-26 08:55:16 -0500123 cat << EOF >> ${1}
124 kernel@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 description = "Linux kernel";
George McCollister185c8ae2016-05-26 08:55:16 -0500126 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 type = "kernel";
128 arch = "${UBOOT_ARCH}";
129 os = "linux";
George McCollister185c8ae2016-05-26 08:55:16 -0500130 compression = "${4}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 load = <${UBOOT_LOADADDRESS}>;
132 entry = <${ENTRYPOINT}>;
133 hash@1 {
134 algo = "${kernel_csum}";
135 };
136 };
137EOF
138}
139
140#
141# Emit the fitImage ITS DTB section
142#
George McCollister185c8ae2016-05-26 08:55:16 -0500143# $1 ... .its filename
144# $2 ... Image counter
145# $3 ... Path to DTB image
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146fitimage_emit_section_dtb() {
147
Brad Bishopf3fd2882019-06-21 08:06:37 -0400148 dtb_csum="${FIT_HASH_ALG}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500149
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800150 dtb_loadline=""
151 dtb_ext=${DTB##*.}
152 if [ "${dtb_ext}" = "dtbo" ]; then
153 if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then
154 dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;"
155 fi
156 elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then
157 dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;"
158 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500159 cat << EOF >> ${1}
160 fdt@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161 description = "Flattened Device Tree blob";
George McCollister185c8ae2016-05-26 08:55:16 -0500162 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163 type = "flat_dt";
164 arch = "${UBOOT_ARCH}";
165 compression = "none";
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800166 ${dtb_loadline}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 hash@1 {
168 algo = "${dtb_csum}";
169 };
170 };
171EOF
172}
173
174#
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600175# Emit the fitImage ITS setup section
176#
177# $1 ... .its filename
178# $2 ... Image counter
179# $3 ... Path to setup image
180fitimage_emit_section_setup() {
181
Brad Bishopf3fd2882019-06-21 08:06:37 -0400182 setup_csum="${FIT_HASH_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600183
184 cat << EOF >> ${1}
185 setup@${2} {
186 description = "Linux setup.bin";
187 data = /incbin/("${3}");
188 type = "x86_setup";
189 arch = "${UBOOT_ARCH}";
190 os = "linux";
191 compression = "none";
192 load = <0x00090000>;
193 entry = <0x00090000>;
194 hash@1 {
195 algo = "${setup_csum}";
196 };
197 };
198EOF
199}
200
201#
George McCollister185c8ae2016-05-26 08:55:16 -0500202# Emit the fitImage ITS ramdisk section
203#
204# $1 ... .its filename
205# $2 ... Image counter
206# $3 ... Path to ramdisk image
207fitimage_emit_section_ramdisk() {
208
Brad Bishopf3fd2882019-06-21 08:06:37 -0400209 ramdisk_csum="${FIT_HASH_ALG}"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000210 ramdisk_loadline=""
211 ramdisk_entryline=""
212
213 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
214 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
215 fi
216 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
217 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
218 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500219
220 cat << EOF >> ${1}
221 ramdisk@${2} {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800222 description = "${INITRAMFS_IMAGE}";
George McCollister185c8ae2016-05-26 08:55:16 -0500223 data = /incbin/("${3}");
224 type = "ramdisk";
225 arch = "${UBOOT_ARCH}";
226 os = "linux";
Brad Bishop00e122a2019-10-05 11:10:57 -0400227 compression = "none";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000228 ${ramdisk_loadline}
229 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500230 hash@1 {
231 algo = "${ramdisk_csum}";
232 };
233 };
234EOF
235}
236
237#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238# Emit the fitImage ITS configuration section
239#
George McCollister185c8ae2016-05-26 08:55:16 -0500240# $1 ... .its filename
241# $2 ... Linux kernel ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500242# $3 ... DTB image name
George McCollister185c8ae2016-05-26 08:55:16 -0500243# $4 ... ramdisk ID
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600244# $5 ... config ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245# $6 ... default flag
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246fitimage_emit_section_config() {
247
Brad Bishopf3fd2882019-06-21 08:06:37 -0400248 conf_csum="${FIT_HASH_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600249 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
250 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
251 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252
253 # Test if we have any DTBs at all
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800254 sep=""
255 conf_desc=""
256 kernel_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600257 fdt_line=""
258 ramdisk_line=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500259 setup_line=""
260 default_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600261
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800262 if [ -n "${2}" ]; then
263 conf_desc="Linux kernel"
264 sep=", "
265 kernel_line="kernel = \"kernel@${2}\";"
266 fi
267
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600268 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800269 conf_desc="${conf_desc}${sep}FDT blob"
270 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500271 fdt_line="fdt = \"fdt@${3}\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600272 fi
273
274 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800275 conf_desc="${conf_desc}${sep}ramdisk"
276 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500277 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600279
280 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800281 conf_desc="${conf_desc}${sep}setup"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600282 setup_line="setup = \"setup@${5}\";"
283 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500285 if [ "${6}" = "1" ]; then
286 default_line="default = \"conf@${3}\";"
287 fi
288
George McCollister185c8ae2016-05-26 08:55:16 -0500289 cat << EOF >> ${1}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 ${default_line}
291 conf@${3} {
292 description = "${6} ${conf_desc}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293 ${kernel_line}
294 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500295 ${ramdisk_line}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600296 ${setup_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 hash@1 {
298 algo = "${conf_csum}";
299 };
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600300EOF
301
302 if [ ! -z "${conf_sign_keyname}" ] ; then
303
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800304 sign_line="sign-images = "
305 sep=""
306
307 if [ -n "${2}" ]; then
308 sign_line="${sign_line}${sep}\"kernel\""
309 sep=", "
310 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600311
312 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800313 sign_line="${sign_line}${sep}\"fdt\""
314 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600315 fi
316
317 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800318 sign_line="${sign_line}${sep}\"ramdisk\""
319 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600320 fi
321
322 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800323 sign_line="${sign_line}${sep}\"setup\""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600324 fi
325
326 sign_line="${sign_line};"
327
328 cat << EOF >> ${1}
329 signature@1 {
330 algo = "${conf_csum},rsa2048";
331 key-name-hint = "${conf_sign_keyname}";
332 ${sign_line}
333 };
334EOF
335 fi
336
337 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338 };
339EOF
340}
341
George McCollister185c8ae2016-05-26 08:55:16 -0500342#
343# Assemble fitImage
344#
345# $1 ... .its filename
346# $2 ... fitImage name
347# $3 ... include ramdisk
348fitimage_assemble() {
349 kernelcount=1
350 dtbcount=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 DTBS=""
George McCollister185c8ae2016-05-26 08:55:16 -0500352 ramdiskcount=${3}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600353 setupcount=""
George McCollister185c8ae2016-05-26 08:55:16 -0500354 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355
George McCollister185c8ae2016-05-26 08:55:16 -0500356 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357
George McCollister185c8ae2016-05-26 08:55:16 -0500358 #
359 # Step 1: Prepare a kernel image section.
360 #
361 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362
George McCollister185c8ae2016-05-26 08:55:16 -0500363 uboot_prep_kimage
364 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365
George McCollister185c8ae2016-05-26 08:55:16 -0500366 #
367 # Step 2: Prepare a DTB image section
368 #
Brad Bishop19323692019-04-05 15:28:33 -0400369
370 if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500372 for DTB in ${KERNEL_DEVICETREE}; do
373 if echo ${DTB} | grep -q '/dts/'; then
374 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
375 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
376 fi
377 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
378 if [ ! -e "${DTB_PATH}" ]; then
379 DTB_PATH="arch/${ARCH}/boot/${DTB}"
380 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500381
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500382 DTB=$(echo "${DTB}" | tr '/' '_')
383 DTBS="${DTBS} ${DTB}"
384 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
George McCollister185c8ae2016-05-26 08:55:16 -0500385 done
386 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387
Brad Bishop19323692019-04-05 15:28:33 -0400388 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
389 dtbcount=1
390 for DTBFILE in ${EXTERNAL_KERNEL_DEVICETREE}/*.dtb; do
391 DTB=`basename ${DTBFILE}`
392 DTB=$(echo "${DTB}" | tr '/' '_')
393 DTBS="${DTBS} ${DTB}"
394 fitimage_emit_section_dtb ${1} ${DTB} ${DTBFILE}
395 done
396 fi
397
George McCollister185c8ae2016-05-26 08:55:16 -0500398 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600399 # Step 3: Prepare a setup section. (For x86)
400 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 if [ -e arch/${ARCH}/boot/setup.bin ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600402 setupcount=1
403 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
404 fi
405
406 #
407 # Step 4: Prepare a ramdisk section.
George McCollister185c8ae2016-05-26 08:55:16 -0500408 #
409 if [ "x${ramdiskcount}" = "x1" ] ; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800410 # Find and use the first initramfs image archive type we find
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800411 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500412 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800413 echo "Using $initramfs_path"
414 if [ -e "${initramfs_path}" ]; then
415 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
416 break
417 fi
418 done
George McCollister185c8ae2016-05-26 08:55:16 -0500419 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420
George McCollister185c8ae2016-05-26 08:55:16 -0500421 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422
George McCollister185c8ae2016-05-26 08:55:16 -0500423 # Force the first Kernel and DTB in the default config
424 kernelcount=1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500425 if [ -n "${dtbcount}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600426 dtbcount=1
427 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428
George McCollister185c8ae2016-05-26 08:55:16 -0500429 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600430 # Step 5: Prepare a configurations section
George McCollister185c8ae2016-05-26 08:55:16 -0500431 #
432 fitimage_emit_section_maint ${1} confstart
433
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500434 if [ -n "${DTBS}" ]; then
435 i=1
436 for DTB in ${DTBS}; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800437 dtb_ext=${DTB##*.}
438 if [ "${dtb_ext}" = "dtbo" ]; then
439 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`"
440 else
441 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
442 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500443 i=`expr ${i} + 1`
444 done
445 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500446
447 fitimage_emit_section_maint ${1} sectend
448
449 fitimage_emit_section_maint ${1} fitend
450
451 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600452 # Step 6: Assemble the image
George McCollister185c8ae2016-05-26 08:55:16 -0500453 #
454 uboot-mkimage \
455 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
456 -f ${1} \
457 arch/${ARCH}/boot/${2}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600458
459 #
460 # Step 7: Sign the image and add public key to U-Boot dtb
461 #
462 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400463 add_key_to_u_boot=""
464 if [ -n "${UBOOT_DTB_BINARY}" ]; then
465 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
466 # both of them, and don't dereference the symlink.
467 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
468 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
469 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600470 uboot-mkimage \
471 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
472 -F -k "${UBOOT_SIGN_KEYDIR}" \
Brad Bishop19323692019-04-05 15:28:33 -0400473 $add_key_to_u_boot \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600474 -r arch/${ARCH}/boot/${2}
475 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500476}
477
478do_assemble_fitimage() {
479 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
480 cd ${B}
481 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482 fi
483}
484
485addtask assemble_fitimage before do_install after do_compile
486
George McCollister185c8ae2016-05-26 08:55:16 -0500487do_assemble_fitimage_initramfs() {
488 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
489 test -n "${INITRAMFS_IMAGE}" ; then
490 cd ${B}
491 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
492 fi
493}
494
Brad Bishop19323692019-04-05 15:28:33 -0400495addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
George McCollister185c8ae2016-05-26 08:55:16 -0500496
497
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500498kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500499kernel_do_deploy_append() {
500 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400501 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502 echo "Copying fit-image.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800503 install -m 0644 ${B}/fit-image.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_NAME}.its
504 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_LINK_NAME}
505
506 echo "Copying linux.bin file..."
507 install -m 0644 ${B}/linux.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin
508 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500509
George McCollister185c8ae2016-05-26 08:55:16 -0500510 if [ -n "${INITRAMFS_IMAGE}" ]; then
511 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800512 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its
513 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its ${DEPLOYDIR}/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}
George McCollister185c8ae2016-05-26 08:55:16 -0500514
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800515 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
516 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin
517 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}
George McCollister185c8ae2016-05-26 08:55:16 -0500518 fi
Brad Bishop19323692019-04-05 15:28:33 -0400519 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
520 # UBOOT_DTB_IMAGE is a realfile, but we can't use
521 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
522 # for u-boot, but we are in kernel env now.
523 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb ${DEPLOYDIR}/
524 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525 fi
526}