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