summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--meta/classes/bootimg.bbclass305
-rw-r--r--meta/classes/gummiboot.bbclass2
-rw-r--r--meta/classes/image-live.bbclass309
-rw-r--r--meta/classes/image-vm.bbclass2
4 files changed, 305 insertions, 313 deletions
diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass
deleted file mode 100644
index 620410136f..0000000000
--- a/meta/classes/bootimg.bbclass
+++ /dev/null
@@ -1,305 +0,0 @@
1# Copyright (C) 2004, Advanced Micro Devices, Inc. All Rights Reserved
2# Released under the MIT license (see packages/COPYING)
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
35PACKAGES = " "
36EXCLUDE_FROM_WORLD = "1"
37
38HDDDIR = "${S}/hddimg"
39ISODIR = "${S}/iso"
40EFIIMGDIR = "${S}/efi_img"
41COMPACT_ISODIR = "${S}/iso.z"
42COMPRESSISO ?= "0"
43
44ISOLINUXDIR ?= "/isolinux"
45ISO_BOOTIMG = "isolinux/isolinux.bin"
46ISO_BOOTCAT = "isolinux/boot.cat"
47MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table"
48
49BOOTIMG_VOLUME_ID ?= "boot"
50BOOTIMG_EXTRA_SPACE ?= "512"
51
52EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
53EFI_PROVIDER ?= "grub-efi"
54EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
55
56KERNEL_IMAGETYPE ??= "bzImage"
57
58# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
59# contain "efi". This way legacy is supported by default if neither is
60# specified, maintaining the original behavior.
61def pcbios(d):
62 pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
63 if pcbios == "0":
64 pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
65 return pcbios
66
67PCBIOS = "${@pcbios(d)}"
68PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS', True) == '1']}"
69
70inherit ${EFI_CLASS}
71inherit ${PCBIOS_CLASS}
72
73populate() {
74 DEST=$1
75 install -d ${DEST}
76
77 # Install kernel, initrd, and rootfs.img in DEST for all loaders to use.
78 install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ${DEST}/vmlinuz
79
80 # initrd is made of concatenation of multiple filesystem images
81 if [ -n "${INITRD}" ]; then
82 rm -f ${DEST}/initrd
83 for fs in ${INITRD}
84 do
85 if [ -s "${fs}" ]; then
86 cat ${fs} >> ${DEST}/initrd
87 else
88 bbfatal "${fs} is invalid. initrd image creation failed."
89 fi
90 done
91 chmod 0644 ${DEST}/initrd
92 fi
93
94 if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
95 install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
96 fi
97
98}
99
100build_iso() {
101 # Only create an ISO if we have an INITRD and NOISO was not set
102 if [ -z "${INITRD}" ] || [ "${NOISO}" = "1" ]; then
103 bbnote "ISO image will not be created."
104 return
105 fi
106 # ${INITRD} is a list of multiple filesystem images
107 for fs in ${INITRD}
108 do
109 if [ ! -s "${fs}" ]; then
110 bbnote "ISO image will not be created. ${fs} is invalid."
111 return
112 fi
113 done
114
115
116 populate ${ISODIR}
117
118 if [ "${PCBIOS}" = "1" ]; then
119 syslinux_iso_populate ${ISODIR}
120 fi
121 if [ "${EFI}" = "1" ]; then
122 efi_iso_populate ${ISODIR}
123 build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img
124 fi
125
126 # EFI only
127 if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then
128 # Work around bug in isohybrid where it requires isolinux.bin
129 # In the boot catalog, even though it is not used
130 mkdir -p ${ISODIR}/${ISOLINUXDIR}
131 install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}
132 fi
133
134 if [ "${COMPRESSISO}" = "1" ] ; then
135 # create compact directory, compress iso
136 mkdir -p ${COMPACT_ISODIR}
137 mkzftree -z 9 -p 4 -F ${ISODIR}/rootfs.img ${COMPACT_ISODIR}/rootfs.img
138
139 # move compact iso to iso, then remove compact directory
140 mv ${COMPACT_ISODIR}/rootfs.img ${ISODIR}/rootfs.img
141 rm -Rf ${COMPACT_ISODIR}
142 mkisofs_compress_opts="-R -z -D -l"
143 else
144 mkisofs_compress_opts="-r"
145 fi
146
147 # Check the size of ${ISODIR}/rootfs.img, use mkisofs -iso-level 3
148 # when it exceeds 3.8GB, the specification is 4G - 1 bytes, we need
149 # leave a few space for other files.
150 mkisofs_iso_level=""
151
152 if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
153 rootfs_img_size=`stat -c '%s' ${ISODIR}/rootfs.img`
154 # 4080218931 = 3.8 * 1024 * 1024 * 1024
155 if [ $rootfs_img_size -gt 4080218931 ]; then
156 bbnote "${ISODIR}/rootfs.img execeeds 3.8GB, using '-iso-level 3' for mkisofs"
157 mkisofs_iso_level="-iso-level 3"
158 fi
159 fi
160
161 if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then
162 # PCBIOS only media
163 mkisofs -V ${BOOTIMG_VOLUME_ID} \
164 -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
165 -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \
166 $mkisofs_compress_opts \
167 ${MKISOFS_OPTIONS} $mkisofs_iso_level ${ISODIR}
168 else
169 # EFI only OR EFI+PCBIOS
170 mkisofs -A ${BOOTIMG_VOLUME_ID} -V ${BOOTIMG_VOLUME_ID} \
171 -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
172 -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \
173 $mkisofs_compress_opts ${MKISOFS_OPTIONS} $mkisofs_iso_level \
174 -eltorito-alt-boot -eltorito-platform efi \
175 -b efi.img -no-emul-boot \
176 ${ISODIR}
177 isohybrid_args="-u"
178 fi
179
180 isohybrid $isohybrid_args ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso
181}
182
183build_fat_img() {
184 FATSOURCEDIR=$1
185 FATIMG=$2
186
187 # Calculate the size required for the final image including the
188 # data and filesystem overhead.
189 # Sectors: 512 bytes
190 # Blocks: 1024 bytes
191
192 # Determine the sector count just for the data
193 SECTORS=$(expr $(du --apparent-size -ks ${FATSOURCEDIR} | cut -f 1) \* 2)
194
195 # Account for the filesystem overhead. This includes directory
196 # entries in the clusters as well as the FAT itself.
197 # Assumptions:
198 # FAT32 (12 or 16 may be selected by mkdosfs, but the extra
199 # padding will be minimal on those smaller images and not
200 # worth the logic here to caclulate the smaller FAT sizes)
201 # < 16 entries per directory
202 # 8.3 filenames only
203
204 # 32 bytes per dir entry
205 DIR_BYTES=$(expr $(find ${FATSOURCEDIR} | tail -n +2 | wc -l) \* 32)
206 # 32 bytes for every end-of-directory dir entry
207 DIR_BYTES=$(expr $DIR_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 32))
208 # 4 bytes per FAT entry per sector of data
209 FAT_BYTES=$(expr $SECTORS \* 4)
210 # 4 bytes per FAT entry per end-of-cluster list
211 FAT_BYTES=$(expr $FAT_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 4))
212
213 # Use a ceiling function to determine FS overhead in sectors
214 DIR_SECTORS=$(expr $(expr $DIR_BYTES + 511) / 512)
215 # There are two FATs on the image
216 FAT_SECTORS=$(expr $(expr $(expr $FAT_BYTES + 511) / 512) \* 2)
217 SECTORS=$(expr $SECTORS + $(expr $DIR_SECTORS + $FAT_SECTORS))
218
219 # Determine the final size in blocks accounting for some padding
220 BLOCKS=$(expr $(expr $SECTORS / 2) + ${BOOTIMG_EXTRA_SPACE})
221
222 # Ensure total sectors is an integral number of sectors per
223 # track or mcopy will complain. Sectors are 512 bytes, and we
224 # generate images with 32 sectors per track. This calculation is
225 # done in blocks, thus the mod by 16 instead of 32.
226 BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16)))
227
228 # mkdosfs will sometimes use FAT16 when it is not appropriate,
229 # resulting in a boot failure from SYSLINUX. Use FAT32 for
230 # images larger than 512MB, otherwise let mkdosfs decide.
231 if [ $(expr $BLOCKS / 1024) -gt 512 ]; then
232 FATSIZE="-F 32"
233 fi
234
235 # mkdosfs will fail if ${FATIMG} exists. Since we are creating an
236 # new image, it is safe to delete any previous image.
237 if [ -e ${FATIMG} ]; then
238 rm ${FATIMG}
239 fi
240
241 if [ -z "${HDDIMG_ID}" ]; then
242 mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
243 ${BLOCKS}
244 else
245 mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
246 ${BLOCKS} -i ${HDDIMG_ID}
247 fi
248
249 # Copy FATSOURCEDIR recursively into the image file directly
250 mcopy -i ${FATIMG} -s ${FATSOURCEDIR}/* ::/
251}
252
253build_hddimg() {
254 # Create an HDD image
255 if [ "${NOHDD}" != "1" ] ; then
256 populate ${HDDDIR}
257
258 if [ "${PCBIOS}" = "1" ]; then
259 syslinux_hddimg_populate ${HDDDIR}
260 fi
261 if [ "${EFI}" = "1" ]; then
262 efi_hddimg_populate ${HDDDIR}
263 fi
264
265 # Check the size of ${HDDDIR}/rootfs.img, error out if it
266 # exceeds 4GB, it is the single file's max size of FAT fs.
267 if [ -f ${HDDDIR}/rootfs.img ]; then
268 rootfs_img_size=`stat -c '%s' ${HDDDIR}/rootfs.img`
269 max_size=`expr 4 \* 1024 \* 1024 \* 1024`
270 if [ $rootfs_img_size -gt $max_size ]; then
271 bberror "${HDDDIR}/rootfs.img execeeds 4GB,"
272 bberror "this doesn't work on FAT filesystem, you can try either of:"
273 bberror "1) Reduce the size of rootfs.img"
274 bbfatal "2) Use iso, vmdk or vdi to instead of hddimg\n"
275 fi
276 fi
277
278 build_fat_img ${HDDDIR} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
279
280 if [ "${PCBIOS}" = "1" ]; then
281 syslinux_hddimg_install
282 fi
283
284 chmod 644 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
285 fi
286}
287
288python do_bootimg() {
289 set_live_vm_vars(d, 'LIVE')
290 if d.getVar("PCBIOS", True) == "1":
291 bb.build.exec_func('build_syslinux_cfg', d)
292 if d.getVar("EFI", True) == "1":
293 bb.build.exec_func('build_efi_cfg', d)
294 bb.build.exec_func('build_hddimg', d)
295 bb.build.exec_func('build_iso', d)
296 bb.build.exec_func('create_symlinks', d)
297}
298do_bootimg[subimages] = "hddimg iso"
299do_bootimg[imgsuffix] = "."
300
301IMAGE_TYPEDEP_iso = "ext4"
302IMAGE_TYPEDEP_hddimg = "ext4"
303IMAGE_TYPES_MASKED += "iso hddimg"
304
305addtask bootimg before do_image_complete
diff --git a/meta/classes/gummiboot.bbclass b/meta/classes/gummiboot.bbclass
index 9a97ac1753..1ebb9462d3 100644
--- a/meta/classes/gummiboot.bbclass
+++ b/meta/classes/gummiboot.bbclass
@@ -4,7 +4,7 @@
4 4
5# gummiboot.bbclass - equivalent of grub-efi.bbclass 5# gummiboot.bbclass - equivalent of grub-efi.bbclass
6# Set EFI_PROVIDER = "gummiboot" to use gummiboot on your live images instead of grub-efi 6# Set EFI_PROVIDER = "gummiboot" to use gummiboot on your live images instead of grub-efi
7# (images built by bootimage.bbclass or boot-directdisk.bbclass) 7# (images built by image-live.bbclass or image-vm.bbclass)
8 8
9do_bootimg[depends] += "${MLPREFIX}gummiboot:do_deploy" 9do_bootimg[depends] += "${MLPREFIX}gummiboot:do_deploy"
10do_bootdirectdisk[depends] += "${MLPREFIX}gummiboot:do_deploy" 10do_bootdirectdisk[depends] += "${MLPREFIX}gummiboot:do_deploy"
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
diff --git a/meta/classes/image-vm.bbclass b/meta/classes/image-vm.bbclass
index 68cf89b68d..ced8eac4d9 100644
--- a/meta/classes/image-vm.bbclass
+++ b/meta/classes/image-vm.bbclass
@@ -1,5 +1,5 @@
1# image-vm.bbclass 1# image-vm.bbclass
2# (loosly based off bootimg.bbclass Copyright (C) 2004, Advanced Micro Devices, Inc.) 2# (loosly based off image-live.bbclass Copyright (C) 2004, Advanced Micro Devices, Inc.)
3# 3#
4# Create an image which can be placed directly onto a harddisk using dd and then 4# Create an image which can be placed directly onto a harddisk using dd and then
5# booted. 5# booted.