blob: 332384de357a0e9bff53cf71cbe2c50c10eb1b20 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit kernel-uboot
2
3python __anonymous () {
He Zhefe76b1e2016-05-25 04:47:16 -04004 kerneltypes = d.getVar('KERNEL_IMAGETYPES', True) or ""
5 if 'fitImage' in kerneltypes.split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006 depends = d.getVar("DEPENDS", True)
7 depends = "%s u-boot-mkimage-native dtc-native" % depends
8 d.setVar("DEPENDS", depends)
9
10 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
11 # to kernel.bbclass . We have to override it, since we pack zImage
12 # (at least for now) into the fitImage .
He Zhefe76b1e2016-05-25 04:47:16 -040013 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE", True) or ""
14 if 'fitImage' in typeformake.split():
15 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', 'zImage'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17 image = d.getVar('INITRAMFS_IMAGE', True)
18 if image:
George McCollister185c8ae2016-05-26 08:55:16 -050019 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
20
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021}
22
Yannick Gicqueld5813b42016-04-27 16:20:55 +020023# Options for the device tree compiler passed to mkimage '-D' feature:
24UBOOT_MKIMAGE_DTCOPTS ??= ""
25
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026#
27# Emit the fitImage ITS header
28#
George McCollister185c8ae2016-05-26 08:55:16 -050029# $1 ... .its filename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030fitimage_emit_fit_header() {
George McCollister185c8ae2016-05-26 08:55:16 -050031 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032/dts-v1/;
33
34/ {
35 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
36 #address-cells = <1>;
37EOF
38}
39
40#
41# Emit the fitImage section bits
42#
George McCollister185c8ae2016-05-26 08:55:16 -050043# $1 ... .its filename
44# $2 ... Section bit type: imagestart - image section start
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045# confstart - configuration section start
46# sectend - section end
47# fitend - fitimage end
48#
49fitimage_emit_section_maint() {
George McCollister185c8ae2016-05-26 08:55:16 -050050 case $2 in
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 imagestart)
George McCollister185c8ae2016-05-26 08:55:16 -050052 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
54 images {
55EOF
56 ;;
57 confstart)
George McCollister185c8ae2016-05-26 08:55:16 -050058 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
60 configurations {
61EOF
62 ;;
63 sectend)
George McCollister185c8ae2016-05-26 08:55:16 -050064 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 };
66EOF
67 ;;
68 fitend)
George McCollister185c8ae2016-05-26 08:55:16 -050069 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070};
71EOF
72 ;;
73 esac
74}
75
76#
77# Emit the fitImage ITS kernel section
78#
George McCollister185c8ae2016-05-26 08:55:16 -050079# $1 ... .its filename
80# $2 ... Image counter
81# $3 ... Path to kernel image
82# $4 ... Compression type
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083fitimage_emit_section_kernel() {
84
85 kernel_csum="sha1"
86
87 ENTRYPOINT=${UBOOT_ENTRYPOINT}
88 if test -n "${UBOOT_ENTRYSYMBOL}"; then
89 ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \
George McCollister185c8ae2016-05-26 08:55:16 -050090 awk '$4=="${UBOOT_ENTRYSYMBOL}" {print $2}'`
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 fi
92
George McCollister185c8ae2016-05-26 08:55:16 -050093 cat << EOF >> ${1}
94 kernel@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 description = "Linux kernel";
George McCollister185c8ae2016-05-26 08:55:16 -050096 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 type = "kernel";
98 arch = "${UBOOT_ARCH}";
99 os = "linux";
George McCollister185c8ae2016-05-26 08:55:16 -0500100 compression = "${4}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 load = <${UBOOT_LOADADDRESS}>;
102 entry = <${ENTRYPOINT}>;
103 hash@1 {
104 algo = "${kernel_csum}";
105 };
106 };
107EOF
108}
109
110#
111# Emit the fitImage ITS DTB section
112#
George McCollister185c8ae2016-05-26 08:55:16 -0500113# $1 ... .its filename
114# $2 ... Image counter
115# $3 ... Path to DTB image
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116fitimage_emit_section_dtb() {
117
118 dtb_csum="sha1"
119
George McCollister185c8ae2016-05-26 08:55:16 -0500120 cat << EOF >> ${1}
121 fdt@${2} {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 description = "Flattened Device Tree blob";
George McCollister185c8ae2016-05-26 08:55:16 -0500123 data = /incbin/("${3}");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 type = "flat_dt";
125 arch = "${UBOOT_ARCH}";
126 compression = "none";
127 hash@1 {
128 algo = "${dtb_csum}";
129 };
130 };
131EOF
132}
133
134#
George McCollister185c8ae2016-05-26 08:55:16 -0500135# Emit the fitImage ITS ramdisk section
136#
137# $1 ... .its filename
138# $2 ... Image counter
139# $3 ... Path to ramdisk image
140fitimage_emit_section_ramdisk() {
141
142 ramdisk_csum="sha1"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800143 ramdisk_ctype="none"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000144 ramdisk_loadline=""
145 ramdisk_entryline=""
146
147 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
148 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
149 fi
150 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
151 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
152 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500153
Rick Altherrbc1b8802017-01-20 11:28:53 -0800154 case $3 in
155 *.gz)
156 ramdisk_ctype="gzip"
157 ;;
158 *.bz2)
159 ramdisk_ctype="bzip2"
160 ;;
161 *.lzma)
162 ramdisk_ctype="lzma"
163 ;;
164 *.lzo)
165 ramdisk_ctype="lzo"
166 ;;
167 *.lz4)
168 ramdisk_ctype="lz4"
169 ;;
170 esac
171
George McCollister185c8ae2016-05-26 08:55:16 -0500172 cat << EOF >> ${1}
173 ramdisk@${2} {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800174 description = "${INITRAMFS_IMAGE}";
George McCollister185c8ae2016-05-26 08:55:16 -0500175 data = /incbin/("${3}");
176 type = "ramdisk";
177 arch = "${UBOOT_ARCH}";
178 os = "linux";
Rick Altherrbc1b8802017-01-20 11:28:53 -0800179 compression = "${ramdisk_ctype}";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000180 ${ramdisk_loadline}
181 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500182 hash@1 {
183 algo = "${ramdisk_csum}";
184 };
185 };
186EOF
187}
188
189#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190# Emit the fitImage ITS configuration section
191#
George McCollister185c8ae2016-05-26 08:55:16 -0500192# $1 ... .its filename
193# $2 ... Linux kernel ID
194# $3 ... DTB image ID
195# $4 ... ramdisk ID
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196fitimage_emit_section_config() {
197
198 conf_csum="sha1"
199
200 # Test if we have any DTBs at all
George McCollister185c8ae2016-05-26 08:55:16 -0500201 if [ -z "${3}" -a -z "${4}" ] ; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 conf_desc="Boot Linux kernel"
203 fdt_line=""
George McCollister185c8ae2016-05-26 08:55:16 -0500204 ramdisk_line=""
205 elif [ -z "${4}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 conf_desc="Boot Linux kernel with FDT blob"
George McCollister185c8ae2016-05-26 08:55:16 -0500207 fdt_line="fdt = \"fdt@${3}\";"
208 ramdisk_line=""
209 elif [ -z "${3}" ]; then
210 conf_desc="Boot Linux kernel with ramdisk"
211 fdt_line=""
212 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
213 else
214 conf_desc="Boot Linux kernel with FDT blob, ramdisk"
215 fdt_line="fdt = \"fdt@${3}\";"
216 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500218 kernel_line="kernel = \"kernel@${2}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219
George McCollister185c8ae2016-05-26 08:55:16 -0500220 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 default = "conf@1";
222 conf@1 {
223 description = "${conf_desc}";
224 ${kernel_line}
225 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500226 ${ramdisk_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227 hash@1 {
228 algo = "${conf_csum}";
229 };
230 };
231EOF
232}
233
George McCollister185c8ae2016-05-26 08:55:16 -0500234#
235# Assemble fitImage
236#
237# $1 ... .its filename
238# $2 ... fitImage name
239# $3 ... include ramdisk
240fitimage_assemble() {
241 kernelcount=1
242 dtbcount=""
243 ramdiskcount=${3}
244 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
George McCollister185c8ae2016-05-26 08:55:16 -0500246 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247
George McCollister185c8ae2016-05-26 08:55:16 -0500248 #
249 # Step 1: Prepare a kernel image section.
250 #
251 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252
George McCollister185c8ae2016-05-26 08:55:16 -0500253 uboot_prep_kimage
254 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255
George McCollister185c8ae2016-05-26 08:55:16 -0500256 #
257 # Step 2: Prepare a DTB image section
258 #
259 if test -n "${KERNEL_DEVICETREE}"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500261 for DTB in ${KERNEL_DEVICETREE}; do
262 if echo ${DTB} | grep -q '/dts/'; then
263 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
264 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
265 fi
266 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
267 if [ ! -e "${DTB_PATH}" ]; then
268 DTB_PATH="arch/${ARCH}/boot/${DTB}"
269 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270
George McCollister185c8ae2016-05-26 08:55:16 -0500271 fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH}
272 dtbcount=`expr ${dtbcount} + 1`
273 done
274 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275
George McCollister185c8ae2016-05-26 08:55:16 -0500276 #
277 # Step 3: Prepare a ramdisk section.
278 #
279 if [ "x${ramdiskcount}" = "x1" ] ; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800280 # Find and use the first initramfs image archive type we find
281 for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz cpio; do
282 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.${img}"
283 echo "Using $initramfs_path"
284 if [ -e "${initramfs_path}" ]; then
285 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}"
286 break
287 fi
288 done
George McCollister185c8ae2016-05-26 08:55:16 -0500289 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290
George McCollister185c8ae2016-05-26 08:55:16 -0500291 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292
George McCollister185c8ae2016-05-26 08:55:16 -0500293 # Force the first Kernel and DTB in the default config
294 kernelcount=1
295 dtbcount=1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500296
George McCollister185c8ae2016-05-26 08:55:16 -0500297 #
298 # Step 4: Prepare a configurations section
299 #
300 fitimage_emit_section_maint ${1} confstart
301
302 fitimage_emit_section_config ${1} ${kernelcount} ${dtbcount} ${ramdiskcount}
303
304 fitimage_emit_section_maint ${1} sectend
305
306 fitimage_emit_section_maint ${1} fitend
307
308 #
309 # Step 5: Assemble the image
310 #
311 uboot-mkimage \
312 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
313 -f ${1} \
314 arch/${ARCH}/boot/${2}
315}
316
317do_assemble_fitimage() {
318 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
319 cd ${B}
320 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321 fi
322}
323
324addtask assemble_fitimage before do_install after do_compile
325
George McCollister185c8ae2016-05-26 08:55:16 -0500326do_assemble_fitimage_initramfs() {
327 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
328 test -n "${INITRAMFS_IMAGE}" ; then
329 cd ${B}
330 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
331 fi
332}
333
334addtask assemble_fitimage_initramfs before do_deploy after do_install
335
336
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500337kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338kernel_do_deploy_append() {
339 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400340 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341 cd ${B}
342 echo "Copying fit-image.its source file..."
He Zhefe76b1e2016-05-25 04:47:16 -0400343 its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
344 its_symlink_name=fitImage-its-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345 install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its
He Zhefe76b1e2016-05-25 04:47:16 -0400346 linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
347 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
349
George McCollister185c8ae2016-05-26 08:55:16 -0500350 if [ -n "${INITRAMFS_IMAGE}" ]; then
351 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Nathan Rossi578589a2016-10-21 22:07:28 +1000352 its_initramfs_base_name="fitImage-its-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
353 its_initramfs_symlink_name=fitImage-its-${INITRAMFS_IMAGE}-${MACHINE}
George McCollister185c8ae2016-05-26 08:55:16 -0500354 install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its
Nathan Rossi578589a2016-10-21 22:07:28 +1000355 fit_initramfs_base_name="fitImage-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
356 fit_initramfs_symlink_name=fitImage-${INITRAMFS_IMAGE}-${MACHINE}
George McCollister185c8ae2016-05-26 08:55:16 -0500357 install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin
358 fi
359
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360 cd ${DEPLOYDIR}
361 ln -sf ${its_base_name}.its ${its_symlink_name}.its
362 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
George McCollister185c8ae2016-05-26 08:55:16 -0500363
364 if [ -n "${INITRAMFS_IMAGE}" ]; then
365 ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its
366 ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin
367 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368 fi
369}