blob: 7e6ea98ff6f00de8c66d50cbbf69f14e23d2d536 [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() {
He Zhefe76b1e2016-05-25 04:47:16 -0400159 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 kernelcount=1
161 dtbcount=""
162 rm -f fit-image.its
163
164 fitimage_emit_fit_header
165
166 #
167 # Step 1: Prepare a kernel image section.
168 #
169 fitimage_emit_section_maint imagestart
170
171 uboot_prep_kimage
172 fitimage_emit_section_kernel "${kernelcount}" linux.bin "${linux_comp}"
173
174 #
175 # Step 2: Prepare a DTB image section
176 #
177 if test -n "${KERNEL_DEVICETREE}"; then
178 dtbcount=1
179 for DTB in ${KERNEL_DEVICETREE}; do
180 if echo ${DTB} | grep -q '/dts/'; then
181 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
182 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
183 fi
184 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
185 if [ ! -e "${DTB_PATH}" ]; then
186 DTB_PATH="arch/${ARCH}/boot/${DTB}"
187 fi
188
189 fitimage_emit_section_dtb ${dtbcount} ${DTB_PATH}
190 dtbcount=`expr ${dtbcount} + 1`
191 done
192 fi
193
194 fitimage_emit_section_maint sectend
195
196 # Force the first Kernel and DTB in the default config
197 kernelcount=1
198 dtbcount=1
199
200 #
201 # Step 3: Prepare a configurations section
202 #
203 fitimage_emit_section_maint confstart
204
205 fitimage_emit_section_config ${kernelcount} ${dtbcount}
206
207 fitimage_emit_section_maint sectend
208
209 fitimage_emit_section_maint fitend
210
211 #
212 # Step 4: Assemble the image
213 #
214 uboot-mkimage -f fit-image.its arch/${ARCH}/boot/fitImage
215 fi
216}
217
218addtask assemble_fitimage before do_install after do_compile
219
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500220kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221kernel_do_deploy_append() {
222 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400223 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224 cd ${B}
225 echo "Copying fit-image.its source file..."
He Zhefe76b1e2016-05-25 04:47:16 -0400226 its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}"
227 its_symlink_name=fitImage-its-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its
He Zhefe76b1e2016-05-25 04:47:16 -0400229 linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}"
230 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
232
233 cd ${DEPLOYDIR}
234 ln -sf ${its_base_name}.its ${its_symlink_name}.its
235 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
236 fi
237}