summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorGeorge McCollister <george.mccollister@gmail.com>2016-05-26 08:55:16 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-10 10:46:33 +0100
commitec755d2524fcbd9dfded23a576f25c990d405a6c (patch)
tree3deffc9dd7fa7ab089374a70c2e537ea1612ab76 /meta/classes
parent3153bd381cee101472a169de327d2152329d261a (diff)
downloadpoky-ec755d2524fcbd9dfded23a576f25c990d405a6c.tar.gz
kernel-fitimage: add initramfs support
If INITRAMFS_IMAGE is set, build an additional fitImage containing the initramfs. Copy the additional fitImage and the source (*.its) file, used to create it to DEPLOYDIR. The fitImage containing the initramfs must be built before do_deploy and after do_install to avoid circular dependencies. UBOOT_RD_LOADADDRESS - Specifies the load address used by u-boot for the initramfs. UBOOT_RD_ENTRYPOINT - Specifies the entry point used by u-boot for the initramfs. (From OE-Core rev: b406a89935f148779569fa3770776e009dd51f13) Signed-off-by: George McCollister <george.mccollister@gmail.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/kernel-fitimage.bbclass285
1 files changed, 189 insertions, 96 deletions
diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass
index 7cca180363..f05d8a54b5 100644
--- a/meta/classes/kernel-fitimage.bbclass
+++ b/meta/classes/kernel-fitimage.bbclass
@@ -16,7 +16,7 @@ python __anonymous () {
16 16
17 image = d.getVar('INITRAMFS_IMAGE', True) 17 image = d.getVar('INITRAMFS_IMAGE', True)
18 if image: 18 if image:
19 d.appendVarFlag('do_assemble_fitimage', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') 19 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
20 20
21 # Verified boot will sign the fitImage and append the public key to 21 # Verified boot will sign the fitImage and append the public key to
22 # U-boot dtb. We ensure the U-Boot dtb is deployed before assembling 22 # U-boot dtb. We ensure the U-Boot dtb is deployed before assembling
@@ -32,8 +32,9 @@ UBOOT_MKIMAGE_DTCOPTS ??= ""
32# 32#
33# Emit the fitImage ITS header 33# Emit the fitImage ITS header
34# 34#
35# $1 ... .its filename
35fitimage_emit_fit_header() { 36fitimage_emit_fit_header() {
36 cat << EOF >> fit-image.its 37 cat << EOF >> ${1}
37/dts-v1/; 38/dts-v1/;
38 39
39/ { 40/ {
@@ -45,32 +46,33 @@ EOF
45# 46#
46# Emit the fitImage section bits 47# Emit the fitImage section bits
47# 48#
48# $1 ... Section bit type: imagestart - image section start 49# $1 ... .its filename
50# $2 ... Section bit type: imagestart - image section start
49# confstart - configuration section start 51# confstart - configuration section start
50# sectend - section end 52# sectend - section end
51# fitend - fitimage end 53# fitend - fitimage end
52# 54#
53fitimage_emit_section_maint() { 55fitimage_emit_section_maint() {
54 case $1 in 56 case $2 in
55 imagestart) 57 imagestart)
56 cat << EOF >> fit-image.its 58 cat << EOF >> ${1}
57 59
58 images { 60 images {
59EOF 61EOF
60 ;; 62 ;;
61 confstart) 63 confstart)
62 cat << EOF >> fit-image.its 64 cat << EOF >> ${1}
63 65
64 configurations { 66 configurations {
65EOF 67EOF
66 ;; 68 ;;
67 sectend) 69 sectend)
68 cat << EOF >> fit-image.its 70 cat << EOF >> ${1}
69 }; 71 };
70EOF 72EOF
71 ;; 73 ;;
72 fitend) 74 fitend)
73 cat << EOF >> fit-image.its 75 cat << EOF >> ${1}
74}; 76};
75EOF 77EOF
76 ;; 78 ;;
@@ -80,9 +82,10 @@ EOF
80# 82#
81# Emit the fitImage ITS kernel section 83# Emit the fitImage ITS kernel section
82# 84#
83# $1 ... Image counter 85# $1 ... .its filename
84# $2 ... Path to kernel image 86# $2 ... Image counter
85# $3 ... Compression type 87# $3 ... Path to kernel image
88# $4 ... Compression type
86fitimage_emit_section_kernel() { 89fitimage_emit_section_kernel() {
87 90
88 kernel_csum="sha1" 91 kernel_csum="sha1"
@@ -90,17 +93,17 @@ fitimage_emit_section_kernel() {
90 ENTRYPOINT=${UBOOT_ENTRYPOINT} 93 ENTRYPOINT=${UBOOT_ENTRYPOINT}
91 if test -n "${UBOOT_ENTRYSYMBOL}"; then 94 if test -n "${UBOOT_ENTRYSYMBOL}"; then
92 ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \ 95 ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \
93 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print $1}'` 96 awk '$4=="${UBOOT_ENTRYSYMBOL}" {print $2}'`
94 fi 97 fi
95 98
96 cat << EOF >> fit-image.its 99 cat << EOF >> ${1}
97 kernel@${1} { 100 kernel@${2} {
98 description = "Linux kernel"; 101 description = "Linux kernel";
99 data = /incbin/("${2}"); 102 data = /incbin/("${3}");
100 type = "kernel"; 103 type = "kernel";
101 arch = "${UBOOT_ARCH}"; 104 arch = "${UBOOT_ARCH}";
102 os = "linux"; 105 os = "linux";
103 compression = "${3}"; 106 compression = "${4}";
104 load = <${UBOOT_LOADADDRESS}>; 107 load = <${UBOOT_LOADADDRESS}>;
105 entry = <${ENTRYPOINT}>; 108 entry = <${ENTRYPOINT}>;
106 hash@1 { 109 hash@1 {
@@ -113,16 +116,17 @@ EOF
113# 116#
114# Emit the fitImage ITS DTB section 117# Emit the fitImage ITS DTB section
115# 118#
116# $1 ... Image counter 119# $1 ... .its filename
117# $2 ... Path to DTB image 120# $2 ... Image counter
121# $3 ... Path to DTB image
118fitimage_emit_section_dtb() { 122fitimage_emit_section_dtb() {
119 123
120 dtb_csum="sha1" 124 dtb_csum="sha1"
121 125
122 cat << EOF >> fit-image.its 126 cat << EOF >> ${1}
123 fdt@${1} { 127 fdt@${2} {
124 description = "Flattened Device Tree blob"; 128 description = "Flattened Device Tree blob";
125 data = /incbin/("${2}"); 129 data = /incbin/("${3}");
126 type = "flat_dt"; 130 type = "flat_dt";
127 arch = "${UBOOT_ARCH}"; 131 arch = "${UBOOT_ARCH}";
128 compression = "none"; 132 compression = "none";
@@ -134,10 +138,39 @@ EOF
134} 138}
135 139
136# 140#
141# Emit the fitImage ITS ramdisk section
142#
143# $1 ... .its filename
144# $2 ... Image counter
145# $3 ... Path to ramdisk image
146fitimage_emit_section_ramdisk() {
147
148 ramdisk_csum="sha1"
149
150 cat << EOF >> ${1}
151 ramdisk@${2} {
152 description = "ramdisk image";
153 data = /incbin/("${3}");
154 type = "ramdisk";
155 arch = "${UBOOT_ARCH}";
156 os = "linux";
157 compression = "none";
158 load = <${UBOOT_RD_LOADADDRESS}>;
159 entry = <${UBOOT_RD_ENTRYPOINT}>;
160 hash@1 {
161 algo = "${ramdisk_csum}";
162 };
163 };
164EOF
165}
166
167#
137# Emit the fitImage ITS configuration section 168# Emit the fitImage ITS configuration section
138# 169#
139# $1 ... Linux kernel ID 170# $1 ... .its filename
140# $2 ... DTB image ID 171# $2 ... Linux kernel ID
172# $3 ... DTB image ID
173# $4 ... ramdisk ID
141fitimage_emit_section_config() { 174fitimage_emit_section_config() {
142 175
143 conf_csum="sha1" 176 conf_csum="sha1"
@@ -146,21 +179,32 @@ fitimage_emit_section_config() {
146 fi 179 fi
147 180
148 # Test if we have any DTBs at all 181 # Test if we have any DTBs at all
149 if [ -z "${2}" ] ; then 182 if [ -z "${3}" -a -z "${4}" ] ; then
150 conf_desc="Boot Linux kernel" 183 conf_desc="Boot Linux kernel"
151 fdt_line="" 184 fdt_line=""
152 else 185 ramdisk_line=""
186 elif [ -z "${4}" ]; then
153 conf_desc="Boot Linux kernel with FDT blob" 187 conf_desc="Boot Linux kernel with FDT blob"
154 fdt_line="fdt = \"fdt@${2}\";" 188 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}\";"
155 fi 198 fi
156 kernel_line="kernel = \"kernel@${1}\";" 199 kernel_line="kernel = \"kernel@${2}\";"
157 200
158 cat << EOF >> fit-image.its 201 cat << EOF >> ${1}
159 default = "conf@1"; 202 default = "conf@1";
160 conf@1 { 203 conf@1 {
161 description = "${conf_desc}"; 204 description = "${conf_desc}";
162 ${kernel_line} 205 ${kernel_line}
163 ${fdt_line} 206 ${fdt_line}
207 ${ramdisk_line}
164 hash@1 { 208 hash@1 {
165 algo = "${conf_csum}"; 209 algo = "${conf_csum}";
166 }; 210 };
@@ -168,103 +212,137 @@ EOF
168 212
169 if [ ! -z "${conf_sign_keyname}" ] ; then 213 if [ ! -z "${conf_sign_keyname}" ] ; then
170 214
171 if [ -z "${2}" ] ; then 215 if [ -z "${3}" -a -z "${4}" ] ; then
172 sign_line="sign-images = \"kernel\";" 216 sign_line="sign-images = \"kernel\";"
173 else 217 elif [ -z "${4}" ]; then
174 sign_line="sign-images = \"fdt\", \"kernel\";" 218 sign_line="sign-images = \"fdt\", \"kernel\";"
219 elif [ -z "${3}" ]; then
220 sign_line="sign-images = \"ramdisk\", \"kernel\";"
221 else
222 sign_line="sign-images = \"ramdisk\", \"fdt\", \"kernel\";"
175 fi 223 fi
176 224
177 cat << EOF >> fit-image.its 225 cat << EOF >> ${1}
178 signature@1 { 226 signature@1 {
179 algo = "${conf_csum},rsa2048"; 227 algo = "${conf_csum},rsa2048";
180 key-name-hint = "${conf_sign_keyname}"; 228 key-name-hint = "${conf_sign_keyname}";
181 sign-images = "fdt", "kernel"; 229 ${sign_line}
182 }; 230 };
183EOF 231EOF
184 fi 232 fi
185 233
186 cat << EOF >> fit-image.its 234 cat << EOF >> ${1}
187 }; 235 };
188EOF 236EOF
189} 237}
190 238
191do_assemble_fitimage() { 239#
192 cd ${B} 240# Assemble fitImage
193 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then 241#
194 kernelcount=1 242# $1 ... .its filename
195 dtbcount="" 243# $2 ... fitImage name
196 rm -f fit-image.its arch/${ARCH}/boot/fitImage 244# $3 ... include ramdisk
197 245fitimage_assemble() {
198 fitimage_emit_fit_header 246 kernelcount=1
199 247 dtbcount=""
200 # 248 ramdiskcount=${3}
201 # Step 1: Prepare a kernel image section. 249 rm -f ${1} arch/${ARCH}/boot/${2}
202 # 250
203 fitimage_emit_section_maint imagestart 251 fitimage_emit_fit_header ${1}
204 252
205 uboot_prep_kimage 253 #
206 fitimage_emit_section_kernel "${kernelcount}" linux.bin "${linux_comp}" 254 # Step 1: Prepare a kernel image section.
207 255 #
208 # 256 fitimage_emit_section_maint ${1} imagestart
209 # Step 2: Prepare a DTB image section 257
210 # 258 uboot_prep_kimage
211 if test -n "${KERNEL_DEVICETREE}"; then 259 fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}"
212 dtbcount=1 260
213 for DTB in ${KERNEL_DEVICETREE}; do 261 #
214 if echo ${DTB} | grep -q '/dts/'; then 262 # Step 2: Prepare a DTB image section
215 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." 263 #
216 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` 264 if test -n "${KERNEL_DEVICETREE}"; then
217 fi 265 dtbcount=1
218 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" 266 for DTB in ${KERNEL_DEVICETREE}; do
219 if [ ! -e "${DTB_PATH}" ]; then 267 if echo ${DTB} | grep -q '/dts/'; then
220 DTB_PATH="arch/${ARCH}/boot/${DTB}" 268 bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
221 fi 269 DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
222 270 fi
223 fitimage_emit_section_dtb ${dtbcount} ${DTB_PATH} 271 DTB_PATH="arch/${ARCH}/boot/dts/${DTB}"
224 dtbcount=`expr ${dtbcount} + 1` 272 if [ ! -e "${DTB_PATH}" ]; then
225 done 273 DTB_PATH="arch/${ARCH}/boot/${DTB}"
226 fi 274 fi
275
276 fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH}
277 dtbcount=`expr ${dtbcount} + 1`
278 done
279 fi
227 280
228 fitimage_emit_section_maint sectend 281 #
282 # Step 3: Prepare a ramdisk section.
283 #
284 if [ "x${ramdiskcount}" = "x1" ] ; then
285 copy_initramfs
286 fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
287 fi
229 288
230 # Force the first Kernel and DTB in the default config 289 fitimage_emit_section_maint ${1} sectend
231 kernelcount=1
232 dtbcount=1
233 290
234 # 291 # Force the first Kernel and DTB in the default config
235 # Step 3: Prepare a configurations section 292 kernelcount=1
236 # 293 dtbcount=1
237 fitimage_emit_section_maint confstart
238 294
239 fitimage_emit_section_config ${kernelcount} ${dtbcount} 295 #
296 # Step 4: Prepare a configurations section
297 #
298 fitimage_emit_section_maint ${1} confstart
240 299
241 fitimage_emit_section_maint sectend 300 fitimage_emit_section_config ${1} ${kernelcount} ${dtbcount} ${ramdiskcount}
242 301
243 fitimage_emit_section_maint fitend 302 fitimage_emit_section_maint ${1} sectend
244 303
245 # 304 fitimage_emit_section_maint ${1} fitend
246 # Step 4: Assemble the image 305
247 # 306 #
307 # Step 5: Assemble the image
308 #
309 uboot-mkimage \
310 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
311 -f ${1} \
312 arch/${ARCH}/boot/${2}
313
314 #
315 # Step 6: Sign the image and add public key to U-Boot dtb
316 #
317 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
248 uboot-mkimage \ 318 uboot-mkimage \
249 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ 319 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
250 -f fit-image.its \ 320 -F -k "${UBOOT_SIGN_KEYDIR}" \
251 arch/${ARCH}/boot/fitImage 321 -K "${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_BINARY}" \
252 322 -r arch/${ARCH}/boot/${2}
253 # 323 fi
254 # Step 5: Sign the image and add public key to U-Boot dtb 324}
255 # 325
256 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then 326do_assemble_fitimage() {
257 uboot-mkimage \ 327 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
258 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ 328 cd ${B}
259 -F -k "${UBOOT_SIGN_KEYDIR}" \ 329 fitimage_assemble fit-image.its fitImage
260 -K "${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_BINARY}" \
261 -r arch/${ARCH}/boot/fitImage
262 fi
263 fi 330 fi
264} 331}
265 332
266addtask assemble_fitimage before do_install after do_compile 333addtask assemble_fitimage before do_install after do_compile
267 334
335do_assemble_fitimage_initramfs() {
336 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
337 test -n "${INITRAMFS_IMAGE}" ; then
338 cd ${B}
339 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
340 fi
341}
342
343addtask assemble_fitimage_initramfs before do_deploy after do_install
344
345
268kernel_do_deploy[vardepsexclude] = "DATETIME" 346kernel_do_deploy[vardepsexclude] = "DATETIME"
269kernel_do_deploy_append() { 347kernel_do_deploy_append() {
270 # Update deploy directory 348 # Update deploy directory
@@ -278,8 +356,23 @@ kernel_do_deploy_append() {
278 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE} 356 linux_bin_symlink_name=fitImage-linux.bin-${MACHINE}
279 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin 357 install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin
280 358
359 if [ -n "${INITRAMFS_IMAGE}" ]; then
360 echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
361 its_initramfs_base_name="${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
362 its_initramfs_symlink_name=${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${MACHINE}
363 install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its
364 fit_initramfs_base_name="${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
365 fit_initramfs_symlink_name=${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE}
366 install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin
367 fi
368
281 cd ${DEPLOYDIR} 369 cd ${DEPLOYDIR}
282 ln -sf ${its_base_name}.its ${its_symlink_name}.its 370 ln -sf ${its_base_name}.its ${its_symlink_name}.its
283 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin 371 ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin
372
373 if [ -n "${INITRAMFS_IMAGE}" ]; then
374 ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its
375 ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin
376 fi
284 fi 377 fi
285} 378}