blob: 72b05ff8d1dd24db14b5788551a8574851d85d5d [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
Brad Bishop64c979e2019-11-04 13:55:29 -050056# fitImage Signature Algo
57FIT_SIGN_ALG ?= "rsa2048"
58
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059#
60# Emit the fitImage ITS header
61#
George McCollister185c8ae2016-05-26 08:55:16 -050062# $1 ... .its filename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063fitimage_emit_fit_header() {
George McCollister185c8ae2016-05-26 08:55:16 -050064 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065/dts-v1/;
66
67/ {
68 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
69 #address-cells = <1>;
70EOF
71}
72
73#
74# Emit the fitImage section bits
75#
George McCollister185c8ae2016-05-26 08:55:16 -050076# $1 ... .its filename
77# $2 ... Section bit type: imagestart - image section start
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078# confstart - configuration section start
79# sectend - section end
80# fitend - fitimage end
81#
82fitimage_emit_section_maint() {
George McCollister185c8ae2016-05-26 08:55:16 -050083 case $2 in
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 imagestart)
George McCollister185c8ae2016-05-26 08:55:16 -050085 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87 images {
88EOF
89 ;;
90 confstart)
George McCollister185c8ae2016-05-26 08:55:16 -050091 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092
93 configurations {
94EOF
95 ;;
96 sectend)
George McCollister185c8ae2016-05-26 08:55:16 -050097 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 };
99EOF
100 ;;
101 fitend)
George McCollister185c8ae2016-05-26 08:55:16 -0500102 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103};
104EOF
105 ;;
106 esac
107}
108
109#
110# Emit the fitImage ITS kernel section
111#
George McCollister185c8ae2016-05-26 08:55:16 -0500112# $1 ... .its filename
113# $2 ... Image counter
114# $3 ... Path to kernel image
115# $4 ... Compression type
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116fitimage_emit_section_kernel() {
117
Brad Bishopf3fd2882019-06-21 08:06:37 -0400118 kernel_csum="${FIT_HASH_ALG}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119
Brad Bishop316dfdd2018-06-25 12:45:53 -0400120 ENTRYPOINT="${UBOOT_ENTRYPOINT}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500121 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
122 ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \
123 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 fi
125
George McCollister185c8ae2016-05-26 08:55:16 -0500126 cat << EOF >> ${1}
127 kernel@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 description = "Linux kernel";
George McCollister185c8ae2016-05-26 08:55:16 -0500129 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 type = "kernel";
131 arch = "${UBOOT_ARCH}";
132 os = "linux";
George McCollister185c8ae2016-05-26 08:55:16 -0500133 compression = "${4}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 load = <${UBOOT_LOADADDRESS}>;
135 entry = <${ENTRYPOINT}>;
136 hash@1 {
137 algo = "${kernel_csum}";
138 };
139 };
140EOF
141}
142
143#
144# Emit the fitImage ITS DTB section
145#
George McCollister185c8ae2016-05-26 08:55:16 -0500146# $1 ... .its filename
147# $2 ... Image counter
148# $3 ... Path to DTB image
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500149fitimage_emit_section_dtb() {
150
Brad Bishopf3fd2882019-06-21 08:06:37 -0400151 dtb_csum="${FIT_HASH_ALG}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800153 dtb_loadline=""
154 dtb_ext=${DTB##*.}
155 if [ "${dtb_ext}" = "dtbo" ]; then
156 if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then
157 dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;"
158 fi
159 elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then
160 dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;"
161 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500162 cat << EOF >> ${1}
163 fdt@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 description = "Flattened Device Tree blob";
George McCollister185c8ae2016-05-26 08:55:16 -0500165 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166 type = "flat_dt";
167 arch = "${UBOOT_ARCH}";
168 compression = "none";
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800169 ${dtb_loadline}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170 hash@1 {
171 algo = "${dtb_csum}";
172 };
173 };
174EOF
175}
176
177#
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600178# Emit the fitImage ITS setup section
179#
180# $1 ... .its filename
181# $2 ... Image counter
182# $3 ... Path to setup image
183fitimage_emit_section_setup() {
184
Brad Bishopf3fd2882019-06-21 08:06:37 -0400185 setup_csum="${FIT_HASH_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600186
187 cat << EOF >> ${1}
188 setup@${2} {
189 description = "Linux setup.bin";
190 data = /incbin/("${3}");
191 type = "x86_setup";
192 arch = "${UBOOT_ARCH}";
193 os = "linux";
194 compression = "none";
195 load = <0x00090000>;
196 entry = <0x00090000>;
197 hash@1 {
198 algo = "${setup_csum}";
199 };
200 };
201EOF
202}
203
204#
George McCollister185c8ae2016-05-26 08:55:16 -0500205# Emit the fitImage ITS ramdisk section
206#
207# $1 ... .its filename
208# $2 ... Image counter
209# $3 ... Path to ramdisk image
210fitimage_emit_section_ramdisk() {
211
Brad Bishopf3fd2882019-06-21 08:06:37 -0400212 ramdisk_csum="${FIT_HASH_ALG}"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000213 ramdisk_loadline=""
214 ramdisk_entryline=""
215
216 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
217 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
218 fi
219 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
220 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
221 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500222
223 cat << EOF >> ${1}
224 ramdisk@${2} {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800225 description = "${INITRAMFS_IMAGE}";
George McCollister185c8ae2016-05-26 08:55:16 -0500226 data = /incbin/("${3}");
227 type = "ramdisk";
228 arch = "${UBOOT_ARCH}";
229 os = "linux";
Brad Bishop00e122a2019-10-05 11:10:57 -0400230 compression = "none";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000231 ${ramdisk_loadline}
232 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500233 hash@1 {
234 algo = "${ramdisk_csum}";
235 };
236 };
237EOF
238}
239
240#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241# Emit the fitImage ITS configuration section
242#
George McCollister185c8ae2016-05-26 08:55:16 -0500243# $1 ... .its filename
244# $2 ... Linux kernel ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245# $3 ... DTB image name
George McCollister185c8ae2016-05-26 08:55:16 -0500246# $4 ... ramdisk ID
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600247# $5 ... config ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500248# $6 ... default flag
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249fitimage_emit_section_config() {
250
Brad Bishopf3fd2882019-06-21 08:06:37 -0400251 conf_csum="${FIT_HASH_ALG}"
Brad Bishop64c979e2019-11-04 13:55:29 -0500252 conf_sign_algo="${FIT_SIGN_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600253 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
254 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
255 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256
257 # Test if we have any DTBs at all
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800258 sep=""
259 conf_desc=""
260 kernel_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600261 fdt_line=""
262 ramdisk_line=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500263 setup_line=""
264 default_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600265
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800266 if [ -n "${2}" ]; then
267 conf_desc="Linux kernel"
268 sep=", "
269 kernel_line="kernel = \"kernel@${2}\";"
270 fi
271
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600272 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800273 conf_desc="${conf_desc}${sep}FDT blob"
274 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500275 fdt_line="fdt = \"fdt@${3}\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600276 fi
277
278 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800279 conf_desc="${conf_desc}${sep}ramdisk"
280 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500281 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500282 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600283
284 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800285 conf_desc="${conf_desc}${sep}setup"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286 setup_line="setup = \"setup@${5}\";"
287 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500289 if [ "${6}" = "1" ]; then
290 default_line="default = \"conf@${3}\";"
291 fi
292
George McCollister185c8ae2016-05-26 08:55:16 -0500293 cat << EOF >> ${1}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500294 ${default_line}
295 conf@${3} {
296 description = "${6} ${conf_desc}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 ${kernel_line}
298 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500299 ${ramdisk_line}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600300 ${setup_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301 hash@1 {
302 algo = "${conf_csum}";
303 };
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600304EOF
305
306 if [ ! -z "${conf_sign_keyname}" ] ; then
307
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800308 sign_line="sign-images = "
309 sep=""
310
311 if [ -n "${2}" ]; then
312 sign_line="${sign_line}${sep}\"kernel\""
313 sep=", "
314 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600315
316 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800317 sign_line="${sign_line}${sep}\"fdt\""
318 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319 fi
320
321 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800322 sign_line="${sign_line}${sep}\"ramdisk\""
323 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600324 fi
325
326 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800327 sign_line="${sign_line}${sep}\"setup\""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600328 fi
329
330 sign_line="${sign_line};"
331
332 cat << EOF >> ${1}
333 signature@1 {
Brad Bishop64c979e2019-11-04 13:55:29 -0500334 algo = "${conf_csum},${conf_sign_algo}";
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600335 key-name-hint = "${conf_sign_keyname}";
336 ${sign_line}
337 };
338EOF
339 fi
340
341 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342 };
343EOF
344}
345
George McCollister185c8ae2016-05-26 08:55:16 -0500346#
347# Assemble fitImage
348#
349# $1 ... .its filename
350# $2 ... fitImage name
351# $3 ... include ramdisk
352fitimage_assemble() {
353 kernelcount=1
354 dtbcount=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500355 DTBS=""
George McCollister185c8ae2016-05-26 08:55:16 -0500356 ramdiskcount=${3}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600357 setupcount=""
George McCollister185c8ae2016-05-26 08:55:16 -0500358 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359
George McCollister185c8ae2016-05-26 08:55:16 -0500360 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361
George McCollister185c8ae2016-05-26 08:55:16 -0500362 #
363 # Step 1: Prepare a kernel image section.
364 #
365 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500366
George McCollister185c8ae2016-05-26 08:55:16 -0500367 uboot_prep_kimage
368 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369
George McCollister185c8ae2016-05-26 08:55:16 -0500370 #
371 # Step 2: Prepare a DTB image section
372 #
Brad Bishop19323692019-04-05 15:28:33 -0400373
374 if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500376 for DTB in ${KERNEL_DEVICETREE}; do
377 if echo ${DTB} | grep -q '/dts/'; then
378 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
379 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
380 fi
381 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
382 if [ ! -e "${DTB_PATH}" ]; then
383 DTB_PATH="arch/${ARCH}/boot/${DTB}"
384 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500386 DTB=$(echo "${DTB}" | tr '/' '_')
387 DTBS="${DTBS} ${DTB}"
388 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
George McCollister185c8ae2016-05-26 08:55:16 -0500389 done
390 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391
Brad Bishop19323692019-04-05 15:28:33 -0400392 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
393 dtbcount=1
Andrew Geissler82c905d2020-04-13 13:39:40 -0500394 for DTB in $(find "${EXTERNAL_KERNEL_DEVICETREE}" \( -name '*.dtb' -o -name '*.dtbo' \) -printf '%P\n' | sort); do
Brad Bishop19323692019-04-05 15:28:33 -0400395 DTB=$(echo "${DTB}" | tr '/' '_')
396 DTBS="${DTBS} ${DTB}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500397 fitimage_emit_section_dtb ${1} ${DTB} "${EXTERNAL_KERNEL_DEVICETREE}/${DTB}"
Brad Bishop19323692019-04-05 15:28:33 -0400398 done
399 fi
400
George McCollister185c8ae2016-05-26 08:55:16 -0500401 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600402 # Step 3: Prepare a setup section. (For x86)
403 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404 if [ -e arch/${ARCH}/boot/setup.bin ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600405 setupcount=1
406 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
407 fi
408
409 #
410 # Step 4: Prepare a ramdisk section.
George McCollister185c8ae2016-05-26 08:55:16 -0500411 #
412 if [ "x${ramdiskcount}" = "x1" ] ; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800413 # Find and use the first initramfs image archive type we find
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800414 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500415 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800416 echo "Using $initramfs_path"
417 if [ -e "${initramfs_path}" ]; then
418 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
419 break
420 fi
421 done
George McCollister185c8ae2016-05-26 08:55:16 -0500422 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500423
George McCollister185c8ae2016-05-26 08:55:16 -0500424 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500425
George McCollister185c8ae2016-05-26 08:55:16 -0500426 # Force the first Kernel and DTB in the default config
427 kernelcount=1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500428 if [ -n "${dtbcount}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600429 dtbcount=1
430 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500431
George McCollister185c8ae2016-05-26 08:55:16 -0500432 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600433 # Step 5: Prepare a configurations section
George McCollister185c8ae2016-05-26 08:55:16 -0500434 #
435 fitimage_emit_section_maint ${1} confstart
436
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500437 if [ -n "${DTBS}" ]; then
438 i=1
439 for DTB in ${DTBS}; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800440 dtb_ext=${DTB##*.}
441 if [ "${dtb_ext}" = "dtbo" ]; then
442 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`"
443 else
444 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
445 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500446 i=`expr ${i} + 1`
447 done
448 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500449
450 fitimage_emit_section_maint ${1} sectend
451
452 fitimage_emit_section_maint ${1} fitend
453
454 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600455 # Step 6: Assemble the image
George McCollister185c8ae2016-05-26 08:55:16 -0500456 #
457 uboot-mkimage \
458 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
459 -f ${1} \
460 arch/${ARCH}/boot/${2}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600461
462 #
463 # Step 7: Sign the image and add public key to U-Boot dtb
464 #
465 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400466 add_key_to_u_boot=""
467 if [ -n "${UBOOT_DTB_BINARY}" ]; then
468 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
469 # both of them, and don't dereference the symlink.
470 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
471 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
472 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600473 uboot-mkimage \
474 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
475 -F -k "${UBOOT_SIGN_KEYDIR}" \
Brad Bishop19323692019-04-05 15:28:33 -0400476 $add_key_to_u_boot \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600477 -r arch/${ARCH}/boot/${2}
478 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500479}
480
481do_assemble_fitimage() {
482 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
483 cd ${B}
484 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500485 fi
486}
487
488addtask assemble_fitimage before do_install after do_compile
489
George McCollister185c8ae2016-05-26 08:55:16 -0500490do_assemble_fitimage_initramfs() {
491 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
492 test -n "${INITRAMFS_IMAGE}" ; then
493 cd ${B}
494 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
495 fi
496}
497
Brad Bishop19323692019-04-05 15:28:33 -0400498addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
George McCollister185c8ae2016-05-26 08:55:16 -0500499
500
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500501kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502kernel_do_deploy_append() {
503 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400504 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500505 echo "Copying fit-image.its source file..."
Brad Bishop64c979e2019-11-04 13:55:29 -0500506 install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its"
507 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800508
509 echo "Copying linux.bin file..."
Brad Bishop64c979e2019-11-04 13:55:29 -0500510 install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin
511 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500512
George McCollister185c8ae2016-05-26 08:55:16 -0500513 if [ -n "${INITRAMFS_IMAGE}" ]; then
514 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Brad Bishop64c979e2019-11-04 13:55:29 -0500515 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its"
516 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 -0500517
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800518 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
Brad Bishop64c979e2019-11-04 13:55:29 -0500519 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin"
520 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 -0500521 fi
Brad Bishop19323692019-04-05 15:28:33 -0400522 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
523 # UBOOT_DTB_IMAGE is a realfile, but we can't use
524 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
525 # for u-boot, but we are in kernel env now.
Brad Bishop64c979e2019-11-04 13:55:29 -0500526 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/"
Brad Bishop19323692019-04-05 15:28:33 -0400527 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500528 fi
529}