blob: 3d1f85588ebb0b788a10cf18591e9bf1967a3bfa [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"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000143 ramdisk_loadline=""
144 ramdisk_entryline=""
145
146 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
147 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
148 fi
149 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
150 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
151 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500152
153 cat << EOF >> ${1}
154 ramdisk@${2} {
155 description = "ramdisk image";
156 data = /incbin/("${3}");
157 type = "ramdisk";
158 arch = "${UBOOT_ARCH}";
159 os = "linux";
160 compression = "none";
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000161 ${ramdisk_loadline}
162 ${ramdisk_entryline}
George McCollister185c8ae2016-05-26 08:55:16 -0500163 hash@1 {
164 algo = "${ramdisk_csum}";
165 };
166 };
167EOF
168}
169
170#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171# Emit the fitImage ITS configuration section
172#
George McCollister185c8ae2016-05-26 08:55:16 -0500173# $1 ... .its filename
174# $2 ... Linux kernel ID
175# $3 ... DTB image ID
176# $4 ... ramdisk ID
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177fitimage_emit_section_config() {
178
179 conf_csum="sha1"
180
181 # Test if we have any DTBs at all
George McCollister185c8ae2016-05-26 08:55:16 -0500182 if [ -z "${3}" -a -z "${4}" ] ; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 conf_desc="Boot Linux kernel"
184 fdt_line=""
George McCollister185c8ae2016-05-26 08:55:16 -0500185 ramdisk_line=""
186 elif [ -z "${4}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 conf_desc="Boot Linux kernel with FDT blob"
George McCollister185c8ae2016-05-26 08:55:16 -0500188 fdt_line="fdt = \"fdt@${3}\";"
189 ramdisk_line=""
190 elif [ -z "${3}" ]; then
191 conf_desc="Boot Linux kernel with ramdisk"
192 fdt_line=""
193 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
194 else
195 conf_desc="Boot Linux kernel with FDT blob, ramdisk"
196 fdt_line="fdt = \"fdt@${3}\";"
197 ramdisk_line="ramdisk = \"ramdisk@${4}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500199 kernel_line="kernel = \"kernel@${2}\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200
George McCollister185c8ae2016-05-26 08:55:16 -0500201 cat << EOF >> ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 default = "conf@1";
203 conf@1 {
204 description = "${conf_desc}";
205 ${kernel_line}
206 ${fdt_line}
George McCollister185c8ae2016-05-26 08:55:16 -0500207 ${ramdisk_line}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208 hash@1 {
209 algo = "${conf_csum}";
210 };
211 };
212EOF
213}
214
George McCollister185c8ae2016-05-26 08:55:16 -0500215#
216# Assemble fitImage
217#
218# $1 ... .its filename
219# $2 ... fitImage name
220# $3 ... include ramdisk
221fitimage_assemble() {
222 kernelcount=1
223 dtbcount=""
224 ramdiskcount=${3}
225 rm -f ${1} arch/${ARCH}/boot/${2}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
George McCollister185c8ae2016-05-26 08:55:16 -0500227 fitimage_emit_fit_header ${1}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228
George McCollister185c8ae2016-05-26 08:55:16 -0500229 #
230 # Step 1: Prepare a kernel image section.
231 #
232 fitimage_emit_section_maint ${1} imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233
George McCollister185c8ae2016-05-26 08:55:16 -0500234 uboot_prep_kimage
235 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236
George McCollister185c8ae2016-05-26 08:55:16 -0500237 #
238 # Step 2: Prepare a DTB image section
239 #
240 if test -n "${KERNEL_DEVICETREE}"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500242 for DTB in ${KERNEL_DEVICETREE}; do
243 if echo ${DTB} | grep -q '/dts/'; then
244 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
245 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
246 fi
247 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
248 if [ ! -e "${DTB_PATH}" ]; then
249 DTB_PATH="arch/${ARCH}/boot/${DTB}"
250 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251
George McCollister185c8ae2016-05-26 08:55:16 -0500252 fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH}
253 dtbcount=`expr ${dtbcount} + 1`
254 done
255 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256
George McCollister185c8ae2016-05-26 08:55:16 -0500257 #
258 # Step 3: Prepare a ramdisk section.
259 #
260 if [ "x${ramdiskcount}" = "x1" ] ; then
261 copy_initramfs
262 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
263 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264
George McCollister185c8ae2016-05-26 08:55:16 -0500265 fitimage_emit_section_maint ${1} sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
George McCollister185c8ae2016-05-26 08:55:16 -0500267 # Force the first Kernel and DTB in the default config
268 kernelcount=1
269 dtbcount=1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270
George McCollister185c8ae2016-05-26 08:55:16 -0500271 #
272 # Step 4: Prepare a configurations section
273 #
274 fitimage_emit_section_maint ${1} confstart
275
276 fitimage_emit_section_config ${1} ${kernelcount} ${dtbcount} ${ramdiskcount}
277
278 fitimage_emit_section_maint ${1} sectend
279
280 fitimage_emit_section_maint ${1} fitend
281
282 #
283 # Step 5: Assemble the image
284 #
285 uboot-mkimage \
286 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
287 -f ${1} \
288 arch/${ARCH}/boot/${2}
289}
290
291do_assemble_fitimage() {
292 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
293 cd ${B}
294 fitimage_assemble fit-image.its fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 fi
296}
297
298addtask assemble_fitimage before do_install after do_compile
299
George McCollister185c8ae2016-05-26 08:55:16 -0500300do_assemble_fitimage_initramfs() {
301 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
302 test -n "${INITRAMFS_IMAGE}" ; then
303 cd ${B}
304 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
305 fi
306}
307
308addtask assemble_fitimage_initramfs before do_deploy after do_install
309
310
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500311kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312kernel_do_deploy_append() {
313 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400314 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 cd ${B}
316 echo "Copying fit-image.its source file..."
He Zhefe76b1e2016-05-25 04:47:16 -0400317 its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
318 its_symlink_name=fitImage-its-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319 install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its
He Zhefe76b1e2016-05-25 04:47:16 -0400320 linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
321 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
323
George McCollister185c8ae2016-05-26 08:55:16 -0500324 if [ -n "${INITRAMFS_IMAGE}" ]; then
325 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
326 its_initramfs_base_name="${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
327 its_initramfs_symlink_name=${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${MACHINE}
328 install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its
329 fit_initramfs_base_name="${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
330 fit_initramfs_symlink_name=${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE}
331 install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin
332 fi
333
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334 cd ${DEPLOYDIR}
335 ln -sf ${its_base_name}.its ${its_symlink_name}.its
336 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
George McCollister185c8ae2016-05-26 08:55:16 -0500337
338 if [ -n "${INITRAMFS_IMAGE}" ]; then
339 ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its
340 ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin
341 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342 fi
343}