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