summaryrefslogtreecommitdiffstats
path: root/meta/classes/grub-efi.bbclass
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2011-11-23 17:56:12 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-11-30 22:18:08 +0000
commiteb4aa3483b1129a7137983ed54596030a5ccba2b (patch)
tree92a8309a4b4c5d51bdd9efe0da502b62ae913f23 /meta/classes/grub-efi.bbclass
parentbcbd57aae576fa262c83f435bccf3bc3184e5506 (diff)
downloadpoky-eb4aa3483b1129a7137983ed54596030a5ccba2b.tar.gz
bootimg: Add grub-efi support
Create a new grub-efi.bbclass and integrate it into bootimg alongside the syslinux support. This new class uses the output from the grub-efi-native recipe. Thanks goes to Josef Ahmad <josef.ahmad@intel.com> for the original build_grub_cfg() routine. The EFI features are only added to the image if MACHINE_FEATURES contains "efi". The resulting images are therefor either legacy boot only (like they were originally) or legacy boot and EFI boot. A new "dummy.bbclass" was added to allow for the conditional include of grub-efi. This makes it so if efi support is not to be built in, we don't spend time building grub-efi-native just because the include adds the dependency. There is a bug in the mkdosfs tool from the dosfstools package which causes it to crash when the directory passed with the -d parameter contains sub-directories. An /EFI/BOOT directory is required for a proper EFI installation. Until it is fixed, we install to the top level directory for the hddimg. (From OE-Core rev: be95f54495bf9e03062f86b929c66cab6e385a03) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Josef Ahmad <josef.ahmad@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/grub-efi.bbclass')
-rw-r--r--meta/classes/grub-efi.bbclass140
1 files changed, 140 insertions, 0 deletions
diff --git a/meta/classes/grub-efi.bbclass b/meta/classes/grub-efi.bbclass
new file mode 100644
index 0000000000..333e6c53c7
--- /dev/null
+++ b/meta/classes/grub-efi.bbclass
@@ -0,0 +1,140 @@
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 filesystem image to use as an initrd (optional)
11# ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
12# ${LABELS} - a list of targets for the automatic config
13# ${APPEND} - an override list of append strings for each label
14# ${GRUB_OPTS} - additional options to add to the config, ';' delimited # (optional)
15# ${GRUB_TIMEOUT} - timeout before executing the deault label (optional)
16
17do_bootimg[depends] += "grub-efi-${TARGET_ARCH}-native:do_deploy"
18
19GRUBCFG = "grub.cfg"
20GRUB_TIMEOUT ?= "10"
21#FIXME: build this from the machine config
22GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
23
24# FIXME: add EFI/BOOT to GRUB_HDDDIR once the mkdosfs subdir bug is resolved
25# http://bugzilla.yoctoproject.org/show_bug.cgi?id=1783
26EFIDIR = "/EFI/BOOT"
27GRUB_HDDDIR = "${HDDDIR}"
28GRUB_ISODIR = "${ISODIR}${EFIDIR}"
29
30grubefi_populate() {
31 DEST=$1
32
33 install -d ${DEST}
34
35 install -m 0644 ${STAGING_DIR_HOST}/kernel/bzImage ${DEST}/vmlinuz
36
37 if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then
38 install -m 0644 ${INITRD} ${DEST}/initrd
39 fi
40
41 if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
42 install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
43 fi
44
45 GRUB_IMAGE="bootia32.efi"
46 if [ "${TARGET_ARCH}" = "x86_64" ]; then
47 GRUB_IMAGE="bootx64.efi"
48 fi
49 install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST}
50
51 install -m 0644 ${GRUBCFG} ${DEST}
52}
53
54grubefi_iso_populate() {
55 grubefi_populate ${GRUB_ISODIR}
56
57 # FIXUP the <EFIDIR> token in the config
58 # FIXME: This can be dropped once mkdosfs is fixed
59 sed -i "s@<EFIDIR>@${EFIDIR}@g" ${GRUB_ISODIR}/${GRUBCFG}
60}
61
62grubefi_hddimg_populate() {
63 grubefi_populate ${GRUB_HDDDIR}
64
65 # FIXUP the <EFIDIR> token in the config
66 # FIXME: This can be dropped once mkdosfs is fixed
67 sed -i "s@<EFIDIR>@@g" ${GRUB_HDDDIR}/${GRUBCFG}
68}
69
70# FIXME: The <EFIDIR> token can be replaced with ${EFIDIR} once the
71# mkdosfs bug is resolved.
72python build_grub_cfg() {
73 import sys
74
75 workdir = d.getVar('WORKDIR', True)
76 if not workdir:
77 bb.error("WORKDIR not defined, unable to package")
78 return
79
80 labels = d.getVar('LABELS', True)
81 if not labels:
82 bb.debug(1, "LABELS not defined, nothing to do")
83 return
84
85 if labels == []:
86 bb.debug(1, "No labels, nothing to do")
87 return
88
89 cfile = d.getVar('GRUBCFG', True)
90 if not cfile:
91 raise bb.build.FuncFailed('Unable to read GRUBCFG')
92
93 #bb.mkdirhier(os.path.dirname(cfile))
94
95 try:
96 cfgfile = file(cfile, 'w')
97 except OSError:
98 raise bb.build.funcFailed('Unable to open %s' % (cfile))
99
100 cfgfile.write('# Automatically created by OE\n')
101
102 opts = d.getVar('GRUB_OPTS', True)
103 if opts:
104 for opt in opts.split(';'):
105 cfgfile.write('%s\n' % opt)
106
107 cfgfile.write('default=%s\n' % (labels.split()[0]))
108
109 timeout = d.getVar('GRUB_TIMEOUT', True)
110 if timeout:
111 cfgfile.write('timeout=%s\n' % timeout)
112 else:
113 cfgfile.write('timeout=50\n')
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 localdata.setVar('OVERRIDES', label + ':' + overrides)
123 bb.data.update_data(localdata)
124
125 cfgfile.write('\nmenuentry \'%s\'{\n' % (label))
126 cfgfile.write('linux <EFIDIR>/vmlinuz LABEL=%s' % (label))
127
128 append = localdata.getVar('APPEND', True)
129 initrd = localdata.getVar('INITRD', True)
130
131 if append:
132 cfgfile.write('%s' % (append))
133 cfgfile.write('\n')
134
135 if initrd:
136 cfgfile.write('initrd <EFIDIR>/initrd')
137 cfgfile.write('\n}\n')
138
139 cfgfile.close()
140}