diff options
Diffstat (limited to 'meta/classes/boot-directdisk.bbclass')
| -rw-r--r-- | meta/classes/boot-directdisk.bbclass | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/meta/classes/boot-directdisk.bbclass b/meta/classes/boot-directdisk.bbclass deleted file mode 100644 index 46f88ac9bf..0000000000 --- a/meta/classes/boot-directdisk.bbclass +++ /dev/null | |||
| @@ -1,190 +0,0 @@ | |||
| 1 | # boot-directdisk.bbclass | ||
| 2 | # (loosly based off bootimg.bbclass Copyright (C) 2004, Advanced Micro Devices, Inc.) | ||
| 3 | # | ||
| 4 | # Create an image which can be placed directly onto a harddisk using dd and then | ||
| 5 | # booted. | ||
| 6 | # | ||
| 7 | # This uses syslinux. extlinux would have been nice but required the ext2/3 | ||
| 8 | # partition to be mounted. grub requires to run itself as part of the install | ||
| 9 | # process. | ||
| 10 | # | ||
| 11 | # The end result is a 512 boot sector populated with an MBR and partition table | ||
| 12 | # followed by an msdos fat16 partition containing syslinux and a linux kernel | ||
| 13 | # completed by the ext2/3 rootfs. | ||
| 14 | # | ||
| 15 | # We have to push the msdos parition table size > 16MB so fat 16 is used as parted | ||
| 16 | # won't touch fat12 partitions. | ||
| 17 | |||
| 18 | # External variables needed | ||
| 19 | |||
| 20 | # ${ROOTFS} - the rootfs image to incorporate | ||
| 21 | |||
| 22 | do_bootdirectdisk[depends] += "dosfstools-native:do_populate_sysroot \ | ||
| 23 | virtual/kernel:do_deploy \ | ||
| 24 | syslinux:do_populate_sysroot \ | ||
| 25 | syslinux-native:do_populate_sysroot \ | ||
| 26 | parted-native:do_populate_sysroot \ | ||
| 27 | mtools-native:do_populate_sysroot " | ||
| 28 | |||
| 29 | PACKAGES = " " | ||
| 30 | EXCLUDE_FROM_WORLD = "1" | ||
| 31 | |||
| 32 | BOOTDD_VOLUME_ID ?= "boot" | ||
| 33 | BOOTDD_EXTRA_SPACE ?= "16384" | ||
| 34 | |||
| 35 | EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}" | ||
| 36 | EFI_PROVIDER ?= "grub-efi" | ||
| 37 | EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}" | ||
| 38 | |||
| 39 | # Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not | ||
| 40 | # contain "efi". This way legacy is supported by default if neither is | ||
| 41 | # specified, maintaining the original behavior. | ||
| 42 | def pcbios(d): | ||
| 43 | pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d) | ||
| 44 | if pcbios == "0": | ||
| 45 | pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d) | ||
| 46 | return pcbios | ||
| 47 | |||
| 48 | def pcbios_class(d): | ||
| 49 | if d.getVar("PCBIOS", True) == "1": | ||
| 50 | return "syslinux" | ||
| 51 | return "" | ||
| 52 | |||
| 53 | PCBIOS = "${@pcbios(d)}" | ||
| 54 | PCBIOS_CLASS = "${@pcbios_class(d)}" | ||
| 55 | |||
| 56 | # Get the build_syslinux_cfg() function from the syslinux class | ||
| 57 | inherit ${PCBIOS_CLASS} | ||
| 58 | inherit ${EFI_CLASS} | ||
| 59 | |||
| 60 | DISK_SIGNATURE ?= "${DISK_SIGNATURE_GENERATED}" | ||
| 61 | ROOT_VM ?= "root=/dev/sda2" | ||
| 62 | |||
| 63 | boot_direct_populate() { | ||
| 64 | dest=$1 | ||
| 65 | install -d $dest | ||
| 66 | |||
| 67 | # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use. | ||
| 68 | if [ -e ${DEPLOY_DIR_IMAGE}/bzImage ]; then | ||
| 69 | install -m 0644 ${DEPLOY_DIR_IMAGE}/bzImage $dest/vmlinuz | ||
| 70 | fi | ||
| 71 | |||
| 72 | # initrd is made of concatenation of multiple filesystem images | ||
| 73 | if [ -n "${INITRD}" ]; then | ||
| 74 | rm -f $dest/initrd | ||
| 75 | for fs in ${INITRD} | ||
| 76 | do | ||
| 77 | if [ -s "${fs}" ]; then | ||
| 78 | cat ${fs} >> $dest/initrd | ||
| 79 | else | ||
| 80 | bbfatal "${fs} is invalid. initrd image creation failed." | ||
| 81 | fi | ||
| 82 | done | ||
| 83 | chmod 0644 $dest/initrd | ||
| 84 | fi | ||
| 85 | } | ||
| 86 | |||
| 87 | build_boot_dd() { | ||
| 88 | HDDDIR="${S}/hdd/boot" | ||
| 89 | HDDIMG="${S}/hdd.image" | ||
| 90 | IMAGE=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hdddirect | ||
| 91 | |||
| 92 | boot_direct_populate $HDDDIR | ||
| 93 | |||
| 94 | if [ "${PCBIOS}" = "1" ]; then | ||
| 95 | syslinux_hddimg_populate $HDDDIR | ||
| 96 | fi | ||
| 97 | if [ "${EFI}" = "1" ]; then | ||
| 98 | efi_hddimg_populate $HDDDIR | ||
| 99 | fi | ||
| 100 | |||
| 101 | if [ "x${AUTO_SYSLINUXMENU}" = "x1" ] ; then | ||
| 102 | install -m 0644 ${STAGING_DIR}/${MACHINE}/usr/share/syslinux/vesamenu.c32 $HDDDIR/${SYSLINUXDIR}/ | ||
| 103 | if [ "x${SYSLINUX_SPLASH}" != "x" ] ; then | ||
| 104 | install -m 0644 ${SYSLINUX_SPLASH} $HDDDIR/${SYSLINUXDIR}/splash.lss | ||
| 105 | fi | ||
| 106 | fi | ||
| 107 | |||
| 108 | BLOCKS=`du -bks $HDDDIR | cut -f 1` | ||
| 109 | BLOCKS=`expr $BLOCKS + ${BOOTDD_EXTRA_SPACE}` | ||
| 110 | |||
| 111 | # Ensure total sectors is an integral number of sectors per | ||
| 112 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 113 | # generate images with 32 sectors per track. This calculation is | ||
| 114 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 115 | BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16))) | ||
| 116 | |||
| 117 | # Remove it since mkdosfs would fail when it exists | ||
| 118 | rm -f $HDDIMG | ||
| 119 | mkdosfs -n ${BOOTDD_VOLUME_ID} -S 512 -C $HDDIMG $BLOCKS | ||
| 120 | mcopy -i $HDDIMG -s $HDDDIR/* ::/ | ||
| 121 | |||
| 122 | if [ "${PCBIOS}" = "1" ]; then | ||
| 123 | syslinux_hdddirect_install $HDDIMG | ||
| 124 | fi | ||
| 125 | chmod 644 $HDDIMG | ||
| 126 | |||
| 127 | ROOTFSBLOCKS=`du -Lbks ${ROOTFS} | cut -f 1` | ||
| 128 | TOTALSIZE=`expr $BLOCKS + $ROOTFSBLOCKS` | ||
| 129 | END1=`expr $BLOCKS \* 1024` | ||
| 130 | END2=`expr $END1 + 512` | ||
| 131 | END3=`expr \( $ROOTFSBLOCKS \* 1024 \) + $END1` | ||
| 132 | |||
| 133 | echo $ROOTFSBLOCKS $TOTALSIZE $END1 $END2 $END3 | ||
| 134 | rm -rf $IMAGE | ||
| 135 | dd if=/dev/zero of=$IMAGE bs=1024 seek=$TOTALSIZE count=1 | ||
| 136 | |||
| 137 | parted $IMAGE mklabel msdos | ||
| 138 | parted $IMAGE mkpart primary fat16 0 ${END1}B | ||
| 139 | parted $IMAGE unit B mkpart primary ext2 ${END2}B ${END3}B | ||
| 140 | parted $IMAGE set 1 boot on | ||
| 141 | |||
| 142 | parted $IMAGE print | ||
| 143 | |||
| 144 | awk "BEGIN { printf \"$(echo ${DISK_SIGNATURE} | fold -w 2 | tac | paste -sd '' | sed 's/\(..\)/\\x&/g')\" }" | \ | ||
| 145 | dd of=$IMAGE bs=1 seek=440 conv=notrunc | ||
| 146 | |||
| 147 | OFFSET=`expr $END2 / 512` | ||
| 148 | if [ "${PCBIOS}" = "1" ]; then | ||
| 149 | dd if=${STAGING_DATADIR}/syslinux/mbr.bin of=$IMAGE conv=notrunc | ||
| 150 | fi | ||
| 151 | |||
| 152 | dd if=$HDDIMG of=$IMAGE conv=notrunc seek=1 bs=512 | ||
| 153 | dd if=${ROOTFS} of=$IMAGE conv=notrunc seek=$OFFSET bs=512 | ||
| 154 | |||
| 155 | cd ${DEPLOY_DIR_IMAGE} | ||
| 156 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect | ||
| 157 | ln -s ${IMAGE_NAME}.hdddirect ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect | ||
| 158 | } | ||
| 159 | |||
| 160 | python do_bootdirectdisk() { | ||
| 161 | validate_disk_signature(d) | ||
| 162 | set_live_vm_vars(d, 'VM') | ||
| 163 | if d.getVar("PCBIOS", True) == "1": | ||
| 164 | bb.build.exec_func('build_syslinux_cfg', d) | ||
| 165 | if d.getVar("EFI", True) == "1": | ||
| 166 | bb.build.exec_func('build_efi_cfg', d) | ||
| 167 | bb.build.exec_func('build_boot_dd', d) | ||
| 168 | } | ||
| 169 | |||
| 170 | def generate_disk_signature(): | ||
| 171 | import uuid | ||
| 172 | |||
| 173 | signature = str(uuid.uuid4())[:8] | ||
| 174 | |||
| 175 | if signature != '00000000': | ||
| 176 | return signature | ||
| 177 | else: | ||
| 178 | return 'ffffffff' | ||
| 179 | |||
| 180 | def validate_disk_signature(d): | ||
| 181 | import re | ||
| 182 | |||
| 183 | disk_signature = d.getVar("DISK_SIGNATURE", True) | ||
| 184 | |||
| 185 | if not re.match(r'^[0-9a-fA-F]{8}$', disk_signature): | ||
| 186 | bb.fatal("DISK_SIGNATURE '%s' must be an 8 digit hex string" % disk_signature) | ||
| 187 | |||
| 188 | DISK_SIGNATURE_GENERATED := "${@generate_disk_signature()}" | ||
| 189 | |||
| 190 | addtask bootdirectdisk before do_image_complete | ||
