Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | # maintenance. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | # |
| 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 | |
| 12 | do_bootimg[depends] += "${MLPREFIX}systemd-boot:do_deploy" |
| 13 | do_bootdirectdisk[depends] += "${MLPREFIX}systemd-boot:do_deploy" |
| 14 | |
| 15 | EFIDIR = "/EFI/BOOT" |
| 16 | |
| 17 | SYSTEMD_BOOT_CFG ?= "${S}/loader.conf" |
| 18 | SYSTEMD_BOOT_ENTRIES ?= "" |
| 19 | SYSTEMD_BOOT_TIMEOUT ?= "10" |
| 20 | |
| 21 | # Need UUID utility code. |
| 22 | inherit fs-uuid |
| 23 | |
| 24 | efi_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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 41 | printf 'fs0:%s\%s\n' "$EFIPATH" "$DEST_EFI_IMAGE" >${DEST}/startup.nsh |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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 | |
| 48 | efi_iso_populate() { |
| 49 | iso_dir=$1 |
| 50 | efi_populate $iso_dir |
| 51 | mkdir -p ${EFIIMGDIR}/${EFIDIR} |
| 52 | cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | cp -r $iso_dir/loader ${EFIIMGDIR} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | 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 | |
| 62 | efi_hddimg_populate() { |
| 63 | efi_populate $1 |
| 64 | } |
| 65 | |
| 66 | python build_efi_cfg() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | s = d.getVar("S") |
| 68 | labels = d.getVar('LABELS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 77 | cfile = d.getVar('SYSTEMD_BOOT_CFG') |
| 78 | cdir = os.path.dirname(cfile) |
| 79 | if not os.path.exists(cdir): |
| 80 | os.makedirs(cdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 81 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 89 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | overrides = localdata.getVar('OVERRIDES') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 99 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 109 | |
| 110 | entrycfg.write('title %s\n' % label) |
| 111 | entrycfg.write('linux /vmlinuz\n') |
| 112 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | append = localdata.getVar('APPEND') |
| 114 | initrd = localdata.getVar('INITRD') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 115 | |
| 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 | } |