summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/kernel-itbimage.bbclass493
1 files changed, 0 insertions, 493 deletions
diff --git a/classes/kernel-itbimage.bbclass b/classes/kernel-itbimage.bbclass
deleted file mode 100644
index 91bceb85..00000000
--- a/classes/kernel-itbimage.bbclass
+++ /dev/null
@@ -1,493 +0,0 @@
1inherit kernel-uboot uboot-sign
2
3python __anonymous () {
4 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
5 if 'itbImage' in kerneltypes.split():
6 depends = d.getVar("DEPENDS")
7 depends = "%s u-boot-mkimage-native dtc-native" % depends
8 d.setVar("DEPENDS", depends)
9
10 if d.getVar("UBOOT_ARCH") == "x86":
11 replacementtype = "bzImage"
12 else:
13 replacementtype = "vmlinux"
14
15 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
16 # to kernel.bbclass . We have to override it, since we pack zImage
17 # (at least for now) into the fitImage .
18 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
19 if 'itbImage' in typeformake.split():
20 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('itbImage', replacementtype))
21
22 image = d.getVar('INITRAMFS_IMAGE')
23 if image:
24 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
25 def extraimage_getdepends(task):
26 deps = ""
27 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
28 deps += " %s:%s" % (dep, task)
29 return deps
30
31 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_lic'))
32 d.appendVarFlag('do_image_complete', 'depends', extraimage_getdepends('do_populate_sysroot'))
33
34 # Verified boot will sign the fitImage and append the public key to
35 # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling
36 # the fitImage:
37 if d.getVar('UBOOT_SIGN_ENABLE') == "1":
38 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
39 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_deploy' % uboot_pn)
40}
41
42# Options for the device tree compiler passed to mkimage '-D' feature:
43UBOOT_MKIMAGE_DTCOPTS ??= ""
44
45#
46# Emit the fitImage ITS header
47#
48# $1 ... .its filename
49fitimage_emit_fit_header() {
50 cat << EOF >> ${1}
51/dts-v1/;
52
53/ {
54 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
55 #address-cells = <1>;
56EOF
57}
58
59#
60# Emit the fitImage section bits
61#
62# $1 ... .its filename
63# $2 ... Section bit type: imagestart - image section start
64# confstart - configuration section start
65# sectend - section end
66# fitend - fitimage end
67#
68fitimage_emit_section_maint() {
69 case $2 in
70 imagestart)
71 cat << EOF >> ${1}
72
73 images {
74EOF
75 ;;
76 confstart)
77 cat << EOF >> ${1}
78
79 configurations {
80EOF
81 ;;
82 sectend)
83 cat << EOF >> ${1}
84 };
85EOF
86 ;;
87 fitend)
88 cat << EOF >> ${1}
89};
90EOF
91 ;;
92 esac
93}
94
95#
96# Emit the fitImage ITS kernel section
97#
98# $1 ... .its filename
99# $2 ... Image counter
100# $3 ... Path to kernel image
101# $4 ... Compression type
102fitimage_emit_section_kernel() {
103
104 kernel_csum="sha1"
105
106 ENTRYPOINT=${UBOOT_ENTRYPOINT}
107 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
108 ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \
109 awk '$4=="${UBOOT_ENTRYSYMBOL}" {print $2}'`
110 fi
111
112 cat << EOF >> ${1}
113 kernel@${2} {
114 description = "Linux kernel";
115 data = /incbin/("${3}");
116 type = "kernel";
117 arch = "${UBOOT_ARCH}";
118 os = "linux";
119 compression = "${4}";
120 load = <${UBOOT_LOADADDRESS}>;
121 entry = <${ENTRYPOINT}>;
122 hash@1 {
123 algo = "${kernel_csum}";
124 };
125 };
126EOF
127}
128
129#
130# Emit the fitImage ITS DTB section
131#
132# $1 ... .its filename
133# $2 ... Image counter
134# $3 ... Path to DTB image
135fitimage_emit_section_dtb() {
136
137 dtb_csum="sha1"
138
139 if [ -n "${DTB_LOAD}" ]; then
140 dtb_loadline="load = <${DTB_LOAD}>;"
141 fi
142
143 cat << EOF >> ${1}
144 fdt@${2} {
145 description = "Flattened Device Tree blob";
146 data = /incbin/("${3}");
147 type = "flat_dt";
148 arch = "${UBOOT_ARCH}";
149 compression = "none";
150 ${dtb_loadline}
151 hash@1 {
152 algo = "${dtb_csum}";
153 };
154 };
155EOF
156}
157
158#
159# Emit the fitImage ITS setup section
160#
161# $1 ... .its filename
162# $2 ... Image counter
163# $3 ... Path to setup image
164fitimage_emit_section_setup() {
165
166 setup_csum="sha1"
167
168 cat << EOF >> ${1}
169 setup@${2} {
170 description = "Linux setup.bin";
171 data = /incbin/("${3}");
172 type = "x86_setup";
173 arch = "${UBOOT_ARCH}";
174 os = "linux";
175 compression = "none";
176 load = <0x00090000>;
177 entry = <0x00090000>;
178 hash@1 {
179 algo = "${setup_csum}";
180 };
181 };
182EOF
183}
184
185#
186# Emit the fitImage ITS ramdisk section
187#
188# $1 ... .its filename
189# $2 ... Image counter
190# $3 ... Path to ramdisk image
191fitimage_emit_section_ramdisk() {
192
193 ramdisk_csum="sha1"
194 ramdisk_ctype="none"
195 ramdisk_loadline=""
196 ramdisk_entryline=""
197
198 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
199 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
200 fi
201 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
202 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
203 fi
204
205 case $3 in
206 *.gz)
207 ramdisk_ctype="gzip"
208 ;;
209 *.bz2)
210 ramdisk_ctype="bzip2"
211 ;;
212 *.lzma)
213 ramdisk_ctype="lzma"
214 ;;
215 *.lzo)
216 ramdisk_ctype="lzo"
217 ;;
218 *.lz4)
219 ramdisk_ctype="lz4"
220 ;;
221 esac
222
223 cat << EOF >> ${1}
224 ramdisk@${2} {
225 description = "${INITRAMFS_IMAGE}";
226 data = /incbin/("${3}");
227 type = "ramdisk";
228 arch = "${UBOOT_ARCH}";
229 os = "linux";
230 compression = "${ramdisk_ctype}";
231 ${ramdisk_loadline}
232 ${ramdisk_entryline}
233 hash@1 {
234 algo = "${ramdisk_csum}";
235 };
236 };
237EOF
238}
239
240#
241# Emit the fitImage ITS configuration section
242#
243# $1 ... .its filename
244# $2 ... Linux kernel ID
245# $3 ... DTB image name
246# $4 ... ramdisk ID
247# $5 ... config ID
248# $6 ... default flag
249fitimage_emit_section_config() {
250
251 conf_csum="sha1"
252 if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then
253 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
254 fi
255
256 # Test if we have any DTBs at all
257 conf_desc="Linux kernel"
258 kernel_line="kernel = \"kernel@${2}\";"
259 fdt_line=""
260 ramdisk_line=""
261 setup_line=""
262 default_line=""
263
264 if [ -n "${3}" ]; then
265 conf_desc="${conf_desc}, FDT blob"
266 fdt_line="fdt = \"fdt@${3}\";"
267 fi
268
269 if [ -n "${4}" ]; then
270 conf_desc="${conf_desc}, ramdisk"
271 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
272 fi
273
274 if [ -n "${5}" ]; then
275 conf_desc="${conf_desc}, setup"
276 setup_line="setup = \"setup@${5}\";"
277 fi
278
279 if [ "${6}" = "1" ]; then
280 default_line="default = \"conf@${3}\";"
281 fi
282
283 cat << EOF >> ${1}
284 ${default_line}
285 conf@${3} {
286 description = "${6} ${conf_desc}";
287 ${kernel_line}
288 ${fdt_line}
289 ${ramdisk_line}
290 ${setup_line}
291 hash@1 {
292 algo = "${conf_csum}";
293 };
294EOF
295
296 if [ ! -z "${conf_sign_keyname}" ] ; then
297
298 sign_line="sign-images = \"kernel\""
299
300 if [ -n "${3}" ]; then
301 sign_line="${sign_line}, \"fdt\""
302 fi
303
304 if [ -n "${4}" ]; then
305 sign_line="${sign_line}, \"ramdisk\""
306 fi
307
308 if [ -n "${5}" ]; then
309 sign_line="${sign_line}, \"setup\""
310 fi
311
312 sign_line="${sign_line};"
313
314 cat << EOF >> ${1}
315 signature@1 {
316 algo = "${conf_csum},rsa2048";
317 key-name-hint = "${conf_sign_keyname}";
318 ${sign_line}
319 };
320EOF
321 fi
322
323 cat << EOF >> ${1}
324 };
325EOF
326}
327
328#
329# Assemble fitImage
330#
331# $1 ... .its filename
332# $2 ... fitImage name
333# $3 ... include ramdisk
334fitimage_assemble() {
335 kernelcount=1
336 dtbcount=""
337 DTBS=""
338 ramdiskcount=${3}
339 setupcount=""
340 rm -f ${1} arch/${ARCH}/boot/${2}
341
342 fitimage_emit_fit_header ${1}
343
344 #
345 # Step 1: Prepare a kernel image section.
346 #
347 fitimage_emit_section_maint ${1} imagestart
348
349 uboot_prep_kimage
350 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
351
352 #
353 # Step 2: Prepare a DTB image section
354 #
355 if [ -n "${KERNEL_DEVICETREE}" ]; then
356 dtbcount=1
357 for DTB in ${KERNEL_DEVICETREE}; do
358 if echo ${DTB} | grep -q '/dts/'; then
359 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
360 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
361 fi
362 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
363 DTB=`basename ${DTB}`
364 if [ ! -e "${DTB_PATH}" ]; then
365 DTB_PATH="arch/${ARCH}/boot/${DTB}"
366 fi
367
368 DTBS="${DTBS} ${DTB}"
369 fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
370 done
371 fi
372
373 #
374 # Step 3: Prepare a setup section. (For x86)
375 #
376 if [ -e arch/${ARCH}/boot/setup.bin ]; then
377 setupcount=1
378 fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin
379 fi
380
381 #
382 # Step 4: Prepare a ramdisk section.
383 #
384 if [ "x${ramdiskcount}" = "x1" ] ; then
385 # Find and use the first initramfs image archive type we find
386 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.zst cpio.xz cpio.gz ext2.gz cpio; do
387 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}"
388 echo "Using $initramfs_path"
389 if [ -e "${initramfs_path}" ]; then
390 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
391 break
392 fi
393 done
394 fi
395
396 fitimage_emit_section_maint ${1} sectend
397
398 # Force the first Kernel and DTB in the default config
399 kernelcount=1
400 if [ -n "${dtbcount}" ]; then
401 dtbcount=1
402 fi
403
404 #
405 # Step 5: Prepare a configurations section
406 #
407 fitimage_emit_section_maint ${1} confstart
408
409 if [ -n "${DTBS}" ]; then
410 i=1
411 for DTB in ${DTBS}; do
412 fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
413 i=`expr ${i} + 1`
414 done
415 fi
416
417 fitimage_emit_section_maint ${1} sectend
418
419 fitimage_emit_section_maint ${1} fitend
420
421 #
422 # Step 6: Assemble the image
423 #
424 uboot-mkimage \
425 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
426 -f ${1} \
427 arch/${ARCH}/boot/${2}
428
429 #
430 # Step 7: Sign the image and add public key to U-Boot dtb
431 #
432 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
433 uboot-mkimage \
434 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
435 -F -k "${UBOOT_SIGN_KEYDIR}" \
436 -K "${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_BINARY}" \
437 -r arch/${ARCH}/boot/${2}
438 fi
439}
440
441do_assemble_fitimage() {
442 if echo ${KERNEL_IMAGETYPES} | grep -wq "itbImage"; then
443 cd ${B}
444 fitimage_assemble itb-image.its itbImage
445 fi
446}
447
448addtask assemble_fitimage before do_install after do_compile
449
450do_assemble_fitimage_initramfs() {
451 if echo ${KERNEL_IMAGETYPES} | grep -wq "itbImage" && \
452 test -n "${INITRAMFS_IMAGE}" ; then
453 cd ${B}
454 fitimage_assemble itb-image-${INITRAMFS_IMAGE}.its itbImage-${INITRAMFS_IMAGE} 1
455 fi
456}
457
458addtask assemble_fitimage_initramfs before do_deploy after do_install
459
460
461kernel_do_deploy[vardepsexclude] = "DATETIME"
462kernel_do_deploy:append() {
463 # Update deploy directory
464 if echo ${KERNEL_IMAGETYPES} | grep -wq "itbImage"; then
465 cd ${B}
466 echo "Copying fit-image.its source file..."
467 its_base_name="itbImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
468 its_symlink_name=itbImage-its-${MACHINE}
469 install -m 0644 itb-image.its ${DEPLOYDIR}/${its_base_name}.its
470 linux_bin_base_name="itbImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
471 linux_bin_symlink_name=itbImage-linux.bin-${MACHINE}
472 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
473
474 if [ -n "${INITRAMFS_IMAGE}" ]; then
475 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
476 its_initramfs_base_name="itbImage-its-${INITRAMFS_IMAGE_NAME}-${PV}-${PR}-${DATETIME}"
477 its_initramfs_symlink_name=itbImage-its-${INITRAMFS_IMAGE_NAME}
478 install -m 0644 itb-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its
479 fit_initramfs_base_name="itbImage-${INITRAMFS_IMAGE_NAME}-${PV}-${PR}-${DATETIME}"
480 fit_initramfs_symlink_name=itbImage-${INITRAMFS_IMAGE_NAME}
481 install -m 0644 arch/${ARCH}/boot/itbImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin
482 fi
483
484 cd ${DEPLOYDIR}
485 ln -sf ${its_base_name}.its ${its_symlink_name}.its
486 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
487
488 if [ -n "${INITRAMFS_IMAGE}" ]; then
489 ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its
490 ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin
491 fi
492 fi
493}