blob: b51882dce4c7418c188354c0b1a8f11e706ff701 [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}"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800210 ramdisk_ctype="none"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000211 ramdisk_loadline=""
212 ramdisk_entryline=""
213
214 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
215 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
216 fi
217 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
218 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
219 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500220
Rick Altherrbc1b8802017-01-20 11:28:53 -0800221 case $3 in
222 *.gz)
223 ramdisk_ctype="gzip"
224 ;;
225 *.bz2)
226 ramdisk_ctype="bzip2"
227 ;;
228 *.lzma)
229 ramdisk_ctype="lzma"
230 ;;
231 *.lzo)
232 ramdisk_ctype="lzo"
233 ;;
234 *.lz4)
235 ramdisk_ctype="lz4"
236 ;;
237 esac
238
George McCollister185c8ae2016-05-26 08:55:16 -0500239 cat << EOF >> ${1}
240 ramdisk@${2} {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800241 description = "${INITRAMFS_IMAGE}";
George McCollister185c8ae2016-05-26 08:55:16 -0500242 data = /incbin/("${3}");
243 type = "ramdisk";
244 arch = "${UBOOT_ARCH}";
245 os = "linux";
Rick Altherrbc1b8802017-01-20 11:28:53 -0800246 compression = "${ramdisk_ctype}";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000247 ${ramdisk_loadline}
248 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500249 hash@1 {
250 algo = "${ramdisk_csum}";
251 };
252 };
253EOF
254}
255
256#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257# Emit the fitImage ITS configuration section
258#
George McCollister185c8ae2016-05-26 08:55:16 -0500259# $1 ... .its filename
260# $2 ... Linux kernel ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261# $3 ... DTB image name
George McCollister185c8ae2016-05-26 08:55:16 -0500262# $4 ... ramdisk ID
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600263# $5 ... config ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500264# $6 ... default flag
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265fitimage_emit_section_config() {
266
Brad Bishopf3fd2882019-06-21 08:06:37 -0400267 conf_csum="${FIT_HASH_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600268 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
269 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
270 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500271
272 # Test if we have any DTBs at all
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800273 sep=""
274 conf_desc=""
275 kernel_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600276 fdt_line=""
277 ramdisk_line=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500278 setup_line=""
279 default_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600280
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800281 if [ -n "${2}" ]; then
282 conf_desc="Linux kernel"
283 sep=", "
284 kernel_line="kernel = \"kernel@${2}\";"
285 fi
286
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600287 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800288 conf_desc="${conf_desc}${sep}FDT blob"
289 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500290 fdt_line="fdt = \"fdt@${3}\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600291 fi
292
293 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800294 conf_desc="${conf_desc}${sep}ramdisk"
295 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500296 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600298
299 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800300 conf_desc="${conf_desc}${sep}setup"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600301 setup_line="setup = \"setup@${5}\";"
302 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500304 if [ "${6}" = "1" ]; then
305 default_line="default = \"conf@${3}\";"
306 fi
307
George McCollister185c8ae2016-05-26 08:55:16 -0500308 cat << EOF >> ${1}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500309 ${default_line}
310 conf@${3} {
311 description = "${6} ${conf_desc}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312 ${kernel_line}
313 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500314 ${ramdisk_line}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600315 ${setup_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316 hash@1 {
317 algo = "${conf_csum}";
318 };
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319EOF
320
321 if [ ! -z "${conf_sign_keyname}" ] ; then
322
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800323 sign_line="sign-images = "
324 sep=""
325
326 if [ -n "${2}" ]; then
327 sign_line="${sign_line}${sep}\"kernel\""
328 sep=", "
329 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600330
331 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800332 sign_line="${sign_line}${sep}\"fdt\""
333 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600334 fi
335
336 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800337 sign_line="${sign_line}${sep}\"ramdisk\""
338 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600339 fi
340
341 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800342 sign_line="${sign_line}${sep}\"setup\""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600343 fi
344
345 sign_line="${sign_line};"
346
347 cat << EOF >> ${1}
348 signature@1 {
349 algo = "${conf_csum},rsa2048";
350 key-name-hint = "${conf_sign_keyname}";
351 ${sign_line}
352 };
353EOF
354 fi
355
356 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 };
358EOF
359}
360
George McCollister185c8ae2016-05-26 08:55:16 -0500361#
362# Assemble fitImage
363#
364# $1 ... .its filename
365# $2 ... fitImage name
366# $3 ... include ramdisk
367fitimage_assemble() {
368 kernelcount=1
369 dtbcount=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370 DTBS=""
George McCollister185c8ae2016-05-26 08:55:16 -0500371 ramdiskcount=${3}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600372 setupcount=""
George McCollister185c8ae2016-05-26 08:55:16 -0500373 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374
George McCollister185c8ae2016-05-26 08:55:16 -0500375 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376
George McCollister185c8ae2016-05-26 08:55:16 -0500377 #
378 # Step 1: Prepare a kernel image section.
379 #
380 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500381
George McCollister185c8ae2016-05-26 08:55:16 -0500382 uboot_prep_kimage
383 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384
George McCollister185c8ae2016-05-26 08:55:16 -0500385 #
386 # Step 2: Prepare a DTB image section
387 #
Brad Bishop19323692019-04-05 15:28:33 -0400388
389 if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500390 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500391 for DTB in ${KERNEL_DEVICETREE}; do
392 if echo ${DTB} | grep -q '/dts/'; then
393 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
394 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
395 fi
396 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
397 if [ ! -e "${DTB_PATH}" ]; then
398 DTB_PATH="arch/${ARCH}/boot/${DTB}"
399 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 DTB=$(echo "${DTB}" | tr '/' '_')
402 DTBS="${DTBS} ${DTB}"
403 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
George McCollister185c8ae2016-05-26 08:55:16 -0500404 done
405 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406
Brad Bishop19323692019-04-05 15:28:33 -0400407 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
408 dtbcount=1
409 for DTBFILE in ${EXTERNAL_KERNEL_DEVICETREE}/*.dtb; do
410 DTB=`basename ${DTBFILE}`
411 DTB=$(echo "${DTB}" | tr '/' '_')
412 DTBS="${DTBS} ${DTB}"
413 fitimage_emit_section_dtb ${1} ${DTB} ${DTBFILE}
414 done
415 fi
416
George McCollister185c8ae2016-05-26 08:55:16 -0500417 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600418 # Step 3: Prepare a setup section. (For x86)
419 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500420 if [ -e arch/${ARCH}/boot/setup.bin ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600421 setupcount=1
422 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
423 fi
424
425 #
426 # Step 4: Prepare a ramdisk section.
George McCollister185c8ae2016-05-26 08:55:16 -0500427 #
428 if [ "x${ramdiskcount}" = "x1" ] ; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800429 # Find and use the first initramfs image archive type we find
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800430 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500431 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800432 echo "Using $initramfs_path"
433 if [ -e "${initramfs_path}" ]; then
434 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
435 break
436 fi
437 done
George McCollister185c8ae2016-05-26 08:55:16 -0500438 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439
George McCollister185c8ae2016-05-26 08:55:16 -0500440 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500441
George McCollister185c8ae2016-05-26 08:55:16 -0500442 # Force the first Kernel and DTB in the default config
443 kernelcount=1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500444 if [ -n "${dtbcount}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600445 dtbcount=1
446 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447
George McCollister185c8ae2016-05-26 08:55:16 -0500448 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600449 # Step 5: Prepare a configurations section
George McCollister185c8ae2016-05-26 08:55:16 -0500450 #
451 fitimage_emit_section_maint ${1} confstart
452
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500453 if [ -n "${DTBS}" ]; then
454 i=1
455 for DTB in ${DTBS}; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800456 dtb_ext=${DTB##*.}
457 if [ "${dtb_ext}" = "dtbo" ]; then
458 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`"
459 else
460 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
461 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500462 i=`expr ${i} + 1`
463 done
464 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500465
466 fitimage_emit_section_maint ${1} sectend
467
468 fitimage_emit_section_maint ${1} fitend
469
470 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600471 # Step 6: Assemble the image
George McCollister185c8ae2016-05-26 08:55:16 -0500472 #
473 uboot-mkimage \
474 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
475 -f ${1} \
476 arch/${ARCH}/boot/${2}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600477
478 #
479 # Step 7: Sign the image and add public key to U-Boot dtb
480 #
481 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400482 add_key_to_u_boot=""
483 if [ -n "${UBOOT_DTB_BINARY}" ]; then
484 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
485 # both of them, and don't dereference the symlink.
486 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
487 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
488 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600489 uboot-mkimage \
490 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
491 -F -k "${UBOOT_SIGN_KEYDIR}" \
Brad Bishop19323692019-04-05 15:28:33 -0400492 $add_key_to_u_boot \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600493 -r arch/${ARCH}/boot/${2}
494 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500495}
496
497do_assemble_fitimage() {
498 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
499 cd ${B}
500 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500501 fi
502}
503
504addtask assemble_fitimage before do_install after do_compile
505
George McCollister185c8ae2016-05-26 08:55:16 -0500506do_assemble_fitimage_initramfs() {
507 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
508 test -n "${INITRAMFS_IMAGE}" ; then
509 cd ${B}
510 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
511 fi
512}
513
Brad Bishop19323692019-04-05 15:28:33 -0400514addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
George McCollister185c8ae2016-05-26 08:55:16 -0500515
516
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500517kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500518kernel_do_deploy_append() {
519 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400520 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500521 echo "Copying fit-image.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800522 install -m 0644 ${B}/fit-image.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_NAME}.its
523 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_LINK_NAME}
524
525 echo "Copying linux.bin file..."
526 install -m 0644 ${B}/linux.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin
527 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500528
George McCollister185c8ae2016-05-26 08:55:16 -0500529 if [ -n "${INITRAMFS_IMAGE}" ]; then
530 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800531 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its
532 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 -0500533
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800534 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
535 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin
536 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 -0500537 fi
Brad Bishop19323692019-04-05 15:28:33 -0400538 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
539 # UBOOT_DTB_IMAGE is a realfile, but we can't use
540 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
541 # for u-boot, but we are in kernel env now.
542 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb ${DEPLOYDIR}/
543 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500544 fi
545}