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