blob: 366dd237388370d4dee887615abb2a2122c5f646 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7SYSTEMD_BOOT_CFG ?= "${S}/loader.conf"
8SYSTEMD_BOOT_ENTRIES ?= ""
9SYSTEMD_BOOT_TIMEOUT ?= "10"
10
11# Uses MACHINE specific KERNEL_IMAGETYPE
12PACKAGE_ARCH = "${MACHINE_ARCH}"
13
14# Need UUID utility code.
15inherit fs-uuid
16
17python build_efi_cfg() {
18 s = d.getVar("S")
19 labels = d.getVar('LABELS')
20 if not labels:
21 bb.debug(1, "LABELS not defined, nothing to do")
22 return
23
24 if labels == []:
25 bb.debug(1, "No labels, nothing to do")
26 return
27
28 cfile = d.getVar('SYSTEMD_BOOT_CFG')
29 cdir = os.path.dirname(cfile)
30 if not os.path.exists(cdir):
31 os.makedirs(cdir)
32 try:
33 cfgfile = open(cfile, 'w')
34 except OSError:
35 bb.fatal('Unable to open %s' % cfile)
36
37 cfgfile.write('# Automatically created by OE\n')
38 cfgfile.write('default %s\n' % (labels.split()[0]))
39 timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT')
40 if timeout:
41 cfgfile.write('timeout %s\n' % timeout)
42 else:
43 cfgfile.write('timeout 10\n')
44 cfgfile.close()
45
46 for label in labels.split():
47 localdata = d.createCopy()
48
49 entryfile = "%s/%s.conf" % (s, label)
50 if not os.path.exists(s):
51 os.makedirs(s)
52 d.appendVar("SYSTEMD_BOOT_ENTRIES", " " + entryfile)
53 try:
54 entrycfg = open(entryfile, "w")
55 except OSError:
56 bb.fatal('Unable to open %s' % entryfile)
57
58 entrycfg.write('title %s\n' % label)
59
60 kernel = localdata.getVar("KERNEL_IMAGETYPE")
61 entrycfg.write('linux /%s\n' % kernel)
62
63 append = localdata.getVar('APPEND')
64 initrd = localdata.getVar('INITRD')
65
66 if initrd:
67 entrycfg.write('initrd /initrd\n')
68 lb = label
69 if label == "install":
70 lb = "install-efi"
71 entrycfg.write('options LABEL=%s ' % lb)
72 if append:
73 append = replace_rootfs_uuid(d, append)
74 entrycfg.write('%s' % append)
75 entrycfg.write('\n')
76 entrycfg.close()
77}