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