blob: ea21b3de3d8c324fe6eca59e93a8bffc3ba072b2 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001# 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
19GRUB_SERIAL ?= "console=ttyS0,115200"
20GRUB_CFG_VM = "${S}/grub_vm.cfg"
21GRUB_CFG_LIVE = "${S}/grub_live.cfg"
22GRUB_TIMEOUT ?= "10"
23#FIXME: build this from the machine config
24GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
25
Brad Bishop316dfdd2018-06-25 12:45:53 -040026GRUB_ROOT ?= "${ROOT}"
27APPEND ?= ""
28
Brad Bishop393846f2019-05-20 12:24:11 -040029# Uses MACHINE specific KERNEL_IMAGETYPE
30PACKAGE_ARCH = "${MACHINE_ARCH}"
31
Brad Bishop316dfdd2018-06-25 12:45:53 -040032# Need UUID utility code.
33inherit fs-uuid
34
35python 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
Andrew Geissler82c905d2020-04-13 13:39:40 -050091 overrides = localdata.getVar('OVERRIDES')
92 if not overrides:
93 bb.fatal('OVERRIDES not defined')
94
95 localdata.setVar('OVERRIDES', 'grub_' + label + ':' + overrides)
96
Brad Bishop316dfdd2018-06-25 12:45:53 -040097 for btype in btypes:
98 cfgfile.write('\nmenuentry \'%s%s\'{\n' % (label, btype[0]))
99 lb = label
100 if label == "install":
101 lb = "install-efi"
102 kernel = localdata.getVar('KERNEL_IMAGETYPE')
103 cfgfile.write('linux /%s LABEL=%s' % (kernel, lb))
104
105 cfgfile.write(' %s' % replace_rootfs_uuid(d, root))
106
107 append = localdata.getVar('APPEND')
108 initrd = localdata.getVar('INITRD')
109
110 if append:
111 append = replace_rootfs_uuid(d, append)
112 cfgfile.write(' %s' % (append))
113
114 cfgfile.write(' %s' % btype[1])
115 cfgfile.write('\n')
116
117 if initrd:
118 cfgfile.write('initrd /initrd')
119 cfgfile.write('\n}\n')
120
121 cfgfile.close()
122}
Andrew Geisslerc723b722021-01-08 16:14:09 -0600123build_efi_cfg[vardepsexclude] += "OVERRIDES"