Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | # grub-efi.bbclass |
| 2 | # Copyright (c) 2011, Intel Corporation. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Released under the MIT license (see packages/COPYING) |
| 6 | |
| 7 | # Provide grub-efi specific functions for building bootable images. |
| 8 | |
| 9 | # External variables |
| 10 | # ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional) |
| 11 | # ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional) |
| 12 | # ${GRUB_GFXSERIAL} - set this to 1 to have graphics and serial in the boot menu |
| 13 | # ${LABELS} - a list of targets for the automatic config |
| 14 | # ${APPEND} - an override list of append strings for each label |
| 15 | # ${GRUB_OPTS} - additional options to add to the config, ';' delimited # (optional) |
| 16 | # ${GRUB_TIMEOUT} - timeout before executing the deault label (optional) |
| 17 | |
| 18 | do_bootimg[depends] += "${MLPREFIX}grub-efi:do_deploy" |
| 19 | do_bootdirectdisk[depends] += "${MLPREFIX}grub-efi:do_deploy" |
| 20 | |
| 21 | GRUB_SERIAL ?= "console=ttyS0,115200" |
| 22 | GRUBCFG = "${S}/grub.cfg" |
| 23 | GRUB_TIMEOUT ?= "10" |
| 24 | #FIXME: build this from the machine config |
| 25 | GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1" |
| 26 | |
| 27 | EFIDIR = "/EFI/BOOT" |
| 28 | |
| 29 | # Need UUID utility code. |
| 30 | inherit fs-uuid |
| 31 | |
| 32 | efi_populate() { |
| 33 | # DEST must be the root of the image so that EFIDIR is not |
| 34 | # nested under a top level directory. |
| 35 | DEST=$1 |
| 36 | |
| 37 | install -d ${DEST}${EFIDIR} |
| 38 | |
| 39 | GRUB_IMAGE="bootia32.efi" |
| 40 | if [ "${TARGET_ARCH}" = "x86_64" ]; then |
| 41 | GRUB_IMAGE="bootx64.efi" |
| 42 | fi |
| 43 | install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST}${EFIDIR} |
| 44 | |
| 45 | install -m 0644 ${GRUBCFG} ${DEST}${EFIDIR}/grub.cfg |
| 46 | } |
| 47 | |
| 48 | efi_iso_populate() { |
| 49 | iso_dir=$1 |
| 50 | efi_populate $iso_dir |
| 51 | # Build a EFI directory to create efi.img |
| 52 | mkdir -p ${EFIIMGDIR}/${EFIDIR} |
| 53 | cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR} |
| 54 | cp $iso_dir/vmlinuz ${EFIIMGDIR} |
| 55 | echo "${GRUB_IMAGE}" > ${EFIIMGDIR}/startup.nsh |
| 56 | if [ -f "$iso_dir/initrd" ] ; then |
| 57 | cp $iso_dir/initrd ${EFIIMGDIR} |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | efi_hddimg_populate() { |
| 62 | efi_populate $1 |
| 63 | } |
| 64 | |
| 65 | python build_efi_cfg() { |
| 66 | import sys |
| 67 | |
| 68 | workdir = d.getVar('WORKDIR', True) |
| 69 | if not workdir: |
| 70 | bb.error("WORKDIR not defined, unable to package") |
| 71 | return |
| 72 | |
| 73 | gfxserial = d.getVar('GRUB_GFXSERIAL', True) or "" |
| 74 | |
| 75 | labels = d.getVar('LABELS', True) |
| 76 | if not labels: |
| 77 | bb.debug(1, "LABELS not defined, nothing to do") |
| 78 | return |
| 79 | |
| 80 | if labels == []: |
| 81 | bb.debug(1, "No labels, nothing to do") |
| 82 | return |
| 83 | |
| 84 | cfile = d.getVar('GRUBCFG', True) |
| 85 | if not cfile: |
| 86 | raise bb.build.FuncFailed('Unable to read GRUBCFG') |
| 87 | |
| 88 | try: |
| 89 | cfgfile = file(cfile, 'w') |
| 90 | except OSError: |
| 91 | raise bb.build.funcFailed('Unable to open %s' % (cfile)) |
| 92 | |
| 93 | cfgfile.write('# Automatically created by OE\n') |
| 94 | |
| 95 | opts = d.getVar('GRUB_OPTS', True) |
| 96 | if opts: |
| 97 | for opt in opts.split(';'): |
| 98 | cfgfile.write('%s\n' % opt) |
| 99 | |
| 100 | cfgfile.write('default=%s\n' % (labels.split()[0])) |
| 101 | |
| 102 | timeout = d.getVar('GRUB_TIMEOUT', True) |
| 103 | if timeout: |
| 104 | cfgfile.write('timeout=%s\n' % timeout) |
| 105 | else: |
| 106 | cfgfile.write('timeout=50\n') |
| 107 | |
| 108 | if gfxserial == "1": |
| 109 | btypes = [ [ " graphics console", "" ], |
| 110 | [ " serial console", d.getVar('GRUB_SERIAL', True) or "" ] ] |
| 111 | else: |
| 112 | btypes = [ [ "", "" ] ] |
| 113 | |
| 114 | for label in labels.split(): |
| 115 | localdata = d.createCopy() |
| 116 | |
| 117 | overrides = localdata.getVar('OVERRIDES', True) |
| 118 | if not overrides: |
| 119 | raise bb.build.FuncFailed('OVERRIDES not defined') |
| 120 | |
| 121 | for btype in btypes: |
| 122 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 123 | bb.data.update_data(localdata) |
| 124 | |
| 125 | cfgfile.write('\nmenuentry \'%s%s\'{\n' % (label, btype[0])) |
| 126 | lb = label |
| 127 | if label == "install": |
| 128 | lb = "install-efi" |
| 129 | cfgfile.write('linux /vmlinuz LABEL=%s' % (lb)) |
| 130 | |
| 131 | append = localdata.getVar('APPEND', True) |
| 132 | initrd = localdata.getVar('INITRD', True) |
| 133 | |
| 134 | if append: |
| 135 | append = replace_rootfs_uuid(d, append) |
| 136 | cfgfile.write('%s' % (append)) |
| 137 | cfgfile.write(' %s' % btype[1]) |
| 138 | cfgfile.write('\n') |
| 139 | |
| 140 | if initrd: |
| 141 | cfgfile.write('initrd /initrd') |
| 142 | cfgfile.write('\n}\n') |
| 143 | |
| 144 | cfgfile.close() |
| 145 | } |