blob: 2517d757466876bd777a89781826f6567e7076aa [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"
13 elif uarch == "mips":
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014 replacementtype = "vmlinuz.bin"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015 elif uarch == "x86":
Patrick Williamsc0f7c042017-02-23 20:41:17 -060016 replacementtype = "bzImage"
Brad Bishop316dfdd2018-06-25 12:45:53 -040017 elif uarch == "microblaze":
18 replacementtype = "linux.bin"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019 else:
20 replacementtype = "zImage"
21
Brad Bishop19323692019-04-05 15:28:33 -040022 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
23 # to kernel.bbclass . We have to override it, since we pack zImage
24 # (at least for now) into the fitImage .
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
He Zhefe76b1e2016-05-25 04:47:16 -040026 if 'fitImage' in typeformake.split():
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', replacementtype))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 image = d.getVar('INITRAMFS_IMAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030 if image:
George McCollister185c8ae2016-05-26 08:55:16 -050031 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
32
Brad Bishop19323692019-04-05 15:28:33 -040033 #check if there are any dtb providers
34 providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
35 if providerdtb:
36 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot')
37 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot')
38 d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree")
39
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040 # Verified boot will sign the fitImage and append the public key to
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042 # the fitImage:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 if d.getVar('UBOOT_SIGN_ENABLE') == "1":
44 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
Brad Bishop19323692019-04-05 15:28:33 -040045 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046}
47
Yannick Gicqueld5813b42016-04-27 16:20:55 +020048# Options for the device tree compiler passed to mkimage '-D' feature:
49UBOOT_MKIMAGE_DTCOPTS ??= ""
50
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051#
52# Emit the fitImage ITS header
53#
George McCollister185c8ae2016-05-26 08:55:16 -050054# $1 ... .its filename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055fitimage_emit_fit_header() {
George McCollister185c8ae2016-05-26 08:55:16 -050056 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057/dts-v1/;
58
59/ {
60 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
61 #address-cells = <1>;
62EOF
63}
64
65#
66# Emit the fitImage section bits
67#
George McCollister185c8ae2016-05-26 08:55:16 -050068# $1 ... .its filename
69# $2 ... Section bit type: imagestart - image section start
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070# confstart - configuration section start
71# sectend - section end
72# fitend - fitimage end
73#
74fitimage_emit_section_maint() {
George McCollister185c8ae2016-05-26 08:55:16 -050075 case $2 in
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 imagestart)
George McCollister185c8ae2016-05-26 08:55:16 -050077 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
79 images {
80EOF
81 ;;
82 confstart)
George McCollister185c8ae2016-05-26 08:55:16 -050083 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
85 configurations {
86EOF
87 ;;
88 sectend)
George McCollister185c8ae2016-05-26 08:55:16 -050089 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090 };
91EOF
92 ;;
93 fitend)
George McCollister185c8ae2016-05-26 08:55:16 -050094 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095};
96EOF
97 ;;
98 esac
99}
100
101#
102# Emit the fitImage ITS kernel section
103#
George McCollister185c8ae2016-05-26 08:55:16 -0500104# $1 ... .its filename
105# $2 ... Image counter
106# $3 ... Path to kernel image
107# $4 ... Compression type
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108fitimage_emit_section_kernel() {
109
110 kernel_csum="sha1"
111
Brad Bishop316dfdd2018-06-25 12:45:53 -0400112 ENTRYPOINT="${UBOOT_ENTRYPOINT}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
114 ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \
115 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 fi
117
George McCollister185c8ae2016-05-26 08:55:16 -0500118 cat << EOF >> ${1}
119 kernel@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 description = "Linux kernel";
George McCollister185c8ae2016-05-26 08:55:16 -0500121 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 type = "kernel";
123 arch = "${UBOOT_ARCH}";
124 os = "linux";
George McCollister185c8ae2016-05-26 08:55:16 -0500125 compression = "${4}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 load = <${UBOOT_LOADADDRESS}>;
127 entry = <${ENTRYPOINT}>;
128 hash@1 {
129 algo = "${kernel_csum}";
130 };
131 };
132EOF
133}
134
135#
136# Emit the fitImage ITS DTB section
137#
George McCollister185c8ae2016-05-26 08:55:16 -0500138# $1 ... .its filename
139# $2 ... Image counter
140# $3 ... Path to DTB image
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141fitimage_emit_section_dtb() {
142
143 dtb_csum="sha1"
144
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800145 dtb_loadline=""
146 dtb_ext=${DTB##*.}
147 if [ "${dtb_ext}" = "dtbo" ]; then
148 if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then
149 dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;"
150 fi
151 elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then
152 dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;"
153 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500154 cat << EOF >> ${1}
155 fdt@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156 description = "Flattened Device Tree blob";
George McCollister185c8ae2016-05-26 08:55:16 -0500157 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 type = "flat_dt";
159 arch = "${UBOOT_ARCH}";
160 compression = "none";
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800161 ${dtb_loadline}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 hash@1 {
163 algo = "${dtb_csum}";
164 };
165 };
166EOF
167}
168
169#
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170# Emit the fitImage ITS setup section
171#
172# $1 ... .its filename
173# $2 ... Image counter
174# $3 ... Path to setup image
175fitimage_emit_section_setup() {
176
177 setup_csum="sha1"
178
179 cat << EOF >> ${1}
180 setup@${2} {
181 description = "Linux setup.bin";
182 data = /incbin/("${3}");
183 type = "x86_setup";
184 arch = "${UBOOT_ARCH}";
185 os = "linux";
186 compression = "none";
187 load = <0x00090000>;
188 entry = <0x00090000>;
189 hash@1 {
190 algo = "${setup_csum}";
191 };
192 };
193EOF
194}
195
196#
George McCollister185c8ae2016-05-26 08:55:16 -0500197# Emit the fitImage ITS ramdisk section
198#
199# $1 ... .its filename
200# $2 ... Image counter
201# $3 ... Path to ramdisk image
202fitimage_emit_section_ramdisk() {
203
204 ramdisk_csum="sha1"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800205 ramdisk_ctype="none"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000206 ramdisk_loadline=""
207 ramdisk_entryline=""
208
209 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
210 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
211 fi
212 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
213 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
214 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500215
Rick Altherrbc1b8802017-01-20 11:28:53 -0800216 case $3 in
217 *.gz)
218 ramdisk_ctype="gzip"
219 ;;
220 *.bz2)
221 ramdisk_ctype="bzip2"
222 ;;
223 *.lzma)
224 ramdisk_ctype="lzma"
225 ;;
226 *.lzo)
227 ramdisk_ctype="lzo"
228 ;;
229 *.lz4)
230 ramdisk_ctype="lz4"
231 ;;
232 esac
233
George McCollister185c8ae2016-05-26 08:55:16 -0500234 cat << EOF >> ${1}
235 ramdisk@${2} {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800236 description = "${INITRAMFS_IMAGE}";
George McCollister185c8ae2016-05-26 08:55:16 -0500237 data = /incbin/("${3}");
238 type = "ramdisk";
239 arch = "${UBOOT_ARCH}";
240 os = "linux";
Rick Altherrbc1b8802017-01-20 11:28:53 -0800241 compression = "${ramdisk_ctype}";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000242 ${ramdisk_loadline}
243 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500244 hash@1 {
245 algo = "${ramdisk_csum}";
246 };
247 };
248EOF
249}
250
251#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252# Emit the fitImage ITS configuration section
253#
George McCollister185c8ae2016-05-26 08:55:16 -0500254# $1 ... .its filename
255# $2 ... Linux kernel ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500256# $3 ... DTB image name
George McCollister185c8ae2016-05-26 08:55:16 -0500257# $4 ... ramdisk ID
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600258# $5 ... config ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500259# $6 ... default flag
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260fitimage_emit_section_config() {
261
262 conf_csum="sha1"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600263 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
264 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
265 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
267 # Test if we have any DTBs at all
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800268 sep=""
269 conf_desc=""
270 kernel_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600271 fdt_line=""
272 ramdisk_line=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500273 setup_line=""
274 default_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600275
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800276 if [ -n "${2}" ]; then
277 conf_desc="Linux kernel"
278 sep=", "
279 kernel_line="kernel = \"kernel@${2}\";"
280 fi
281
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600282 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800283 conf_desc="${conf_desc}${sep}FDT blob"
284 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500285 fdt_line="fdt = \"fdt@${3}\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286 fi
287
288 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800289 conf_desc="${conf_desc}${sep}ramdisk"
290 sep=", "
George McCollister185c8ae2016-05-26 08:55:16 -0500291 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600293
294 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800295 conf_desc="${conf_desc}${sep}setup"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600296 setup_line="setup = \"setup@${5}\";"
297 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500299 if [ "${6}" = "1" ]; then
300 default_line="default = \"conf@${3}\";"
301 fi
302
George McCollister185c8ae2016-05-26 08:55:16 -0500303 cat << EOF >> ${1}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500304 ${default_line}
305 conf@${3} {
306 description = "${6} ${conf_desc}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307 ${kernel_line}
308 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500309 ${ramdisk_line}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600310 ${setup_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311 hash@1 {
312 algo = "${conf_csum}";
313 };
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600314EOF
315
316 if [ ! -z "${conf_sign_keyname}" ] ; then
317
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800318 sign_line="sign-images = "
319 sep=""
320
321 if [ -n "${2}" ]; then
322 sign_line="${sign_line}${sep}\"kernel\""
323 sep=", "
324 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600325
326 if [ -n "${3}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800327 sign_line="${sign_line}${sep}\"fdt\""
328 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600329 fi
330
331 if [ -n "${4}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800332 sign_line="${sign_line}${sep}\"ramdisk\""
333 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600334 fi
335
336 if [ -n "${5}" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800337 sign_line="${sign_line}${sep}\"setup\""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600338 fi
339
340 sign_line="${sign_line};"
341
342 cat << EOF >> ${1}
343 signature@1 {
344 algo = "${conf_csum},rsa2048";
345 key-name-hint = "${conf_sign_keyname}";
346 ${sign_line}
347 };
348EOF
349 fi
350
351 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352 };
353EOF
354}
355
George McCollister185c8ae2016-05-26 08:55:16 -0500356#
357# Assemble fitImage
358#
359# $1 ... .its filename
360# $2 ... fitImage name
361# $3 ... include ramdisk
362fitimage_assemble() {
363 kernelcount=1
364 dtbcount=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500365 DTBS=""
George McCollister185c8ae2016-05-26 08:55:16 -0500366 ramdiskcount=${3}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600367 setupcount=""
George McCollister185c8ae2016-05-26 08:55:16 -0500368 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369
George McCollister185c8ae2016-05-26 08:55:16 -0500370 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371
George McCollister185c8ae2016-05-26 08:55:16 -0500372 #
373 # Step 1: Prepare a kernel image section.
374 #
375 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376
George McCollister185c8ae2016-05-26 08:55:16 -0500377 uboot_prep_kimage
378 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500379
George McCollister185c8ae2016-05-26 08:55:16 -0500380 #
381 # Step 2: Prepare a DTB image section
382 #
Brad Bishop19323692019-04-05 15:28:33 -0400383
384 if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500386 for DTB in ${KERNEL_DEVICETREE}; do
387 if echo ${DTB} | grep -q '/dts/'; then
388 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
389 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
390 fi
391 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
392 if [ ! -e "${DTB_PATH}" ]; then
393 DTB_PATH="arch/${ARCH}/boot/${DTB}"
394 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500396 DTB=$(echo "${DTB}" | tr '/' '_')
397 DTBS="${DTBS} ${DTB}"
398 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
George McCollister185c8ae2016-05-26 08:55:16 -0500399 done
400 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401
Brad Bishop19323692019-04-05 15:28:33 -0400402 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
403 dtbcount=1
404 for DTBFILE in ${EXTERNAL_KERNEL_DEVICETREE}/*.dtb; do
405 DTB=`basename ${DTBFILE}`
406 DTB=$(echo "${DTB}" | tr '/' '_')
407 DTBS="${DTBS} ${DTB}"
408 fitimage_emit_section_dtb ${1} ${DTB} ${DTBFILE}
409 done
410 fi
411
George McCollister185c8ae2016-05-26 08:55:16 -0500412 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600413 # Step 3: Prepare a setup section. (For x86)
414 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500415 if [ -e arch/${ARCH}/boot/setup.bin ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600416 setupcount=1
417 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
418 fi
419
420 #
421 # Step 4: Prepare a ramdisk section.
George McCollister185c8ae2016-05-26 08:55:16 -0500422 #
423 if [ "x${ramdiskcount}" = "x1" ] ; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800424 # Find and use the first initramfs image archive type we find
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800425 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500426 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800427 echo "Using $initramfs_path"
428 if [ -e "${initramfs_path}" ]; then
429 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
430 break
431 fi
432 done
George McCollister185c8ae2016-05-26 08:55:16 -0500433 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500434
George McCollister185c8ae2016-05-26 08:55:16 -0500435 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436
George McCollister185c8ae2016-05-26 08:55:16 -0500437 # Force the first Kernel and DTB in the default config
438 kernelcount=1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500439 if [ -n "${dtbcount}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600440 dtbcount=1
441 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500442
George McCollister185c8ae2016-05-26 08:55:16 -0500443 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600444 # Step 5: Prepare a configurations section
George McCollister185c8ae2016-05-26 08:55:16 -0500445 #
446 fitimage_emit_section_maint ${1} confstart
447
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500448 if [ -n "${DTBS}" ]; then
449 i=1
450 for DTB in ${DTBS}; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800451 dtb_ext=${DTB##*.}
452 if [ "${dtb_ext}" = "dtbo" ]; then
453 fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`"
454 else
455 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
456 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500457 i=`expr ${i} + 1`
458 done
459 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500460
461 fitimage_emit_section_maint ${1} sectend
462
463 fitimage_emit_section_maint ${1} fitend
464
465 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600466 # Step 6: Assemble the image
George McCollister185c8ae2016-05-26 08:55:16 -0500467 #
468 uboot-mkimage \
469 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
470 -f ${1} \
471 arch/${ARCH}/boot/${2}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600472
473 #
474 # Step 7: Sign the image and add public key to U-Boot dtb
475 #
476 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400477 add_key_to_u_boot=""
478 if [ -n "${UBOOT_DTB_BINARY}" ]; then
479 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
480 # both of them, and don't dereference the symlink.
481 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
482 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
483 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600484 uboot-mkimage \
485 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
486 -F -k "${UBOOT_SIGN_KEYDIR}" \
Brad Bishop19323692019-04-05 15:28:33 -0400487 $add_key_to_u_boot \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600488 -r arch/${ARCH}/boot/${2}
489 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500490}
491
492do_assemble_fitimage() {
493 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
494 cd ${B}
495 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500496 fi
497}
498
499addtask assemble_fitimage before do_install after do_compile
500
George McCollister185c8ae2016-05-26 08:55:16 -0500501do_assemble_fitimage_initramfs() {
502 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
503 test -n "${INITRAMFS_IMAGE}" ; then
504 cd ${B}
505 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
506 fi
507}
508
Brad Bishop19323692019-04-05 15:28:33 -0400509addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
George McCollister185c8ae2016-05-26 08:55:16 -0500510
511
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500512kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500513kernel_do_deploy_append() {
514 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400515 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500516 echo "Copying fit-image.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800517 install -m 0644 ${B}/fit-image.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_NAME}.its
518 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_LINK_NAME}
519
520 echo "Copying linux.bin file..."
521 install -m 0644 ${B}/linux.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin
522 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500523
George McCollister185c8ae2016-05-26 08:55:16 -0500524 if [ -n "${INITRAMFS_IMAGE}" ]; then
525 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800526 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its
527 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 -0500528
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800529 echo "Copying fitImage-${INITRAMFS_IMAGE} file..."
530 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin
531 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 -0500532 fi
Brad Bishop19323692019-04-05 15:28:33 -0400533 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
534 # UBOOT_DTB_IMAGE is a realfile, but we can't use
535 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
536 # for u-boot, but we are in kernel env now.
537 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb ${DEPLOYDIR}/
538 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500539 fi
540}