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) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 17 | # ${GRUB_ROOT} - grub's root device. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
| 19 | do_bootimg[depends] += "${MLPREFIX}grub-efi:do_deploy" |
| 20 | do_bootdirectdisk[depends] += "${MLPREFIX}grub-efi:do_deploy" |
| 21 | |
| 22 | GRUB_SERIAL ?= "console=ttyS0,115200" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 23 | GRUB_CFG_VM = "${S}/grub_vm.cfg" |
| 24 | GRUB_CFG_LIVE = "${S}/grub_live.cfg" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | GRUB_TIMEOUT ?= "10" |
| 26 | #FIXME: build this from the machine config |
| 27 | GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1" |
| 28 | |
| 29 | EFIDIR = "/EFI/BOOT" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 30 | GRUB_ROOT ?= "${ROOT}" |
| 31 | APPEND ?= "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
| 33 | # Need UUID utility code. |
| 34 | inherit fs-uuid |
| 35 | |
| 36 | efi_populate() { |
| 37 | # DEST must be the root of the image so that EFIDIR is not |
| 38 | # nested under a top level directory. |
| 39 | DEST=$1 |
| 40 | |
| 41 | install -d ${DEST}${EFIDIR} |
| 42 | |
| 43 | GRUB_IMAGE="bootia32.efi" |
| 44 | if [ "${TARGET_ARCH}" = "x86_64" ]; then |
| 45 | GRUB_IMAGE="bootx64.efi" |
| 46 | fi |
| 47 | install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST}${EFIDIR} |
| 48 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 49 | install -m 0644 ${GRUB_CFG} ${DEST}${EFIDIR}/grub.cfg |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | efi_iso_populate() { |
| 53 | iso_dir=$1 |
| 54 | efi_populate $iso_dir |
| 55 | # Build a EFI directory to create efi.img |
| 56 | mkdir -p ${EFIIMGDIR}/${EFIDIR} |
| 57 | cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR} |
| 58 | cp $iso_dir/vmlinuz ${EFIIMGDIR} |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 59 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 60 | echo "fs0:${EFIPATH}\\${GRUB_IMAGE}" > ${EFIIMGDIR}/startup.nsh |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | if [ -f "$iso_dir/initrd" ] ; then |
| 62 | cp $iso_dir/initrd ${EFIIMGDIR} |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | efi_hddimg_populate() { |
| 67 | efi_populate $1 |
| 68 | } |
| 69 | |
| 70 | python build_efi_cfg() { |
| 71 | import sys |
| 72 | |
| 73 | workdir = d.getVar('WORKDIR', True) |
| 74 | if not workdir: |
| 75 | bb.error("WORKDIR not defined, unable to package") |
| 76 | return |
| 77 | |
| 78 | gfxserial = d.getVar('GRUB_GFXSERIAL', True) or "" |
| 79 | |
| 80 | labels = d.getVar('LABELS', True) |
| 81 | if not labels: |
| 82 | bb.debug(1, "LABELS not defined, nothing to do") |
| 83 | return |
| 84 | |
| 85 | if labels == []: |
| 86 | bb.debug(1, "No labels, nothing to do") |
| 87 | return |
| 88 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 89 | cfile = d.getVar('GRUB_CFG', True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | if not cfile: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 91 | raise bb.build.FuncFailed('Unable to read GRUB_CFG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | |
| 93 | try: |
| 94 | cfgfile = file(cfile, 'w') |
| 95 | except OSError: |
| 96 | raise bb.build.funcFailed('Unable to open %s' % (cfile)) |
| 97 | |
| 98 | cfgfile.write('# Automatically created by OE\n') |
| 99 | |
| 100 | opts = d.getVar('GRUB_OPTS', True) |
| 101 | if opts: |
| 102 | for opt in opts.split(';'): |
| 103 | cfgfile.write('%s\n' % opt) |
| 104 | |
| 105 | cfgfile.write('default=%s\n' % (labels.split()[0])) |
| 106 | |
| 107 | timeout = d.getVar('GRUB_TIMEOUT', True) |
| 108 | if timeout: |
| 109 | cfgfile.write('timeout=%s\n' % timeout) |
| 110 | else: |
| 111 | cfgfile.write('timeout=50\n') |
| 112 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 113 | root = d.getVar('GRUB_ROOT', True) |
| 114 | if not root: |
| 115 | raise bb.build.FuncFailed('GRUB_ROOT not defined') |
| 116 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | if gfxserial == "1": |
| 118 | btypes = [ [ " graphics console", "" ], |
| 119 | [ " serial console", d.getVar('GRUB_SERIAL', True) or "" ] ] |
| 120 | else: |
| 121 | btypes = [ [ "", "" ] ] |
| 122 | |
| 123 | for label in labels.split(): |
| 124 | localdata = d.createCopy() |
| 125 | |
| 126 | overrides = localdata.getVar('OVERRIDES', True) |
| 127 | if not overrides: |
| 128 | raise bb.build.FuncFailed('OVERRIDES not defined') |
| 129 | |
| 130 | for btype in btypes: |
| 131 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 132 | bb.data.update_data(localdata) |
| 133 | |
| 134 | cfgfile.write('\nmenuentry \'%s%s\'{\n' % (label, btype[0])) |
| 135 | lb = label |
| 136 | if label == "install": |
| 137 | lb = "install-efi" |
| 138 | cfgfile.write('linux /vmlinuz LABEL=%s' % (lb)) |
| 139 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 140 | cfgfile.write(' %s' % replace_rootfs_uuid(d, root)) |
| 141 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | append = localdata.getVar('APPEND', True) |
| 143 | initrd = localdata.getVar('INITRD', True) |
| 144 | |
| 145 | if append: |
| 146 | append = replace_rootfs_uuid(d, append) |
| 147 | cfgfile.write('%s' % (append)) |
| 148 | cfgfile.write(' %s' % btype[1]) |
| 149 | cfgfile.write('\n') |
| 150 | |
| 151 | if initrd: |
| 152 | cfgfile.write('initrd /initrd') |
| 153 | cfgfile.write('\n}\n') |
| 154 | |
| 155 | cfgfile.close() |
| 156 | } |