summaryrefslogtreecommitdiffstats
path: root/meta/classes/image-live.bbclass
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2016-03-30 00:23:10 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-03-31 23:01:37 +0100
commitd6d75260fa0a9874a62acd3251b7405ed59f0cfa (patch)
treedf5381d8154fe95504cefc7591e81a5ce0478736 /meta/classes/image-live.bbclass
parent723fa563a09daaf7d1b7e9c1bb079139b3e84677 (diff)
downloadpoky-d6d75260fa0a9874a62acd3251b7405ed59f0cfa.tar.gz
bootimg.bbclass: merge it into image-live.bbclass
They are doing the same things: create live images, merge them into one bbclass makes it easy to understand. (From OE-Core rev: bfd4d95210b3f841aa2e7c5a06ac89667523438d) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/image-live.bbclass')
-rw-r--r--meta/classes/image-live.bbclass309
1 files changed, 303 insertions, 6 deletions
diff --git a/meta/classes/image-live.bbclass b/meta/classes/image-live.bbclass
index 05e416abe0..a08715cd83 100644
--- a/meta/classes/image-live.bbclass
+++ b/meta/classes/image-live.bbclass
@@ -1,15 +1,47 @@
1# Copyright (C) 2004, Advanced Micro Devices, Inc. All Rights Reserved
2# Released under the MIT license (see packages/COPYING)
1 3
4# Creates a bootable image using syslinux, your kernel and an optional
5# initrd
6
7#
8# End result is two things:
9#
10# 1. A .hddimg file which is an msdos filesystem containing syslinux, a kernel,
11# an initrd and a rootfs image. These can be written to harddisks directly and
12# also booted on USB flash disks (write them there with dd).
13#
14# 2. A CD .iso image
15
16# Boot process is that the initrd will boot and process which label was selected
17# in syslinux. Actions based on the label are then performed (e.g. installing to
18# an hdd)
19
20# External variables (also used by syslinux.bbclass)
21# ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional)
22# ${COMPRESSISO} - Transparent compress ISO, reduce size ~40% if set to 1
23# ${NOISO} - skip building the ISO image if set to 1
24# ${NOHDD} - skip building the HDD image if set to 1
25# ${HDDIMG_ID} - FAT image volume-id
26# ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
27
28do_bootimg[depends] += "dosfstools-native:do_populate_sysroot \
29 mtools-native:do_populate_sysroot \
30 cdrtools-native:do_populate_sysroot \
31 virtual/kernel:do_deploy \
32 ${MLPREFIX}syslinux:do_populate_sysroot \
33 ${@oe.utils.ifelse(d.getVar('COMPRESSISO', False),'zisofs-tools-native:do_populate_sysroot','')} \
34 ${PN}:do_image_ext4 \
35 "
36
37
38LABELS_LIVE ?= "boot install"
39ROOT_LIVE ?= "root=/dev/ram0"
2INITRD_IMAGE_LIVE ?= "core-image-minimal-initramfs" 40INITRD_IMAGE_LIVE ?= "core-image-minimal-initramfs"
3INITRD_LIVE ?= "${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE_LIVE}-${MACHINE}.cpio.gz" 41INITRD_LIVE ?= "${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE_LIVE}-${MACHINE}.cpio.gz"
4ROOT_LIVE ?= "root=/dev/ram0"
5LABELS_LIVE ?= "boot install"
6 42
7ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ext4" 43ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ext4"
8 44
9do_bootimg[depends] += "${PN}:do_image_ext4"
10
11inherit bootimg
12
13IMAGE_TYPEDEP_live = "ext4" 45IMAGE_TYPEDEP_live = "ext4"
14IMAGE_TYPEDEP_iso = "ext4" 46IMAGE_TYPEDEP_iso = "ext4"
15IMAGE_TYPEDEP_hddimg = "ext4" 47IMAGE_TYPEDEP_hddimg = "ext4"
@@ -24,3 +56,268 @@ python() {
24 else: 56 else:
25 d.appendVarFlag('do_bootimg', 'depends', ' %s:do_image_complete' % initrd_i) 57 d.appendVarFlag('do_bootimg', 'depends', ' %s:do_image_complete' % initrd_i)
26} 58}
59
60HDDDIR = "${S}/hddimg"
61ISODIR = "${S}/iso"
62EFIIMGDIR = "${S}/efi_img"
63COMPACT_ISODIR = "${S}/iso.z"
64COMPRESSISO ?= "0"
65
66ISOLINUXDIR ?= "/isolinux"
67ISO_BOOTIMG = "isolinux/isolinux.bin"
68ISO_BOOTCAT = "isolinux/boot.cat"
69MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table"
70
71BOOTIMG_VOLUME_ID ?= "boot"
72BOOTIMG_EXTRA_SPACE ?= "512"
73
74EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
75EFI_PROVIDER ?= "grub-efi"
76EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
77
78KERNEL_IMAGETYPE ??= "bzImage"
79
80# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
81# contain "efi". This way legacy is supported by default if neither is
82# specified, maintaining the original behavior.
83def pcbios(d):
84 pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
85 if pcbios == "0":
86 pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
87 return pcbios
88
89PCBIOS = "${@pcbios(d)}"
90PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS', True) == '1']}"
91
92inherit ${EFI_CLASS}
93inherit ${PCBIOS_CLASS}
94
95populate() {
96 DEST=$1
97 install -d ${DEST}
98
99 # Install kernel, initrd, and rootfs.img in DEST for all loaders to use.
100 install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ${DEST}/vmlinuz
101
102 # initrd is made of concatenation of multiple filesystem images
103 if [ -n "${INITRD}" ]; then
104 rm -f ${DEST}/initrd
105 for fs in ${INITRD}
106 do
107 if [ -s "${fs}" ]; then
108 cat ${fs} >> ${DEST}/initrd
109 else
110 bbfatal "${fs} is invalid. initrd image creation failed."
111 fi
112 done
113 chmod 0644 ${DEST}/initrd
114 fi
115
116 if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
117 install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
118 fi
119
120}
121
122build_iso() {
123 # Only create an ISO if we have an INITRD and NOISO was not set
124 if [ -z "${INITRD}" ] || [ "${NOISO}" = "1" ]; then
125 bbnote "ISO image will not be created."
126 return
127 fi
128 # ${INITRD} is a list of multiple filesystem images
129 for fs in ${INITRD}
130 do
131 if [ ! -s "${fs}" ]; then
132 bbnote "ISO image will not be created. ${fs} is invalid."
133 return
134 fi
135 done
136
137
138 populate ${ISODIR}
139
140 if [ "${PCBIOS}" = "1" ]; then
141 syslinux_iso_populate ${ISODIR}
142 fi
143 if [ "${EFI}" = "1" ]; then
144 efi_iso_populate ${ISODIR}
145 build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img
146 fi
147
148 # EFI only
149 if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then
150 # Work around bug in isohybrid where it requires isolinux.bin
151 # In the boot catalog, even though it is not used
152 mkdir -p ${ISODIR}/${ISOLINUXDIR}
153 install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}
154 fi
155
156 if [ "${COMPRESSISO}" = "1" ] ; then
157 # create compact directory, compress iso
158 mkdir -p ${COMPACT_ISODIR}
159 mkzftree -z 9 -p 4 -F ${ISODIR}/rootfs.img ${COMPACT_ISODIR}/rootfs.img
160
161 # move compact iso to iso, then remove compact directory
162 mv ${COMPACT_ISODIR}/rootfs.img ${ISODIR}/rootfs.img
163 rm -Rf ${COMPACT_ISODIR}
164 mkisofs_compress_opts="-R -z -D -l"
165 else
166 mkisofs_compress_opts="-r"
167 fi
168
169 # Check the size of ${ISODIR}/rootfs.img, use mkisofs -iso-level 3
170 # when it exceeds 3.8GB, the specification is 4G - 1 bytes, we need
171 # leave a few space for other files.
172 mkisofs_iso_level=""
173
174 if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
175 rootfs_img_size=`stat -c '%s' ${ISODIR}/rootfs.img`
176 # 4080218931 = 3.8 * 1024 * 1024 * 1024
177 if [ $rootfs_img_size -gt 4080218931 ]; then
178 bbnote "${ISODIR}/rootfs.img execeeds 3.8GB, using '-iso-level 3' for mkisofs"
179 mkisofs_iso_level="-iso-level 3"
180 fi
181 fi
182
183 if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then
184 # PCBIOS only media
185 mkisofs -V ${BOOTIMG_VOLUME_ID} \
186 -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
187 -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \
188 $mkisofs_compress_opts \
189 ${MKISOFS_OPTIONS} $mkisofs_iso_level ${ISODIR}
190 else
191 # EFI only OR EFI+PCBIOS
192 mkisofs -A ${BOOTIMG_VOLUME_ID} -V ${BOOTIMG_VOLUME_ID} \
193 -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
194 -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \
195 $mkisofs_compress_opts ${MKISOFS_OPTIONS} $mkisofs_iso_level \
196 -eltorito-alt-boot -eltorito-platform efi \
197 -b efi.img -no-emul-boot \
198 ${ISODIR}
199 isohybrid_args="-u"
200 fi
201
202 isohybrid $isohybrid_args ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso
203}
204
205build_fat_img() {
206 FATSOURCEDIR=$1
207 FATIMG=$2
208
209 # Calculate the size required for the final image including the
210 # data and filesystem overhead.
211 # Sectors: 512 bytes
212 # Blocks: 1024 bytes
213
214 # Determine the sector count just for the data
215 SECTORS=$(expr $(du --apparent-size -ks ${FATSOURCEDIR} | cut -f 1) \* 2)
216
217 # Account for the filesystem overhead. This includes directory
218 # entries in the clusters as well as the FAT itself.
219 # Assumptions:
220 # FAT32 (12 or 16 may be selected by mkdosfs, but the extra
221 # padding will be minimal on those smaller images and not
222 # worth the logic here to caclulate the smaller FAT sizes)
223 # < 16 entries per directory
224 # 8.3 filenames only
225
226 # 32 bytes per dir entry
227 DIR_BYTES=$(expr $(find ${FATSOURCEDIR} | tail -n +2 | wc -l) \* 32)
228 # 32 bytes for every end-of-directory dir entry
229 DIR_BYTES=$(expr $DIR_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 32))
230 # 4 bytes per FAT entry per sector of data
231 FAT_BYTES=$(expr $SECTORS \* 4)
232 # 4 bytes per FAT entry per end-of-cluster list
233 FAT_BYTES=$(expr $FAT_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 4))
234
235 # Use a ceiling function to determine FS overhead in sectors
236 DIR_SECTORS=$(expr $(expr $DIR_BYTES + 511) / 512)
237 # There are two FATs on the image
238 FAT_SECTORS=$(expr $(expr $(expr $FAT_BYTES + 511) / 512) \* 2)
239 SECTORS=$(expr $SECTORS + $(expr $DIR_SECTORS + $FAT_SECTORS))
240
241 # Determine the final size in blocks accounting for some padding
242 BLOCKS=$(expr $(expr $SECTORS / 2) + ${BOOTIMG_EXTRA_SPACE})
243
244 # Ensure total sectors is an integral number of sectors per
245 # track or mcopy will complain. Sectors are 512 bytes, and we
246 # generate images with 32 sectors per track. This calculation is
247 # done in blocks, thus the mod by 16 instead of 32.
248 BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16)))
249
250 # mkdosfs will sometimes use FAT16 when it is not appropriate,
251 # resulting in a boot failure from SYSLINUX. Use FAT32 for
252 # images larger than 512MB, otherwise let mkdosfs decide.
253 if [ $(expr $BLOCKS / 1024) -gt 512 ]; then
254 FATSIZE="-F 32"
255 fi
256
257 # mkdosfs will fail if ${FATIMG} exists. Since we are creating an
258 # new image, it is safe to delete any previous image.
259 if [ -e ${FATIMG} ]; then
260 rm ${FATIMG}
261 fi
262
263 if [ -z "${HDDIMG_ID}" ]; then
264 mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
265 ${BLOCKS}
266 else
267 mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
268 ${BLOCKS} -i ${HDDIMG_ID}
269 fi
270
271 # Copy FATSOURCEDIR recursively into the image file directly
272 mcopy -i ${FATIMG} -s ${FATSOURCEDIR}/* ::/
273}
274
275build_hddimg() {
276 # Create an HDD image
277 if [ "${NOHDD}" != "1" ] ; then
278 populate ${HDDDIR}
279
280 if [ "${PCBIOS}" = "1" ]; then
281 syslinux_hddimg_populate ${HDDDIR}
282 fi
283 if [ "${EFI}" = "1" ]; then
284 efi_hddimg_populate ${HDDDIR}
285 fi
286
287 # Check the size of ${HDDDIR}/rootfs.img, error out if it
288 # exceeds 4GB, it is the single file's max size of FAT fs.
289 if [ -f ${HDDDIR}/rootfs.img ]; then
290 rootfs_img_size=`stat -c '%s' ${HDDDIR}/rootfs.img`
291 max_size=`expr 4 \* 1024 \* 1024 \* 1024`
292 if [ $rootfs_img_size -gt $max_size ]; then
293 bberror "${HDDDIR}/rootfs.img execeeds 4GB,"
294 bberror "this doesn't work on FAT filesystem, you can try either of:"
295 bberror "1) Reduce the size of rootfs.img"
296 bbfatal "2) Use iso, vmdk or vdi to instead of hddimg\n"
297 fi
298 fi
299
300 build_fat_img ${HDDDIR} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
301
302 if [ "${PCBIOS}" = "1" ]; then
303 syslinux_hddimg_install
304 fi
305
306 chmod 644 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
307 fi
308}
309
310python do_bootimg() {
311 set_live_vm_vars(d, 'LIVE')
312 if d.getVar("PCBIOS", True) == "1":
313 bb.build.exec_func('build_syslinux_cfg', d)
314 if d.getVar("EFI", True) == "1":
315 bb.build.exec_func('build_efi_cfg', d)
316 bb.build.exec_func('build_hddimg', d)
317 bb.build.exec_func('build_iso', d)
318 bb.build.exec_func('create_symlinks', d)
319}
320do_bootimg[subimages] = "hddimg iso"
321do_bootimg[imgsuffix] = "."
322
323addtask bootimg before do_image_complete