summaryrefslogtreecommitdiffstats
path: root/meta/classes/grub-efi.bbclass
diff options
context:
space:
mode:
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..96fb98b043
--- /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# ${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] += "grub-efi-${TRANSLATED_TARGET_ARCH}-native:do_deploy"
19
20GRUB_SERIAL ?= "console=ttyS0,115200"
21GRUBCFG = "${S}/grub.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"
27
28grubefi_populate() {
29 # DEST must be the root of the image so that EFIDIR is not
30 # nested under a top level directory.
31 DEST=$1
32
33 install -d ${DEST}${EFIDIR}
34
35 GRUB_IMAGE="bootia32.efi"
36 if [ "${TARGET_ARCH}" = "x86_64" ]; then
37 GRUB_IMAGE="bootx64.efi"
38 fi
39 install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST}${EFIDIR}
40
41 install -m 0644 ${GRUBCFG} ${DEST}${EFIDIR}
42}
43
44grubefi_iso_populate() {
45 iso_dir=$1
46 grubefi_populate $iso_dir
47 # Build a EFI directory to create efi.img
48 mkdir -p ${EFIIMGDIR}/${EFIDIR}
49 cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
50 cp $iso_dir/vmlinuz ${EFIIMGDIR}
51 echo "EFI\\BOOT\\${GRUB_IMAGE}" > ${EFIIMGDIR}/startup.nsh
52 if [ -f "$iso_dir/initrd" ] ; then
53 cp $iso_dir/initrd ${EFIIMGDIR}
54 fi
55}
56
57grubefi_hddimg_populate() {
58 grubefi_populate $1
59}
60
61python build_grub_cfg() {
62 import sys
63
64 workdir = d.getVar('WORKDIR', True)
65 if not workdir:
66 bb.error("WORKDIR not defined, unable to package")
67 return
68
69 gfxserial = d.getVar('GRUB_GFXSERIAL', True) or ""
70
71 labels = d.getVar('LABELS', True)
72 if not labels:
73 bb.debug(1, "LABELS not defined, nothing to do")
74 return
75
76 if labels == []:
77 bb.debug(1, "No labels, nothing to do")
78 return
79
80 cfile = d.getVar('GRUBCFG', True)
81 if not cfile:
82 raise bb.build.FuncFailed('Unable to read GRUBCFG')
83
84 try:
85 cfgfile = file(cfile, 'w')
86 except OSError:
87 raise bb.build.funcFailed('Unable to open %s' % (cfile))
88
89 cfgfile.write('# Automatically created by OE\n')
90
91 opts = d.getVar('GRUB_OPTS', True)
92 if opts:
93 for opt in opts.split(';'):
94 cfgfile.write('%s\n' % opt)
95
96 cfgfile.write('default=%s\n' % (labels.split()[0]))
97
98 timeout = d.getVar('GRUB_TIMEOUT', True)
99 if timeout:
100 cfgfile.write('timeout=%s\n' % timeout)
101 else:
102 cfgfile.write('timeout=50\n')
103
104 if gfxserial == "1":
105 btypes = [ [ " graphics console", "" ],
106 [ " serial console", d.getVar('GRUB_SERIAL', True) or "" ] ]
107 else:
108 btypes = [ [ "", "" ] ]
109
110 for label in labels.split():
111 localdata = d.createCopy()
112
113 overrides = localdata.getVar('OVERRIDES', True)
114 if not overrides:
115 raise bb.build.FuncFailed('OVERRIDES not defined')
116
117 for btype in btypes:
118 localdata.setVar('OVERRIDES', label + ':' + overrides)
119 bb.data.update_data(localdata)
120
121 cfgfile.write('\nmenuentry \'%s%s\'{\n' % (label, btype[0]))
122 lb = label
123 if label == "install":
124 lb = "install-efi"
125 cfgfile.write('linux /vmlinuz LABEL=%s' % (lb))
126
127 append = localdata.getVar('APPEND', True)
128 initrd = localdata.getVar('INITRD', True)
129
130 if append:
131 cfgfile.write('%s' % (append))
132 cfgfile.write(' %s' % btype[1])
133 cfgfile.write('\n')
134
135 if initrd:
136 cfgfile.write('initrd /initrd')
137 cfgfile.write('\n}\n')
138
139 cfgfile.close()
140}