diff options
Diffstat (limited to 'meta/classes/bootimg.bbclass')
-rw-r--r-- | meta/classes/bootimg.bbclass | 305 |
1 files changed, 0 insertions, 305 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 | |||
28 | do_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 | |||
35 | PACKAGES = " " | ||
36 | EXCLUDE_FROM_WORLD = "1" | ||
37 | |||
38 | HDDDIR = "${S}/hddimg" | ||
39 | ISODIR = "${S}/iso" | ||
40 | EFIIMGDIR = "${S}/efi_img" | ||
41 | COMPACT_ISODIR = "${S}/iso.z" | ||
42 | COMPRESSISO ?= "0" | ||
43 | |||
44 | ISOLINUXDIR ?= "/isolinux" | ||
45 | ISO_BOOTIMG = "isolinux/isolinux.bin" | ||
46 | ISO_BOOTCAT = "isolinux/boot.cat" | ||
47 | MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table" | ||
48 | |||
49 | BOOTIMG_VOLUME_ID ?= "boot" | ||
50 | BOOTIMG_EXTRA_SPACE ?= "512" | ||
51 | |||
52 | EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}" | ||
53 | EFI_PROVIDER ?= "grub-efi" | ||
54 | EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}" | ||
55 | |||
56 | KERNEL_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. | ||
61 | def 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 | |||
67 | PCBIOS = "${@pcbios(d)}" | ||
68 | PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS', True) == '1']}" | ||
69 | |||
70 | inherit ${EFI_CLASS} | ||
71 | inherit ${PCBIOS_CLASS} | ||
72 | |||
73 | populate() { | ||
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 | |||
100 | build_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 | |||
183 | build_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 | |||
253 | build_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 | |||
288 | python 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 | } | ||
298 | do_bootimg[subimages] = "hddimg iso" | ||
299 | do_bootimg[imgsuffix] = "." | ||
300 | |||
301 | IMAGE_TYPEDEP_iso = "ext4" | ||
302 | IMAGE_TYPEDEP_hddimg = "ext4" | ||
303 | IMAGE_TYPES_MASKED += "iso hddimg" | ||
304 | |||
305 | addtask bootimg before do_image_complete | ||