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