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