blob: 80dfc15cc15fae1176f854e82b372faa25ac3e98 [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:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050019 d.appendVarFlag('do_assemble_fitimage', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020}
21
Yannick Gicqueld5813b42016-04-27 16:20:55 +020022# Options for the device tree compiler passed to mkimage '-D' feature:
23UBOOT_MKIMAGE_DTCOPTS ??= ""
24
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025#
26# Emit the fitImage ITS header
27#
28fitimage_emit_fit_header() {
29 cat << EOF >> fit-image.its
30/dts-v1/;
31
32/ {
33 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
34 #address-cells = <1>;
35EOF
36}
37
38#
39# Emit the fitImage section bits
40#
41# $1 ... Section bit type: imagestart - image section start
42# confstart - configuration section start
43# sectend - section end
44# fitend - fitimage end
45#
46fitimage_emit_section_maint() {
47 case $1 in
48 imagestart)
49 cat << EOF >> fit-image.its
50
51 images {
52EOF
53 ;;
54 confstart)
55 cat << EOF >> fit-image.its
56
57 configurations {
58EOF
59 ;;
60 sectend)
61 cat << EOF >> fit-image.its
62 };
63EOF
64 ;;
65 fitend)
66 cat << EOF >> fit-image.its
67};
68EOF
69 ;;
70 esac
71}
72
73#
74# Emit the fitImage ITS kernel section
75#
76# $1 ... Image counter
77# $2 ... Path to kernel image
78# $3 ... Compression type
79fitimage_emit_section_kernel() {
80
81 kernel_csum="sha1"
82
83 ENTRYPOINT=${UBOOT_ENTRYPOINT}
84 if test -n "${UBOOT_ENTRYSYMBOL}"; then
85 ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \
86 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print $1}'`
87 fi
88
89 cat << EOF >> fit-image.its
90 kernel@${1} {
91 description = "Linux kernel";
92 data = /incbin/("${2}");
93 type = "kernel";
94 arch = "${UBOOT_ARCH}";
95 os = "linux";
96 compression = "${3}";
97 load = <${UBOOT_LOADADDRESS}>;
98 entry = <${ENTRYPOINT}>;
99 hash@1 {
100 algo = "${kernel_csum}";
101 };
102 };
103EOF
104}
105
106#
107# Emit the fitImage ITS DTB section
108#
109# $1 ... Image counter
110# $2 ... Path to DTB image
111fitimage_emit_section_dtb() {
112
113 dtb_csum="sha1"
114
115 cat << EOF >> fit-image.its
116 fdt@${1} {
117 description = "Flattened Device Tree blob";
118 data = /incbin/("${2}");
119 type = "flat_dt";
120 arch = "${UBOOT_ARCH}";
121 compression = "none";
122 hash@1 {
123 algo = "${dtb_csum}";
124 };
125 };
126EOF
127}
128
129#
130# Emit the fitImage ITS configuration section
131#
132# $1 ... Linux kernel ID
133# $2 ... DTB image ID
134fitimage_emit_section_config() {
135
136 conf_csum="sha1"
137
138 # Test if we have any DTBs at all
139 if [ -z "${2}" ] ; then
140 conf_desc="Boot Linux kernel"
141 fdt_line=""
142 else
143 conf_desc="Boot Linux kernel with FDT blob"
144 fdt_line="fdt = \"fdt@${2}\";"
145 fi
146 kernel_line="kernel = \"kernel@${1}\";"
147
148 cat << EOF >> fit-image.its
149 default = "conf@1";
150 conf@1 {
151 description = "${conf_desc}";
152 ${kernel_line}
153 ${fdt_line}
154 hash@1 {
155 algo = "${conf_csum}";
156 };
157 };
158EOF
159}
160
161do_assemble_fitimage() {
Andrew Bradfordc6b8b142016-08-04 13:40:40 -0400162 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400163 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 kernelcount=1
165 dtbcount=""
166 rm -f fit-image.its
167
168 fitimage_emit_fit_header
169
170 #
171 # Step 1: Prepare a kernel image section.
172 #
173 fitimage_emit_section_maint imagestart
174
175 uboot_prep_kimage
176 fitimage_emit_section_kernel "${kernelcount}" linux.bin "${linux_comp}"
177
178 #
179 # Step 2: Prepare a DTB image section
180 #
181 if test -n "${KERNEL_DEVICETREE}"; then
182 dtbcount=1
183 for DTB in ${KERNEL_DEVICETREE}; do
184 if echo ${DTB} | grep -q '/dts/'; then
185 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
186 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
187 fi
188 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
189 if [ ! -e "${DTB_PATH}" ]; then
190 DTB_PATH="arch/${ARCH}/boot/${DTB}"
191 fi
192
193 fitimage_emit_section_dtb ${dtbcount} ${DTB_PATH}
194 dtbcount=`expr ${dtbcount} + 1`
195 done
196 fi
197
198 fitimage_emit_section_maint sectend
199
200 # Force the first Kernel and DTB in the default config
201 kernelcount=1
202 dtbcount=1
203
204 #
205 # Step 3: Prepare a configurations section
206 #
207 fitimage_emit_section_maint confstart
208
209 fitimage_emit_section_config ${kernelcount} ${dtbcount}
210
211 fitimage_emit_section_maint sectend
212
213 fitimage_emit_section_maint fitend
214
215 #
216 # Step 4: Assemble the image
217 #
Yannick Gicqueld5813b42016-04-27 16:20:55 +0200218 uboot-mkimage \
219 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
220 -f fit-image.its \
221 arch/${ARCH}/boot/fitImage
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 fi
223}
224
225addtask assemble_fitimage before do_install after do_compile
226
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228kernel_do_deploy_append() {
229 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400230 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 cd ${B}
232 echo "Copying fit-image.its source file..."
He Zhefe76b1e2016-05-25 04:47:16 -0400233 its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
234 its_symlink_name=fitImage-its-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235 install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its
He Zhefe76b1e2016-05-25 04:47:16 -0400236 linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
237 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
239
240 cd ${DEPLOYDIR}
241 ln -sf ${its_base_name}.its ${its_symlink_name}.its
242 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
243 fi
244}