blob: 937307076f7c94b7cc2d4495fdff28a724e991db [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007# maintenance.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008#
9# Set EFI_PROVIDER = "systemd-boot" to use systemd-boot on your live images instead of grub-efi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010# (images built by image-live.bbclass)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011
12do_bootimg[depends] += "${MLPREFIX}systemd-boot:do_deploy"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060013
14EFIDIR = "/EFI/BOOT"
15
16SYSTEMD_BOOT_CFG ?= "${S}/loader.conf"
17SYSTEMD_BOOT_ENTRIES ?= ""
18SYSTEMD_BOOT_TIMEOUT ?= "10"
19
20# Need UUID utility code.
21inherit fs-uuid
22
23efi_populate() {
24 DEST=$1
25
26 EFI_IMAGE="systemd-bootia32.efi"
27 DEST_EFI_IMAGE="bootia32.efi"
28 if [ "${TARGET_ARCH}" = "x86_64" ]; then
29 EFI_IMAGE="systemd-bootx64.efi"
30 DEST_EFI_IMAGE="bootx64.efi"
31 fi
32
33 install -d ${DEST}${EFIDIR}
34 # systemd-boot requires these paths for configuration files
35 # they are not customizable so no point in new vars
36 install -d ${DEST}/loader
37 install -d ${DEST}/loader/entries
38 install -m 0644 ${DEPLOY_DIR_IMAGE}/${EFI_IMAGE} ${DEST}${EFIDIR}/${DEST_EFI_IMAGE}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
40 printf 'fs0:%s\%s\n' "$EFIPATH" "$DEST_EFI_IMAGE" >${DEST}/startup.nsh
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041 install -m 0644 ${SYSTEMD_BOOT_CFG} ${DEST}/loader/loader.conf
42 for i in ${SYSTEMD_BOOT_ENTRIES}; do
43 install -m 0644 ${i} ${DEST}/loader/entries
44 done
45}
46
47efi_iso_populate() {
48 iso_dir=$1
49 efi_populate $iso_dir
50 mkdir -p ${EFIIMGDIR}/${EFIDIR}
51 cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 cp -r $iso_dir/loader ${EFIIMGDIR}
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 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() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 s = d.getVar("S")
67 labels = d.getVar('LABELS')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050076 cfile = d.getVar('SYSTEMD_BOOT_CFG')
77 cdir = os.path.dirname(cfile)
78 if not os.path.exists(cdir):
79 os.makedirs(cdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060080 try:
81 cfgfile = open(cfile, 'w')
82 except OSError:
83 bb.fatal('Unable to open %s' % cfile)
84
85 cfgfile.write('# Automatically created by OE\n')
86 cfgfile.write('default %s\n' % (labels.split()[0]))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060088 if timeout:
89 cfgfile.write('timeout %s\n' % timeout)
90 else:
91 cfgfile.write('timeout 10\n')
92 cfgfile.close()
93
94 for label in labels.split():
95 localdata = d.createCopy()
96
Brad Bishop6e60e8b2018-02-01 10:27:11 -050097 overrides = localdata.getVar('OVERRIDES')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060098 if not overrides:
99 bb.fatal('OVERRIDES not defined')
100
101 entryfile = "%s/%s.conf" % (s, label)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500102 if not os.path.exists(s):
103 os.makedirs(s)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600104 d.appendVar("SYSTEMD_BOOT_ENTRIES", " " + entryfile)
105 try:
106 entrycfg = open(entryfile, "w")
107 except OSError:
108 bb.fatal('Unable to open %s' % entryfile)
109 localdata.setVar('OVERRIDES', label + ':' + overrides)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600110
111 entrycfg.write('title %s\n' % label)
112 entrycfg.write('linux /vmlinuz\n')
113
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114 append = localdata.getVar('APPEND')
115 initrd = localdata.getVar('INITRD')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600116
117 if initrd:
118 entrycfg.write('initrd /initrd\n')
119 lb = label
120 if label == "install":
121 lb = "install-efi"
122 entrycfg.write('options LABEL=%s ' % lb)
123 if append:
124 append = replace_rootfs_uuid(d, append)
125 entrycfg.write('%s' % append)
126 entrycfg.write('\n')
127 entrycfg.close()
128}