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