summaryrefslogtreecommitdiffstats
path: root/meta/classes/systemd-boot.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/systemd-boot.bbclass')
-rw-r--r--meta/classes/systemd-boot.bbclass124
1 files changed, 124 insertions, 0 deletions
diff --git a/meta/classes/systemd-boot.bbclass b/meta/classes/systemd-boot.bbclass
new file mode 100644
index 0000000000..9e9398a2a5
--- /dev/null
+++ b/meta/classes/systemd-boot.bbclass
@@ -0,0 +1,124 @@
1# Copyright (C) 2016 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5# systemd-boot.bbclass - The "systemd-boot" is essentially the gummiboot merged into systemd.
6# The original standalone gummiboot project is dead without any more
7# maintenance. As a start point, we replace all gummitboot occurrences
8# with systemd-boot in gummiboot.bbclass to have a base version of this
9# systemd-boot.bbclass.
10#
11# Set EFI_PROVIDER = "systemd-boot" to use systemd-boot on your live images instead of grub-efi
12# (images built by image-live.bbclass or image-vm.bbclass)
13
14do_bootimg[depends] += "${MLPREFIX}systemd-boot:do_deploy"
15do_bootdirectdisk[depends] += "${MLPREFIX}systemd-boot:do_deploy"
16
17EFIDIR = "/EFI/BOOT"
18
19SYSTEMD_BOOT_CFG ?= "${S}/loader.conf"
20SYSTEMD_BOOT_ENTRIES ?= ""
21SYSTEMD_BOOT_TIMEOUT ?= "10"
22
23# Need UUID utility code.
24inherit fs-uuid
25
26efi_populate() {
27 DEST=$1
28
29 EFI_IMAGE="systemd-bootia32.efi"
30 DEST_EFI_IMAGE="bootia32.efi"
31 if [ "${TARGET_ARCH}" = "x86_64" ]; then
32 EFI_IMAGE="systemd-bootx64.efi"
33 DEST_EFI_IMAGE="bootx64.efi"
34 fi
35
36 install -d ${DEST}${EFIDIR}
37 # systemd-boot requires these paths for configuration files
38 # they are not customizable so no point in new vars
39 install -d ${DEST}/loader
40 install -d ${DEST}/loader/entries
41 install -m 0644 ${DEPLOY_DIR_IMAGE}/${EFI_IMAGE} ${DEST}${EFIDIR}/${DEST_EFI_IMAGE}
42 install -m 0644 ${SYSTEMD_BOOT_CFG} ${DEST}/loader/loader.conf
43 for i in ${SYSTEMD_BOOT_ENTRIES}; do
44 install -m 0644 ${i} ${DEST}/loader/entries
45 done
46}
47
48efi_iso_populate() {
49 iso_dir=$1
50 efi_populate $iso_dir
51 mkdir -p ${EFIIMGDIR}/${EFIDIR}
52 cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
53 cp $iso_dir/vmlinuz ${EFIIMGDIR}
54 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
55 echo "fs0:${EFIPATH}\\${DEST_EFI_IMAGE}" > ${EFIIMGDIR}/startup.nsh
56 if [ -f "$iso_dir/initrd" ] ; then
57 cp $iso_dir/initrd ${EFIIMGDIR}
58 fi
59}
60
61efi_hddimg_populate() {
62 efi_populate $1
63}
64
65python build_efi_cfg() {
66 s = d.getVar("S", True)
67 labels = d.getVar('LABELS', True)
68 if not labels:
69 bb.debug(1, "LABELS not defined, nothing to do")
70 return
71
72 if labels == []:
73 bb.debug(1, "No labels, nothing to do")
74 return
75
76 cfile = d.getVar('SYSTEMD_BOOT_CFG', True)
77 try:
78 cfgfile = open(cfile, 'w')
79 except OSError:
80 raise bb.build.funcFailed('Unable to open %s' % (cfile))
81
82 cfgfile.write('# Automatically created by OE\n')
83 cfgfile.write('default %s\n' % (labels.split()[0]))
84 timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT', True)
85 if timeout:
86 cfgfile.write('timeout %s\n' % timeout)
87 else:
88 cfgfile.write('timeout 10\n')
89 cfgfile.close()
90
91 for label in labels.split():
92 localdata = d.createCopy()
93
94 overrides = localdata.getVar('OVERRIDES', True)
95 if not overrides:
96 raise bb.build.FuncFailed('OVERRIDES not defined')
97
98 entryfile = "%s/%s.conf" % (s, label)
99 d.appendVar("SYSTEMD_BOOT_ENTRIES", " " + entryfile)
100 try:
101 entrycfg = open(entryfile, "w")
102 except OSError:
103 raise bb.build.funcFailed('Unable to open %s' % (entryfile))
104 localdata.setVar('OVERRIDES', label + ':' + overrides)
105 bb.data.update_data(localdata)
106
107 entrycfg.write('title %s\n' % label)
108 entrycfg.write('linux /vmlinuz\n')
109
110 append = localdata.getVar('APPEND', True)
111 initrd = localdata.getVar('INITRD', True)
112
113 if initrd:
114 entrycfg.write('initrd /initrd\n')
115 lb = label
116 if label == "install":
117 lb = "install-efi"
118 entrycfg.write('options LABEL=%s ' % lb)
119 if append:
120 append = replace_rootfs_uuid(d, append)
121 entrycfg.write('%s' % append)
122 entrycfg.write('\n')
123 entrycfg.close()
124}