blob: 95a134437faf91d982432477ff356392fe4a6ec3 [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"
143
144 cat << EOF >> ${1}
145 ramdisk@${2} {
146 description = "ramdisk image";
147 data = /incbin/("${3}");
148 type = "ramdisk";
149 arch = "${UBOOT_ARCH}";
150 os = "linux";
151 compression = "none";
152 load = <${UBOOT_RD_LOADADDRESS}>;
153 entry = <${UBOOT_RD_ENTRYPOINT}>;
154 hash@1 {
155 algo = "${ramdisk_csum}";
156 };
157 };
158EOF
159}
160
161#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162# Emit the fitImage ITS configuration section
163#
George McCollister185c8ae2016-05-26 08:55:16 -0500164# $1 ... .its filename
165# $2 ... Linux kernel ID
166# $3 ... DTB image ID
167# $4 ... ramdisk ID
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168fitimage_emit_section_config() {
169
170 conf_csum="sha1"
171
172 # Test if we have any DTBs at all
George McCollister185c8ae2016-05-26 08:55:16 -0500173 if [ -z "${3}" -a -z "${4}" ] ; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 conf_desc="Boot Linux kernel"
175 fdt_line=""
George McCollister185c8ae2016-05-26 08:55:16 -0500176 ramdisk_line=""
177 elif [ -z "${4}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 conf_desc="Boot Linux kernel with FDT blob"
George McCollister185c8ae2016-05-26 08:55:16 -0500179 fdt_line="fdt = \"fdt@${3}\";"
180 ramdisk_line=""
181 elif [ -z "${3}" ]; then
182 conf_desc="Boot Linux kernel with ramdisk"
183 fdt_line=""
184 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
185 else
186 conf_desc="Boot Linux kernel with FDT blob, ramdisk"
187 fdt_line="fdt = \"fdt@${3}\";"
188 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500190 kernel_line="kernel = \"kernel@${2}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191
George McCollister185c8ae2016-05-26 08:55:16 -0500192 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 default = "conf@1";
194 conf@1 {
195 description = "${conf_desc}";
196 ${kernel_line}
197 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500198 ${ramdisk_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199 hash@1 {
200 algo = "${conf_csum}";
201 };
202 };
203EOF
204}
205
George McCollister185c8ae2016-05-26 08:55:16 -0500206#
207# Assemble fitImage
208#
209# $1 ... .its filename
210# $2 ... fitImage name
211# $3 ... include ramdisk
212fitimage_assemble() {
213 kernelcount=1
214 dtbcount=""
215 ramdiskcount=${3}
216 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217
George McCollister185c8ae2016-05-26 08:55:16 -0500218 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219
George McCollister185c8ae2016-05-26 08:55:16 -0500220 #
221 # Step 1: Prepare a kernel image section.
222 #
223 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224
George McCollister185c8ae2016-05-26 08:55:16 -0500225 uboot_prep_kimage
226 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227
George McCollister185c8ae2016-05-26 08:55:16 -0500228 #
229 # Step 2: Prepare a DTB image section
230 #
231 if test -n "${KERNEL_DEVICETREE}"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500233 for DTB in ${KERNEL_DEVICETREE}; do
234 if echo ${DTB} | grep -q '/dts/'; then
235 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
236 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
237 fi
238 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
239 if [ ! -e "${DTB_PATH}" ]; then
240 DTB_PATH="arch/${ARCH}/boot/${DTB}"
241 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500242
George McCollister185c8ae2016-05-26 08:55:16 -0500243 fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH}
244 dtbcount=`expr ${dtbcount} + 1`
245 done
246 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247
George McCollister185c8ae2016-05-26 08:55:16 -0500248 #
249 # Step 3: Prepare a ramdisk section.
250 #
251 if [ "x${ramdiskcount}" = "x1" ] ; then
252 copy_initramfs
253 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
254 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255
George McCollister185c8ae2016-05-26 08:55:16 -0500256 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257
George McCollister185c8ae2016-05-26 08:55:16 -0500258 # Force the first Kernel and DTB in the default config
259 kernelcount=1
260 dtbcount=1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261
George McCollister185c8ae2016-05-26 08:55:16 -0500262 #
263 # Step 4: Prepare a configurations section
264 #
265 fitimage_emit_section_maint ${1} confstart
266
267 fitimage_emit_section_config ${1} ${kernelcount} ${dtbcount} ${ramdiskcount}
268
269 fitimage_emit_section_maint ${1} sectend
270
271 fitimage_emit_section_maint ${1} fitend
272
273 #
274 # Step 5: Assemble the image
275 #
276 uboot-mkimage \
277 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
278 -f ${1} \
279 arch/${ARCH}/boot/${2}
280}
281
282do_assemble_fitimage() {
283 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
284 cd ${B}
285 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 fi
287}
288
289addtask assemble_fitimage before do_install after do_compile
290
George McCollister185c8ae2016-05-26 08:55:16 -0500291do_assemble_fitimage_initramfs() {
292 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
293 test -n "${INITRAMFS_IMAGE}" ; then
294 cd ${B}
295 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
296 fi
297}
298
299addtask assemble_fitimage_initramfs before do_deploy after do_install
300
301
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500302kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303kernel_do_deploy_append() {
304 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400305 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 cd ${B}
307 echo "Copying fit-image.its source file..."
He Zhefe76b1e2016-05-25 04:47:16 -0400308 its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
309 its_symlink_name=fitImage-its-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its
He Zhefe76b1e2016-05-25 04:47:16 -0400311 linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
312 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
314
George McCollister185c8ae2016-05-26 08:55:16 -0500315 if [ -n "${INITRAMFS_IMAGE}" ]; then
316 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
317 its_initramfs_base_name="${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
318 its_initramfs_symlink_name=${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${MACHINE}
319 install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its
320 fit_initramfs_base_name="${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
321 fit_initramfs_symlink_name=${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE}
322 install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin
323 fi
324
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325 cd ${DEPLOYDIR}
326 ln -sf ${its_base_name}.its ${its_symlink_name}.its
327 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
George McCollister185c8ae2016-05-26 08:55:16 -0500328
329 if [ -n "${INITRAMFS_IMAGE}" ]; then
330 ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its
331 ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin
332 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 fi
334}