Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [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 | # ${GRUB_ROOT} - grub's root device. |
| 18 | |
| 19 | GRUB_SERIAL ?= "console=ttyS0,115200" |
| 20 | GRUB_CFG_VM = "${S}/grub_vm.cfg" |
| 21 | GRUB_CFG_LIVE = "${S}/grub_live.cfg" |
| 22 | GRUB_TIMEOUT ?= "10" |
| 23 | #FIXME: build this from the machine config |
| 24 | GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1" |
| 25 | |
| 26 | EFIDIR = "/EFI/BOOT" |
| 27 | GRUB_ROOT ?= "${ROOT}" |
| 28 | APPEND ?= "" |
| 29 | |
| 30 | # Need UUID utility code. |
| 31 | inherit fs-uuid |
| 32 | |
| 33 | python build_efi_cfg() { |
| 34 | import sys |
| 35 | |
| 36 | workdir = d.getVar('WORKDIR') |
| 37 | if not workdir: |
| 38 | bb.error("WORKDIR not defined, unable to package") |
| 39 | return |
| 40 | |
| 41 | gfxserial = d.getVar('GRUB_GFXSERIAL') or "" |
| 42 | |
| 43 | labels = d.getVar('LABELS') |
| 44 | if not labels: |
| 45 | bb.debug(1, "LABELS not defined, nothing to do") |
| 46 | return |
| 47 | |
| 48 | if labels == []: |
| 49 | bb.debug(1, "No labels, nothing to do") |
| 50 | return |
| 51 | |
| 52 | cfile = d.getVar('GRUB_CFG') |
| 53 | if not cfile: |
| 54 | bb.fatal('Unable to read GRUB_CFG') |
| 55 | |
| 56 | try: |
| 57 | cfgfile = open(cfile, 'w') |
| 58 | except OSError: |
| 59 | bb.fatal('Unable to open %s' % cfile) |
| 60 | |
| 61 | cfgfile.write('# Automatically created by OE\n') |
| 62 | |
| 63 | opts = d.getVar('GRUB_OPTS') |
| 64 | if opts: |
| 65 | for opt in opts.split(';'): |
| 66 | cfgfile.write('%s\n' % opt) |
| 67 | |
| 68 | cfgfile.write('default=%s\n' % (labels.split()[0])) |
| 69 | |
| 70 | timeout = d.getVar('GRUB_TIMEOUT') |
| 71 | if timeout: |
| 72 | cfgfile.write('timeout=%s\n' % timeout) |
| 73 | else: |
| 74 | cfgfile.write('timeout=50\n') |
| 75 | |
| 76 | root = d.getVar('GRUB_ROOT') |
| 77 | if not root: |
| 78 | bb.fatal('GRUB_ROOT not defined') |
| 79 | |
| 80 | if gfxserial == "1": |
| 81 | btypes = [ [ " graphics console", "" ], |
| 82 | [ " serial console", d.getVar('GRUB_SERIAL') or "" ] ] |
| 83 | else: |
| 84 | btypes = [ [ "", "" ] ] |
| 85 | |
| 86 | for label in labels.split(): |
| 87 | localdata = d.createCopy() |
| 88 | |
| 89 | for btype in btypes: |
| 90 | cfgfile.write('\nmenuentry \'%s%s\'{\n' % (label, btype[0])) |
| 91 | lb = label |
| 92 | if label == "install": |
| 93 | lb = "install-efi" |
| 94 | kernel = localdata.getVar('KERNEL_IMAGETYPE') |
| 95 | cfgfile.write('linux /%s LABEL=%s' % (kernel, lb)) |
| 96 | |
| 97 | cfgfile.write(' %s' % replace_rootfs_uuid(d, root)) |
| 98 | |
| 99 | append = localdata.getVar('APPEND') |
| 100 | initrd = localdata.getVar('INITRD') |
| 101 | |
| 102 | if append: |
| 103 | append = replace_rootfs_uuid(d, append) |
| 104 | cfgfile.write(' %s' % (append)) |
| 105 | |
| 106 | cfgfile.write(' %s' % btype[1]) |
| 107 | cfgfile.write('\n') |
| 108 | |
| 109 | if initrd: |
| 110 | cfgfile.write('initrd /initrd') |
| 111 | cfgfile.write('\n}\n') |
| 112 | |
| 113 | cfgfile.close() |
| 114 | } |