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