blob: 9597759927d11dc09257851843ce6fe3b21c56b5 [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
10# (images built by image-live.bbclass or image-vm.bbclass)
11
12do_bootimg[depends] += "${MLPREFIX}systemd-boot:do_deploy"
13do_bootdirectdisk[depends] += "${MLPREFIX}systemd-boot:do_deploy"
14
15EFIDIR = "/EFI/BOOT"
16
17SYSTEMD_BOOT_CFG ?= "${S}/loader.conf"
18SYSTEMD_BOOT_ENTRIES ?= ""
19SYSTEMD_BOOT_TIMEOUT ?= "10"
20
21# Need UUID utility code.
22inherit fs-uuid
23
24efi_populate() {
25 DEST=$1
26
27 EFI_IMAGE="systemd-bootia32.efi"
28 DEST_EFI_IMAGE="bootia32.efi"
29 if [ "${TARGET_ARCH}" = "x86_64" ]; then
30 EFI_IMAGE="systemd-bootx64.efi"
31 DEST_EFI_IMAGE="bootx64.efi"
32 fi
33
34 install -d ${DEST}${EFIDIR}
35 # systemd-boot requires these paths for configuration files
36 # they are not customizable so no point in new vars
37 install -d ${DEST}/loader
38 install -d ${DEST}/loader/entries
39 install -m 0644 ${DEPLOY_DIR_IMAGE}/${EFI_IMAGE} ${DEST}${EFIDIR}/${DEST_EFI_IMAGE}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
41 printf 'fs0:%s\%s\n' "$EFIPATH" "$DEST_EFI_IMAGE" >${DEST}/startup.nsh
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042 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}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053 cp -r $iso_dir/loader ${EFIIMGDIR}
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054 cp $iso_dir/vmlinuz ${EFIIMGDIR}
55 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
56 echo "fs0:${EFIPATH}\\${DEST_EFI_IMAGE}" > ${EFIIMGDIR}/startup.nsh
57 if [ -f "$iso_dir/initrd" ] ; then
58 cp $iso_dir/initrd ${EFIIMGDIR}
59 fi
60}
61
62efi_hddimg_populate() {
63 efi_populate $1
64}
65
66python build_efi_cfg() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050067 s = d.getVar("S")
68 labels = d.getVar('LABELS')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069 if not labels:
70 bb.debug(1, "LABELS not defined, nothing to do")
71 return
72
73 if labels == []:
74 bb.debug(1, "No labels, nothing to do")
75 return
76
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077 cfile = d.getVar('SYSTEMD_BOOT_CFG')
78 cdir = os.path.dirname(cfile)
79 if not os.path.exists(cdir):
80 os.makedirs(cdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060081 try:
82 cfgfile = open(cfile, 'w')
83 except OSError:
84 bb.fatal('Unable to open %s' % cfile)
85
86 cfgfile.write('# Automatically created by OE\n')
87 cfgfile.write('default %s\n' % (labels.split()[0]))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050088 timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060089 if timeout:
90 cfgfile.write('timeout %s\n' % timeout)
91 else:
92 cfgfile.write('timeout 10\n')
93 cfgfile.close()
94
95 for label in labels.split():
96 localdata = d.createCopy()
97
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 overrides = localdata.getVar('OVERRIDES')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099 if not overrides:
100 bb.fatal('OVERRIDES not defined')
101
102 entryfile = "%s/%s.conf" % (s, label)
103 d.appendVar("SYSTEMD_BOOT_ENTRIES", " " + entryfile)
104 try:
105 entrycfg = open(entryfile, "w")
106 except OSError:
107 bb.fatal('Unable to open %s' % entryfile)
108 localdata.setVar('OVERRIDES', label + ':' + overrides)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600109
110 entrycfg.write('title %s\n' % label)
111 entrycfg.write('linux /vmlinuz\n')
112
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 append = localdata.getVar('APPEND')
114 initrd = localdata.getVar('INITRD')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600115
116 if initrd:
117 entrycfg.write('initrd /initrd\n')
118 lb = label
119 if label == "install":
120 lb = "install-efi"
121 entrycfg.write('options LABEL=%s ' % lb)
122 if append:
123 append = replace_rootfs_uuid(d, append)
124 entrycfg.write('%s' % append)
125 entrycfg.write('\n')
126 entrycfg.close()
127}