diff options
Diffstat (limited to 'meta/classes/bootimg.bbclass')
-rw-r--r-- | meta/classes/bootimg.bbclass | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass new file mode 100644 index 0000000000..859d517dbd --- /dev/null +++ b/meta/classes/bootimg.bbclass | |||
@@ -0,0 +1,267 @@ | |||
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 | ${@oe.utils.ifelse(d.getVar('COMPRESSISO'),'zisofs-tools-native:do_populate_sysroot','')}" | ||
32 | |||
33 | PACKAGES = " " | ||
34 | EXCLUDE_FROM_WORLD = "1" | ||
35 | |||
36 | HDDDIR = "${S}/hddimg" | ||
37 | ISODIR = "${S}/iso" | ||
38 | EFIIMGDIR = "${S}/efi_img" | ||
39 | COMPACT_ISODIR = "${S}/iso.z" | ||
40 | COMPRESSISO ?= "0" | ||
41 | |||
42 | BOOTIMG_VOLUME_ID ?= "boot" | ||
43 | BOOTIMG_EXTRA_SPACE ?= "512" | ||
44 | |||
45 | EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}" | ||
46 | EFI_PROVIDER ?= "grub-efi" | ||
47 | EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}" | ||
48 | |||
49 | # Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not | ||
50 | # contain "efi". This way legacy is supported by default if neither is | ||
51 | # specified, maintaining the original behavior. | ||
52 | def pcbios(d): | ||
53 | pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d) | ||
54 | if pcbios == "0": | ||
55 | pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d) | ||
56 | return pcbios | ||
57 | |||
58 | PCBIOS = "${@pcbios(d)}" | ||
59 | |||
60 | # The syslinux is required for the isohybrid command and boot catalog | ||
61 | inherit syslinux | ||
62 | inherit ${EFI_CLASS} | ||
63 | |||
64 | populate() { | ||
65 | DEST=$1 | ||
66 | install -d ${DEST} | ||
67 | |||
68 | # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use. | ||
69 | install -m 0644 ${STAGING_KERNEL_DIR}/bzImage ${DEST}/vmlinuz | ||
70 | |||
71 | # initrd is made of concatenation of multiple filesystem images | ||
72 | if [ -n "${INITRD}" ]; then | ||
73 | rm -f ${DEST}/initrd | ||
74 | for fs in ${INITRD} | ||
75 | do | ||
76 | if [ -s "${fs}" ]; then | ||
77 | cat ${fs} >> ${DEST}/initrd | ||
78 | else | ||
79 | bbfatal "${fs} is invalid. initrd image creation failed." | ||
80 | fi | ||
81 | done | ||
82 | chmod 0644 ${DEST}/initrd | ||
83 | fi | ||
84 | |||
85 | if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then | ||
86 | install -m 0644 ${ROOTFS} ${DEST}/rootfs.img | ||
87 | fi | ||
88 | |||
89 | } | ||
90 | |||
91 | build_iso() { | ||
92 | # Only create an ISO if we have an INITRD and NOISO was not set | ||
93 | if [ -z "${INITRD}" ] || [ "${NOISO}" = "1" ]; then | ||
94 | bbnote "ISO image will not be created." | ||
95 | return | ||
96 | fi | ||
97 | # ${INITRD} is a list of multiple filesystem images | ||
98 | for fs in ${INITRD} | ||
99 | do | ||
100 | if [ ! -s "${fs}" ]; then | ||
101 | bbnote "ISO image will not be created. ${fs} is invalid." | ||
102 | return | ||
103 | fi | ||
104 | done | ||
105 | |||
106 | |||
107 | populate ${ISODIR} | ||
108 | |||
109 | if [ "${PCBIOS}" = "1" ]; then | ||
110 | syslinux_iso_populate ${ISODIR} | ||
111 | fi | ||
112 | if [ "${EFI}" = "1" ]; then | ||
113 | efi_iso_populate ${ISODIR} | ||
114 | build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img | ||
115 | fi | ||
116 | |||
117 | # EFI only | ||
118 | if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then | ||
119 | # Work around bug in isohybrid where it requires isolinux.bin | ||
120 | # In the boot catalog, even though it is not used | ||
121 | mkdir -p ${ISODIR}/${ISOLINUXDIR} | ||
122 | install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR} | ||
123 | fi | ||
124 | |||
125 | if [ "${COMPRESSISO}" = "1" ] ; then | ||
126 | # create compact directory, compress iso | ||
127 | mkdir -p ${COMPACT_ISODIR} | ||
128 | mkzftree -z 9 -p 4 -F ${ISODIR}/rootfs.img ${COMPACT_ISODIR}/rootfs.img | ||
129 | |||
130 | # move compact iso to iso, then remove compact directory | ||
131 | mv ${COMPACT_ISODIR}/rootfs.img ${ISODIR}/rootfs.img | ||
132 | rm -Rf ${COMPACT_ISODIR} | ||
133 | mkisofs_compress_opts="-R -z -D -l" | ||
134 | else | ||
135 | mkisofs_compress_opts="-r" | ||
136 | fi | ||
137 | |||
138 | if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then | ||
139 | # PCBIOS only media | ||
140 | mkisofs -V ${BOOTIMG_VOLUME_ID} \ | ||
141 | -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \ | ||
142 | -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \ | ||
143 | $mkisofs_compress_opts \ | ||
144 | ${MKISOFS_OPTIONS} ${ISODIR} | ||
145 | else | ||
146 | # EFI only OR EFI+PCBIOS | ||
147 | mkisofs -A ${BOOTIMG_VOLUME_ID} -V ${BOOTIMG_VOLUME_ID} \ | ||
148 | -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \ | ||
149 | -b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \ | ||
150 | $mkisofs_compress_opts ${MKISOFS_OPTIONS} \ | ||
151 | -eltorito-alt-boot -eltorito-platform efi \ | ||
152 | -b efi.img -no-emul-boot \ | ||
153 | ${ISODIR} | ||
154 | isohybrid_args="-u" | ||
155 | fi | ||
156 | |||
157 | isohybrid $isohybrid_args ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso | ||
158 | |||
159 | cd ${DEPLOY_DIR_IMAGE} | ||
160 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.iso | ||
161 | ln -s ${IMAGE_NAME}.iso ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.iso | ||
162 | } | ||
163 | |||
164 | build_fat_img() { | ||
165 | FATSOURCEDIR=$1 | ||
166 | FATIMG=$2 | ||
167 | |||
168 | # Calculate the size required for the final image including the | ||
169 | # data and filesystem overhead. | ||
170 | # Sectors: 512 bytes | ||
171 | # Blocks: 1024 bytes | ||
172 | |||
173 | # Determine the sector count just for the data | ||
174 | SECTORS=$(expr $(du --apparent-size -ks ${FATSOURCEDIR} | cut -f 1) \* 2) | ||
175 | |||
176 | # Account for the filesystem overhead. This includes directory | ||
177 | # entries in the clusters as well as the FAT itself. | ||
178 | # Assumptions: | ||
179 | # FAT32 (12 or 16 may be selected by mkdosfs, but the extra | ||
180 | # padding will be minimal on those smaller images and not | ||
181 | # worth the logic here to caclulate the smaller FAT sizes) | ||
182 | # < 16 entries per directory | ||
183 | # 8.3 filenames only | ||
184 | |||
185 | # 32 bytes per dir entry | ||
186 | DIR_BYTES=$(expr $(find ${FATSOURCEDIR} | tail -n +2 | wc -l) \* 32) | ||
187 | # 32 bytes for every end-of-directory dir entry | ||
188 | DIR_BYTES=$(expr $DIR_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 32)) | ||
189 | # 4 bytes per FAT entry per sector of data | ||
190 | FAT_BYTES=$(expr $SECTORS \* 4) | ||
191 | # 4 bytes per FAT entry per end-of-cluster list | ||
192 | FAT_BYTES=$(expr $FAT_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 4)) | ||
193 | |||
194 | # Use a ceiling function to determine FS overhead in sectors | ||
195 | DIR_SECTORS=$(expr $(expr $DIR_BYTES + 511) / 512) | ||
196 | # There are two FATs on the image | ||
197 | FAT_SECTORS=$(expr $(expr $(expr $FAT_BYTES + 511) / 512) \* 2) | ||
198 | SECTORS=$(expr $SECTORS + $(expr $DIR_SECTORS + $FAT_SECTORS)) | ||
199 | |||
200 | # Determine the final size in blocks accounting for some padding | ||
201 | BLOCKS=$(expr $(expr $SECTORS / 2) + ${BOOTIMG_EXTRA_SPACE}) | ||
202 | |||
203 | # Ensure total sectors is an integral number of sectors per | ||
204 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
205 | # generate images with 32 sectors per track. This calculation is | ||
206 | # done in blocks, thus the mod by 16 instead of 32. | ||
207 | BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16))) | ||
208 | |||
209 | # mkdosfs will sometimes use FAT16 when it is not appropriate, | ||
210 | # resulting in a boot failure from SYSLINUX. Use FAT32 for | ||
211 | # images larger than 512MB, otherwise let mkdosfs decide. | ||
212 | if [ $(expr $BLOCKS / 1024) -gt 512 ]; then | ||
213 | FATSIZE="-F 32" | ||
214 | fi | ||
215 | |||
216 | if [ -z "${HDDIMG_ID}" ]; then | ||
217 | mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \ | ||
218 | ${BLOCKS} | ||
219 | else | ||
220 | mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \ | ||
221 | ${BLOCKS} -i ${HDDIMG_ID} | ||
222 | fi | ||
223 | |||
224 | # Copy FATSOURCEDIR recursively into the image file directly | ||
225 | mcopy -i ${FATIMG} -s ${FATSOURCEDIR}/* ::/ | ||
226 | } | ||
227 | |||
228 | build_hddimg() { | ||
229 | # Create an HDD image | ||
230 | if [ "${NOHDD}" != "1" ] ; then | ||
231 | populate ${HDDDIR} | ||
232 | |||
233 | if [ "${PCBIOS}" = "1" ]; then | ||
234 | syslinux_hddimg_populate ${HDDDIR} | ||
235 | fi | ||
236 | if [ "${EFI}" = "1" ]; then | ||
237 | efi_hddimg_populate ${HDDDIR} | ||
238 | fi | ||
239 | |||
240 | build_fat_img ${HDDDIR} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg | ||
241 | |||
242 | if [ "${PCBIOS}" = "1" ]; then | ||
243 | syslinux_hddimg_install | ||
244 | fi | ||
245 | |||
246 | chmod 644 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg | ||
247 | |||
248 | cd ${DEPLOY_DIR_IMAGE} | ||
249 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hddimg | ||
250 | ln -s ${IMAGE_NAME}.hddimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hddimg | ||
251 | fi | ||
252 | } | ||
253 | |||
254 | python do_bootimg() { | ||
255 | if d.getVar("PCBIOS", True) == "1": | ||
256 | bb.build.exec_func('build_syslinux_cfg', d) | ||
257 | if d.getVar("EFI", True) == "1": | ||
258 | bb.build.exec_func('build_efi_cfg', d) | ||
259 | bb.build.exec_func('build_hddimg', d) | ||
260 | bb.build.exec_func('build_iso', d) | ||
261 | } | ||
262 | |||
263 | IMAGE_TYPEDEP_iso = "ext3" | ||
264 | IMAGE_TYPEDEP_hddimg = "ext3" | ||
265 | IMAGE_TYPES_MASKED += "iso hddimg" | ||
266 | |||
267 | addtask bootimg before do_build | ||